Parsing ip and calledid with AGI

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:

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 :smile: