; THIS CONFIGURATION PROVIDES SIP AND IAX2 CONNECTIVITY TO LEGACY 
; OR COLLECTIBLE TELEPHONE SYSTEMS THAT ARE SET UP AS PBXES.
;
; THIS EXAMPLE FILE ASSUMES A CERTAIN CONFIGURATION, BUT CAN EASILY BE
; MODIFIED TO PROVIDE FOR DIFFERENCES WITH INDIVIDUAL PHONE SWITCHES.
;
; THIS SAMPLE SYSTEM IS CONFIGURED AS FOLLOWS:
; 	+ MEMBERSHIP ON THE PRIVATE "976" OFFICE CODE (NXX).
;	+ OWNERSHIP OF THE DID BLOCK 976-9900 THROUGH 976-9999.
;	+ TWO-DIGIT DIALING TOWARDS PHONE SYSTEM FROM ASTERISK
;       + DIAL-8 AND 4-DIGIT DIALING ACROSS THE NET
;
; The "General" category is for certain variables.  
;
[general]
;
; You can include other config files, use the #include command (without the ';')
; Note that this is different from the "include" command that includes contexts within 
; other contexts. The #include command works in all asterisk configuration files.
;#include "filename.conf"

; The "Globals" category contains global variables that can be referenced
; in the dialplan with ${VARIABLE} or ${ENV(VARIABLE)} for Environmental variable
; ${${VARIABLE}} or ${text${VARIABLE}} or any hybrid
;
;
;
exten => i,1,Background(ss-noservice)
;
;
[globals]
CNETANI=9769900
CONSOLE=Console/dsp                             ; Console interface for demo
MYNAME=DOAKES JOE
TRUNK=Zap/g1                                    ; Trunk interface (TK GP 1)
TRUNKMSD=1
;
;
; Any category other than "General" and "Globals" represent 
; extension contexts, which are collections of extensions.  
;
; Extension names may be numbers, letters, or combinations
; thereof. If an extension name is prefixed by a '_'
; character, it is interpreted as a pattern rather than a
; literal.  In patterns, some characters have special meanings:
;
;   X - any digit from 0-9
;   Z - any digit from 1-9
;   N - any digit from 2-9
;   [1235-9] - any digit in the brackets (in this example, 1,2,3,5,6,7,8,9)
;   . - wildcard, matches anything remaining (e.g. _9011. matches 
;	anything starting with 9011 excluding 9011 itself)
;
; For example the extension _NXXXXXX would match normal 7 digit dialings, 
; while _1NXXNXXXXXX would represent an area code plus phone number
; preceeded by a one.
;
; Contexts contain several lines, one for each step of each
; extension, which can take one of two forms as listed below,
; with the first form being preferred.  One may include another
; context in the current one as well, optionally with a
; date and time.  Included contexts are included in the order
; they are listed.
;
;[context]
;exten => someexten,priority,application(arg1,arg2,...)
;exten => someexten,priority,application,arg1|arg2...
;
; Timing list for includes is 
;
;   <time range>|<days of week>|<days of month>|<months>
;
;include => daytime|9:00-17:00|mon-fri|*|*
;
; ignorepat can be used to instruct drivers to not cancel dialtone upon
; receipt of a particular pattern.  The most commonly used example is
; of course '9' like this:
;
;ignorepat => 9
;
; so that dialtone remains even after dialing a 9.
;
;
[macro-dialswitch]
;
;   ${ARG1} - Extension  (we could have used ${MACRO_EXTEN} here as well
;   ${ARG2} - Device(s) to ring
;
exten => s,1,Dial(ZAP/g1/${ARG1},360,tT)        ; Dial extension on zaptel trk grp 1
exten => s,2,Macro(fastbusy)            
;
;
[macro-dialcnet]
;
; Collectors' Network -- All calls are on the "200" Area Code
; and, from this dial plan, can be reached via 1-200-NXX-XXXX
;
; NOTE:  
;        If your switch cannot deliver outgoing ANI on a per-station
;        basis, use the first "SetCallerID" command and comment
;        out the second "SetCallerID" command. (below)
;
;	 If your switch can deliver outgoing ANI on a per-station
;        basis, use the second "SetCallerID" command and comment
;        out the first "SetCallerID" command. (below)
;
;	 Default assumes that your switch cannot deliver outgoing ANI.
;
exten => s,1,SetCallerID(${MYNAME} <${CNETANI}>)
; exten => s,1,SetCallerID(${MYNAME} <97699${CALLERIDNUM}>)
exten => s,2,EnumLookup(${ARG1})
exten => s,3,GotoIf($[$[${ENUM:0:3} = SIP] | $[${ENUM:0:3} = IAX2]]?4:5) ; enum match?
exten => s,4,Dial(${ENUM})             ; If match, dial $ENUM
exten => s,5,Dial(${ENUM})
;
exten => s,53,NoOp(53 ENUM Server not reachable -- giving up)
exten => s,54,Macro(fastbusy)
;
exten => s,103,NoOp(103 No ENUM e164 match found -- number does not exist on CNET)
exten => s,104,Macro(invalid)
;
;
[macro-invalid]
exten => s,1,Answer
exten => s,2,Wait(1)
exten => s,3,Playtones(480*20/2000,0/4000)
exten => s,4,Wait(8)
exten => s,5,Playtones(!950/330,!1400/330,!1800/330,0)
exten => s,6,Wait(2)
exten => s,7,Playback(discon-or-out-of-service)
exten => s,8,Wait(1)
exten => s,9,Playback(976-99)
exten => s,10,Wait(5)
exten => s,11,Hangup
;
[macro-Milliwatt]
exten => s,1,Answer
exten => s,2,Playtones(1004)
exten => s,3,Wait(${ARG1})
exten => s,4,Hangup
;
[cnet]
;
exten => _XXXX,1,Macro(dialcnet,976${EXTEN})
;
[homies]
;
include => cnet
include => internal
;
exten => i,1,Macro(invalid)
;
[internal]
;
exten => s,1,Dial(ZAP/g1/00,360,tT) ; "switch" number dials 00 into trunks
                                    ; towards the legacy phone system
exten => s,2,Hangup
;
; First non-vacant DID is 976-9911
;
exten => 11,1,Goto(internal,s,1) ; re-routes incoming 976-9911 to "switch" number (00)
;
exten => 12,1,Macro(dialswitch,12) ; first normally routed number
;
exten => 13,1,Macro(dialswitch,13) 
;
exten => 14,1,Macro(dialswitch,14)
;
exten => 15,1,Macro(dialswitch,15)
;
exten => 16,1,Macro(dialswitch,16)
;
exten => 17,1,Macro(dialswitch,17)
;
exten => 18,1,Macro(dialswitch,18)
;
exten => 19,1,Macro(dialswitch,19)
;
; Invalid Extension
exten => i,1,Macro(invalid)
;
; Hangup
exten => h,1,Hangup
;
; Timeout
exten => t,1,congestion
;
;
[inbound]
;
; inbound sip calls
; New version of asterisk requires that 
; acct name be sent to an extension of
; the same name.
;
exten => 976-9900,1,Goto(internal,s,1) ; Main number goes to "switch" extension
; PBX extensions 01 through 10 not used,
; so they are omitted from this list.
;
exten => 9769911,1,Goto(internal,11,1)
exten => 9769912,1,Goto(internal,12,1)
exten => 9769913,1,Goto(internal,13,1)
exten => 9769914,1,Goto(internal,14,1)
exten => 9769915,1,Goto(internal,15,1)
exten => 9769916,1,Goto(internal,16,1)
exten => 9769917,1,Goto(internal,17,1)
exten => 9769918,1,Goto(internal,18,1)
exten => 9769919,1,Goto(internal,19,1)
exten => _97699XX,1,Macro(invalid) ; for incoming calls to vacant numbers.
;
