Hi,
I created a PHP Script for reverse lookup of callerids. The script looks up in a sqlite DB and the whole script is perfectly working in the command line:
#!/usr/bin/php
<?
error_reporting(0);
//set_time_limit(5);
require("./phpagi.php");
$agi = new AGI();
function resolve($nr){
$sqliteDb='./book.sqlite';
$db = new PDO('sqlite:'.$sqliteDb);
$no=preg_replace("#[^0-9]#","",$nr);//remove any non numeric characters
$name = "";
$row=$db->query("SELECT * FROM numbers WHERE home LIKE '%".$no."%' OR office LIKE '%".$no."%' OR mobile LIKE '%".$no."%' OR other LIKE '%".$no."%'");
$row=$row->fetchAll();
//var_dump($row);
if(count($row) >= 1){
$row2=$db->query("SELECT * FROM contacts WHERE numbers_id = '".$row[0]['id']."'");
$row2=$row2->fetchAll();
//var_dump($row2);
if(count($row2)>=1){
if ($row2[0]['surname'] || $row2[0]['lastname']) $name .= $row[0]['surname']." ".$row[0]['lastname'];
else $name .= $row2[0]['enterprise']." ";
}
}
else $name=$no;//else set calleridname to callerid numb
return $name;
}
//$agi->request[agi_callerid])
$agi->set_variable("lookupcid", resolve($agi->request['agi_callerid']));
//echo "AGI SAYS: ".$agi->get_variable("lookupcid");
exit;
?>
And this is what I wrote in the extensions.conf:
exten => xx0,1,NoOp(Incoming call)
exten => xx0,n,AGI(/var/www/sccp_phonebook/lookup.php)
exten => xx0,n,Set(CALLERID(name)=${lookupcid})
exten => xx0,n,Ringing
exten => xx0,n,Goto(from-trunk,${CUT(CUT(SIP_HEADER(To),@,1),:,2):2},1)
But Asterisk does not resolve this. The Debug output is:
Log:
-- Launched AGI Script /var/www/sccp_phonebook/lookup.php
<SIP/xx0-0000000e>AGI Tx >> agi_request: /var/www/sccp_phonebook/lookup.php
<SIP/xx0-0000000e>AGI Tx >> agi_channel: SIP/xx0-0000000e
<SIP/xx0-0000000e>AGI Tx >> agi_language: de
<SIP/xx0-0000000e>AGI Tx >> agi_type: SIP
<SIP/xx0-0000000e>AGI Tx >> agi_uniqueid: 1378338766.35
<SIP/xx0-0000000e>AGI Tx >> agi_version: 1.8.13.1~dfsg-3
<SIP/xx0-0000000e>AGI Tx >> agi_callerid: 9799
<SIP/xx0-0000000e>AGI Tx >> agi_calleridname: 9799
<SIP/xx0-0000000e>AGI Tx >> agi_callingpres: 0
<SIP/xx0-0000000e>AGI Tx >> agi_callingani2: 0
<SIP/xx0-0000000e>AGI Tx >> agi_callington: 0
<SIP/xx0-0000000e>AGI Tx >> agi_callingtns: 0
<SIP/xx0-0000000e>AGI Tx >> agi_dnid: xx0
<SIP/xx0-0000000e>AGI Tx >> agi_rdnis: unknown
<SIP/xx0-0000000e>AGI Tx >> agi_context: sipgate-in
<SIP/xx0-0000000e>AGI Tx >> agi_extension: xx0
<SIP/xx0-0000000e>AGI Tx >> agi_priority: 2
<SIP/xx0-0000000e>AGI Tx >> agi_enhanced: 0.0
<SIP/xx0-0000000e>AGI Tx >> agi_accountcode:
<SIP/xx0-0000000e>AGI Tx >> agi_threadid: -1281641360
<SIP/xx0-0000000e>AGI Tx >>
-- <SIP/xx0-0000000e>AGI Script /var/www/sccp_phonebook/lookup.php completed, returning 0
What’s going wrong?