|
|
|
#!/usr/bin/php -q
|
|
|
|
<?php
|
|
|
|
include('bd.php');
|
|
|
|
include('util/util.php');
|
|
|
|
|
|
|
|
ob_implicit_flush(true);
|
|
|
|
set_time_limit(6);
|
|
|
|
error_reporting(0);
|
|
|
|
$in = fopen("php://stdin", "r");
|
|
|
|
$stdlog = fopen("/var/log/asterisk/envia_sms.log", "w");
|
|
|
|
|
|
|
|
// Habilita modo debugging (mais verbose)
|
|
|
|
$debug = false;
|
|
|
|
|
|
|
|
// Do function definitions before we start the main loop
|
|
|
|
function read() {
|
|
|
|
global $in, $debug, $stdlog;
|
|
|
|
$input = str_replace("\n", "", fgets($in, 4096));
|
|
|
|
if ($debug)
|
|
|
|
fputs($stdlog, "read: $input\n");
|
|
|
|
return $input;
|
|
|
|
}
|
|
|
|
|
|
|
|
function write($line) {
|
|
|
|
global $debug, $stdlog;
|
|
|
|
if ($debug)
|
|
|
|
fputs($stdlog, "write: $line\n");
|
|
|
|
echo $line . "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Colocando headers AGI dentro de um array
|
|
|
|
while ($env = read()) {
|
|
|
|
$s = explode(": ", $env);
|
|
|
|
$agi[str_replace("agi_", "", $s[0])] = trim($s[1]);
|
|
|
|
if (($env == "") || ($env == "\n")) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$SMS_SIP_ID = $argv[1];
|
|
|
|
$SMS_TRONCO_ENVIO = $argv[2];
|
|
|
|
$SMS_DESTINO = $argv[3];
|
|
|
|
$SMS_MENSAGEM = QuotedStr($argv[4]);
|
|
|
|
$SMS_STATUS = $argv[5];
|
|
|
|
$SMS_COD_ERRO = $argv[6];
|
|
|
|
$SMS_NOME_ERRO = $argv[7];
|
|
|
|
$SMS_TRONCO_SAIDA = $argv[8];
|
|
|
|
$SMS_ID_ENVIO = $argv[9];
|
|
|
|
|
|
|
|
$query = "insert into pbx_sms_send (sms_sip_id, sms_tronco_envio, sms_destino, sms_mensagem, sms_status, sms_cod_erro, sms_nome_erro, sms_tronco_saida, sms_id_envio) values ('$SMS_SIP_ID','$SMS_TRONCO_ENVIO','$SMS_DESTINO',$SMS_MENSAGEM,'$SMS_STATUS','$SMS_COD_ERRO','$SMS_NOME_ERRO','$SMS_TRONCO_SAIDA','$SMS_ID_ENVIO')";
|
|
|
|
pg_query($query);
|
|
|
|
pg_close();
|
|
|
|
|
|
|
|
fclose($in);
|
|
|
|
fclose($stdlog);
|
|
|
|
exit;
|
|
|
|
?>
|