|
|
|
#!/usr/bin/php -q
|
|
|
|
<?php
|
|
|
|
include('bd.php');
|
|
|
|
|
|
|
|
ob_implicit_flush(true);
|
|
|
|
set_time_limit(6);
|
|
|
|
$in = fopen("php://stdin", "r");
|
|
|
|
$stdlog = fopen("/var/log/asterisk/verifica-rota.log", "w");
|
|
|
|
|
|
|
|
// toggle debugging output (more verbose)
|
|
|
|
$debug = false;
|
|
|
|
|
|
|
|
function read() {
|
|
|
|
global $in, $debug, $stdlog;
|
|
|
|
$input = str_replace("\n", "", fgets($in, 4096));
|
|
|
|
if ($debug)
|
|
|
|
fputs($stdlog, "read: $input\n");
|
|
|
|
return $input;
|
|
|
|
}
|
|
|
|
|
|
|
|
function errlog($line) {
|
|
|
|
global $err;
|
|
|
|
echo "VERBOSE \"$line\"\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
function write($line) {
|
|
|
|
global $debug, $stdlog;
|
|
|
|
if ($debug)
|
|
|
|
fputs($stdlog, "write: $line\n");
|
|
|
|
echo $line . "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse agi headers into array
|
|
|
|
while ($env = read()) {
|
|
|
|
$s = explode(": ", $env);
|
|
|
|
$agi[str_replace("agi_", "", $s[0])] = trim($s[1]);
|
|
|
|
if (($env == "") || ($env == "\n")) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//parametro vindo do dialplan
|
|
|
|
$canal = explode('-', $argv[1]);
|
|
|
|
$dispositivo = $canal[0];
|
|
|
|
|
|
|
|
if (substr($dispositivo, 0, 5) == 'Agent') {
|
|
|
|
$canal = explode('/', $dispositivo);
|
|
|
|
$matricula = $canal[1];
|
|
|
|
|
|
|
|
$query = "select ramal from pbx_supervisor_agentes where matricula = '$matricula'";
|
|
|
|
$result = pg_query($conexao, $query);
|
|
|
|
$dados = pg_fetch_row($result);
|
|
|
|
$ramal = $dados[0];
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$query = "select nome from pbx_ramais where dispositivo = '$dispositivo'";
|
|
|
|
$result = pg_query($conexao, $query);
|
|
|
|
$dados = pg_fetch_row($result);
|
|
|
|
$ramal = $dados[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
write("SET VARIABLE CALLERID(all) $ramal");
|
|
|
|
read();
|
|
|
|
|
|
|
|
|
|
|
|
// clean up file handlers etc.
|
|
|
|
fclose($in);
|
|
|
|
fclose($stdlog);
|
|
|
|
?>
|