|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
function GetSocket($host, $port, $login, $pass, &$erro)
|
|
|
|
|
{
|
|
|
|
|
$port = empty($port ) ? "5038" : $port;
|
|
|
|
|
$errno = 0;
|
|
|
|
|
$errstr = "";
|
|
|
|
|
$erro = "";
|
|
|
|
|
$tentaConexao = 0;
|
|
|
|
|
$timeout = 10;
|
|
|
|
|
|
|
|
|
|
// $socket = fsockopen("192.168.80.13","5038", $errno, $errstr, $timeout);
|
|
|
|
|
|
|
|
|
|
$socket = @fsockopen($host, $port, $errno, $errstr, $timeout);
|
|
|
|
|
if(!$socket)
|
|
|
|
|
{
|
|
|
|
|
$erro = "N<EFBFBD>o foi poss<EFBFBD>vel estabelecer uma conex<EFBFBD>o com o servidor! Erro: N<EFBFBD>: $errno Msg:$errstr ";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fwrite($socket, "action: login\r\n");
|
|
|
|
|
fwrite($socket, "username: $login\r\n");
|
|
|
|
|
fwrite($socket, "secret: $pass\r\n");
|
|
|
|
|
fwrite($socket, "Events: off\r\n");
|
|
|
|
|
$actionid=rand(000000000,9999999999);
|
|
|
|
|
fwrite($socket, "actionid: ".$actionid."\r\n\r\n");
|
|
|
|
|
usleep(500);
|
|
|
|
|
|
|
|
|
|
while (!feof($socket))
|
|
|
|
|
{
|
|
|
|
|
$buffer=fgets($socket);
|
|
|
|
|
if(stristr($buffer,"Authentication accepted"))
|
|
|
|
|
{
|
|
|
|
|
$erro = "";
|
|
|
|
|
return $socket;
|
|
|
|
|
}
|
|
|
|
|
elseif(stristr($buffer,"Authentication failed"))
|
|
|
|
|
{
|
|
|
|
|
$erro = "N<EFBFBD>o foi poss<EFBFBD>vel se logar-se no servidor!";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else if($tentaConexao == MAX_CONECT_SOCKET)
|
|
|
|
|
{
|
|
|
|
|
$erro = "N<EFBFBD>o foi poss<EFBFBD>vel se logar-se no servidor, o n<EFBFBD>mero m<EFBFBD>ximo de tentavas foi excedido!";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
$tentaConexao++;
|
|
|
|
|
usleep(500000);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function GetDataSocket($socket, $comando, $evento, &$dataInfo)
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
* O array "chaves" determina os valores que v<EFBFBD>o ser recuperados,
|
|
|
|
|
* o <EFBFBD>ndice "0"($chaves[0]) <EFBFBD> o valor que representa o in<EFBFBD>cio
|
|
|
|
|
* do bloco de informa<EFBFBD><EFBFBD>es ex.:
|
|
|
|
|
* $chaves = array("Agents", "Agent");
|
|
|
|
|
* Primeira linha do bloco = "Event: Agents"
|
|
|
|
|
* $chave[0] = "Agents"; //In<EFBFBD>cio de bloco
|
|
|
|
|
* Segunda linha do bloco = Agent: 1000
|
|
|
|
|
* $chave[1] = "Agent"; //retorna o valor "1000"
|
|
|
|
|
*/
|
|
|
|
|
$buffer = "";
|
|
|
|
|
$evt_fim = trim($evento);
|
|
|
|
|
$linhas = 0;
|
|
|
|
|
$actionid=rand(000000000,9999999999);
|
|
|
|
|
$actionid="actionid: ".$actionid."\r\n";
|
|
|
|
|
$cmd .= $comando . $actionid."\r\n";
|
|
|
|
|
fwrite($socket, $cmd);
|
|
|
|
|
usleep(500);
|
|
|
|
|
$idx = -1;
|
|
|
|
|
|
|
|
|
|
while(!feof($socket))
|
|
|
|
|
{
|
|
|
|
|
$buffer = trim(fgets($socket));
|
|
|
|
|
|
|
|
|
|
if(stristr($buffer,$evt_fim))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else if(!empty($buffer))
|
|
|
|
|
{
|
|
|
|
|
$dataInfo[] = $buffer;
|
|
|
|
|
}
|
|
|
|
|
//Garante que o script nao vai rodar infinitamente
|
|
|
|
|
if(trim($buffer) == "")
|
|
|
|
|
{
|
|
|
|
|
$linhas++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if($linhas > 30)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function GetInfoDataSocket($source,$chaves)
|
|
|
|
|
{
|
|
|
|
|
$buffer = "";
|
|
|
|
|
$chave = "";
|
|
|
|
|
$value = "";
|
|
|
|
|
$ch = array();
|
|
|
|
|
$dataInfo = array();
|
|
|
|
|
|
|
|
|
|
foreach($source as $buffer)
|
|
|
|
|
{
|
|
|
|
|
$ch = split(':', $buffer);
|
|
|
|
|
$chave = trim($ch[0]);
|
|
|
|
|
$value = trim($ch[1]);
|
|
|
|
|
|
|
|
|
|
if($value == $chaves[0])
|
|
|
|
|
$idx++;
|
|
|
|
|
|
|
|
|
|
if($chaves && array_search($chave, $chaves))
|
|
|
|
|
$dataInfo[$idx][$chave] = $value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $dataInfo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function GetSatatusAgt($status)
|
|
|
|
|
{
|
|
|
|
|
if($status == "")
|
|
|
|
|
return "Ocupado";
|
|
|
|
|
else if($status == "Livre")
|
|
|
|
|
return "";
|
|
|
|
|
else if($status == "Pausa")
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
function GetInfoSoket($socket, $comando, $evento, $chaves)
|
|
|
|
|
{
|
|
|
|
|
*
|
|
|
|
|
* O array "chaves" determina os valores que v<EFBFBD>o ser recuperados,
|
|
|
|
|
* o <EFBFBD>ndice "0"($chaves[0]) <EFBFBD> o valor que representa o in<EFBFBD>cio
|
|
|
|
|
* do bloco de informa<EFBFBD><EFBFBD>es ex.:
|
|
|
|
|
* $chaves = array("Agents", "Agent");
|
|
|
|
|
* Primeira linha do bloco = "Event: Agents"
|
|
|
|
|
* $chave[0] = "Agents"; //In<EFBFBD>cio de bloco
|
|
|
|
|
* Segunda linha do bloco = Agent: 1000
|
|
|
|
|
* $chave[1] = "Agent"; //retorna o valor "1000"
|
|
|
|
|
*
|
|
|
|
|
$buffer = "";
|
|
|
|
|
$data = "";
|
|
|
|
|
$evt_fim = trim($evento);
|
|
|
|
|
$linhas = 0;
|
|
|
|
|
$actionid=rand(000000000,9999999999);
|
|
|
|
|
$actionid="actionid: ".$actionid."\r\n";
|
|
|
|
|
$cmd .= $comando . $actionid."\r\n";
|
|
|
|
|
fwrite($socket, $cmd);
|
|
|
|
|
usleep(500);
|
|
|
|
|
$dataInlfo = array();
|
|
|
|
|
$idx = -1;
|
|
|
|
|
|
|
|
|
|
while(!feof($socket))
|
|
|
|
|
{
|
|
|
|
|
$buffer = trim(fgets($socket));
|
|
|
|
|
|
|
|
|
|
$data .= $buffer . "<br>";
|
|
|
|
|
$ch = split(':', $buffer);
|
|
|
|
|
$chave = trim($ch[0]);
|
|
|
|
|
$value = trim($ch[1]);
|
|
|
|
|
|
|
|
|
|
if($value == $chaves[0])
|
|
|
|
|
{
|
|
|
|
|
$idx++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if($chaves && array_search($chave, $chaves))
|
|
|
|
|
{
|
|
|
|
|
$dataInlfo[$idx][$chave] = $value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(stristr($buffer,$evt_fim))
|
|
|
|
|
{
|
|
|
|
|
return $dataInlfo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*
|
|
|
|
|
* Garante que o script nao vai rodar infinitamente
|
|
|
|
|
* se nao encontrar o evento de finaliza<EFBFBD><EFBFBD>o
|
|
|
|
|
*
|
|
|
|
|
|
|
|
|
|
if(trim($buffer) == "")
|
|
|
|
|
{
|
|
|
|
|
$linhas++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if($linhas > 30)
|
|
|
|
|
{
|
|
|
|
|
return $dataInlfo;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
?>
|