|
|
|
|
|
|
|
|
|
<?php
|
|
|
|
|
$tpLayout = 0;
|
|
|
|
|
$servidor = ''; //192.168.115.2'; // "127.0.0.1"
|
|
|
|
|
$socket = ConectaManager(GetSckConnect());
|
|
|
|
|
$ramalBase = trim($_SESSION["SSramalIntercalar"]);
|
|
|
|
|
$numero = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (IsAjax()) {
|
|
|
|
|
$tipoDispositivo = $_SESSION['tipoDispositivo'];
|
|
|
|
|
$statusDispositivo = $_SESSION['statusDispositivo'];
|
|
|
|
|
$servidorApi = $servidor;
|
|
|
|
|
$userApi = "sinccontasenha";
|
|
|
|
|
$senhaApi = "s3ncC0nt@S2nh@";
|
|
|
|
|
$acao = $_GET["acao"];
|
|
|
|
|
|
|
|
|
|
if (strtoupper($acao) == "DISCARDIRETO") {
|
|
|
|
|
$numero = trim($_GET["numero"]);
|
|
|
|
|
$url = "http://$servidorApi/integracao?method=DiscarDireto&numeroDiscar=$numero&ramal=$ramalBase&login=$userApi&senha=$senhaApi&tipoRetorno=XML";
|
|
|
|
|
//$xml = GetApi($url);
|
|
|
|
|
$xml = simplexml_load_string(GetApi($url));
|
|
|
|
|
$ret = trim(strval($xml->result));
|
|
|
|
|
echo ($ret == "true") ? "OK" : "ERRO";
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (!isPostBack()) {
|
|
|
|
|
$statusDispositivo = 'todos';
|
|
|
|
|
$tipoDispositivo = 3;
|
|
|
|
|
} else {
|
|
|
|
|
$statusDispositivo = $_POST['statusDispositivo'];
|
|
|
|
|
$tipoDispositivo = $_POST['tipoDispositivo'];
|
|
|
|
|
}
|
|
|
|
|
$_SESSION['tipoDispositivo'] = $tipoDispositivo;
|
|
|
|
|
$_SESSION['statusDispositivo'] = $statusDispositivo;
|
|
|
|
|
|
|
|
|
|
$option .= "<option value=\"on\" " . ($statusDispositivo == 'on' ? 'selected' : '') . ">ON</option>";
|
|
|
|
|
$option .= "<option value=\"off\" " . ($statusDispositivo == 'off' ? 'selected' : '') . ">OFF</option>";
|
|
|
|
|
$option .= "<option value=\"todos\" " . ($statusDispositivo == 'todos' ? 'selected' : '') . ">TODOS</option>";
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
* Retorna trocos e ramais cadastrados no banco de dados.
|
|
|
|
|
*/
|
|
|
|
|
$troncosCad = array();
|
|
|
|
|
$troncosCad = GetRamaisNome($tipoDispositivo);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Retorna os troncos monitorados no manager.
|
|
|
|
|
*/
|
|
|
|
|
$troncosMonitor = array();
|
|
|
|
|
GetDisplayIax($socket, $troncosMonitor);
|
|
|
|
|
GetDisplaySip($socket, $troncosMonitor);
|
|
|
|
|
//print_r($troncosMonitor); exit;
|
|
|
|
|
/*
|
|
|
|
|
* Monta o html do relat<EFBFBD>rio.
|
|
|
|
|
*/
|
|
|
|
|
$a = 0;
|
|
|
|
|
$resultados = '';
|
|
|
|
|
asort($troncosCad);
|
|
|
|
|
foreach ($troncosCad as $dispositivo) {
|
|
|
|
|
$idDispositivo = trim($dispositivo['nome']);
|
|
|
|
|
$nomeRamal = $dispositivo['callerid'];
|
|
|
|
|
$tipoRamal = $dispositivo['tipo'];
|
|
|
|
|
list($channeltype, $objectname, $ipaddress, $statusRamal ) = array_values($troncosMonitor[$idDispositivo]);
|
|
|
|
|
|
|
|
|
|
$status = stripos($statusRamal, 'ok') !== false && soNumero($ipaddress);
|
|
|
|
|
$isRamalOperador = $ramalBase == $numRamal;
|
|
|
|
|
|
|
|
|
|
if(!$status){
|
|
|
|
|
$link = 'N<EFBFBD>O REGISTRADO';
|
|
|
|
|
}else if($tipoRamal == 'T'){
|
|
|
|
|
$link = $ipaddress;
|
|
|
|
|
}else{
|
|
|
|
|
$link = sprintf('<a href="http://%s" target="_new" style="color:#000000">%s</a>', $ipaddress, $ipaddress);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$imgRamal = GetImgTipo($tipoRamal, $status);
|
|
|
|
|
$linkRamal = !$status || !$tipoRamal ? "$imgRamal" : (($isRamalOperador) ? $imgRamal : "<a href=\"javaScript:DiscarDireto('$ramal');\">$imgRamal</a>");
|
|
|
|
|
$nomeRamal = isset($nomeRamal) && ($tipoRamal != 'T') ? $nomeRamal : '-';
|
|
|
|
|
$mostrar = true;
|
|
|
|
|
if($statusDispositivo == 'on'){
|
|
|
|
|
$mostrar = $status;
|
|
|
|
|
}else if($statusDispositivo == 'off'){
|
|
|
|
|
$mostrar = !$status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if($mostrar){
|
|
|
|
|
$resultados .= "<tr>
|
|
|
|
|
<td align=\"left\">$idDispositivo</td>
|
|
|
|
|
<td align=\"left\">$nomeRamal</td>
|
|
|
|
|
<td align=\"left\">$link</td>
|
|
|
|
|
<td align=\"center\">$linkRamal</td>
|
|
|
|
|
</tr>";
|
|
|
|
|
$a++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
// <th style="text-align: center;"> </th>
|
|
|
|
|
$head = '<table width="100%" border="1" cellspacing="0" cellpadding="2" class="grid">
|
|
|
|
|
<tr>
|
|
|
|
|
<th align="left">Ramal</th>
|
|
|
|
|
<th align="left">Nome</th>
|
|
|
|
|
<th align="left">Endere<EFBFBD>o IP</th>
|
|
|
|
|
<th style="text-align: center;">Status</th>
|
|
|
|
|
</tr>';
|
|
|
|
|
$foot = "<tr>
|
|
|
|
|
<th colspan=\"3\">Quantidade Total:</th>
|
|
|
|
|
<th align=\"center\">$a</th>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>";
|
|
|
|
|
$resultados = $head . $resultados . $foot;
|
|
|
|
|
|
|
|
|
|
if (IsAjax()) {
|
|
|
|
|
echo $resultados;
|
|
|
|
|
exit;
|
|
|
|
|
} else {
|
|
|
|
|
$jsStartup[] = "var idSet = window.setInterval(\"timedRefresh()\", 3000);";
|
|
|
|
|
$smarty->assign('resultados', $resultados);
|
|
|
|
|
$smarty->assign('option', $option);
|
|
|
|
|
$smarty->assign('tipoDispositivo', $tipoDispositivo);
|
|
|
|
|
$smarty->display("monitorRamal.tpl");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function GetConnection($conStr) {
|
|
|
|
|
$ret = pg_connect($conStr, PGSQL_CONNECT_FORCE_NEW);
|
|
|
|
|
if (!$ret) {
|
|
|
|
|
logTrb('GetConnection', "Conexao com banco de dados", "Erro ao executar conexao no banco", 'ERRO', $conStr);
|
|
|
|
|
}
|
|
|
|
|
return $ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function GetRamaisNome($tipoDispositivo) {
|
|
|
|
|
global $servidor;
|
|
|
|
|
$ret = array();
|
|
|
|
|
$conn = !$servidor ? '' : sprintf("host='%s' port='%s' dbname='%s' user='%s' password='%s'", $servidor, '5432', 'pbx', 'contacte', 'ctepgSQL');
|
|
|
|
|
$db = GetConnection($conn ? $conn : GetDefStrDb());
|
|
|
|
|
$query = "";
|
|
|
|
|
if(($tipoDispositivo == 1) || ($tipoDispositivo == 3)){
|
|
|
|
|
$query = "select 'R' as tipo, nome, callerid, tipo_table as protocol from pbx_ramais_mesa where tipo_table in('IAX', 'SIP')\n";
|
|
|
|
|
}
|
|
|
|
|
if(($tipoDispositivo == 2) || ($tipoDispositivo == 3)){
|
|
|
|
|
if($query){
|
|
|
|
|
$query .= "union all\n";
|
|
|
|
|
}
|
|
|
|
|
$query .= "select 'T' as tipo,nome, callerid, tipo as protocol from pbx_troncos where tipo in('SIP', 'IAX2')\n";
|
|
|
|
|
}
|
|
|
|
|
$result = pg_query($db, $query);
|
|
|
|
|
if (pg_num_rows($result)) {
|
|
|
|
|
while ($dados = pg_fetch_array($result)) {
|
|
|
|
|
$ret[$dados["nome"]] = $dados;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function GetDisplaySip($socket, &$troncosMonitor) {
|
|
|
|
|
$buffer = '';
|
|
|
|
|
$param = '';
|
|
|
|
|
$value = '';
|
|
|
|
|
$start = false;
|
|
|
|
|
$startInfo = false;
|
|
|
|
|
$arInfo = array();
|
|
|
|
|
$actionid = rand(000000000, 9999999999);
|
|
|
|
|
fwrite($socket, "action: sippeers\r\n");
|
|
|
|
|
fwrite($socket, "ActionID: " . $actionid . "\r\n\r\n");
|
|
|
|
|
|
|
|
|
|
while (!feof($socket)) {
|
|
|
|
|
$buffer = fgets($socket);
|
|
|
|
|
list($param, $value) = GetExplode($buffer);
|
|
|
|
|
if(!$start){
|
|
|
|
|
$start = (strtoupper($param) == 'ACTIONID') && ($actionid == (int) $value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($start) {
|
|
|
|
|
/*
|
|
|
|
|
* Vefirica o inicio de um blolco de informacoes.
|
|
|
|
|
*
|
|
|
|
|
* Event: PeerEntry
|
|
|
|
|
* ActionID: 56dd6666094747
|
|
|
|
|
* Channeltype: SIP
|
|
|
|
|
* ObjectName: PORTABILIDADE
|
|
|
|
|
* ChanObjectType: peer
|
|
|
|
|
* IPaddress: 127.0.0.1
|
|
|
|
|
* IPport: 5060
|
|
|
|
|
* Dynamic: no
|
|
|
|
|
* AutoForcerport: no
|
|
|
|
|
* Forcerport: yes
|
|
|
|
|
* AutoComedia: no
|
|
|
|
|
* Comedia: yes
|
|
|
|
|
* VideoSupport: yes
|
|
|
|
|
* TextSupport: no
|
|
|
|
|
* ACL: yes
|
|
|
|
|
* Status: OK (1 ms)
|
|
|
|
|
* RealtimeDevice: no
|
|
|
|
|
* Description:
|
|
|
|
|
* Accountcode:
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
if(!$startInfo){
|
|
|
|
|
$startInfo = ($param == 'Event') && ($value == 'PeerEntry');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Finaliza a leitura de um bloco.
|
|
|
|
|
*/
|
|
|
|
|
if ($startInfo && (trim($buffer) == "")) {
|
|
|
|
|
$troncosMonitor[$arInfo['objectname']] = $arInfo;
|
|
|
|
|
$startInfo = false;
|
|
|
|
|
$arInfo = array();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($startInfo) {
|
|
|
|
|
/*
|
|
|
|
|
* Le o bloco de informa<EFBFBD><EFBFBD>es.
|
|
|
|
|
*/
|
|
|
|
|
switch ($param) {
|
|
|
|
|
case 'ObjectName':
|
|
|
|
|
list($nome) = explode("/", $value);
|
|
|
|
|
$arInfo[strtolower($param)] = $nome;
|
|
|
|
|
break;
|
|
|
|
|
case 'IPaddress':
|
|
|
|
|
case 'Channeltype':
|
|
|
|
|
case 'Status':
|
|
|
|
|
$arInfo[strtolower($param)] = $value;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
* Encerra a leitura.
|
|
|
|
|
*/
|
|
|
|
|
if (($param == 'Event') && ($value == "PeerlistComplete")) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function GetDisplayIax($socket, &$troncosMonitor) {
|
|
|
|
|
$buffer = '';
|
|
|
|
|
$param = '';
|
|
|
|
|
$value = '';
|
|
|
|
|
$start = false;
|
|
|
|
|
$startInfo = false;
|
|
|
|
|
$arInfo = array();
|
|
|
|
|
$actionid = rand(000000000, 9999999999);
|
|
|
|
|
fwrite($socket, "action: iaxpeers\r\n");
|
|
|
|
|
fwrite($socket, "ActionID: " . $actionid . "\r\n\r\n");
|
|
|
|
|
|
|
|
|
|
while (!feof($socket)) {
|
|
|
|
|
$buffer = fgets($socket);
|
|
|
|
|
list($param, $value) = GetExplode($buffer);
|
|
|
|
|
if(!$start){
|
|
|
|
|
$start = (strtoupper($param) == 'ACTIONID') && ($actionid == (int) $value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($start) {
|
|
|
|
|
/*
|
|
|
|
|
* Vefirica o inicio de um blolco de informacoes.
|
|
|
|
|
*
|
|
|
|
|
* Event: PeerEntry
|
|
|
|
|
* Channeltype: IAX2
|
|
|
|
|
* ObjectName: TROPICAL_PNEUS_TANGARA/SIMPLESIP
|
|
|
|
|
* ChanObjectType: peer
|
|
|
|
|
* IPaddress: 10.254.254.205
|
|
|
|
|
* IPport: 4569
|
|
|
|
|
* Dynamic: no
|
|
|
|
|
* Trunk: yes
|
|
|
|
|
* Encryption: no
|
|
|
|
|
* Status: OK (79 ms)
|
|
|
|
|
* Description:
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
if(!$startInfo){
|
|
|
|
|
$startInfo = (trim($param) == 'Event') && (trim($value) == 'PeerEntry');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Finaliza a leitura de um bloco.
|
|
|
|
|
*/
|
|
|
|
|
if ($startInfo && (trim($buffer) == "")) {
|
|
|
|
|
$troncosMonitor[$arInfo['objectname']] = $arInfo;
|
|
|
|
|
$startInfo = false;
|
|
|
|
|
$arInfo = array();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($startInfo) {
|
|
|
|
|
/*
|
|
|
|
|
* Le o bloco de informa<EFBFBD><EFBFBD>es.
|
|
|
|
|
*/
|
|
|
|
|
switch ($param) {
|
|
|
|
|
case 'ObjectName':
|
|
|
|
|
list($nome) = explode("/", $value);
|
|
|
|
|
$arInfo[strtolower($param)] = $nome;
|
|
|
|
|
break;
|
|
|
|
|
case 'IPaddress':
|
|
|
|
|
case 'Status':
|
|
|
|
|
case 'Channeltype':
|
|
|
|
|
$arInfo[strtolower($param)] = $value;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
* Encerra a leitura.
|
|
|
|
|
*/
|
|
|
|
|
if (($param == 'Event') && ($value == "PeerlistComplete")) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function RemoveDuploSpaco($str) {
|
|
|
|
|
$s = str_replace(' ', ' ', $str);
|
|
|
|
|
return strstr($s, ' ') === false ? $s : RemoveDuploSpaco($s);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function GetImgTipo($tipo, $status) {
|
|
|
|
|
if ($tipo != 'T') {
|
|
|
|
|
return $status ? "<img src=\"imgSite/ramalOn16.png\" border=\"0\" width=\"20\" height=\"20\">" : "<img src=\"imgSite/ramalOff16.png\" border=\"0\" width=\"20\" height=\"20\">";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $status ? "<img src=\"imgSite/troncoOn16.png\" border=\"0\" width=\"20\" height=\"20\">" : "<img src=\"imgSite/troncoOff16.png\" border=\"0\" width=\"20\" height=\"20\">";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function GetExplode($str, $ch = ':'){
|
|
|
|
|
$ar = explode($ch, $str);
|
|
|
|
|
return array(trim($ar[0]), trim($ar[1]));
|
|
|
|
|
}
|
|
|
|
|
?>
|
|
|
|
|
|