set_error_handler("exception_error_handler");
    function exception_handler(Exception $exception)
    {
        $errno = $exception->getCode();
        $msg = "Критическая ошибка установки #{$errno}: \"" . $exception->getMessage() . "\" в строке " . $exception->getLine() . " файла " . $exception->getFile() . "\n";
        if ($errno != 0) {
            $msg .= "Подробнее об ошибке http://errors.umi-cms.ru/{$errno}/\n";
        }
        // write into stderr
        if ($fp = fopen("php://stderr", "w")) {
            fputs($fp, $msg);
        }
        die;
    }
    set_exception_handler('exception_handler');
    $args = parse_argv($_SERVER['argv']);
} else {
    $args = $_REQUEST;
    header("Content-type: text/xml; charset=utf-8");
}
$install_mode = true;
// Install
if (in_array(substr(dirname(__FILE__), -4, 4), array('/smu', '\\smu'))) {
    define("CURRENT_WORKING_DIR", realpath(dirname(__FILE__) . '/..'));
    if (is_file(CURRENT_WORKING_DIR . '/installed')) {
        // Update
        $install_mode = false;
    }
} else {
    define("CURRENT_WORKING_DIR", realpath(dirname(__FILE__)));
}
Example #2
0
 function handle($doc, $argv = null)
 {
     try {
         if ($argv === null && isset($_SERVER['argv'])) {
             $argv = array_slice($_SERVER['argv'], 1);
         }
         $usageSections = parse_section('usage:', $doc);
         if (count($usageSections) == 0) {
             throw new LanguageError('"usage:" (case-insensitive) not found.');
         } elseif (count($usageSections) > 1) {
             throw new LanguageError('More than one "usage:" (case-insensitive).');
         }
         $usage = $usageSections[0];
         // temp fix until python port provides solution
         ExitException::$usage = $usage;
         $options = parse_defaults($doc);
         $formalUse = formal_usage($usage);
         $pattern = parse_pattern($formalUse, $options);
         $argv = parse_argv(new Tokens($argv), $options, $this->optionsFirst);
         $patternOptions = $pattern->flat('Option');
         foreach ($pattern->flat('OptionsShortcut') as $optionsShortcut) {
             $docOptions = parse_defaults($doc);
             $optionsShortcut->children = array_diff((array) $docOptions, $patternOptions);
         }
         extras($this->help, $this->version, $argv, $doc);
         list($matched, $left, $collected) = $pattern->fix()->match($argv);
         if ($matched && !$left) {
             $return = array();
             foreach (array_merge($pattern->flat(), $collected) as $a) {
                 $name = $a->name;
                 if ($name) {
                     $return[$name] = $a->value;
                 }
             }
             return new Response($return);
         }
         throw new ExitException();
     } catch (ExitException $ex) {
         $this->handleExit($ex);
         return new Response(null, $ex->status, $ex->getMessage());
     }
 }
 function handle($doc, $argv = null)
 {
     try {
         if (!$argv && isset($_SERVER['argv'])) {
             $argv = array_slice($_SERVER['argv'], 1);
         }
         ExitException::$usage = printable_usage($doc);
         $options = parse_defaults($doc);
         $formalUse = formal_usage(ExitException::$usage);
         $pattern = parse_pattern($formalUse, $options);
         $argv = parse_argv(new TokenStream($argv, 'ExitException'), $options, $this->optionsFirst);
         foreach ($pattern->flat('AnyOptions') as $ao) {
             $docOptions = parse_defaults($doc);
             $ao->children = array_diff((array) $docOptions, $pattern->flat('Option'));
         }
         extras($this->help, $this->version, $argv, $doc);
         list($matched, $left, $collected) = $pattern->fix()->match($argv);
         if ($matched && !$left) {
             $return = array();
             foreach (array_merge($pattern->flat(), $collected) as $a) {
                 $name = $a->name;
                 if ($name) {
                     $return[$name] = $a->value;
                 }
             }
             return new Response($return);
         }
         throw new ExitException();
     } catch (ExitException $ex) {
         $this->handleExit($ex);
         return new Response(null, $ex->status, $ex->getMessage());
     }
 }
Example #4
0
function doit()
{
    global $argv;
    global $url, $token, $host, $service, $state, $output, $type, $checktype, $usestdin;
    global $delim;
    $type = "host";
    // get and check command line args
    check_args(parse_argv($argv));
    /*
    echo "URL=$url\n";
    echo "TOKEN=$token\n";
    echo "TYPE=$type\n";
    echo "CHECKTYPE=$checktype\n";
    echo "HOST=$host\n";
    echo "SERVICE=$service\n";
    echo "STATE=$state\n";
    echo "OUTPUT=".$output."\n";
    */
    $hostchecks = array();
    $servicechecks = array();
    // process single check from command line
    if ($host != "") {
        // service check
        if ($service != "") {
            $newc = array("hostname" => $host, "servicename" => $service, "state" => $state, "output" => $output);
            $servicechecks[] = $newc;
        } else {
            $newc = array("hostname" => $host, "state" => $state, "output" => $output);
            $hostchecks[] = $newc;
        }
    }
    // use read from stdin
    if ($usestdin != "") {
        //echo "READING FROM STDIN\n";
        while ($buf = rtrim(fgets(STDIN), "\n")) {
            //echo "READ: $buf\n";
            $parts = explode("\t", $buf);
            //print_r($parts);
            $fields = count($parts);
            // host check
            if ($fields == 3) {
                $hostname = $parts[0];
                $state = $parts[1];
                $output = $parts[2];
                $newc = array("hostname" => $hostname, "state" => $state, "output" => $output);
                $hostchecks[] = $newc;
            } else {
                if ($fields == 4) {
                    $hostname = $parts[0];
                    $servicename = $parts[1];
                    $state = $parts[2];
                    $output = $parts[3];
                    $newc = array("hostname" => $hostname, "servicename" => $servicename, "state" => $state, "output" => $output);
                    $servicechecks[] = $newc;
                }
            }
        }
    }
    // craft the XML to send
    $checkresultopts = "";
    $checkresultopts = " checktype='" . $checktype . "'";
    $xml = "<?xml version='1.0'?> \r\n<checkresults>\r\n";
    foreach ($hostchecks as $hc) {
        $hostname = $hc["hostname"];
        $state = $hc["state"];
        $output = $hc["output"];
        $xml .= "\r\n\t<checkresult type='host' " . $checkresultopts . ">\r\n\t\t<hostname>" . htmlentities($hostname) . "</hostname>\r\n\t\t<state>" . $state . "</state>\r\n\t\t<output>" . htmlentities($output) . "</output>\r\n\t</checkresult>\r\n\t\t";
    }
    foreach ($servicechecks as $sc) {
        $hostname = $sc["hostname"];
        $servicename = $sc["servicename"];
        $state = $sc["state"];
        $output = $sc["output"];
        $xml .= "\r\n\t<checkresult type='service' " . $checkresultopts . ">\r\n\t\t<hostname>" . htmlentities($hostname) . "</hostname>\r\n\t\t<servicename>" . htmlentities($servicename) . "</servicename>\r\n\t\t<state>" . $state . "</state>\r\n\t\t<output>" . htmlentities($output) . "</output>\r\n\t</checkresult>\r\n\t\t";
    }
    $xml .= "\r\n</checkresults>\r\n";
    //echo "XML=\n$xml\n";
    //exit();
    // build url
    $theurl = $url . "/?token=" . $token . "&cmd=submitcheck&XMLDATA=" . urlencode($xml);
    //echo "URL=$theurl\n";
    // send data to NRDP
    $opts = array("method" => "post", "timeout" => 30, "return_info" => true);
    $result = load_url($theurl, $opts);
    //echo "RESULT=\n";
    //print_r($result);
    exit(0);
}