<?php
header('Content-Type: application/json'); $arr=array(); $agent=$_GET['agent']; $socket = fsockopen("127.0.0.1","7831", $errno, $errstr,60); if (!$socket){ echo "$errstr ($errno)\n"; }else{ fputs($socket, "Action: Login\r\n"); fputs($socket, "UserName: admin\r\n"); fputs($socket, "Secret: 113333333\r\n\r\n"); fputs($socket, "Action: ConfbridgeList\r\n"); fputs($socket, "Conference: $agent\r\n\r\n"); fputs($socket, "Action: Logoff\r\n\r\n"); while (!feof($socket)){ // echo fgets($socket).'<br>'; $arr[]=fgets($socket); } fclose($socket); } foreach($arr as $key=>$value){ //echo "$key - $value<br>"; // to show all values if(substr_count($value,"hold")){ ///search value $arr['channel']= explode(" ",$value)[1]; //grab the exact info } } if (isset($arr['channel'])) { echo json_encode(array('channel' => trim($arr['channel']))); //foreach($arr as $k=>$v){ //echo "$k:$v"; //} } else { // If the channel does not exist, create an error message and encode $arr $arr['e'] = "No conference channel found"; echo json_encode(array('e' => $arr['e'])); } ?>
No hay comentarios:
Publicar un comentario