Special Extensions For External Calls

If we add features like call forwarding, we may wish to forward calls to outside lines, if the users are not present to answer their phones. Or, we may wish to define special extensions that place outside calls that can be accessed from the IVR menu (allowing an outside caller to select a number of predefined extensions, that turn around and place outside calls, is much safer than enabling DISA). Or, using IAX2 or VOIP, we may wish to define extensions that ring remote switches or faraway lands. There are a lot of reasons why one might want to define an extension (that can be used anywhere an extension can be used) that does something special.

We'll call this kind of extension a virtual extension, since it doesn't actually connect to any physical extension. We've chosen to enable this feature by setting a number of variables in the variables.conf file:

.

       .

; Pattern used to match any virtual extensions. This pattern should be ; defined whether you use virtual extensions or not. You can pick some ; bogus pattern (such as 999) if you don't use virtual extensions, but it ; should be OK the way it is.
;
; Optional switch that turns on virtual extensions from inside (i.e. local ; extensions).
;
; Optional switch used to let outside callers through to the inside so ; that they can dial the virtual extensions too. You may or may not want ; to do this, depending on what the virtual extensions do. VIRTPATTERN=8[0-8]X
VIRTINSIDE=1
VIRTOUTSIDE=1

These three variables define what the virtual extensions look like and whether they can be invoked from within the system and/or from outside the system. They are checked at the approprate places in ivr-menutree.conf and dahdi-extensions.conf. If virtual extensions are enabled, they are invoked wherever an extension is dialed by jumping to the virtual-extensions context, which we've chosen to encapsulate in a single file plan-virtualexts.conf.

/etc/asterisk/local/plan-virtualexts.conf:

     ; local/plan-virtualexts.conf - Dial plan for virtual extensions.
     ;
     ; This module is included at the appropriate spot in the dialplan (defined
     ; by extensions.conf).  It defines the dial plan for virtual extensions
     ; (i.e. special extensions that can make outside calls, connect to other
     ; Asterisk switches, make VOIP calls, etc.).
     ;
     ;
     ; Here we'll define a context with all of the virtual extensions.  Note
     ; that these extensions don't actually need to have any physical, local
     ; channel attached to them (hence the name virtual).  Instead, they may
     ; dial remote locations using IAX2, SIP or the PSTN.
     ;
     ; This context can be conditionally branched to by the IVR menu tree (if
     ; the virtual extensions are to be allowed from the outside lines) or by
     ; the local, inside lines, (if virtual extensions are to be allowed from
     ; inside lines).  For example:
     ;
     ;   exten => _${VIRTPATTERN},1,Gotoif($[${EXISTS(${VIRTOUTSIDE})}]?\
     ;                                     virtual-extensions,${EXTEN},1:)
     ;   exten => _${VIRTPATTERN},n,Playback(sorry2)
     ;   exten => _${VIRTPATTERN},n,Hangup()
     ;
     ; or
     ;
     ;   exten => _${VIRTPATTERN},1,Gotoif($[${EXISTS(${VIRTINSIDE})}]?\
     ;                                     virtual-extensions,${EXTEN},1:)
     ;   exten => _${VIRTPATTERN},n,Playback(sorry2)
     ;   exten => _${VIRTPATTERN},n,Hangup()
     ;
     ; This allows the outside lines to dial the virtual extensions and/or the
     ; local extensions to forward to or dial the virtual extensions.
     ;
     ; Virtual extensions can be used to dial complicated dialing sequences
     ; easily (i.e. like speed dial) or to transfer calls to outside phones
     ; via call forward or anywhere else you can use an extension.  But, beware
     ; the consequences if you open this up to the outside world and some yahoo
     ; figures out how to use it to their advantage.  In other words, think
     ; carefully about this before you open up DISA to the world.
     ;
     [virtual-extensions]
     ; The 801 virtual extension dials 201-123-4567 using the outside VOIP group.
     exten => 801,1,Goto(outside-virtgroup,2011234567,1)
     ; The 802 virtual extension dials 201-123-7654 using the outside VOIP group.
     exten => 802,1,Goto(outside-virtgroup,2011237654,1)
     ; The 810 virtual extension dials 416-123-4567 using the outside VOIP group.
     exten => 810,1,Goto(outside-virtgroup,4161234567,1)
     ; The 811 virtual extension dials 416-567-1234 using the outside VOIP group.
     exten => 811,1,Goto(outside-virtgroup,4165671234,1)
     ; In this context, we need to define the invalid extension, since the
     ; caller may enter one that is invalid.  Let's give them some kind of
     ; noncommittal error message.
     exten => i,1,Playback(sorry2)
     exten => i,n,Hangup()
     ;
     ; Context that defines the outside hunt group used by the virtual
     ; extensions.  This hunt group can be used by the virtual extensions to
     ; dial out on special lines (i.e. different from those used for regular
     ; outside dialing) only.  We could use a DAHDI group but this way we get
     ; to use lines out of order, resequence them at will, etc.
     ;
     [outside-virtgroup]
     exten => _X.,n,Dial(dahdi/12/${EXTEN})
     exten => _X.,1,Dial(dahdi/11/${EXTEN})
     exten => _X.,n,Playback(sorry2)
     exten => _X.,n,Hangup()