<?php
require("setting.php");
$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);
$result.=date("Y-m-d H:i:s");
$events=array("HangupRequest","MusicOnHoldStart","MusicOnHoldStop");
foreach($events as $value) {
if (preg_match("/\b$value\b/i", $result, $match)){
if (preg_match("/\bHangupRequest\b/i", $result, $match)){
$elements=explode("\n",$result);
foreach($elements as $key=>$value) {
echo "$key $value\n";
$message="You have missed call from number $elements[5]\n to extension $elements[7] at $elements[17]";
}
$num=explode(" ",$elements[5]);
$extensions=array(1001,101,1005);
if(in_array($num[1],$extensions)){
mail("ambiorixg12@gmail.com"," You have a missed call from $num[1]",$message);
}
}
}
continue;
}
}
}
fclose($socket);
?>
No hay comentarios:
Publicar un comentario