All pastes #926653 Raw Edit

Unnamed

public text v1 · immutable
·published 2008-03-03 20:04 UTC
rendered paste body
#!/usr/bin/php -q
<?php

set_time_limit(60);
ob_implicit_flush(false);
error_reporting(0);
if (!defined('STDIN'))
{
   define('STDIN', fopen('php://stdin', 'r'));
}
if (!defined('STDOUT'))
{
   define('STDOUT', fopen('php://stdout', 'w'));
}
if (!defined('STDERR'))
{
   define('STDERR', fopen('php://stderr', 'w'));
}
if (!defined('STDLOG'))
{
        define('STDLOG', fopen("/var/log/asterisk/my_agi.log", "a"));
}
if (!defined('DEBUG'))
{
        define ('DEBUG', FALSE);
} 
if (!defined('SAVELOG'))
{
        define ('SAVELOG', FALSE);
}



function write_console($STR_MESSAGE){
        fwrite(STDOUT,"verbose \"$STR_MESSAGE\" \n");
}


function exec_command($STR_CMD, $STR_PARAM){
        $COMMAND = "$STR_CMD \"$STR_PARAM\" \n";

        fwrite(STDOUT,"$COMMAND");
        fflush(STDOUT);
}

function checkresult($res) 
        { 
                trim($res); 
                if (preg_match('/^200/',$res)) 
                { 
                        if (! preg_match('/result=(-?\d+)/',$res,$matches)) 
                        { 
                                fwrite(STDERR,"FAIL ($res)\n"); 
                                fflush(STDERR); 
                                return 0; 
                        } 
                        else 
                        { 
                                fwrite(STDERR,"PASS (".$matches[1].")\n"); 
                                fflush(STDERR); 
                                return $matches[1]; 
                        } 
                } 
                else 
                { 
                        fwrite(STDERR,"FAIL (unexpected result '$res')\n"); 
                        fflush(STDERR); 
                        return -1; 
                } 
        } 


while (!feof(STDIN))
{
    $TEMP = trim(fgets(STDIN,4096));
    if (($TEMP == "") || ($TEMP == "\n"))
    {
        break;
    }
    $SPLIT = split(":",$TEMP);
    $NAME = str_replace("agi_","",$SPLIT[0]);
    $AGI[$NAME] = trim($SPLIT[1]);
}

# Escre na tela todas as variaveis do AGI
# para proposito de DEBUG

if (DEBUG) {
        write_console("Asterisk AGI Variables");
        write_console("==================================================");

        foreach($AGI as $KEY=>$VALUE)
        {
                write_console("-- agi_$KEY = $VALUE");
        }
}

# Executa a funcao exec_command 
exec_command("GET VARIABLE","UNIQUEID");


$UNIQUEID = fgets(STDIN, 4096);
fwrite(STDLOG,$UNIQUEID. "\n");
$UNIQUEID = trim($UNIQUEID);



write_console("=======Variavel UNIQUEID vale:  $UNIQUEID===========");