function _gs_siemens_prov_phone_checkcfg_by_ip_do_siemens($ip, $reboot = true, $pre_sleep = 0)
{
    if (_gs_prov_phone_checkcfg_exclude_ip($ip)) {
        return;
    }
    $cmd = 'wget -q -O /dev/null -o /dev/null -b --tries=1' . ' --timeout=10 --retry-connrefused --no-http-keep-alive' . ' --user-agent=' . escapeShellArg('Jakarta Commons-HttpClient/3.0') . ' --header=' . escapeShellArg('Content-type: application/x-www-form-urlencoded; charset=utf-8') . ' --post-data=' . escapeShellArg('ContactMe=true') . ' ' . escapeShellArg('http://' . $ip . ':8085/contact_dls.html/ContactDLS');
    # Sometimes the phone just ignores the ContactMe request so we need
    # to send this twice to be sure. But then again 2 requests within 1
    # second would cause the phone's web server to die.
    # So don't just do  for ($i=0; $i<2; ++$i) @exec($cmd, $out, $err);
    # Edit: Retrying more than once a minute or so is very likely to
    # crash the phone.
    /* FIXME: does not work via SSH
    	if (! gs_get_conf('GS_INSTALLATION_TYPE_SINGLE')) {
    		$listen_to_ids = gs_get_listen_to_ids();
    		if (is_array($listen_to_ids) && count($listen_to_ids)>0) {
    			$cmd = 'ssh -o StrictHostKeyChecking=no -o BatchMode=yes -l root '. qsa( GS_PROV_HOST ) .' '. qsa($cmd);
    		}
    		unset($listen_to_ids);
    	}
    	*/
    $ign_out = '1>>/dev/null 2>>/dev/null';
    if ($pre_sleep < 1) {
        @exec($cmd, $out, $err);
    } else {
        $s = (int) $pre_sleep;
        @exec('(sleep ' . $s . '; ' . $cmd . ') ' . $ign_out . ' &', $out, $err);
    }
}
Beispiel #2
0
function qsa($str)
{
    # escapeShellArg() is broken! it returns an un-quoted empty string
    # for empty strings. (that does not count as a shell argument!)
    # that bug is known since at least 2002, see
    # http://www.php.net/manual/en/function.escapeshellarg.php
    # but has not been fixed
    $ret = escapeShellArg($str);
    return trim($ret) != '' ? $ret : '\'\'';
}
Beispiel #3
0
 function qsa($str)
 {
     return $str != '' ? escapeShellArg($str) : '\'\'';
 }
Beispiel #4
0
require_once GS_DIR . 'inc/util.php';
require_once GS_DIR . 'inc/log.php';
# The AGI environment is going to be made available in $AGI_ENV by this library.
# The Asterisk environment is available in $_ENV['AST_...'].
$AGI_ENV = array();
$agi_basename = baseName($_SERVER['SCRIPT_FILENAME']);
$agi_log_prefix = $agi_basename . '[' . getMyPid() . ']| ';
function gs_agi_log($level, $msg)
{
    global $agi_log_prefix;
    return gs_log($level, $agi_log_prefix . $msg, 'agi.log', true);
}
gs_agi_log(GS_LOG_DEBUG, 'Launched ---------------------------');
$log_cmdline = baseName($argv[0]);
for ($i = 1; $i < $argc; ++$i) {
    $log_cmdline .= ' ' . ($argv[$i] != '' ? escapeShellArg($argv[$i]) : '\'\'');
}
gs_agi_log(GS_LOG_DEBUG, 'Cmdline: ' . $log_cmdline);
unset($log_cmd);
function gs_agi_str_esc($str)
{
    $str = str_replace(array('\\', ' ', "\n", "\r", "\t", '"'), array('\\\\', '\\ ', '\\ ', '\\ ', '\\ ', '\\"'), $str);
    return $str == '' ? '""' : $str;
}
/*
function _gs_agi_read_response()
{
	uSleep(1);
	stream_set_blocking(STDIN, false);
	$buf = '';
	$i=0;
Beispiel #5
0
    exit(1);
}
putEnv('AST_AGI_DIR=/tmp/FAKE');
putEnv('AST_CONFIG_DIR=/tmp/FAKE');
putEnv('AST_CONFIG_FILE=');
putEnv('AST_DATA_DIR=/tmp/FAKE');
putEnv('AST_KEY_DIR=/tmp/FAKE');
putEnv('AST_LOG_DIR=/tmp/FAKE');
putEnv('AST_MODULE_DIR=/tmp/FAKE');
putEnv('AST_MONITOR_DIR=/tmp/FAKE');
putEnv('AST_RUN_DIR=/tmp/FAKE');
putEnv('AST_SPOOL_DIR=/tmp/FAKE');
putEnv('AST_VAR_DIR=/tmp/FAKE');
$cmd = $AGI_SCRIPT;
for ($i = 2; $i < $argc; ++$i) {
    $cmd .= ' ' . ($argv[$i] != '' ? escapeShellArg($argv[$i]) : '\'\'');
}
//echo "### CMD: ".$cmd."\n";
gs_log(GS_LOG_DEBUG, "Fake AGI invocation: {$AGI_SCRIPT} ...");
$pipes = array();
$proc = proc_open($cmd, array(0 => array('pipe', 'rb'), 1 => array('pipe', 'wb'), 2 => array('pipe', 'wb')), $pipes, '/tmp');
if (!$proc) {
    gs_log(GS_LOG_WARNING, 'Failed to run AGI script!');
    echo '### Failed to run AGI script!' . "\n";
    exit(1);
}
function _fake_agi_send($fd, $line)
{
    $bytes = fWrite($fd, $line . "\n", strLen($line) + 1);
    fFlush($fd);
    return $bytes;
function _write_raw_log($str, $is_incoming = false)
{
    global $raw_debug, $debug_file, $_SERVER;
    static $complain = true;
    if (!$raw_debug) {
        return false;
    }
    if (!file_exists($debug_file)) {
        @exec('touch ' . escapeShellArg($debug_file) . ' 1>>/dev/null 2>>/dev/null', $out, $err);
        if ($err != 0) {
            if ($complain) {
                gs_log(GS_LOG_DEBUG, "Siemens prov.: Failed to create \"{$debug_file}\"");
            }
            $complain = false;
            # complain only once
            return false;
        }
    }
    if (!is_writable($debug_file)) {
        if ($complain) {
            gs_log(GS_LOG_DEBUG, "Siemens prov.: File \"{$debug_file}\" not writable");
        }
        $complain = false;
        # complain only once
        return false;
    }
    $fh = @fOpen($debug_file, 'ab');
    if (!is_resource($fh)) {
        if ($complain) {
            gs_log(GS_LOG_DEBUG, "Siemens prov.: Failed to open \"{$debug_file}\"");
        }
        $complain = false;
        # complain only once
        return false;
    }
    $ok = @fWrite($fh, str_repeat($is_incoming ? '>' : '<', 40) . "\n" . date('Y-m-d H:i:s') . "  -  " . $str . "\n");
    if (!$ok) {
        if ($complain) {
            gs_log(GS_LOG_DEBUG, "Siemens prov.: Failed to write to \"{$debug_file}\"");
        }
        $complain = false;
        # complain only once
        return false;
    }
    //@fFlush($fh);
    @fClose($fh);
    return true;
}