Пример #1
0
function search()
{
    $tpl = new templates();
    $MyPage = CurrentPageName();
    $table = "events";
    $page = 1;
    $ORDER = "ORDER BY zDate DESC";
    $total = 0;
    $pattern = base64_encode($_GET["search"]);
    $sock = new sockets();
    $removeService = false;
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    if ($_POST["qtype"] == "service") {
        if ($_POST["query"] != null) {
            $_GET["prefix"] = $_POST["query"];
            $_POST["query"] = null;
        }
    }
    if ($_POST["qtype"] == "service") {
        if ($_POST["query"] != null) {
            $_GET["prefix"] = $_POST["query"];
            $_POST["query"] = null;
        }
    }
    if ($_GET["force-prefix"] != null) {
        if ($_POST["qtype"] == "service") {
            $_POST["query"] = null;
        }
        $_GET["prefix"] = $_GET["force-prefix"];
        $removeService = true;
    }
    $syslogpath = urlencode($_GET["syslog-path"]);
    if ($_GET["query"] != null) {
        $search = base64_encode($_POST["query"]);
        $sock->getFrameWork("cmd.php?syslog-query={$search}&prepend={$_GET["prepend"]}&rp={$_POST["rp"]}&prefix={$_GET["prefix"]}&syslog-path={$syslogpath}");
        $array = explode("\n", @file_get_contents("/usr/share/artica-postfix/ressources/logs/web/syslog.query"));
        $total = count($array);
    } else {
        $sock->getFrameWork("cmd.php?syslog-query=&prepend={$_GET["prepend"]}&rp={$_POST["rp"]}&prefix={$_GET["prefix"]}&syslog-path={$syslogpath}");
        $array = explode("\n", @file_get_contents("/usr/share/artica-postfix/ressources/logs/web/syslog.query"));
        $total = count($array);
    }
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    if ($_POST["sortname"] != null) {
        if ($_POST["sortorder"] == "desc") {
            krsort($array);
        } else {
            ksort($array);
        }
    }
    $today = $tpl->_ENGINE_parse_body("{today}");
    $c = 0;
    if ($GLOBALS["VERBOSE"]) {
        echo "<H1>Array of " . count($array) . " Lines</H1>\n";
    }
    while (list($key, $line) = each($array)) {
        if (trim($line) == null) {
            continue;
        }
        $date = null;
        $host = null;
        $service = null;
        $pid = null;
        $color = "black";
        if (preg_match("#(ERROR|WARN|FATAL|UNABLE|Failed|not found|denied|OVERLOAD)#i", $line)) {
            $color = "#D61010";
        }
        $style = "<span style='color:{$color}'>";
        $styleoff = "</span>";
        if (preg_match("#^(.*?)\\s+([0-9]+)\\s+([0-9:]+)\\s+(.*?)\\s+(.*?)\\[([0-9]+)\\]:\\s+(.*)#", $line, $re)) {
            $date = "{$re[1]} {$re[2]} " . date('Y') . " {$re[3]}";
            $host = $re[4];
            $service = $re[5];
            $pid = $re[6];
            $line = $re[7];
            $strtotime = strtotime($date);
            if (date("Y-m-d", $strtotime) == date("Y-m-d")) {
                $date = $today . " " . date('H:i:s', strtotime($date));
            } else {
                $date = date('m-d H:i:s', strtotime($date));
            }
            if ($_GET["prefix"] == "haproxy") {
                $line = Parse_haproxy($line);
            }
            $lines = array();
            $lines[] = "{$style}{$date}{$styleoff}";
            if (!$removeService) {
                $lines[] = "{$style}{$service}{$styleoff}";
            }
            $lines[] = "{$style}{$pid}{$styleoff}";
            $lines[] = "{$style}{$line}{$styleoff}";
            $c++;
            $data['rows'][] = array('id' => md5($line), 'cell' => $lines);
            continue;
        }
        if (preg_match("#^(.*?)\\s+([0-9]+)\\s+([0-9:]+)\\s+(.*?)\\s+(.*?):\\s+(.*)#", $line, $re)) {
            $date = "{$re[1]} {$re[2]} " . date('Y') . " {$re[3]}";
            $host = $re[4];
            $service = $re[5];
            $pid = null;
            $line = $re[6];
            $strtotime = strtotime($date);
            if (date("Y-m-d", $strtotime) == date("Y-m-d")) {
                $date = $today . " " . date('H:i:s', strtotime($date));
            } else {
                $date = date('m-d H:i:s', strtotime($date));
            }
            if ($_GET["prefix"] == "haproxy") {
                $line = Parse_haproxy($line);
            }
            $lines = array();
            $lines[] = "{$style}{$date}{$styleoff}";
            if (!$removeService) {
                $lines[] = "{$style}{$service}{$styleoff}";
            }
            $lines[] = "{$style}{$pid}{$styleoff}";
            $lines[] = "{$style}{$line}{$styleoff}";
            $c++;
            $data['rows'][] = array('id' => md5($line), 'cell' => $lines);
            continue;
        }
        if ($_GET["prefix"] == "haproxy") {
            $line = Parse_haproxy($line);
        }
        $lines = array();
        $lines[] = "{$style}{$date}{$styleoff}";
        if (!$removeService) {
            $lines[] = "{$style}{$service}{$styleoff}";
        }
        $lines[] = "{$style}{$pid}{$styleoff}";
        $lines[] = "{$style}{$line}{$styleoff}";
        $c++;
        $data['rows'][] = array('id' => md5($line), 'cell' => $lines);
    }
    if ($c == 0) {
        json_error_show("no data");
    }
    $data['total'] = $c;
    echo json_encode($data);
}
Пример #2
0
function search()
{
    $tpl = new templates();
    $MyPage = CurrentPageName();
    $users = new usersMenus();
    $page = 1;
    $total = 0;
    $pattern = base64_encode($_GET["search"]);
    $sock = new sockets();
    $removeService = false;
    $maillogpath = $users->maillog_path;
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    if ($_POST["qtype"] == "service") {
        if ($_POST["query"] != null) {
            $_GET["prefix"] = $_POST["query"];
            $_POST["query"] = null;
        }
    }
    if ($_POST["qtype"] == "service") {
        if ($_POST["query"] != null) {
            $_GET["prefix"] = $_POST["query"];
            $_POST["query"] = null;
        }
    }
    if ($_GET["force-prefix"] != null) {
        if ($_POST["qtype"] == "service") {
            $_POST["query"] = null;
        }
        $_GET["prefix"] = $_GET["force-prefix"];
        $removeService = true;
    }
    if ($_POST["query"] != null) {
        $search = base64_encode(string_to_regex($_POST["query"]));
        $sock->getFrameWork("klms.php?syslog-query={$search}&prepend={$_GET["prepend"]}&rp={$_POST["rp"]}&prefix={$_GET["prefix"]}&maillog={$maillogpath}");
        $array = explode("\n", @file_get_contents("/usr/share/artica-postfix/ressources/logs/web/syslog.query"));
        $total = count($array);
    } else {
        $sock->getFrameWork("klms.php?syslog-query=&prepend={$_GET["prepend"]}&rp={$_POST["rp"]}&prefix={$_GET["prefix"]}&maillog={$maillogpath}");
        $array = explode("\n", @file_get_contents("/usr/share/artica-postfix/ressources/logs/web/syslog.query"));
        $total = count($array);
    }
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    if ($_POST["sortname"] != null) {
        if ($_POST["sortorder"] == "desc") {
            krsort($array);
        } else {
            ksort($array);
        }
    }
    $c = 0;
    while (list($key, $line) = each($array)) {
        if (trim($line) == null) {
            continue;
        }
        $date = null;
        $host = null;
        $service = null;
        $pid = null;
        $color = "black";
        if (preg_match("#(ERROR|WARN|FATAL|UNABLE|crashed|out of date|expires soon)#i", $line)) {
            $color = "#D61010";
        }
        $style = "<span style='color:{$color}'>";
        $styleoff = "</span>";
        if (preg_match("#^(.*?)\\s+([0-9]+)\\s+([0-9:]+)\\s+(.*?)\\s+(.*?):\\s+(.*)#", $line, $re)) {
            $date = "{$re[1]} {$re[2]} " . date('Y') . " {$re[3]}";
            $host = $re[4];
            $service = $re[5];
            $pid = null;
            $line = $re[6];
            $date = date('m-d H:i:s', strtotime($date));
            if ($_GET["prefix"] == "haproxy") {
                $line = Parse_haproxy($line);
            }
            $lines = array();
            $lines[] = "{$style}{$date}{$styleoff}";
            $lines[] = "{$style}{$line}{$styleoff}";
            $c++;
            $data['rows'][] = array('id' => md5($line), 'cell' => $lines);
            continue;
        }
        if ($_GET["prefix"] == "haproxy") {
            $line = Parse_haproxy($line);
        }
        $lines = array();
        $lines[] = "{$style}{$date}{$styleoff}";
        if (!$removeService) {
            $lines[] = "{$style}{$service}{$styleoff}";
        }
        $lines[] = "{$style}{$pid}{$styleoff}";
        $lines[] = "{$style}{$line}{$styleoff}";
        $c++;
        $data['rows'][] = array('id' => md5($line), 'cell' => $lines);
    }
    $data['total'] = $c;
    echo json_encode($data);
}