Re: Asterisk и AGI
Под Linux FC5, скрипт такой:
# cat test.php
#!/usr/bin/php -q
<?php
ob_implicit_flush(true);
set_time_limit(6);
$in = fopen("php://stdin","r");
$stdlog = fopen("/var/log/asterisk/my_agi.log", "w");
$debug=true;
// 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 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 = split(": ",$env);
$agi[str_replace("agi_","",$s[0])] = trim($s[1]);
if ($env == "") {
break;
}
}
write("ANSWER");
read();
write("EXEC Read MYVARTEST|ru/vm-password|7");
read();
write("GET VARIABLE MYVARTEST"); // X is the escape digit. since X is not DTMF, no exit is possible
$vartest = read();
$vartest = str_replace("200 result=1 (","",$vartest);
$vartest = str_replace(")","",$vartest);
errlog("PINCODE: $vartest");
read();
if ($vartest == "4455426"){
write("EXEC Read DIALTO|vm-toenternumber");
read();
write("GET VARIABLE DIALTO");
$vardial = read();
$vardial = str_replace("200 result=1 (","",$vardial);
$vardial = str_replace(")","",$vardial);
errlog("DIAL TO: $vardial");
read();
errlog("PIN IS RIGHT, DIAL");
read();
write("EXEC Dial SIP/$vardial@89.20.132.131");
$result = read();
errlog("Dial status: $result");
read();
} else {
errlog("PIN WRONG, HANGUP");
read();
}
fclose($in);
fclose($stdlog);
pcntl_signal(SIGHUP, SIG_IGN);
exit;
?>
|