[Asterisk-Users] Extension vs. Mailbox numbers and an example of an AGI script...

Tim Pozar pozar at lns.com
Sat Jan 28 20:08:47 MST 2006


I have users with multiple extensions (ie. office, home, etc.) and I
wanted my users to have only one mail box for all of these extensions.
Perhaps I didn't see it in the Asterisk docs and I have bastardized the
sip.conf but I did the following.  Constructive flames appreciated.

Tim

In sip.conf the mailbox line shows the common mailbox number (ie "1015")
with the optional context:
[...]
[1015]
type=friend
username=1015
callerid = Tim Pozar <1015>
secret=HACKME
host=dynamic
nat=yes
context=default
canreinvite=no
mailbox=1015

[1078]
type=friend
username=1078
secret=HACKME
host=dynamic
nat=yes
context=default
canreinvite=no
mailbox=1015 at default
callerid=Tim Pozar HOME <1078>
[...]

In extesions.conf I run an AGI that goes out and gets the mailbox
numberr and passes it to the Voicemail and VoicemailMain commands...

[...]
exten=_1XXX,1,dial(SIP/${EXTEN},20,tr)
exten=_1XXX,2,Wait,1
exten=_1XXX,3,agi(parse_asterisk_sip_conf.agi|${EXTEN}|mailbox)
exten=_1XXX,4,Voicemail(u${MAILBOX})
exten=_1XXX,5,Hangup

exten => 8500,1,Answer
exten => 8500,2,Wait,1
exten => 8500,3,agi(parse_asterisk_sip_conf.agi|${CALLERIDNUM}|mailbox)
exten => 8500,4,VoicemailMain(${MAILBOX})
exten => 8500,5,Hangup
[...]

parse_asterisk_sip_conf.agi looks like this...
---
#!/usr/bin/perl
use strict;

#####################################################
# Parses the sip config to pass back the mailbox number.
# There should be more error checking in this script.
#
# Tim Pozar - Sat Jan 28 18:22:40 PST 2006
#####################################################

$|=1;

my $asterisk_conf_dir = "/etc/asterisk";
my $sip_conf = "$asterisk_conf_dir/sip.conf";
my $value = "9999";
my $sip_extennum = $ARGV[0];
my $sip_variable = $ARGV[1];
my $variablename;
my %AGI;

while(<STDIN>) {
   chomp;
   last unless length($_);
   if (/^agi_(\w+)\:\s+(.*)$/) {
      $AGI{$1} = $2;
   }
}

open(CONF, "$sip_conf") || die "can't open $sip_conf";
while (<CONF>) {
   chop;
   if ((!/^;/) && (!/^#/)) {   # Skip comments at the start of lines
      if (/^\[$sip_extennum\]/) {
         $_ = <CONF>;
         chop;
         while ((!/^\[/)){
            if (/^$sip_variable/) {
               ($variablename, $value) = split('=');
               last;
            }
            $_ = <CONF>;
            chop;
         }
      }
   }
}

# Make sure you pass back something and not just a blank.  Asterisk
# doesn't like that.

$variablename = uc($variablename);	

print "SET VARIABLE $variablename $value\n\n";
exit 0
---
-- 
1978 45th Ave / San Francisco CA 94116 / USA // POTS: +1 415 665 3790
 GPG Fingerprint: 4821 CFDA 06E7 49F3 BF05  3F02 11E3 390F 8338 5B04
                Life is playful - Ben Olizar
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pozar.vcf
Type: text/x-vcard
Size: 413 bytes
Desc: not available
Url : http://lists.digium.com/pipermail/asterisk-users/attachments/20060128/8cf71f79/pozar.vcf


More information about the asterisk-users mailing list