Exemple #1
0
 public function pushToSiteMapXML($post)
 {
     if (isset($post['text'])) {
         Fx::io()->write(Fx::io()->path(root, 'sitemap.xml'), $post['text']);
     }
     load_url();
 }
function cache_file($url, $file_name = false, $return_id = false, $cache_timeout = 15552000)
{
    /*{{{*/
    global $database;
    $cache_id = sha1($url);
    $cache_file = $GLOBALS['cache_dir'] . '/' . $cache_id;
    $directory = dirname($_SERVER['REQUEST_URI']);
    if (substr($directory, -1) != '/') {
        $directory .= '/';
    }
    $cache_url = 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://' . $_SERVER['SERVER_NAME'] . $directory . 'cache.php?cache_id=' . $cache_id;
    $cache_exists = file_exists($cache_file);
    $content = load_url($url, false, $cache_exists ? filemtime($cache_file) : false);
    if ($content && $content !== true) {
        // Nur den Cache neu schreiben, wenn sich tatsächlich etwas verändert hat
        // Dadurch verhindern wir, dass Zettel immer wieder als „Neu“ zählen, weil
        // ein Webserver schlampig konfiguriert ist.
        if (!file_exists($cache_file) || sha1_file($cache_file) != sha1($content)) {
            file_put_contents($cache_file, $content);
        }
        // In der Datenbank ein Update ausführen
        // Das auch, wenn eigentlich nichts geändert wurde - weil wir nämlich durch
        // den Aufruf wissen, dass die Daten noch gebraucht werden.
        $query = $database->prepare('SELECT COUNT(*) FROM cache WHERE id = ?');
        $query->execute(array($cache_id));
        if ($query->fetchColumn() == 0) {
            $query = $database->prepare('INSERT INTO cache (created_timestamp, max_age, filename, id) VALUES (?, ?, ?, ?)');
        } else {
            $query = $database->prepare('UPDATE cache SET created_timestamp = ?, max_age = ?, filename = ? WHERE id = ?');
        }
        $query->execute(array(time(), $cache_timeout, $file_name ? $file_name : basename($url), $cache_id));
    }
    if ($return_id) {
        return $cache_id;
    }
    return $cache_url;
}
 }
 // }}}
 // Neue Standardanfrage {{{
 if ($_POST['url'] && $_POST['search'] && $_POST['exercise'] && trim($_POST['desc'])) {
     // Einen Testdurchlauf machen
     $old_reporthing = ini_set('display_errors', 0);
     $error = '';
     if (!preg_match('#^https?://#i', $_POST['url'])) {
         $error = 'URL ungültig.';
     } else {
         if (preg_match('/^(.).+\\1([a-zA-Z]*)$/', $_POST['search'], $modifier) && strpos($modifier[2], 'e') === false) {
             set_error_handler(function ($errno, $errstr) use($error) {
                 $error .= $errstr;
             });
             try {
                 $contents = load_url($_POST['url']);
             } catch (Exception $e) {
                 $error .= $e->getMessage();
             }
             $contents = html_entity_decode($contents, ENT_COMPAT, "utf-8");
             preg_match_all($_POST['search'], $contents, $matches, PREG_SET_ORDER);
             restore_error_handler();
             if (preg_last_error() != PREG_NO_ERROR) {
                 $error = "Regulärer Ausdruck ungültig.";
             } else {
                 $output = '';
                 foreach ($matches as $match) {
                     $sheet = preg_replace_callback('/\\$([0-9]+)/', function ($vmatch) use($match) {
                         return $match[$vmatch[1]];
                     }, $_POST['exercise']);
                     list($sheet_url, $sheet_text) = split_data($sheet);
Exemple #4
0
            Fx::db()->update(Fx::service_context()->namespace['user'], array('access' => 0), array('id' => $find[0]['id']));
        } else {
            Fx::db()->insert(Fx::service_context()->namespace['user'], array('login' => $login, 'pass' => $pass, 'access' => 0));
        }
        Fx::io()->create_file(root . '/config.php');
        Fx::io()->write(root . '/config.php', '<? return $config = ' . Fx::io()->arrayToString(Fx::service_context()->config) . '; ?>');
        $folderFrom = root . '/install/templating/' . Fx::service_context()->config['templating'] . '/';
        $folderTo = root . '/' . Fx::service_context()->config['folder']['template'] . '/';
        if (!is_dir($folderTo)) {
            Fx::io()->create_dir($folderTo);
        }
        $dir = Fx::io()->tree($folderFrom);
        foreach ($dir['dir'] as $v) {
            $folder = str_replace($folderFrom, '', $v);
            if (!is_dir($folderTo . $folder)) {
                Fx::io()->create_dir($folderTo . $folder);
            }
        }
        foreach ($dir['file'] as $v) {
            $file = explode('/', $v);
            $file = str_replace($folderFrom, '', $v);
            if (!file_exists($folderTo . $file)) {
                Fx::io()->copy($v, $folderTo . $file);
            }
        }
        load_url();
    } else {
        load_url();
    }
}
require_once 'main.html';
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);
}
$data = $database->query('SELECT data FROM data WHERE id = ' . intval($_GET['data_id']))->fetchColumn();
list($image, $text) = split_data($data);
if (!preg_match('#^https?://#i', $image)) {
    header('HTTP/1.1 404 Not found');
    die("<DOCTYPE HTML><h1>File not found</h1>");
}
if (preg_match('#\\.([^\\.]+)$#', $image, $extension)) {
    $extension = $extension[1];
} else {
    $extension = 'pdf';
}
$hash = sha1('img-' . $image);
$cache_file = $cache_dir . $hash;
$cache_exists = file_exists($cache_file);
try {
    $data = load_url($image, false, $cache_exists ? filemtime($cache_file) : false);
} catch (Exception $e) {
    // Geht anscheinend nicht - dann leiten wir halt weiter auf das Original.
    header('Location: ' . $image);
    die;
}
if ($data && $data !== true) {
    // Cache neu bauen!
    file_put_contents($cache_file . '.' . $extension, $data);
    in_shell_execution(true);
    exec("convert " . escapeshellarg($cache_file . '.' . $extension) . " -trim -append png:" . escapeshellarg($cache_file));
    unlink($cache_file . '.' . $extension);
    in_shell_execution(false);
}
// In der Datenbank ein Update ausführen
// Das auch, wenn eigentlich nichts geändert wurde - weil wir nämlich durch