Attached is the latest version of my privacy manager dialplan.
Changes include...
Now handles whitelist in addition to blacklist. If "whitelistcomment" field
exists in the AstDB then this is used for CALLERID(name).
To bypass privacy manager, authentication password is now taken from
whitelist, so you can have multiple users able to bypass leaving an
introductory message. Just enter a four digit PIN as the whitelist'ed
number.
Warning message is loged to syslog for unhandled blacklist/whitelist/soft
error conditions.
Will handle multiple simultaneous inbound calls (temp file derived from
channel uniqueid)
As a reminder, requires EXTRA_SOUNDS_EN.
Also, whitelist and blacklist actions are sensitive to the order in which
the actions appear in the action list in the Astlinux web interface. Do Not
change the default order. You can add to the end of the list (for example,
you can add "Privacy Mgr" to the end of the blacklist action list in the
Prefs page, but not to the front). This is an unfortunate side effect of
current Astlinux web interface design.
Have fun.
David
On Tue, Aug 18, 2009 at 2:29 PM, David Kerr <[email protected]> wrote:
> Attached is the latest version of my blacklist and anonymous caller
> handling in my dialplan which I thought might be useful to others.
> This implements Privacy Manager to let an anonymous caller leave an
> introductory message for callee to listen to and decide whether to accept
> the call or not.
>
> Also handles blacklisted callers with all the default actions available
> through the AstLinux web interface... No Answer, Zapateller, Voicemail.
> Requires Asterisk EXTRA_SOUNDS_EN -- either manually added to your
> astlinux system, or custom compiled into your Astlinux build (you must use
> GSM versions of both extra and core sounds for them to fit in a custom
> build).
>
> Tested on astlinux trunk (pre 0.7). For explanation of the code,
> see embedded comments.
>
> David.
>
>
[globals]
; Append to your [globals] section in extensions.conf
; These are examples only, change to suit your specific purposes.
PRIVACY_MGR_VOICEMAIL = voicemenu-custom-3
PRIVACY_MGR_EXTEN = local/6...@ringgroups
PRIVACY_MGR_IVR = voicemenu-custom-2
[default]
; your inbound context
exten = _X.,1,Gosub(check-private,s,1)
exten = _X.,n,Goto(where-ever-you-normally-go,s,1)
exten = s,1,Gosub(check-private,s,1)
exten = s,n,Goto(where-ever-you-normally-go,s,1)
[check-private]
; Subroutine to check callerID number against whitelist, blacklist, anonymous
callers
; and to implement Privacy Manager.
; Constants must be set in [globals] section of this file...
; PRIVACY_MGR_VOICEMAIL = context to handle voicemail, will branch to s,1
; PRIVACY_MGR_IVR = context to handle IVR, will branch to s,1
; PRIVACY_MGR_EXTEN = internal extension to ring, eg. local/6...@ringgroups
; If caller presses 0 (zero) during prompt to leave name, then they can enter
PIN to bypass
; leaving an introduction message. PINs are retrieved from the Asterisk DB
Whitelist.
exten = s,1,NoOp(PrivacyManager - ${CALLERID(name)} ${CALLERID(num)}
${CALLERID(ani)})
exten = s,n,Ringing()
; First lookup number in asterisk DB for a Caller ID name.
exten =
s,n,Set(CALLERID(name)=${IF(${DB_EXISTS(cidname/${CALLERID(num)})}?${DB_RESULT}:${CALLERID(name)})})
; Now check against whitelist.
exten = s,n,GotoIf(${DB_EXISTS(whitelist/${CALLERID(num)})}?onwhitelist)
; Not on whitelist, check it against blacklist
exten = s,n,GotoIf(${DB_EXISTS(blacklist/${CALLERID(num)})}?onblacklist)
; Not on blacklist either, check Caller ID number for anonymous conditions...
; If all zeros (with or without international dialing + sign) then caller is
anonymous.
exten = s,n,GotoIf($[${REGEX("^[+]?0+$" ${CALLERID(num)})} = 1]?unknown)
; If Caller ID is not a number at least 4 digits long (with or without + sign)
; then caller is assumed to be anonymous. Alphabetic Caller ID "numbers"
; will therefore be considered anonymous. Common numbers for anonymous callers
; are: "asterisk, unknown, anonymous, private, unavailable" which may be upper,
lower
; or mixed case. The regular expression catches everything non-numeric.
; If you want to permit a specific non-numeric Caller ID "number" add it to
whitelist.
exten = s,n,GotoIf($[${REGEX("^[+]?[0-9]{4\,}$" ${CALLERID(num)})} !=
1]?unknown)
; Caller ID looks good. Return to continue with dialplan processing.
exten = s,n,Return()
; Anonymous caller. Set Caller ID name to "Privacy Manager"...
exten = s,n(unknown),Set(CALLERID(name)="Privacy Manager")
exten = s,n,Set(CDR(userfield)="Anonymous")
exten = s,n,Goto(privacymgr,1)
; Caller is on whitelist...
exten = s,n(onwhitelist),Set(CDR(userfield)="Whitelist")
exten = s,n,Goto(whitelist,1)
; Caller is on blacklist...
exten = s,n(onblacklist),Set(CDR(userfield)="Blacklist")
exten = s,n,Goto(blacklist,1)
; Implement privacy manager. Play a message to caller, record introduction,
dial callee...
exten = privacymgr,1,Wait(2)
exten = privacymgr,n,Answer()
exten = privacymgr,n,Background(privacy-unident&vm-rec-name,m)
exten =
privacymgr,n,Set(SCREEN_FILE=/tmp/ast-priv-${FILTER(0123456789,${UNIQUEID})})
exten = privacymgr,n,Record(${SCREEN_FILE}.gsm,4,5)
exten = privacymgr,n,Background(priv-introsaved,m)
; Caller has recorded a message. Dial inbound extension. If extension answers
then pass
; control to macro-call-screen that will inform callee of the Anonymous caller.
; UniqueID is passed as parameter so that we can capture a return value from
the macro.
exten =
privacymgr,n,Dial(${PRIVACY_MGR_EXTEN},20,gmM(call-screen^${SCREEN_FILE}^${UNIQUEID}))
; We are back from the call. First delete the recorded file, then act on the
return code...
exten = privacymgr,n,System(rm ${SCREEN_FILE}.gsm)
exten = privacymgr,n,Goto(privacymgr-${DIALSTATUS},1)
; Callee extension answered. Check whether they accepted the caller or just
hungup...
exten = privacymgr-ANSWER,1,Set(CDR(userfield)=${CDR(userfield)}-"Ignore")
; If hangup without accepting then go to voicemail, else just hangup...
exten = privacymgr-ANSWER,n,GotoIf($[${${UNIQUEID}} != 1]?voicemail,1)
exten = privacymgr-ANSWER,n,Set(CDR(userfield)=${CDR(userfield)}-"Answer")
exten = privacymgr-ANSWER,n,Hangup()
; Callee extension did not answer...
exten = privacymgr-NOANSWER,1,Set(CDR(userfield)=${CDR(userfield)}-"NoAnswer")
exten = privacymgr-NOANSWER,n,Goto(voicemail,1)
; Callee extension was busy...
exten = privacymgr-BUSY,1,Set(CDR(userfield)=${CDR(userfield)}-"Busy")
exten = privacymgr-BUSY,n,Goto(voicemail,1)
exten = _privacymgr-!,1,Log(WARNING,Unhandled Dial Status in Privacy Manager:
${DIALSTATUS})
exten = _privacymgr-!,n,Goto(voicemail,1)
; Caller is on whitelist, or authenticated with whitelisted number...
exten = whitelist,1,Set(WL_ACTION=${DB_RESULT})
exten =
whitelist,n,Set(CALLERID(name)=${IF(${DB_EXISTS(whitelistcomment/${CDR(accountcode)})}?${DB_RESULT}:${CALLERID(name)})})
exten = whitelist,n,Goto(whitelist-${WL_ACTION},1)
exten = whitelist-0,1,Goto(whitelist-voicemail,1)
exten = whitelist-1,1,Goto(whitelist-priority,1)
exten = whitelist-2,1,Goto(whitelist-standard,1)
exten = whitelist-3,1,Goto(whitelist-follow-me,1)
exten = whitelist-4,1,Goto(whitelist-ivr,1)
exten = whitelist-voicemail,1,Set(CDR(userfield)=${CDR(userfield)}-"Voicemail")
exten = whitelist-voicemail,n,Wait(2)
exten = whitelist-voicemail,n,Goto(voicemail,1)
exten = whitelist-priority,1,Set(CDR(userfield)=${CDR(userfield)}-"Priority")
exten = whitelist-priority,n,Log(WARNING, Whitelist action Priority not
implemented)
exten = whitelist-priority,n,Return()
exten = whitelist-standard,1,Set(CDR(userfield)=${CDR(userfield)}-"Standard")
exten = whitelist-standard,n,Return()
exten = whitelist-follow-me,1,Set(CDR(userfield)=${CDR(userfield)}-"FollowMe")
exten = whitelist-follow-me,n,Log(WARNING, Whitelist action Follow-Me not
implemented)
exten = whitelist-follow-me,n,Return()
exten = whitelist-ivr,1,Set(CDR(userfield)=${CDR(userfield)}-"IVR")
exten = whitelist-ivr,n,Goto(${PRIVACY_MGR_IVR},s,1)
exten = _whitelist-!,1,Log(WARNING,Unrecognized whitelist action: ${WL_ACTION})
exten = _whitelist-!,n,Return()
; Caller is on blacklist...
exten = blacklist,1,Ringing()
exten = blacklist,n,Goto(blacklist-${DB_RESULT},1)
exten = blacklist-0,1,Goto(blacklist-noanswer,1)
exten = blacklist-1,1,Goto(blacklist-zapateller,1)
exten = blacklist-2,1,Goto(blacklist-voicemail,1)
exten = blacklist-3,1,Goto(blacklist-privacymgr,1)
exten = blacklist-voicemail,1,Set(CDR(userfield)=${CDR(userfield)}-"Voicemail")
exten = blacklist-voicemail,n,Wait(2)
exten = blacklist-voicemail,n,Goto(voicemail,1)
exten = blacklist-noanswer,1,Set(CDR(userfield)=${CDR(userfield)}-"NoAnswer")
exten = blacklist-noanswer,n,wait(45)
exten = blacklist-noanswer,n,Hangup()
exten =
blacklist-zapateller,1,Set(CDR(userfield)=${CDR(userfield)}-"Zapateller")
exten = blacklist-zapateller,n,Zapateller(answer)
exten = blacklist-zapateller,n,Playback(discon-or-out-of-service)
exten = blacklist-zapateller,n,Hangup()
exten =
blacklist-privacymgr,1,Set(CDR(userfield)=${CDR(userfield)}-"PrivacyMgr")
exten = blacklist-privacymgr,n,Goto(privacymgr,1)
exten = _blacklist-!,1,Log(WARNING,Unrecognized blacklist action: ${DB_RESULT})
exten = _blacklist-!,n,Goto(voicemail,1)
; Send caller to voicemail...
exten = voicemail,1,Goto(${PRIVACY_MGR_VOICEMAIL},s,1)
; Handle invalid key pressed...
exten = i,1,Playback(call-terminated&goodbye)
exten = i,n,Set(CDR(userfield)=${CDR(userfield)}-"Invalid")
exten = i,n,Hangup()
; Handle timeout situation...
exten = t,1,Playback(call-terminated&goodbye)
exten = t,n,Set(CDR(userfield)=${CDR(userfield)}-"Timeout")
exten = t,n,Hangup()
; Caller hangs up...
exten = h,1,Set(CDR(userfield)=${CDR(userfield)}-"Hungup")
exten = h,n,Hangup()
; Caller interrupted prompts by pressing 0 (zero). This is an escape to let
caller
; authenticate themselves with a PIN, thereby bypassing need to record their
name...
exten = 0,1,Authenticate(/whitelist,da,4)
exten = 0,n,Set(CDR(userfield)=${CDR(userfield)}-"PIN OK")
exten = 0,n,Set(CALLERID(ani)=${CDR(accountcode)})
exten = 0,n,Set(CALLERID(num)=${CDR(accountcode)})
exten = 0,n,Set(DB_RESULT=${DB(whitelist/${CDR(accountcode)})})
exten = 0,n,Goto(whitelist,1)
[macro-call-screen]
; This macro executes when an internal extension answers a call from an
anonymous caller
; handled by check-private subroutine (Privacy Manager)
exten = s,1,Set(TIMEOUT(response)=5)
exten = s,n,Set(GLOBAL(${ARG2})=0)
exten = s,n,Background(priv-callpending,m,en,macro-call-screen)
;playback recording caller made, then delete temporary file.
exten = s,n,Background(${ARG1},m,en,macro-call-screen)
exten = s,n,System(rm ${ARG1}.gsm)
exten = s,n(repeat-options),Read(ACCEPT-CALL,followme/options,1)
exten = s,n,GotoIf($["${ACCEPT-CALL}" = ""] ?t,1) ;timeout, no digit pressed
exten = s,n,GotoIf($[${ACCEPT-CALL} = 1] ?call-accepted)
exten = s,n,GotoIf($[${ACCEPT-CALL} = 2] ?call-declined:repeat-options)
; If callee rejects the call they are thanked and the caller is passed onto an
IVR
; menu with more options, like leaving a voicemail
exten = s,n(call-declined),Playback(privacy-thankyou)
exten = s,n,Set(MACRO_RESULT=GOTO:${check-private^voicemail^1)
exten = s,n,MacroExit()
; If callee accepts the call then they are thanked and the macro exits, which
will
; automatically bridge the caller and callee together. We set the following
global to
; indicate that we accetped the call
exten = s,n(call-accepted),Playback(privacy-thankyou)
exten = s,n,Set(GLOBAL(${ARG2})=1) ;
exten = s,n,MacroExit()
; Handle timeout situation.
exten = t,1,Goto(s,call-declined)
; Press 1 to accept the call.
exten = 1,1,Goto(macro-call-screen,s,call-accepted)
; Press 2 to reject the call.
exten = 2,1,Goto(macro-call-screen.s,call-declined)
------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Astlinux-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/astlinux-users
Donations to support AstLinux are graciously accepted via PayPal to
[email protected].