Changeset 5505

Show
Ignore:
Timestamp:
12/15/07 21:49:19 (1 year ago)
Author:
p_lindheimer
Message:

macro-dialout-trunk, macro-user-callerid, macro-dialout-enum, macro-outbound-callerid, macro-agent-add, macro-agent-del: moved to core auto-generation to deal with syntax change in execif command in Asterisk 1.6

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/branches/2.4/core/etc/extensions.conf

    r5450 r5505  
    653653; 
    654654 
    655  
    656 ; dialout using a trunk, using pattern matching (don't strip any prefix) 
    657 ; arg1 = trunk number, arg2 = number, arg3 = route password 
    658 ; 
    659 ; MODIFIED (PL) 
    660 ; 
    661 ; Modified both Dial() commands to include the new TRUNK_OPTIONS from the general 
    662 ; screen of AMP 
    663 ; 
    664 [macro-dialout-trunk] 
    665 exten => s,1,Set(DIAL_TRUNK=${ARG1}) 
    666 exten => s,n,ExecIf($[$["${ARG3}" != ""] & $["${DB(AMPUSER/${AMPUSER}/pinless)}" != "NOPASSWD"]],Authenticate,${ARG3}) 
    667 exten => s,n,GotoIf($["x${OUTDISABLE_${DIAL_TRUNK}}" = "xon"]?disabletrunk,1) 
    668 exten => s,n,Set(DIAL_NUMBER=${ARG2}) ; fixlocalprefix depends on this 
    669 exten => s,n,Set(DIAL_TRUNK_OPTIONS=${DIAL_OPTIONS}) // will be reset to TRUNK_OPTIONS if not intra-company 
    670 exten => s,n,Set(GROUP()=OUT_${DIAL_TRUNK}) 
    671 exten => s,n,GotoIf($["${OUTMAXCHANS_${DIAL_TRUNK}}foo" = "foo"]?nomax) 
    672 exten => s,n,GotoIf($[ ${GROUP_COUNT(OUT_${DIAL_TRUNK})} > ${OUTMAXCHANS_${DIAL_TRUNK}} ]?chanfull) 
    673 exten => s,n(nomax),GotoIf($["${INTRACOMPANYROUTE}" = "YES"]?skipoutcid) ;Set to YES if treated like internal 
    674 exten => s,n,Set(DIAL_TRUNK_OPTIONS=${TRUNK_OPTIONS}) 
    675 exten => s,n,Macro(outbound-callerid,${DIAL_TRUNK}) 
    676 exten => s,n(skipoutcid),AGI(fixlocalprefix) ; this sets DIAL_NUMBER to the proper dial string for this trunk 
    677 exten => s,n,Set(OUTNUM=${OUTPREFIX_${DIAL_TRUNK}}${DIAL_NUMBER}) ; OUTNUM is the final dial number 
    678 exten => s,n,Set(custom=${CUT(OUT_${DIAL_TRUNK},:,1)}) ; Custom trunks are prefixed with "AMP:" 
    679  
    680 ; Back to normal processing, whether intracompany or not. 
    681 ; But add the macro-setmusic if we don't want music on this outbound call 
    682 ; 
    683 exten => s,n,GotoIf($[$["${MOHCLASS}" = "default"] | $["foo${MOHCLASS}" = "foo"]]?gocall) ; Set to YES if we should pump silence 
    684 exten => s,n,Set(DIAL_TRUNK_OPTIONS=M(setmusic^${MOHCLASS})${DIAL_TRUNK_OPTIONS})       ; set MoH or off 
    685  
    686 ; This macro call will always be blank and is provided as a hook for customization required prior to making a call 
    687 ; such as adding SIP header information or other requirements. All the channel variables from above are present 
    688 ; 
    689 exten => s,n(gocall),Macro(dialout-trunk-predial-hook) 
    690 exten => s,n,GotoIf($["${PREDIAL_HOOK_RET}" = "BYPASS"]?bypass,1) 
    691  
    692 exten => s,n,GotoIf($["${custom}" = "AMP"]?customtrunk) 
    693 exten => s,n,Dial(${OUT_${DIAL_TRUNK}}/${OUTNUM},300,${DIAL_TRUNK_OPTIONS}) ; Regular Trunk Dial 
    694 exten => s,n,Goto(s-${DIALSTATUS},1) 
    695 exten => s,n(customtrunk),Set(pre_num=${CUT(OUT_${DIAL_TRUNK},$,1)}) 
    696 exten => s,n,Set(the_num=${CUT(OUT_${DIAL_TRUNK},$,2)}) ; this is where we expect to find string OUTNUM 
    697 exten => s,n,Set(post_num=${CUT(OUT_${DIAL_TRUNK},$,3)}) 
    698 exten => s,n,GotoIf($["${the_num}" = "OUTNUM"]?outnum:skipoutnum) ; if we didn't find "OUTNUM", then skip to Dial 
    699 exten => s,n(outnum),Set(the_num=${OUTNUM}) ; replace "OUTNUM" with the actual number to dial 
    700 exten => s,n(skipoutnum),Dial(${pre_num:4}${the_num}${post_num},300,${DIAL_TRUNK_OPTIONS}) 
    701 exten => s,n,Goto(s-${DIALSTATUS},1) 
    702  
    703 exten => s,n(chanfull),Noop(max channels used up) 
    704  
    705 exten => s-BUSY,1,NoOp(Dial failed due to trunk reporting BUSY - giving up) 
    706 exten => s-BUSY,n,Playtones(busy) 
    707 exten => s-BUSY,n,Busy(20) 
    708  
    709 exten => s-NOANSWER,1,NoOp(Dial failed due to trunk reporting NOANSWER - giving up) 
    710 exten => s-NOANSWER,n,Playtones(congestion) 
    711 exten => s-NOANSWER,n,Congestion(20) 
    712  
    713 exten => s-CANCEL,1,NoOp(Dial failed due to trunk reporting CANCEL - giving up) 
    714 exten => s-CANCEL,n,Playtones(congestion) 
    715 exten => s-CANCEL,n,Congestion(20) 
    716  
    717 exten => _s-.,1,GotoIf($["x${OUTFAIL_${ARG1}}" = "x"]?noreport) 
    718 exten => _s-.,n,AGI(${OUTFAIL_${ARG1}}) 
    719 exten => _s-.,n(noreport),Noop(TRUNK Dial failed due to ${DIALSTATUS} - failing through to other trunks) 
    720  
    721 exten => disabletrunk,1,Noop(TRUNK: ${OUT_${DIAL_TRUNK}} DISABLED - falling through to next trunk) 
    722 exten => bypass,1,Noop(TRUNK: ${OUT_${DIAL_TRUNK}} BYPASSING because dialout-trunk-predial-hook) 
    723  
    724 exten => h,1,Macro(hangupcall) 
    725  
    726 ; Adds a dynamic agent/member to a Queue 
    727 ; Prompts for call-back number - in not entered, uses CIDNum 
    728 [macro-agent-add] 
    729 exten => s,1,Wait(1) 
    730 exten => s,n,Macro(user-callerid,SKIPTTL) 
    731 exten => s,n(a3),Read(CALLBACKNUM,agent-user)   ; get callback number from user 
    732 exten => s,n,GotoIf($["${CALLBACKNUM}" != ""]?a7)       ; if user just pressed # or timed out, use cidnum 
    733 exten => s,n(a5),Set(CALLBACKNUM=${AMPUSER}) 
    734 exten => s,n,ExecIf($["${CALLBACKNUM}" = ""],Set,CALLBACKNUM=${CALLERID(number)}) 
    735 exten => s,n,GotoIf($["${CALLBACKNUM}" = ""]?a3)        ; if still no number, start over 
    736 exten => s,n(a7),GotoIf($["${CALLBACKNUM}" = "${ARG1}"]?invalid)        ; Error, they put in the queue number 
    737 exten => s,n,ExecIf($["${ARG2}" != ""],Authenticate,${ARG2}) 
    738 exten => s,n(a9),AddQueueMember(${ARG1},Local/${CALLBACKNUM}@from-internal/n)   ; using chan_local allows us to have agents over trunks 
    739 exten => s,n,UserEvent(Agentlogin,Agent: ${CALLBACKNUM}) 
    740 exten => s,n,Wait(1) 
    741 exten => s,n,Playback(agent-loginok&with&extension) 
    742 exten => s,n,SayDigits(${CALLBACKNUM}) 
    743 exten => s,n,Hangup() 
    744 exten => s,n+1(invalid),Playback(pbx-invalid) 
    745 exten => s,n,Goto(a3) 
    746  
    747  
    748 ; Removes a dynamic agent/member from a Queue 
    749 ; Prompts for call-back number - in not entered, uses CIDNum 
    750 [macro-agent-del] 
    751 exten => s,1,Wait(1) 
    752 exten => s,n,Macro(user-callerid,SKIPTTL) 
    753 exten => s,n(a3),Read(CALLBACKNUM,agent-user)   ; get callback number from user 
    754 exten => s,n,GotoIf($["${CALLBACKNUM}" = ""]?a5:a7)     ; if user just pressed # or timed out, use cidnum 
    755 exten => s,n(a5),Set(CALLBACKNUM=${AMPUSER}) 
    756 exten => s,n,ExecIf($["${CALLBACKNUM}" = ""],Set,CALLBACKNUM=${CALLERID(number)}) 
    757 exten => s,n,GotoIf($["${CALLBACKNUM}" = ""]?a3)        ; if still no number, start over 
    758 exten => s,n(a7),RemoveQueueMember(${ARG1},Local/${CALLBACKNUM}@from-internal/n) 
    759 exten => s,n,UserEvent(RefreshQueue) 
    760 exten => s,n,Wait(1) 
    761 exten => s,n,Playback(agent-loggedoff) 
    762 exten => s,n,Hangup() 
    763  
    764 ; arg1 = trunk number, arg2 = number 
    765 [macro-dialout-enum] 
    766 ; Re-written to use enumlookup.agi 
    767 exten => s,1,ExecIf($[$["${ARG3}" != ""] & $["${DB(AMPUSER/${AMPUSER}/pinless)}" != "NOPASSWD"]],Authenticate,${ARG3}) 
    768 exten => s,n,Macro(outbound-callerid,${ARG1}) 
    769 exten => s,n,Set(GROUP()=OUT_${ARG1}) 
    770 exten => s,n,GotoIf($["${OUTMAXCHANS_${ARG1}}foo" = "foo"]?nomax) 
    771 exten => s,n,GotoIf($[ ${GROUP_COUNT(OUT_${ARG1})} > ${OUTMAXCHANS_${ARG1}} ]?nochans) 
    772 exten => s,n(nomax),Set(DIAL_NUMBER=${ARG2}) 
    773 exten => s,n,Set(DIAL_TRUNK=${ARG1}) 
    774 exten => s,n,AGI(fixlocalprefix)  ; this sets DIAL_NUMBER to the proper dial string for this trunk 
    775 ; Replacement for asterisk's ENUMLOOKUP function 
    776 exten => s,n,AGI(enumlookup.agi) 
    777 ; Now we have the variable DIALARR set to a list of URI's that can be called, in order of priority 
    778 ; Loop through them trying them in order. 
    779 exten => s,n(dialloop),GotoIf($["foo${DIALARR}"="foo"]?end) 
    780 exten => s,n,Set(TRYDIAL=${CUT(DIALARR,%,1)}) 
    781 exten => s,n,Set(DIALARR=${CUT(DIALARR,%,2-)}) 
    782 exten => s,n,Dial(${TRYDIAL}) 
    783 exten => s,n,NoOp(Dial exited in macro-enum-dialout with ${DIALSTATUS}) 
    784  
    785 ; Now, if we're still here, that means the Dial failed for some reason.  
    786 ; If it's CONGESTION or CHANUNAVAIL we want to try again on a different 
    787 ; different channel. If there's no more left, the dialloop tag will exit. 
    788 exten => s,n,GotoIf($[ $[ "${DIALSTATUS}" = "CHANUNAVAIL" ] | $[ "${DIALSTATUS}" = "CONGESTION" ] ]?dialloop) 
    789  
    790 ; If we're here, then it's BUSY or NOANSWER or something and well, deal with it. 
    791 exten => s,n(dialfailed),Goto(s-${DIALSTATUS},1) 
    792  
    793 ; Here are the exit points for the macro. 
    794  
    795 exten => s,n(nochans),NoOp(max channels used up) 
    796  
    797 exten => s,n(end),NoOp(Exiting macro-dialout-enum) 
    798  
    799 exten => s-BUSY,1,NoOp(Trunk is reporting BUSY) 
    800 exten => s-BUSY,2,Busy(20) 
    801  
    802 exten => _s-.,1,NoOp(Dial failed due to ${DIALSTATUS}) 
    803655 
    804656[macro-record-enable] 
     
    928780 
    929781 
    930 ; 
    931 ; ############################################################################ 
    932 ; CallerID Handling 
    933 ; ############################################################################ 
    934  
    935 ;sets the callerid of the device to that of the logged in user 
    936 ; 
    937 ; ${AMPUSER} is set upon return to the real user despite any aliasing that may 
    938 ; have been set as a result of the AMPUSER/<nnn>/cidnum field. This is used by 
    939 ; features like DND, CF, etc. to set the proper structure on aliased instructions 
    940 ; 
    941 [macro-user-callerid] 
    942 exten => s,1,Noop(user-callerid: ${CALLERID(name)} ${CALLERID(number)}) 
    943  
    944 ; make sure AMPUSER is set if it doesn't get set below 
    945 ; 
    946 exten => s,n,Set(AMPUSER=${IF($["foo${AMPUSER}" = "foo"]?${CALLERID(number)}:${AMPUSER})}) 
    947 exten => s,n,GotoIf($["${CHANNEL:0:5}" = "Local"]?report)  
    948 exten => s,n,ExecIf($["${REALCALLERIDNUM:1:2}" = ""],Set,REALCALLERIDNUM=${CALLERID(number)}) 
    949 exten => s,n(start),NoOp(REALCALLERIDNUM is ${REALCALLERIDNUM}) 
    950 exten => s,n,Set(AMPUSER=${DB(DEVICE/${REALCALLERIDNUM}/user)}) 
    951 exten => s,n,Set(AMPUSERCIDNAME=${DB(AMPUSER/${AMPUSER}/cidname)}) 
    952 exten => s,n,GotoIf($["x${AMPUSERCIDNAME:1:2}" = "x"]?report)  
    953  
    954 ; user may masquerade as a different user internally, so set the internal cid as indicated 
    955 ; but keep the REALCALLERID which is used to determine their true identify and lookup info 
    956 ; during outbound calls. 
    957 ; 
    958 exten => s,n,Set(AMPUSERCID=${IF($["${DB_EXISTS(AMPUSER/${AMPUSER}/cidnum)}" = "1"]?${DB_RESULT}:${AMPUSER})}) 
    959 exten => s,n,Set(CALLERID(all)="${AMPUSERCIDNAME}" <${AMPUSERCID}>) 
    960 exten => s,n,Set(REALCALLERIDNUM=${DB(DEVICE/${REALCALLERIDNUM}/user)}) 
    961 exten => s,n,ExecIf($[ "${DB(AMPUSER/${AMPUSER}/language)}" != "" ],Set,LANGUAGE()=${DB(AMPUSER/${AMPUSER}/language)}) 
    962 exten => s,n(report),Noop(TTL: ${TTL} ARG1: ${ARG1}) 
    963 exten => s,n,GotoIf($[ "${ARG1}" = "SKIPTTL" ]?continue) 
    964 exten => s,n(report2),Set(__TTL=${IF($["foo${TTL}" = "foo"]?64:$[ ${TTL} - 1 ])}) 
    965 exten => s,n,GotoIf($[ ${TTL} > 0 ]?continue) 
    966 exten => s,n,Wait(${RINGTIMER}) ; wait for a while, to give it a chance to be picked up by voicemail 
    967 exten => s,n,Answer() 
    968 exten => s,n,Wait(2) 
    969 exten => s,n,Playback(im-sorry&an-error-has-occured&with&call-forwarding) 
    970 exten => s,n,Macro(hangupcall) 
    971 exten => s,n,Congestion() 
    972 exten => s,n(continue),NoOp(Using CallerID ${CALLERID(all)}) 
    973 exten => h,1,Macro(hangupcall) 
    974  
    975 ; overrides callerid out trunks 
    976 ; arg1 is trunk 
    977 ; macro-user-callerid should be called _before_ using this macro 
    978 [macro-outbound-callerid] 
    979 ; Keep the original CallerID number, for failover to the next trunk. 
    980 exten => s,1,GotoIf($["${REALCALLERIDNUM:1:2}" != ""]?start) 
    981 exten => s,n,Set(REALCALLERIDNUM=${CALLERID(number)}) 
    982 exten => s,n(start),NoOp(REALCALLERIDNUM is ${REALCALLERIDNUM}) 
    983  
    984 ; If this came through a ringgroup or CF, then we want to retain original CID unless 
    985 ; OUTKEEPCID_${trunknum} is set. 
    986 ; Save then CIDNAME while it is still intact in case we end up sending out this same CID 
    987 ; 
    988 exten => s,n,GotoIf($["${KEEPCID}" != "TRUE"]?normcid) ;Set to TRUE if coming from ringgroups, CF, etc. 
    989 exten => s,n,GotoIf($["x${OUTKEEPCID_${ARG1}}" = "xon"]?normcid) 
    990 exten => s,n,GotoIf($["foo${REALCALLERIDNUM}" = "foo"]?normcid) ;if not set to anything, go through normal processing 
    991 exten => s,n,Set(USEROUTCID=${REALCALLERIDNUM}) 
    992 exten => s,n,Set(REALCALLERIDNAME=${CALLERID(name)}) 
    993  
    994 ; We now have to make sure the CID is valid. If we find an AMPUSER with the same CID, we assume it is an internal  
    995 ; call (would be quite a conincidence if not) and go through the normal processing to get that CID. If a device  
    996 ; is set for this CID, then it must be internal  
    997 ; If we end up using USEROUTCID at the end, it may still be the REALCALLERIDNUM we saved above. That is determined 
    998 ; if the two are equal, AND there is no CALLERID(name) present since it has been removed by the CALLERID(all)=${USEROUTCID} 
    999 ; setting. If this is the case, then we put the orignal name back in to send out. Although the CNAME is not honored by most 
    1000 ; carriers, there are cases where it is so this preserves that information to be used by those carriers who do honor it. 
    1001 ;  
    1002 exten => s,n,GotoIf($["foo${DB(AMPUSER/${REALCALLERIDNUM}/device)}" = "foo"]?bypass:normcid)  
    1003  
    1004 exten => s,n(normcid),Set(USEROUTCID=${DB(AMPUSER/${REALCALLERIDNUM}/outboundcid)}) 
    1005 exten => s,n(bypass),Set(EMERGENCYCID=${DB(DEVICE/${REALCALLERIDNUM}/emergency_cid)}) 
    1006 exten => s,n,Set(TRUNKOUTCID=${OUTCID_${ARG1}}) 
    1007 exten => s,n,GotoIf($["${EMERGENCYROUTE:1:2}" = ""]?trunkcid) ; check EMERGENCY ROUTE 
    1008 exten => s,n,GotoIf($["${EMERGENCYCID:1:2}" = ""]?trunkcid) ; empty EMERGENCY CID, so default back to trunk 
    1009 exten => s,n,Set(CALLERID(all)=${EMERGENCYCID}) ; emergency cid for device 
    1010 exten => s,n,Goto(report) 
    1011 exten => s,n(trunkcid),GotoIf($["${TRUNKOUTCID:1:2}" = ""]?usercid)  ;check for CID override for trunk (global var) 
    1012 exten => s,n,Set(CALLERID(all)=${TRUNKOUTCID}) 
    1013 exten => s,n(usercid),GotoIf($["${USEROUTCID:1:2}" = ""]?report) ; check CID override for extension 
    1014 exten => s,n,Set(CALLERID(all)=${USEROUTCID}) 
    1015 exten => s,n,GotoIf($["x${CALLERID(name)}"!="xhidden"]?checkname:hidecid) ; check CID blocking for extension 
    1016 exten => s,n(hidecid),SetCallerPres(prohib_passed_screen) ; Only works with ISDN (T1/E1/BRI) 
    1017 exten => s,n(checkname),ExecIf($[ $[ "${CALLERID(number)}" = "${REALCALLERIDNUM}" ] & $[ "${CALLERID(name)}" = "" ] ],Set,CALLERID(name)=${REALCALLERIDNAME}) 
    1018 exten => s,n(report),NoOp(CallerID set to ${CALLERID(all)}) 
    1019  
    1020782; Privacy Manager Macro makes sure that any calls that don't pass the privacy manager are presented 
    1021783; with congestion since there have been observed cases of the call continuing if not stopped with a  
  • modules/branches/2.4/core/functions.inc.php

    r5499 r5505  
    961961                        } 
    962962 
     963                        $context = 'macro-dialout-trunk'; 
     964                        $exten = 's'; 
     965                         
     966                        /* 
     967                         * dialout using a trunk, using pattern matching (don't strip any prefix) 
     968                         * arg1 = trunk number, arg2 = number, arg3 = route password 
     969                         * 
     970                         * MODIFIED (PL) 
     971                         * 
     972                         * Modified both Dial() commands to include the new TRUNK_OPTIONS from the general 
     973                         * screen of AMP 
     974                         */ 
     975                        $ext->add($context, $exten, '', new ext_set('DIAL_TRUNK', '${ARG1}')); 
     976                        $ext->add($context, $exten, '', new ext_execif('$[$["${ARG3}" != ""] & $["${DB(AMPUSER/${AMPUSER}/pinless)}" != "NOPASSWD"]]', 'Authenticate', '${ARG3}')); 
     977                        $ext->add($context, $exten, '', new ext_gotoif('$["x${OUTDISABLE_${DIAL_TRUNK}}" = "xon"]', 'disabletrunk,1')); 
     978                        $ext->add($context, $exten, '', new ext_set('DIAL_NUMBER', '${ARG2}')); // fixlocalprefix depends on this 
     979                        $ext->add($context, $exten, '', new ext_set('DIAL_TRUNK_OPTIONS', '${DIAL_OPTIONS}')); // will be reset to TRUNK_OPTIONS if not intra-company 
     980                        $ext->add($context, $exten, '', new ext_set('GROUP()', 'OUT_${DIAL_TRUNK}')); 
     981                        $ext->add($context, $exten, '', new ext_gotoif('$["${OUTMAXCHANS_${DIAL_TRUNK}}foo" = "foo"]', 'nomax')); 
     982                        $ext->add($context, $exten, '', new ext_gotoif('$[ ${GROUP_COUNT(OUT_${DIAL_TRUNK})} > ${OUTMAXCHANS_${DIAL_TRUNK}} ]', 'chanfull')); 
     983                        $ext->add($context, $exten, 'nomax', new ext_gotoif('$["${INTRACOMPANYROUTE}" = "YES"]', 'skipoutcid'));  // Set to YES if treated like internal 
     984                        $ext->add($context, $exten, '', new ext_set('DIAL_TRUNK_OPTIONS', '${TRUNK_OPTIONS}')); 
     985                        $ext->add($context, $exten, '', new ext_macro('outbound-callerid', '${DIAL_TRUNK}')); 
     986                        $ext->add($context, $exten, 'skipoutcid', new ext_agi('fixlocalprefix'));  // this sets DIAL_NUMBER to the proper dial string for this trunk 
     987                        $ext->add($context, $exten, '', new ext_set('OUTNUM', '${OUTPREFIX_${DIAL_TRUNK}}${DIAL_NUMBER}'));  // OUTNUM is the final dial number 
     988                        $ext->add($context, $exten, '', new ext_set('custom', '${CUT(OUT_${DIAL_TRUNK},:,1)}'));  // Custom trunks are prefixed with "AMP:" 
     989                 
     990                        // Back to normal processing, whether intracompany or not. 
     991                        // But add the macro-setmusic if we don't want music on this outbound call 
     992                        $ext->add($context, $exten, '', new ext_gotoif('$[$["${MOHCLASS}" = "default"] | $["foo${MOHCLASS}" = "foo"]]', 'gocall'));  // Set to YES if we should pump silence 
     993                        $ext->add($context, $exten, '', new ext_set('DIAL_TRUNK_OPTIONS', 'M(setmusic^${MOHCLASS})${DIAL_TRUNK_OPTIONS}'));  // set MoH or off 
     994                 
     995                        // This macro call will always be blank and is provided as a hook for customization required prior to making a call 
     996                        // such as adding SIP header information or other requirements. All the channel variables from above are present 
     997                         
     998                        $ext->add($context, $exten, 'gocall', new ext_macro('dialout-trunk-predial-hook')); 
     999                        $ext->add($context, $exten, '', new ext_gotoif('$["${PREDIAL_HOOK_RET}" = "BYPASS"]', 'bypass,1')); 
     1000                 
     1001                        $ext->add($context, $exten, '', new ext_gotoif('$["${custom}" = "AMP"]', 'customtrunk')); 
     1002                        $ext->add($context, $exten, '', new ext_dial('${OUT_${DIAL_TRUNK}}/${OUTNUM}', '300,${DIAL_TRUNK_OPTIONS}'));  // Regular Trunk Dial 
     1003                        $ext->add($context, $exten, '', new ext_goto(1, 's-${DIALSTATUS}')); 
     1004                         
     1005                        $ext->add($context, $exten, 'customtrunk', new ext_set('pre_num', '${CUT(OUT_${DIAL_TRUNK},$,1)}')); 
     1006                        $ext->add($context, $exten, '', new ext_set('the_num', '${CUT(OUT_${DIAL_TRUNK},$,2)}'));  // this is where we expect to find string OUTNUM 
     1007                        $ext->add($context, $exten, '', new ext_set('post_num', '${CUT(OUT_${DIAL_TRUNK},$,3)}')); 
     1008                        $ext->add($context, $exten, '', new ext_gotoif('$["${the_num}" = "OUTNUM"]', 'outnum', 'skipoutnum'));  // if we didn't find "OUTNUM", then skip to Dial 
     1009                        $ext->add($context, $exten, 'outnum', new ext_set('the_num', '${OUTNUM}'));  // replace "OUTNUM" with the actual number to dial 
     1010                        $ext->add($context, $exten, 'skipoutnum', new ext_dial('${pre_num:4}${the_num}${post_num}', '300,${DIAL_TRUNK_OPTIONS}')); 
     1011                        $ext->add($context, $exten, '', new ext_goto(1, 's-${DIALSTATUS}')); 
     1012                         
     1013                        $ext->add($context, $exten, 'chanfull', new ext_noop('max channels used up')); 
     1014                 
     1015                        $exten = 's-BUSY'; 
     1016                        $ext->add($context, $exten, '', new ext_noop('Dial failed due to trunk reporting BUSY - giving up')); 
     1017                        $ext->add($context, $exten, '', new ext_playtones('busy')); 
     1018                        $ext->add($context, $exten, '', new ext_busy(20)); 
     1019                 
     1020                        $exten = 's-NOANSWER'; 
     1021                        $ext->add($context, $exten, '', new ext_noop('Dial failed due to trunk reporting NOANSWER - giving up')); 
     1022                        $ext->add($context, $exten, '', new ext_playtones('congestion')); 
     1023                        $ext->add($context, $exten, '', new ext_congestion(20)); 
     1024                 
     1025                        $exten = 's-CANCEL'; 
     1026                        $ext->add($context, $exten, '', new ext_noop('Dial failed due to trunk reporting CANCEL - giving up')); 
     1027                        $ext->add($context, $exten, '', new ext_playtones('congestion')); 
     1028                        $ext->add($context, $exten, '', new ext_congestion(20)); 
     1029                 
     1030                        $exten = '_s-.'; 
     1031                        $ext->add($context, $exten, '', new ext_gotoif('$["x${OUTFAIL_${ARG1}}" = "x"]', 'noreport')); 
     1032                        $ext->add($context, $exten, '', new ext_agi('${OUTFAIL_${ARG1}}')); 
     1033                        $ext->add($context, $exten, 'noreport', new ext_noop('TRUNK Dial failed due to ${DIALSTATUS} - failing through to other trunks')); 
     1034                         
     1035                        $ext->add($context, 'disabletrunk', '', new ext_noop('TRUNK: ${OUT_${DIAL_TRUNK}} DISABLED - falling through to next trunk')); 
     1036                        $ext->add($context, 'bypass', '', new ext_noop('TRUNK: ${OUT_${DIAL_TRUNK}} BYPASSING because dialout-trunk-predial-hook')); 
     1037                 
     1038                        $ext->add($context, 'h', '', new ext_macro('hangupcall')); 
     1039 
     1040 
     1041                        /* 
     1042                         * sets the callerid of the device to that of the logged in user 
     1043                         * 
     1044                         * ${AMPUSER} is set upon return to the real user despite any aliasing that may 
     1045                         * have been set as a result of the AMPUSER/<nnn>/cidnum field. This is used by 
     1046                         * features like DND, CF, etc. to set the proper structure on aliased instructions  
     1047                         */ 
     1048                        $context = 'macro-user-callerid'; 
     1049                        $exten = 's'; 
     1050                         
     1051                        $ext->add($context, $exten, '', new ext_noop('user-callerid: ${CALLERID(name)} ${CALLERID(number)}')); 
     1052                                                         
     1053                        // make sure AMPUSER is set if it doesn't get set below                  
     1054                        $ext->add($context, $exten, '', new ext_set('AMPUSER', '${IF($["foo${AMPUSER}" = "foo"]?${CALLERID(number)}:${AMPUSER})}')); 
     1055                        $ext->add($context, $exten, '', new ext_gotoif('$["${CHANNEL:0:5}" = "Local"]', 'report')); 
     1056                        $ext->add($context, $exten, '', new ext_execif('$["${REALCALLERIDNUM:1:2}" = ""]', 'Set', 'REALCALLERIDNUM=${CALLERID(number)}')); 
     1057                        $ext->add($context, $exten, 'start', new ext_noop('REALCALLERIDNUM is ${REALCALLERIDNUM}')); 
     1058                        $ext->add($context, $exten, '', new ext_set('AMPUSER', '${DB(DEVICE/${REALCALLERIDNUM}/user)}')); 
     1059                        $ext->add($context, $exten, '', new ext_set('AMPUSERCIDNAME', '${DB(AMPUSER/${AMPUSER}/cidname)}')); 
     1060                        $ext->add($context, $exten, '', new ext_gotoif('$["x${AMPUSERCIDNAME:1:2}" = "x"]', 'report')); 
     1061 
     1062                        // user may masquerade as a different user internally, so set the internal cid as indicated 
     1063                        // but keep the REALCALLERID which is used to determine their true identify and lookup info 
     1064                        // during outbound calls. 
     1065                        $ext->add($context, $exten, '', new ext_set('AMPUSERCID', '${IF($["${DB_EXISTS(AMPUSER/${AMPUSER}/cidnum)}" = "1"]?${DB_RESULT}:${AMPUSER})}')); 
     1066                        $ext->add($context, $exten, '', new ext_set('CALLERID(all)', '"${AMPUSERCIDNAME}" <${AMPUSERCID}>')); 
     1067                        $ext->add($context, $exten, '', new ext_set('REALCALLERIDNUM', '${DB(DEVICE/${REALCALLERIDNUM}/user)}')); 
     1068                        $ext->add($context, $exten, '', new ext_execif('$["${DB(AMPUSER/${AMPUSER}/language)}" != ""]', 'Set', 'LANGUAGE()=${DB(AMPUSER/${AMPUSER}/language)}')); 
     1069                        $ext->add($context, $exten, 'report', new ext_noop('TTL: ${TTL} ARG1: ${ARG1}')); 
     1070                        $ext->add($context, $exten, '', new ext_gotoif('$[ "${ARG1}" = "SKIPTTL" ]', 'continue')); 
     1071                        $ext->add($context, $exten, 'report2', new ext_set('__TTL', '${IF($["foo${TTL}" = "foo"]?64:$[ ${TTL} - 1 ])}')); 
     1072                        $ext->add($context, $exten, '', new ext_gotoif('$[ ${TTL} > 0 ]', 'continue')); 
     1073                        $ext->add($context, $exten, '', new ext_wait('${RINGTIMER}'));  // wait for a while, to give it a chance to be picked up by voicemail 
     1074                        $ext->add($context, $exten, '', new ext_answer()); 
     1075                        $ext->add($context, $exten, '', new ext_wait('2')); 
     1076                        $ext->add($context, $exten, '', new ext_playback('im-sorry&an-error-has-occured&with&call-forwarding')); 
     1077                        $ext->add($context, $exten, '', new ext_macro('hangupcall')); 
     1078                        $ext->add($context, $exten, '', new ext_congestion(20)); 
     1079                        $ext->add($context, $exten, 'continue', new ext_noop('Using CallerID ${CALLERID(all)}')); 
     1080                        $ext->add($context, 'h', '', new ext_macro('hangupcall')); 
     1081                         
     1082                        /* 
     1083                         * arg1 = trunk number, arg2 = number 
     1084                         *  
     1085                         * Re-written to use enumlookup.agi 
     1086                         */ 
     1087         
     1088                        $context = 'macro-dialout-enum'; 
     1089                        $exten = 's'; 
     1090         
     1091                        $ext->add($context, $exten, '', new ext_execif('$[$["${ARG3}" != ""] & $["${DB(AMPUSER/${AMPUSER}/pinless)}" != "NOPASSWD"]]', 'Authenticate', '${ARG3}')); 
     1092                        $ext->add($context, $exten, '', new ext_macro('outbound-callerid', '${ARG1}')); 
     1093                        $ext->add($context, $exten, '', new ext_set('GROUP()', 'OUT_${ARG1}')); 
     1094                        $ext->add($context, $exten, '', new ext_gotoif('$["${OUTMAXCHANS_${ARG1}}foo" = "foo"]', 'nomax')); 
     1095                        $ext->add($context, $exten, '', new ext_gotoif('$[ ${GROUP_COUNT(OUT_${ARG1})} > ${OUTMAXCHANS_${ARG1}} ]', 'nochans')); 
     1096                        $ext->add($context, $exten, 'nomax', new ext_set('DIAL_NUMBER', '${ARG2}')); 
     1097                        $ext->add($context, $exten, '', new ext_set('DIAL_TRUNK', '${ARG1}')); 
     1098                        $ext->add($context, $exten, '', new ext_agi('fixlocalprefix'));  // this sets DIAL_NUMBER to the proper dial string for this trunk 
     1099                        //  Replacement for asterisk's ENUMLOOKUP function 
     1100                        $ext->add($context, $exten, '', new ext_agi('enumlookup.agi')); 
     1101                        // Now we have the variable DIALARR set to a list of URI's that can be called, in order of priority 
     1102                        // Loop through them trying them in order. 
     1103                        $ext->add($context, $exten, 'dialloop', new ext_gotoif('$["foo${DIALARR}"="foo"]', 'end')); 
     1104                        $ext->add($context, $exten, '', new ext_set('TRYDIAL', '${CUT(DIALARR,%,1)}')); 
     1105                        $ext->add($context, $exten, '', new ext_set('DIALARR', '${CUT(DIALARR,%,2-)}')); 
     1106                        $ext->add($context, $exten, '', new ext_dial('${TRYDIAL}', '')); 
     1107                        $ext->add($context, $exten, '', new ext_noop('Dial exited in macro-enum-dialout with ${DIALSTATUS}')); 
     1108                        // Now, if we're still here, that means the Dial failed for some reason.  
     1109                        // If it's CONGESTION or CHANUNAVAIL we want to try again on a different 
     1110                        // different channel. If there's no more left, the dialloop tag will exit. 
     1111                        $ext->add($context, $exten, '', new ext_gotoif('$[ $[ "${DIALSTATUS}" = "CHANUNAVAIL" ] | $[ "${DIALSTATUS}" = "CONGESTION" ] ]', 'dialloop')); 
     1112                        // If we're here, then it's BUSY or NOANSWER or something and well, deal with it. 
     1113                        $ext->add($context, $exten, 'dialfailed', new ext_goto(1, 's-${DIALSTATUS}')); 
     1114                        // Here are the exit points for the macro. 
     1115                        $ext->add($context, $exten, 'nochans', new ext_noop('max channels used up')); 
     1116                        $ext->add($context, $exten, 'end', new ext_noop('Exiting macro-dialout-enum')); 
     1117                        $ext->add($context, 's-BUSY', '', new ext_noop('Trunk is reporting BUSY')); 
     1118                        $ext->add($context, 's-BUSY', '', new ext_busy(20)); 
     1119                        $ext->add($context, '_s-.', '', new ext_noop('Dial failed due to ${DIALSTATUS}'));                       
     1120                         
     1121                        /* 
     1122                         * overrides callerid out trunks 
     1123                         * arg1 is trunk 
     1124                         * macro-user-callerid should be called _before_ using this macro 
     1125                         */ 
     1126 
     1127                        $context = 'macro-outbound-callerid'; 
     1128                        $exten = 's'; 
     1129                         
     1130                        // Keep the original CallerID number, for failover to the next trunk. 
     1131                        $ext->add($context, $exten, '', new ext_gotoif('$["${REALCALLERIDNUM:1:2}" != ""]', 'start')); 
     1132                        $ext->add($context, $exten, '', new ext_set('REALCALLERIDNUM', '${CALLERID(number)}')); 
     1133                        $ext->add($context, $exten, 'start', new ext_noop('REALCALLERIDNUM is ${REALCALLERIDNUM}')); 
     1134 
     1135                        // If this came through a ringgroup or CF, then we want to retain original CID unless 
     1136                        // OUTKEEPCID_${trunknum} is set. 
     1137                        // Save then CIDNAME while it is still intact in case we end up sending out this same CID 
     1138                        $ext->add($context, $exten, '', new ext_gotoif('$["${KEEPCID}" != "TRUE"]', 'normcid'));  // Set to TRUE if coming from ringgroups, CF, etc. 
     1139                        $ext->add($context, $exten, '', new ext_gotoif('$["x${OUTKEEPCID_${ARG1}}" = "xon"]', 'normcid')); 
     1140                        $ext->add($context, $exten, '', new ext_gotoif('$["foo${REALCALLERIDNUM}" = "foo"]', 'normcid'));  // if not set to anything, go through normal processing 
     1141                        $ext->add($context, $exten, '', new ext_set('USEROUTCID', '${REALCALLERIDNUM}')); 
     1142                        $ext->add($context, $exten, '', new ext_set('REALCALLERIDNAME', '${CALLERID(name)}')); 
     1143 
     1144                        // We now have to make sure the CID is valid. If we find an AMPUSER with the same CID, we assume it is an internal  
     1145                        // call (would be quite a conincidence if not) and go through the normal processing to get that CID. If a device  
     1146                        // is set for this CID, then it must be internal  
     1147                        // If we end up using USEROUTCID at the end, it may still be the REALCALLERIDNUM we saved above. That is determined 
     1148                        // if the two are equal, AND there is no CALLERID(name) present since it has been removed by the CALLERID(all)=${USEROUTCID} 
     1149                        // setting. If this is the case, then we put the orignal name back in to send out. Although the CNAME is not honored by most 
     1150                        // carriers, there are cases where it is so this preserves that information to be used by those carriers who do honor it. 
     1151                        $ext->add($context, $exten, '', new ext_gotoif('$["foo${DB(AMPUSER/${REALCALLERIDNUM}/device)}" = "foo"]', 'bypass', 'normcid')); 
     1152 
     1153                        $ext->add($context, $exten, 'normcid', new ext_set('USEROUTCID', '${DB(AMPUSER/${REALCALLERIDNUM}/outboundcid)}')); 
     1154                        $ext->add($context, $exten, 'bypass', new ext_set('EMERGENCYCID', '${DB(DEVICE/${REALCALLERIDNUM}/emergency_cid)}')); 
     1155                        $ext->add($context, $exten, '', new ext_set('TRUNKOUTCID', '${OUTCID_${ARG1}}')); 
     1156                        $ext->add($context, $exten, '', new ext_gotoif('$["${EMERGENCYROUTE:1:2}" = ""]', 'trunkcid'));  // check EMERGENCY ROUTE 
     1157                        $ext->add($context, $exten, '', new ext_gotoif('$["${EMERGENCYCID:1:2}" = ""]', 'trunkcid'));  // empty EMERGENCY CID, so default back to trunk 
     1158                        $ext->add($context, $exten, '', new ext_set('CALLERID(all)', '${EMERGENCYCID}'));  // emergency cid for device 
     1159                        $ext->add($context, $exten, '', new ext_goto('report')); 
     1160                        $ext->add($context, $exten, 'trunkcid', new ext_gotoif('$["${TRUNKOUTCID:1:2}" = ""]', 'usercid'));  // check for CID override for trunk (global var) 
     1161                        $ext->add($context, $exten, '', new ext_set('CALLERID(all)', '${TRUNKOUTCID}')); 
     1162                        $ext->add($context, $exten, 'usercid', new ext_gotoif('$["${USEROUTCID:1:2}" = ""]', 'report'));  // check CID override for extension 
     1163                        $ext->add($context, $exten, '', new ext_set('CALLERID(all)', '${USEROUTCID}')); 
     1164                        $ext->add($context, $exten, '', new ext_gotoif('$["x${CALLERID(name)}"!="xhidden"]', 'checkname', 'hidecid'));  // check CID blocking for extension 
     1165                        $ext->add($context, $exten, 'hidecid', new ext_setcallerpres('prohib_passed_screen'));  // Only works with ISDN (T1/E1/BRI) 
     1166                        $ext->add($context, $exten, 'checkname', new ext_execif('$[ $[ "${CALLERID(number)}" = "${REALCALLERIDNUM}" ] & $[ "${CALLERID(name)}" = "" ] ]', 'Set', 'CALLERID(name)=${REALCALLERIDNAME}')); 
     1167                        $ext->add($context, $exten, 'report', new ext_noop('CallerID set to ${CALLERID(all)}'));                         
     1168 
     1169                         
     1170                        /* 
     1171                         * Adds a dynamic agent/member to a Queue 
     1172                         * Prompts for call-back number - in not entered, uses CIDNum 
     1173                         */ 
     1174 
     1175                        $context = 'macro-agent-add'; 
     1176                        $exten = 's'; 
     1177                         
     1178                        $ext->add($context, $exten, '', new ext_wait(1)); 
     1179                        $ext->add($context, $exten, '', new ext_macro('user-callerid', 'SKIPTTL')); 
     1180                        $ext->add($context, $exten, 'a3', new ext_read('CALLBACKNUM', 'agent-user'));  // get callback number from user 
     1181                        $ext->add($context, $exten, '', new ext_gotoif('$["${CALLBACKNUM}" != ""]', 'a7'));  // if user just pressed # or timed out, use cidnum 
     1182                        $ext->add($context, $exten, 'a5', new ext_set('CALLBACKNUM', '${AMPUSER}')); 
     1183                        $ext->add($context, $exten, '', new ext_execif('$["${CALLBACKNUM}" = ""]', 'Set', 'CALLBACKNUM=${CALLERID(number)}')); 
     1184                        $ext->add($context, $exten, '', new ext_gotoif('$["${CALLBACKNUM}" = ""]', 'a3'));  // if still no number, start over 
     1185                        $ext->add($context, $exten, 'a7', new ext_gotoif('$["${CALLBACKNUM}" = "${ARG1}"]', 'invalid'));  // Error, they put in the queue number 
     1186                        $ext->add($context, $exten, '', new ext_execif('$["${ARG2}" != ""]', 'Authenticate', '${ARG2}')); 
     1187                        $ext->add($context, $exten, 'a9', new ext_addqueuemember('${ARG1}', 'Local/${CALLBACKNUM}@from-internal/n'));  // using chan_local allows us to have agents over trunks 
     1188                        $ext->add($context, $exten, '', new ext_userevent('Agentlogin', 'Agent: ${CALLBACKNUM}')); 
     1189                        $ext->add($context, $exten, '', new ext_wait(1)); 
     1190                        $ext->add($context, $exten, '', new ext_playback('agent-loginok&with&extension')); 
     1191                        $ext->add($context, $exten, '', new ext_saydigits('${CALLBACKNUM}')); 
     1192                        $ext->add($context, $exten, '', new ext_hangup()); 
     1193                        $ext->add($context, $exten, '', new ext_macroexit()); 
     1194                        $ext->add($context, $exten, 'invalid', new ext_playback('pbx-invalid')); 
     1195                        $ext->add($context, $exten, '', new ext_goto('a3')); 
     1196 
     1197                        /* 
     1198                         * Removes a dynamic agent/member from a Queue 
     1199                         * Prompts for call-back number - in not entered, uses CIDNum  
     1200                         */ 
     1201 
     1202                        $context = 'macro-agent-del'; 
     1203                         
     1204                        $ext->add($context, $exten, '', new ext_wait(1)); 
     1205                        $ext->add($context, $exten, '', new ext_macro('user-callerid', 'SKIPTTL')); 
     1206                        $ext->add($context, $exten, 'a3', new ext_read('CALLBACKNUM', 'agent-user'));  // get callback number from user 
     1207                        $ext->add($context, $exten, '', new ext_gotoif('$["${CALLBACKNUM}" = ""]', 'a5', 'a7'));  // if user just pressed # or timed out, use cidnum 
     1208                        $ext->add($context, $exten, 'a5', new ext_set('CALLBACKNUM', '${AMPUSER}')); 
     1209                        $ext->add($context, $exten, '', new ext_execif('$["${CALLBACKNUM}" = ""]', 'Set', 'CALLBACKNUM=${CALLERID(number)}')); 
     1210                        $ext->add($context, $exten, '', new ext_gotoif('$["${CALLBACKNUM}" = ""]', 'a3'));  // if still no number, start over 
     1211                        $ext->add($context, $exten, 'a7', new ext_removequeuemember('${ARG1}', 'Local/${CALLBACKNUM}@from-internal/n')); 
     1212                        $ext->add($context, $exten, '', new ext_userevent('RefreshQueue')); 
     1213                        $ext->add($context, $exten, '', new ext_wait(1)); 
     1214                        $ext->add($context, $exten, '', new ext_playback('agent-loggedoff')); 
     1215                        $ext->add($context, $exten, '', new ext_hangup()); 
     1216                         
    9631217                break; 
    9641218        } 
    9651219} 
    966  
    967  
    968  
    9691220 
    9701221