PABX da Simples IP
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

75 lines
1.5 KiB

#!/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/update.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;
}
}
write("GET VARIABLE CONTA");
$CONTA = substr(strrchr(read(), "("), 1, -1);
write("GET VARIABLE NOVA");
$NOVA = substr(strrchr(read(), "("), 1, -1);
$query = "update pbx_cs_usuarios set senha='$NOVA',tag='1',data_atualizacao=(select CURRENT_TIMESTAMP) where matricula = '$CONTA' and tag <> '2'";
pg_query($query);
$query2 = "select senha from pbx_cs_usuarios where matricula = '$CONTA' and senha = '$NOVA'";
$result = pg_fetch_array(pg_query($query2));
pg_close();
if ($result[0] != null) {
fclose($in);
fclose($stdlog);
exit;
} else {
$EXTEN = substr($agi['extension'], 0, 4);
write("EXEC Goto $EXTEN,invalida");
read();
}
// clean up file handlers etc.
fclose($in);
fclose($stdlog);
?>