Softpanorama

May the source be with you, but remember the KISS principle ;-)
Home Switchboard Unix Administration Red Hat TCP/IP Networks Neoliberalism Toxic Managers
(slightly skeptical) Educational society promoting "Back to basics" movement against IT overcomplexity and  bastardization of classic Unix

Extensions.conf

News Asterisk Recommended Links Context Inclusion  Dialplan Patterns Dialplan debugging
Lua Dialplan Programming Constructs Asterisk variables Simple menu programming Queue Voicemail
Users, Peers and Friends   Troubleshooting Festival Humor Etc

Adapted from Asterisk config extensions.conf - voip-info.org. You are encouraged to read the original first as some material is omitted  to simplify presentation. Attempt was made to reformulate the concepts in term of subroutines, which are probably more understandable to programmers who get used to languages such as C, Java, Perl, etc.

The configuration file "extensions.conf" contains so called "dial plan" of Asterisk. This is ad hoc scripting language that provides idiosyncratic (pretty obscure) way of  specifying control flow and operations of Asterisk PBX.  Program in this language specified in extensions.conf  controls how incoming and outgoing calls are handled and routed.  In version 1.6 dialplan can be programmed in Lua which I highly recommend ( see lua.sample ). It requires a new module that was developed by Matt Nicholson of Digium

The content of "extensions.conf" is organized in sections, which can be either for static settings and definitions, or for executable dialplan components in which case they are referred to as Asterisk context.

Every user-defined context section in extensions.conf starts with the name of the section contained within square brackets somewhat similar to Windows .ini file format.  Simplifying we can view context as a group of extensions. Only those extensions that exist in particular context can be dialed from the channel that uses it  (channels are defined in sip.conf and can be viewed as devices connected to you VIOP network. In other words each extension exists within a particular context.

Tip:

[general]

[globals] User defined contexts

Context Inclusion

One extension context can include the contents of another. For example, consider the following contexts:

Context "default":
Extension Description
101 Mark Spencer
102 Wil Meadows
0 Operator

Context "local":
Extension Description
_9NXXXXXX Local calls
include => "default"

Context "longdistance":
Extension Description
_91NXXNXXXXXX Long distance calls
include => "local"

Here we have defined three extensions:

Using extension contexts, you need carefully control who has access to toll services.

If more than one pattern matches a dialed number, Asterisk may not use the one you expect. See Sort Order of Extension Patterns.

Adding to an existing section (I believe this is a 1.4 feature; additional info on similar option are in doc/configuration.txt of asterisk src tree)

[section]
label = value

[section](+)
label2 = value2

In this case, the plus sign indicates that the second section (with the same name) is an addition to the first section. The second section can be in another file (by using the #include statement). If the section name referred to before the plus is missing, the configuration will fail to load.

When Asterisk receives an incoming connection on a channel, Asterisk call the subroutune -- the context defined for that channel. This subroutine contains set of extension that are availble for anybody who dial this channel.

In turn the context consists of several subroutines, each defining one or multipole extentions.

For some kinds of connections - such incoming calls from an outside telephone line - the user has not dialed an extension. In that case, Asterisk behaves as if the user had dialed a special extension named "s" (for Start). Asterisk will look for an extension "number" s in the definition of the context for that channel for instructions about what it should do to handle the call.

Let's say, for example, that you have a channel "Incoming" which is a connection from your VOIP provider. The condfigation file for SIP channels is sip.conf. In it you need to define context=incoming. So when you call from your cell phone this number, Asterisk will lookup the context with the name "incoming" in extensions.conf to find out what it should do with the call:

[incoming]

Within this context Asterisk will try to find subroutine that corresponds to the extention dialed.

This subroutine connects the call with the other phone or mailbox and/or perform additional actions on the call It usually ends the command Handup.

A set of extensions defined in each context of extension.conf can consists of members of two types:
See Asterisk standard extensions for details.

Extention definition in Asterisk is a subroutine which specifies set of commands to execute. Like in eary Fortran command are generally executed in the order defined by their labels called "priority" tag. Some commands, such as the Dial and GotoIf commands, have the ability to redirect somewhere else, based on some condition.

When an extension is dialed, the command tagged with a priority of 1 is executed, followed by command priority 2, and so on. This goes on until:

In the syntax of the extensions.conf file, each execution step in an extension is written in this format:

exten = extension,priority,Command(parameters)

where the equal sign can also be ornamented as an arrow, i.e., "=>", a form most often seen in many examples.
The components of an extension execution step or command line are the following:

Note: Auto increment n can be used instead of numeric priorities other then 1 (see Asterisk standard extensions), for example:

exten => 123,1,Answer
exten => 123,n,Playback(welcome)
exten => 123,n,Voicemail(44)
exten => 123,n,Hangup

This is the definition of a single extension with name "123". When a call is made to extension 123, Asterisk will answer the call itself, play a sound file called "welcome", give the user an opportunity to leave a voicemail message for mailbox 44, and then hang-up.

Other options for defining extensions include an option commonly referred to as the ex-girlfriend logic. This logic will match the dialed extension, whether it came from outside or inside, based on the callerid of the person calling it. For example:

exten => 123/100,1,Answer()
exten => 123/100,2,Playback(tt-weasels)
exten => 123/100,3,Voicemail(123)
exten => 123/100,4,Hangup()

This will match extension 123 and perform the following options ONLY if the Caller-ID Number of the calling user is 100. This can also be accomplished with pattern matching, as seen below:

exten => 1234/_256NXXXXXX,1,Answer()
and so on...

This will only match for 1234 if the Caller ID Number is something beginning with 256. This is very useful to keep locals from dialing your toll-free number and charging you for the call.

You can even do this:

exten => s,1,Answer
exten => s/9184238080,2,Set(CALLERID(name)=EVIL BASTARD)
exten => s,2,Set(CALLERID(name)=Good Person)
exten => s,3,Dial(SIP/goodperson)

Basically the call comes in, at 2 you change callerID for the people you don't like out, everybody else stays in the path and at 3 everybody is back in the main path.

Syntax for defining a context: keywords exten, include, ignorepat and switch.

Reloading

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

Either connect to your asterisk process with asterisk -r or rasterisk and type in the command, or send the command directly with:

asterisk -rx 'dialplan reload'

Macro 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})

NEWS CONTENTS

Old News

Asterisk config extensions.conf - voip-info.org

Hi
I need to add a line which will let callers to enter * if they have made a mistake entering the extension.

for example if they have entered 123 and they want to clear it all and enter 1245

by amirsp55, Wednesday 28 of May, 2008 [17:39:01]

Re: Extentions


It's pretty simple to manipulate sip extensions with Asterisk. I see no one answered this so here's the soluion...

; --- user dials 9+ and we manipulate dialled digits ---

; --- just wait two seconds before dialling the extension ---
exten => _9.,1,Wait(2)

; --- prefix + and strip off user dialled 9 then place call for two seconds ---
exten => _9.,n,Dial(SIP/+${EXTEN:1}@sipcarrier,2)

; --- prefix + and strip off user dialled 9 then place call to othersipcarrier ---
exten => _9.,n,Dial(SIP/+${EXTEN:1}@othersipcarrier)

Recommended Links



Etc

Society

Groupthink : Two Party System as Polyarchy : Corruption of Regulators : Bureaucracies : Understanding Micromanagers and Control Freaks : Toxic Managers :   Harvard Mafia : Diplomatic Communication : Surviving a Bad Performance Review : Insufficient Retirement Funds as Immanent Problem of Neoliberal Regime : PseudoScience : Who Rules America : Neoliberalism  : The Iron Law of Oligarchy : Libertarian Philosophy

Quotes

War and Peace : Skeptical Finance : John Kenneth Galbraith :Talleyrand : Oscar Wilde : Otto Von Bismarck : Keynes : George Carlin : Skeptics : Propaganda  : SE quotes : Language Design and Programming Quotes : Random IT-related quotesSomerset Maugham : Marcus Aurelius : Kurt Vonnegut : Eric Hoffer : Winston Churchill : Napoleon Bonaparte : Ambrose BierceBernard Shaw : Mark Twain Quotes

Bulletin:

Vol 25, No.12 (December, 2013) Rational Fools vs. Efficient Crooks The efficient markets hypothesis : Political Skeptic Bulletin, 2013 : Unemployment Bulletin, 2010 :  Vol 23, No.10 (October, 2011) An observation about corporate security departments : Slightly Skeptical Euromaydan Chronicles, June 2014 : Greenspan legacy bulletin, 2008 : Vol 25, No.10 (October, 2013) Cryptolocker Trojan (Win32/Crilock.A) : Vol 25, No.08 (August, 2013) Cloud providers as intelligence collection hubs : Financial Humor Bulletin, 2010 : Inequality Bulletin, 2009 : Financial Humor Bulletin, 2008 : Copyleft Problems Bulletin, 2004 : Financial Humor Bulletin, 2011 : Energy Bulletin, 2010 : Malware Protection Bulletin, 2010 : Vol 26, No.1 (January, 2013) Object-Oriented Cult : Political Skeptic Bulletin, 2011 : Vol 23, No.11 (November, 2011) Softpanorama classification of sysadmin horror stories : Vol 25, No.05 (May, 2013) Corporate bullshit as a communication method  : Vol 25, No.06 (June, 2013) A Note on the Relationship of Brooks Law and Conway Law

History:

Fifty glorious years (1950-2000): the triumph of the US computer engineering : Donald Knuth : TAoCP and its Influence of Computer Science : Richard Stallman : Linus Torvalds  : Larry Wall  : John K. Ousterhout : CTSS : Multix OS Unix History : Unix shell history : VI editor : History of pipes concept : Solaris : MS DOSProgramming Languages History : PL/1 : Simula 67 : C : History of GCC developmentScripting Languages : Perl history   : OS History : Mail : DNS : SSH : CPU Instruction Sets : SPARC systems 1987-2006 : Norton Commander : Norton Utilities : Norton Ghost : Frontpage history : Malware Defense History : GNU Screen : OSS early history

Classic books:

The Peter Principle : Parkinson Law : 1984 : The Mythical Man-MonthHow to Solve It by George Polya : The Art of Computer Programming : The Elements of Programming Style : The Unix Hater’s Handbook : The Jargon file : The True Believer : Programming Pearls : The Good Soldier Svejk : The Power Elite

Most popular humor pages:

Manifest of the Softpanorama IT Slacker Society : Ten Commandments of the IT Slackers Society : Computer Humor Collection : BSD Logo Story : The Cuckoo's Egg : IT Slang : C++ Humor : ARE YOU A BBS ADDICT? : The Perl Purity Test : Object oriented programmers of all nations : Financial Humor : Financial Humor Bulletin, 2008 : Financial Humor Bulletin, 2010 : The Most Comprehensive Collection of Editor-related Humor : Programming Language Humor : Goldman Sachs related humor : Greenspan humor : C Humor : Scripting Humor : Real Programmers Humor : Web Humor : GPL-related Humor : OFM Humor : Politically Incorrect Humor : IDS Humor : "Linux Sucks" Humor : Russian Musical Humor : Best Russian Programmer Humor : Microsoft plans to buy Catholic Church : Richard Stallman Related Humor : Admin Humor : Perl-related Humor : Linus Torvalds Related humor : PseudoScience Related Humor : Networking Humor : Shell Humor : Financial Humor Bulletin, 2011 : Financial Humor Bulletin, 2012 : Financial Humor Bulletin, 2013 : Java Humor : Software Engineering Humor : Sun Solaris Related Humor : Education Humor : IBM Humor : Assembler-related Humor : VIM Humor : Computer Viruses Humor : Bright tomorrow is rescheduled to a day after tomorrow : Classic Computer Humor

The Last but not Least Technology is dominated by two types of people: those who understand what they do not manage and those who manage what they do not understand ~Archibald Putt. Ph.D


Copyright © 1996-2021 by Softpanorama Society. www.softpanorama.org was initially created as a service to the (now defunct) UN Sustainable Development Networking Programme (SDNP) without any remuneration. This document is an industrial compilation designed and created exclusively for educational use and is distributed under the Softpanorama Content License. Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.

FAIR USE NOTICE This site contains copyrighted material the use of which has not always been specifically authorized by the copyright owner. We are making such material available to advance understanding of computer science, IT technology, economic, scientific, and social issues. We believe this constitutes a 'fair use' of any such copyrighted material as provided by section 107 of the US Copyright Law according to which such material can be distributed without profit exclusively for research and educational purposes.

This is a Spartan WHYFF (We Help You For Free) site written by people for whom English is not a native language. Grammar and spelling errors should be expected. The site contain some broken links as it develops like a living tree...

You can use PayPal to to buy a cup of coffee for authors of this site

Disclaimer:

The statements, views and opinions presented on this web page are those of the author (or referenced source) and are not endorsed by, nor do they necessarily reflect, the opinions of the Softpanorama society. We do not warrant the correctness of the information provided or its fitness for any purpose. The site uses AdSense so you need to be aware of Google privacy policy. You you do not want to be tracked by Google please disable Javascript for this site. This site is perfectly usable without Javascript.

Last modified: March 12, 2019