Here’s the allpage.agi
#!/usr/bin/perl -w
#
# allpage.agi - Copyright Rob Thomas ([email protected]) 2005.
#
# Revision 1.1 - 14th October 2005 - Added Polycom Support
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of Version 2 of the GNU General
# Public License as published by the Free Software Foundation
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# Simple AGI to page all SIP extensions (no IAX device, because at the time
# of writing this, no device supported IAX_ANSWER_IMMED) that aren't on
# the phone. Tested with Asterisk 1.2. Should work out-of-the-box with
# Grandstream GXP phones with firmware greater than 1.0.12, and Snoms with
# 'enable intercom' on and 'filter packets from registrar' off.
#
# Documentation:
# Your dialplan consists of two things. Firstly, in the context that your
# normal phones are in, you need to have something like this:
# exten => 999,1,AGI,allpage.agi
# exten => 999,2,MeetMe(999,dq)
# exten => 999,3,Playback(beep)
# exten => 999,4,Hangup
#
# The paged phones then jump to this context:
# all-page
# exten => s,1,AbsoluteTimeout(10)
# exten => s,2,MeetMe(999,dmq)
# exten => s,3,Hangup
# exten => t,1,Hangup
# exten => T,1,Hangup
#
# Any questions? Join
#openpbx on irc.freenode.net
# --Rob Thomas 28th Sep, 2005.
use Net::Telnet;
# You need to configure this: Your manager API username and password. This
# is the information from /etc/asterisk/manager.conf. You need something like
# this in it:
# admin
# secret = amp111
# deny=0.0.0.0/0.0.0.0
# permit=127.0.0.0/255.255.255.0
# read = system,call,log,verbose,command,agent,user
# write = system,call,log,verbose,command,agent,user
# IF that's what you have in your conf file, this is what you should have here:
my $mgruser = "admin";
my $mgrpass = "amp111";
my $mgrport = 5038;
# If you're using a SNOM they need a 'sip:ip.add.re.ss' added to the Call-Info field,
# with the IP address of the registrar. Most other phones will silently ignore this,
# but if you have trouble, you may need to fiddle with this line. Change the IP Address
# to be that of your Asterisk Server.
#my $callinfo = 'Call-Info: sip:10.10.100.1\; answer-after=0';
# This is for Polycom phones - see
# http://www.voip-info.org/tiki-index.php?page=Polycom+auto-answer+config
#my $alertinfo = 'Alert-Info: Ring Answer';
# AASTRA Phones
my $alertinfo = 'Call-Info: sip:\;answer-after=0'
# That's it. Nothing else should need to be changed
# Some variables we use later...
my @tocall;
my %useref;
# If you don't want any intelligence, you can just delete all the logic above
# here, and specify the SIP extensions to call here. Also useful for debugging.
#@tocall = (1000,1003,1004,1006,1007,1008,1009,1012,1013,1015,1021,1027,1033,1035,1037,1038,1040,1041);
@tocall = (2995);
# Now, we have an array (@tocall) with all valid SIP extensions.
while (my $sipxtn = shift @tocall)
{
# Open connection to AGI
my $tn = new Net::Telnet ( Port => $mgrport, Prompt => '/.*$%#> $/', Output_record_separator => '', Errmode => 'return', );
$tn->open("127.0.0.1");
$tn->waitfor('/0\n$/');
$tn->print("Action: Login\n");
$tn->print("Username: $mgruser\n");
$tn->print("Secret: $mgrpass\n");
$tn->print("Events: off\n\n");
my ($pm, $m) = $tn->waitfor('/Authentication (.+)\n\n/');
if ($m =~ /Authentication failed/)
{
print "VERBOSE \"Incorrect MGRUSER or MGRPASS - unable to connect to manager interface\" 0\n";
exit;
}
$tn->print("Action: Originate\nChannel: SIP/$sipxtn\nContext: all-page\nPriority: 1\n");
#$tn->print("Variable: SIPADDHEADER=\"$callinfo\"\n");
$tn->print("Variable: SIPADDHEADER=\"$alertinfo\"\n");
$tn->print("Variable: SIPADDHEADER=\"$callinfo\"\n");
$tn->print("Extension: s\nCallerID: SYSTEM PAGE\n\n");
$tn->print("Action: Logoff\n\n");
$tn->close;
}