<?php
$host="localhost";
$username="admin";
$secret="amp111";
$socket = fsockopen($host,"5038", $errno, $errstr,10);
if (!$socket){
echo "$errstr ($errno)\n";
}else{
fputs($socket, "Action: Login\r\n");
fputs($socket, "UserName: $username\r\n");
fputs($socket, "Secret: $secret\r\n\r\n");
fputs($socket, "Action: WaitEvent\r\n");
fputs($socket, "Action: Logoff\r\n\r\n");
while(!feof($socket)){
$result=fread($socket,5000);
if (preg_match("/\b$argv[1]\b/i", $result, $match)){
$r=explode("\n",$result);
//catch the event name
$event=explode(" ",$r[0]);
echo "Event name is $event[1]\n";
//Match the Event
if (preg_match("/AgentCalled/","$event[1]")){
//extract parameters from AgentCalled
foreach( $r as $key=>$value){
echo " $key : $value\n";
}
//clean variables
$member=cleanstr($r[32]);
$queue=cleanstr($r[30]);
$descaller=cleanstr($r[19]);
$callerid=cleanstr($r[5]);
$linkedid=cleanstr($r[15]);
echo "$member\n";
echo "$queue\n";
echo "$descaller\n";
echo "$callerid\n";
echo "$linkedid\n";
echo count_chars($member,3);
//clean variables from special characters.We could use trim($var,"\r")
$member=trim($member);
$queue=trim($queue);
$descaller=trim($descaller);
$callerid=trim($callerid);
$linkedid=trim($linkedid);
//$postback=file_get_contents("http://65.181.118.232/code.php?id=$queue&pos=$member");
System("curl -X GET \"http://msn.com/Webservice1.asmx/GetDataFromAsterisk?Queue=$queue&MemberName=$member&DestCallerIdNum=$descaller&CallerIdNum=$callerid&Linkedid=$linkedid\"");
echo ("http://alterscheduler.kindlebit.com/Webservice1.asmx/GetDataFromAsterisk?Queue=$queue&MemberName=$member&DestCallerIdNum=$descaller&CallerIdNum=$callerid&Linkedid=$linkedid");
}
continue;
}
}
}
fclose($socket);
function cleanstr($var){
$var = explode(" ",$var);
$var=$var[1];
return($var);
}
?>
No hay comentarios:
Publicar un comentario