[Asterisk-Users] Hint: how to include dialplan files from remote systems

John Todd jtodd at loligo.com
Thu Dec 1 19:51:54 MST 2005


Every once in a while I find a nice, compact little project is good enough to share to the rest of the user community as a single post.  Here's something that I was happy worked as planned.  This is not particularly clever, but uses some infrequently-used tricks of running system commands from within Asterisk in two different ways: System and #exec.  File this away under the heading of "Not really clever, but impresses management."

I've got a user community who doesn't want to log into their Asterisk servers much, but they have general housekeeping tasks they want to perform on their dialplan which is really just mapping usernames to extension (for SIP tasks, so that "jwhorfin" ends up calling "Zap/g1/2939")  This shouldn't involve them doing anything other than updating a file somewhere.  They know how to put files on a webserver, so the trick was how to make them able to edit this file on their "easy-to-use" webserver and make it magically appear on the "somewhat opaque" Asterisk system.  I gave them a template file for them to store on their well-understood and internally accessible webserver, that they can edit with WordPad or other text editors.  This means that they don't have to learn any significant processes to update the list of user-to-number mappings if they know how to publish something on their webserver.  Here's the template example:


; -- Start File --
; Template for usernames-to-numbers
; 
; Save in the "privatefiles" directory of the public
;  webserver, accessible by anyone.
;
; Comments start with the semi-colon character
;
; After making changes on this list and saving it
;  to the webserver, you must call ext. 2900 to 
;  cause the Asterisk system to update itself 
;  with the contents of this file.
; 
[username-to-numbers]
exten => jwhorfin,1,Dial(Zap/g1/2939)
exten => rnevada,1,Dial(Zap/g1/2988)
;
; -- end file --
;


So, in the dialplan, here's what I do to include this file (note that the "echo" user is just to illustrate that other "names" can be included in the chain of contexts manually):

; ...more extensions.conf above here.
;
[from-internet]
;
; If any calls come in to user "echo", play back an echo test
;
exten => echo,1,Set(TIMEOUT(absolute)=500
exten => echo,n,Echo
;
; Now, include any users that have been configured by the client..
;
; (watch out for accidental line wraps here!  Next two lines start with "#")
#exec /usr/bin/curl -s http://webserver.domain.com/privatefiles/username-to-numbers > /etc/asterisk/username-to-numbers
#include username-to-numbers
include => username-to-numbers
;
;
; more extensions.conf below here...
;
;

Now, just as trivially clever is that in a different context (from their PBX) I can allow them to dial a "special" number that allows the administrator to re-load/re-parse this file at will:

;
[from-pbx]
;
exten => 2900,1,System(/usr/sbin/asterisk -rx "extensions reload")
;


Don't forget to add this set of 2 lines to asterisk.conf to allow the config files to execute commands with "#exec":

[options]
execincludes=yes

Good luck!

JT



More information about the asterisk-users mailing list