[Asterisk-Users] paging agi
Tzafrir Cohen
tzafrir at cohens.org.il
Fri Jan 27 01:21:00 MST 2006
Hi
Some petty notes notes regarding the perl:
On Thu, Jan 26, 2006 at 11:23:27PM -0800, Jeremy wrote:
1. you didn't use strict and -w. Debugging will be a whole lot tougher
2. Consider using the nagging -T (taint mode), to explicitly know when
you trust the input.
3. Consider the latency this cases. Note that this script is run at the
startup of every call. Let's see what it does:
> #
> #Check for Telnet
> if (eval "require Net::Telnet;") {
> use Net::Telnet;
> } else {
> print "VERBOSE \"Net::Telnet NOT INSTALLED - this is required\"
> 0\n";
> exit 0;
> }
Just use:
use Net::Telnet;
This will generate a compile-time (perl -c) check which is easy to test
automatically.
BTW: why not use an existing perl module to talk to
>
> # 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.0.0.0
> # read = system,call,log,verbose,command,agent,user
> # write = system,call,log,verbose,command,agent,user
Now, why generate entries to talk to the the manager interface on
localhost with full the permissions? Are all of those permissions
necessary?
Wouldn't it make more sense to send commands directly to the unix domain
socket of Asterisk? Basically you connect there and send separate
commands in separate writes.
> # 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;
> # set our array of phones that we will NOT be paging
> @bypass = @ARGV;
> # Get our needed info for idle sip phones
> @sips = grep(/^\s+\d+\s.*/, `asterisk -rx "show hints"`);
ah, but you do use it, indirectly. Why not get that information from the
manager interface?
>
> # Now check each sip phone to see if it's in use and also
> # against our exclude list. If it passes both, it's
> # added to our array of calls to make
>
> foreach $sipline (@sips) {
> my ($junk0, $exten, $junk1, $chan, $state, $junk2) = split(/ +/,
> $sipline,6);
>
> unless (($state ne "State:Idle") || (grep(/$exten/i, @bypass))) {
> push (@mypage, "$exten");
>
> }
> }
> $page= join ("&SIP/", @mypage);
> print "$page";{
>
> # Open connection to AGI and set Global Variable PAGE_GROUP
> # to our completed array of sip phones
> my $tn = new Net::Telnet ( Port => $mgrport,
> Prompt => '/.*[\$%#>] $/',
> Output_record_separator => '',
> Input_Log=> "/tmp/input.log",
> Output_Log=> "/tmp/output.log",
> 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: Setvar\n");
> $tn->print("Variable: PAGE_GROUP\n");
> $tn->print("Value: $page\n\n");
> $tn->print("Action: Logoff\n\n");
> $tn->close;
> }
>
> Then add the following to your dialplan:
>
> exten => *61,1,Set(TIMEOUT(absolute) = 15)
> exten => *61,n,AGI(page.agi|<arg>|<arg>)
> exten => *61,n,SetCallerID("Page:${CALLERIDNAME}" <${CALLERIDNUM}>)
> exten => *61,n,Set(_ALERT_INFO="Ring Answer")
> exten => *61,n,SIPAddHeader(Call-Info: answer-after=0)
> exten => *61,n,Page(SIP/${PAGE_GROUP})
> exten => *61,n,Hangup()
I really don't see why you need to connect to the manager just to set a
global variable. You can easily do that from the dialplan or from the
AGI itself. Or am I missing anything?
--
Tzafrir Cohen | tzafrir at jbr.cohens.org.il | VIM is
http://tzafrir.org.il | | a Mutt's
tzafrir at cohens.org.il | | best
ICQ# 16849755 | | friend
More information about the asterisk-users
mailing list