Hello,
I’m using PHPAGI with Asterisk and my Aastra.
My problems is: I’m trying to parse the ip of the phone who is making a call, and called id, which the phone called.
Example:
exten => _91.,1,AGI(my_ip.php)
So whenever my phone calles 91xxx, the AGI script will start - Parse the IP of my phone and the number I called (example: 91555), and put it in variables, so i can use it in my XML script for Aastra.
I tried PHPAGI my_ip.php:
[quote]#!/usr/bin/php -q
<?php
set_time_limit(30);
require('phpagi.php');
function my_ip(&$agi, $peer)
{
$ip = 'unknown';
$asm = $agi->new_AsteriskManager();
if($asm->connect())
{
$peer = $asm->command("sip show peer $peer");
$asm->disconnect();
if(!strpos($peer['data'], ':'))
echo $peer['data'];
else
{
$data = array();
foreach(explode("\n", $peer['data']) as $line)
{
$a = strpos('z'.$line, ':') - 1;
if($a >= 0) $data[trim(substr($line, 0, $a))] = trim(substr($line, $a + 1));
}
}
if(isset($data['Addr->IP']))
{
$ip = explode(' ', trim($data['Addr->IP']));
$ip = $ip[0];
}
}
$agi->text2wav("Your IP address is $ip");
}
?> [/quote]
And I get this error:
-- Launched AGI Script /var/lib/asterisk/agi-bin/my_ip.php
AGI Tx >> agi_request: proba.php
AGI Tx >> agi_channel: SIP/800-08cf9f78
AGI Tx >> agi_language: en
AGI Tx >> agi_type: SIP
AGI Tx >> agi_uniqueid: 1205828466.54
AGI Tx >> agi_callerid: 800
AGI Tx >> agi_calleridname: 800
AGI Tx >> agi_callingpres: 0
AGI Tx >> agi_callingani2: 0
AGI Tx >> agi_callington: 0
AGI Tx >> agi_callingtns: 0
AGI Tx >> agi_dnid: 706
AGI Tx >> agi_rdnis: unknown
AGI Tx >> agi_context: office
AGI Tx >> agi_extension: 706
AGI Tx >> agi_priority: 2
AGI Tx >> agi_enhanced: 0.0
AGI Tx >> agi_accountcode:
AGI Tx >> LI>
AGI Rx << I>
AGI Tx >> 510 Invalid or unknown command
– AGI Script proba.php completed, returning 0
I think it stopes at: function my_ip(&$agi, $peer)
I have no idea why.
Could somebody help me?[/i]
I’ve got it:
#!/usr/bin/php -q
<?php
require 'phpagi.php';
$agi = new AGI();
$ip = 'unknown';
$asm = $agi->new_AsteriskManager();
if($asm->connect())
{
$stev = $agi->request["agi_callerid"];
$peer = $asm->command("sip show peer $stev");
$asm->disconnect();
if(!strpos($peer['data'], ':'))
echo $peer['data'];
else
{
$data = array();
foreach(explode("\n", $peer['data']) as $line)
{
$a = strpos('z'.$line, ':') - 1;
if($a >= 0) $data[trim(substr($line, 0, $a))] = trim(substr($line, $a + 1));
}
}
if(isset($data['Addr->IP']))
{
$ip = explode(' ', trim($data['Addr->IP']));
$ip = $ip[0];
}
if(isset($data['Def. Username']))
{
$ext = explode(' ', trim($data['Def. Username']));
$ext = $ext[0];
}
}
$sperma = $agi->request["agi_dnid"];
$agi->text2wav("Your IP address is $ip and your number is $ext and you called $sperma");
?>
Works perfectly. Thank me for all the help