Whitelist functionality?

I have two DIDs and I have the blacklist function working on the first DID, where I want to accept all calls except those I have explicitly blacklisted. On the second DID I want to be able to accept calls based on a whitelist. Does anyone have any config examples?

I figured out one way myself, posting it here for future reference.

Within the context of the DID, I have a lookup against the database for a whitelist variable:

exten => s,n,GotoIf(${DB_EXISTS(whitelist/${CALLERID(num)})}?time,s,1)
exten => s,n,Playback(custom/not-auth)

If there’s an entry, it jumps to the [time] context to determine if the hours are acceptable. If not I play a custom recording saying that the phone number is not authorized to call.

To add a number to the database, you simply do a ‘database put whitelist 1xxxyyyzzzz 1’.