Iscriviti   Guestbook   Immagini   Forum   Download   Mappa   1482 utenti on line 
Italiano
MENU
CONFIGURAZIONI
RISORSE
INFO
Login

DOWNLOAD
Device
Suggerimenti

 

Extensions.conf - the dial plan of Asterisk

Extensions.conf is the main configuration file, that handles the dial plan for incoming calls and outbound calls in the Asterisk Open Source? PBX.
This is where you control the behaviour for all connections through your PBX.

Each extension is defined with one or more lines like this:
  exten => ,,)'>()

The priority field ranges the various definitions. Asterisk starts execution of an extension on the lowest priority. Some applications add values to priorities and thus forces Asterisk to jump over some definitions.

include 't' for callee to be able to transfer call, 'T' to allow caller to be able to transfer call & 'r' which fakes the ringing indication for the caller.
(NB Use of 't' &/or 'T' implies that Asterisk has to stay in the media path since it needs to listen out for the '#' keypress to initiate transfer.)

Defining contexts and extensions

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 form 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 including 9011)

For example the extenzion _NXXXXXX would match normal 7 digit dialings, while _1NXXNXXXXXX would represent an area code plus phone number preceeded by a one.

Special extensions

  • i: Invalid
  • s: Start
  • h?: Hangup
  • t: Timeout
  • T: AbsolutTimeout (use e.g. for Playback)



How Asterisk parses the dial plan


Asterisk will try to match the "normal" lines first, then included lines.

Ordering of matches in extensions.conf is irrelevant within contexts, except where "include" is concerned. All lines within a particular context are re-sorted upon loading into memory in numerical order. The only way you can force one set of matches ahead of another within a specific context is to split up the match statements and use 'include' to force their ordering. The 'include' statement will force matches to happen in the order in which the include lines are specified in extensions.conf, but you must "include" all possible matches if you want to truly force the ordering exactly the way you want. You can be safe only if matches against unique things like "h" or "fax" are made in the primary context.

Let's say we're passing a call into context foo that we want (in order of preference) the SIP extensions to be matched first, then if those aren't matched, we want to see if the number starts with a "9" and if so, send it out our Zap analog channel, and finally, if that doesn't match, we want to play a recording and hangup.

So, we put something like this together:


 [foo]
 exten => 1234,1,Dial(SIP/1234)
 exten => 9992,1,Dial(SIP/9992)
 exten => _9.,1,Dial(Zap/1/${EXTEN})
 exten => _.,1,Playback(sorry-no-match)
 exten => _.,2,Hangup
 exten => h,1,Hangup    ; we always include an "h" extension

But this doesn't work! As soon as we pass a number into the context, it matches successfully against _., and we get our sorry-no-match recording and the line hangs up. Here's how we force the ordering by using "include" to regulate order of matching:


 [foo]
 include => foo1
 include => foo2
 include => foo3
 exten => h,1,Hangup

 [foo1]
 exten => 1234,1,Dial(SIP/1234)
 exten => 9992,1,Dial(SIP/9992)

 [foo2]
 exten => _9.,1,Dial(Zap/1/${EXTEN})

 [foo3]
 exten => _.,1,Playback(sorry-no-match)
 exten => _.,2,Hangup



Use numeric suffixes at the end of the basename of the context for similar matches. Thus, if the main context is "foo", then "foo1, foo2, etc." would be the followup matches. You'll find that you may even have sub-sub contexts, and adding a dot and a number might make sense ("foo1.2, foo1.3" might be included in "foo1" if you get complex.)

Note that this example doesn't work with some types of dialing, such as match-as-you-go (commonly used for FXS/FXO interfaces) since those will try to run through the entire list of all included lines during each keypress. SIP phones, as an example, will work fine with this example since they send their entire dialstring all at once for matching, instead of allowing Asterisk to see each digit as it is typed into the keypad.

Variables and expressions

There is support for using variables using the ${VARIABLENAME} construct. You can also use expressions with the $[EXPRESSION] construct, where expressions can be regular expressions, comparision, addition, substraction and much more. .

Reloading

If you want to reload the dial plan after changes, without reloading all of Asterisk's config, use the extensions reload Asterisk CLI command.

One big file or several small?

With the #include statement in extensions.conf, other files are included. This way you can setup a system where extensions.conf is the main file, users.conf contain your local users, services.conf contain various services, like conferencing. This way, the dial plan may be easier to maintain, depending on the size of your setup. The #include statement is not the same as the include statement. The #include statement works in all Asterisk configuration files.

Forwarding to another Asterisk


Syntax:
  [iaxprovider]
  switch => IAX2/user:[key]@server/context

Specifies forwarding to another server. The user and key needs to be defined in the iax.conf file of the server which is called. The context is a context in the called servers extensions.conf.

 


Controlling extensions.conf from outside

  • Asterisk extensions from mysql
  • as with all .conf files you can use the #include statement to include another file

Examples

Using a macro to create extensions_
[globals]
PHONE1=Zap/1
PHONE2=SIP/6002

[macro-oneline]
exten => s,1,Dial(${ARG1},20,t)
exten => s,2,Voicemail(u${MACRO_EXTEN})
exten => s,3,Hangup
exten => s,102,Voicemail(b${MACRO_EXTEN})
exten => s,103,Hangup

[local]
exten => 6601,1,Macro(oneline,${PHONE1})
exten => 6602,1,Macro(oneline,${PHONE2})

Example files on the net




 

Valid CSS!