예제 #1
0
function tabs()
{
    $page = CurrentPageName();
    $tpl = new templates();
    $artica_meta = new mysql_meta();
    $isProxyAll = $artica_meta->isProxyAll();
    if ($isProxyAll > 0) {
        $array["proxys"] = "Proxys ({$isProxyAll})";
    }
    $array["hosts"] = '{hosts}';
    $array["groups"] = '{groups2}';
    if ($isProxyAll > 0) {
        if ($artica_meta->COUNT_ROWS("hotspot_members") > 0) {
            $array["hotspot_members"] = '{hotspot_members}';
        }
    }
    if ($isProxyAll > 0) {
        $array["categories"] = '{your_categories}';
        $array["acls"] = '{acls}';
    }
    $array["server-params"] = "{main_parameters}";
    //$array["uploads"]='{uploads}';
    while (list($num, $ligne) = each($array)) {
        if ($num == "proxys") {
            $html[] = $tpl->_ENGINE_parse_body("<li><a href=\"artica-meta.proxys.php\"><span style='font-size:22px'>{$ligne}</span></a></li>\n");
            continue;
        }
        if ($num == "hosts") {
            $html[] = $tpl->_ENGINE_parse_body("<li><a href=\"artica-meta.hosts.php\"><span style='font-size:22px'>{$ligne}</span></a></li>\n");
            continue;
        }
        if ($num == "categories") {
            $html[] = $tpl->_ENGINE_parse_body("<li><a href=\"artica-meta.proxys.categories.php\"><span style='font-size:22px'>{$ligne}</span></a></li>\n");
            continue;
        }
        if ($num == "groups") {
            $html[] = $tpl->_ENGINE_parse_body("<li><a href=\"artica-meta.groups.php\"><span style='font-size:22px'>{$ligne}</span></a></li>\n");
            continue;
        }
        if ($num == "server-params") {
            $html[] = $tpl->_ENGINE_parse_body("<li><a href=\"artica-meta.php?parameters=yes\"><span style='font-size:22px'>{$ligne}</span></a></li>\n");
            continue;
        }
        if ($num == "hotspot_members") {
            $html[] = $tpl->_ENGINE_parse_body("<li><a href=\"artica-meta.hotspot_members.php\"><span style='font-size:22px'>{$ligne}</span></a></li>\n");
            continue;
        }
        if ($num == "uploads") {
            $html[] = $tpl->_ENGINE_parse_body("<li><a href=\"artica-meta.uploads.php\"><span style='font-size:22px'>{$ligne}</span></a></li>\n");
            continue;
        }
        if ($num == "acls") {
            $html[] = $tpl->_ENGINE_parse_body("<li><a href=\"artica-meta.proxy.acls.php\"><span style='font-size:22px'>{$ligne}</span></a></li>\n");
            continue;
        }
        $html[] = $tpl->_ENGINE_parse_body("<li><a href=\"{$page}?{$num}=yes&uuid=" . urlencode($_GET["uuid"]) . "\"><span style='font-size:22px'>{$ligne}</span></a></li>\n");
    }
    echo build_artica_tabs($html, "meta-start", 1490);
}
function SearchComputers()
{
    $tpl = new templates();
    $MyPage = CurrentPageName();
    $q = new mysql_meta();
    $fontsize = "14px";
    $cs = 0;
    $page = 1;
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $_POST["query"] = trim($_POST["query"]);
    $FORCE = 1;
    if ($_GET["uuid"] != null) {
        $FORCE = "uuid='{$_GET["uuid"]}'";
    }
    $search = '%';
    $table = "networks_hosts";
    $page = 1;
    $total = 0;
    if ($q->COUNT_ROWS($table) == 0) {
        json_error_show("no data", 1);
    }
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    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'];
    }
    $searchstring = string_to_flexquery();
    if ($searchstring != null) {
        $sql = "SELECT COUNT(*) as TCOUNT FROM `{$table}` WHERE {$FORCE}  {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_events"));
        if (!$q->ok) {
            if (preg_match("#marked as crashed#", $q->mysql_error)) {
                $q->QUERY_SQL("DROP TABLE `{$table}`", "artica_events");
            }
        }
        $total = $ligne["TCOUNT"];
    } else {
        if (strlen($FORCE) > 2) {
            $sql = "SELECT COUNT(*) as TCOUNT FROM `{$table}` WHERE {$FORCE}";
            $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_events"));
            if (!$q->ok) {
                if (preg_match("#marked as crashed#", $q->mysql_error)) {
                    $q->QUERY_SQL("DROP TABLE `{$table}`", "artica_events");
                }
            }
            $total = $ligne["TCOUNT"];
        } else {
            $total = $q->COUNT_ROWS($table, "artica_events");
        }
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    if (!is_numeric($rp)) {
        $rp = 50;
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $sql = "SELECT *  FROM `{$table}` WHERE {$FORCE} {$searchstring} {$ORDER} {$limitSql}";
    $results = $q->QUERY_SQL($sql, "artica_events");
    if (!$q->ok) {
        if (preg_match("#marked as crashed#", $q->mysql_error)) {
            $q->QUERY_SQL("DROP TABLE `{$table}`", "artica_events");
        }
    }
    if (!$q->ok) {
        json_error_show($q->mysql_error . "<br>{$sql}", 0);
    }
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    $CurrentPage = CurrentPageName();
    if (mysql_num_rows($results) == 0) {
        json_error_show("no data");
    }
    $uuid = urlencode($_GET["uuid"]);
    while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) {
        if ($ligne["OSNAME"] == "Unknown") {
            $ligne["OSNAME"] = null;
        }
        $cs++;
        $macenc = urlencode($ligne["MAC"]);
        $jslink = "<a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('{$MyPage}?mac-js={$macenc}&uuid={$uuid}&t={$_GET["t"]}');\"\n\t\tstyle='font-size:{$fontsize};text-decoration:underline'>";
        $data['rows'][] = array('id' => md5(serialize($ligne)), 'cell' => array("<span style='font-size:{$fontsize}'>{$jslink}{$ligne["hostname"]}</a></span>", "<span style='font-size:{$fontsize}'>{$jslink}{$ligne["IPADDR"]}</a></span>", "<span style='font-size:{$fontsize}'>{$jslink}{$ligne["MAC"]}</a></span>", "<span style='font-size:{$fontsize}'>{$jslink}{$ligne["OSNAME"]}</a></span>", "<span style='font-size:{$fontsize}'>{$jslink}{$ligne["username"]}</a></span>", ""));
    }
    echo json_encode($data);
}
function table_list()
{
    $tpl = new templates();
    $MyPage = CurrentPageName();
    $q = new mysql_meta();
    $fontsize = "16px";
    $cs = 0;
    $page = 1;
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    if (!is_numeric($rp)) {
        $rp = 50;
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $_POST["query"] = trim($_POST["query"]);
    $FORCE = "uuid='{$_GET["uuid"]}'";
    $search = '%';
    $table = "philesight";
    if ($_GET["dev"] != null) {
        $FORCE = " ((partition='{$_GET["dev"]}') OR (hd='{$_GET["dev"]}')) AND (uuid='{$_GET["uuid"]}')";
    }
    $page = 1;
    if (!$q->TABLE_EXISTS($table, "artica_backup")) {
        $q->check_storage_table();
    }
    if (!$q->TABLE_EXISTS($table, "artica_backup")) {
        json_error_show("{$table} no such table", 1);
    }
    $total = 0;
    if ($q->COUNT_ROWS($table, "artica_backup") == 0) {
        json_error_show("no data", 1);
    }
    $searchstring = string_to_flexquery();
    if ($searchstring != null) {
        $sql = "SELECT COUNT(*) as TCOUNT FROM `{$table}` WHERE {$FORCE}  {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup"));
        if (!$q->ok) {
            if (preg_match("#marked as crashed#", $q->mysql_error)) {
                $q->QUERY_SQL("DROP TABLE `{$table}`", "artica_events");
            }
        }
        $total = $ligne["TCOUNT"];
    } else {
        $total = $q->COUNT_ROWS($table, "artica_backup");
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    if (!is_numeric($rp)) {
        $rp = 50;
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    $sql = "SELECT *  FROM `{$table}` WHERE {$FORCE} {$searchstring} {$ORDER} {$limitSql}";
    $results = $q->QUERY_SQL($sql, "artica_backup");
    if (!$q->ok) {
        if (preg_match("#marked as crashed#", $q->mysql_error)) {
            $q->QUERY_SQL("DROP TABLE `{$table}`", "artica_events");
        }
    }
    if (!$q->ok) {
        json_error_show($q->mysql_error . "<br>{$sql}", 0);
    }
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    $CurrentPage = CurrentPageName();
    if (mysql_num_rows($results) == 0) {
        json_error_show("no data");
    }
    $uuid = urlencode($_GET["uuid"]);
    while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) {
        $color = "black";
        $icon = "&nbsp;";
        $directory = $ligne["directory"];
        $md5 = md5($directory);
        $partition = $ligne["partition"];
        $hd = $ligne["hd"];
        $maxtime = $ligne["maxtime"];
        $lastscan = $ligne["lastscan"];
        $USED = $ligne["USED"];
        $md5 = $ligne["zmd5"];
        $FREEMB = $ligne["FREEMB"];
        if ($lastscan > 0) {
            $lastscan = date("Y-m-d H:i:s", $lastscan);
        }
        $FREEMB = FormatBytes($FREEMB * 1024);
        $directoryenc = urlencode($directory);
        $jslink = "<a href=\"javascript:blur();\"\n\tOnClick=\"javascript:Loadjs('{$MyPage}?directory-js=yes&directory={$directoryenc}');\"\n\tstyle='font-size:{$fontsize};text-decoration:underline;color:{$color}'>";
        $distance = $tpl->_ENGINE_parse_body(distanceOfTimeInWords($ligne["lastscan"], time(), true));
        $icon = imgsimple("graph-32.png", null, "Loadjs('{$MyPage}?graph-js={$directoryenc}&uuid={$_GET["uuid"]}&md5={$md5}')");
        $delete = imgsimple("delete-32.png", null, "Loadjs('{$MyPage}?delete-js={$directoryenc}&uuid={$_GET["uuid"]}')");
        $data['rows'][] = array('id' => md5(serialize($ligne)), 'cell' => array("<span style='font-size:{$fontsize};color:{$color}'>{$jslink}{$lastscan}</a></span><br><i>{$distance}</i>", "<span style='font-size:{$fontsize};color:{$color}'>{$jslink}{$directory}</a></span>", "<span style='font-size:{$fontsize};color:{$color}'>{$jslink}{$partition}</a></span>", "<span style='font-size:{$fontsize};color:{$color}'>{$jslink}{$hd}</a></span>", "<span style='font-size:{$fontsize};color:{$color}'>{$jslink}{$USED}%</a></span>", "<span style='font-size:{$fontsize};color:{$color}'>{$jslink}{$FREEMB}</a></span>", "<span style='font-size:{$fontsize};color:{$color}'>{$icon}</a></span>"));
    }
    echo json_encode($data);
}
예제 #4
0
function search()
{
    $MyPage = CurrentPageName();
    $page = CurrentPageName();
    $tpl = new templates();
    $sock = new sockets();
    $q = new mysql_meta();
    $ArticaMetaPooling = intval($sock->GET_INFO("ArticaMetaPooling"));
    $ArticaMetaUseSendClient = intval($sock->GET_INFO("ArticaMetaUseSendClient"));
    if ($ArticaMetaPooling == 0) {
        $ArticaMetaPooling = 15;
    }
    $switch = intval($_GET["switch"]);
    $table = "metahosts";
    $searchstring = string_to_flexquery();
    $page = 1;
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY `{$_POST["sortname"]}` {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    if ($searchstring != null) {
        $sql = "SELECT COUNT( * ) AS tcount FROM {$table} WHERE 1 {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql));
        if (!$q->ok) {
            json_error_show("Mysql Error [" . __LINE__ . "]: <br>{$q->mysql_error}.<br>{$sql}", 1);
        }
        $total = $ligne["tcount"];
    } else {
        $total = $q->COUNT_ROWS($table);
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    if (!is_numeric($rp)) {
        $rp = 50;
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $sql = "SELECT * FROM {$table} WHERE 1 {$searchstring} {$ORDER} {$limitSql} ";
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        if ($q->mysql_error != null) {
            json_error_show(date("H:i:s") . "<br>SORT:{$_POST["sortname"]}:<br>Mysql Error [L." . __LINE__ . "]: {$q->mysql_error}<br>{$sql}", 1);
        }
    }
    if (mysql_num_rows($results) == 0) {
        json_error_show("no data", 1);
    }
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    $fontsize = "18";
    if ($switch == 1) {
        $fontsize = 12;
    }
    $style = "<span style='font-size:{$fontsize}px'>";
    $free_text = $tpl->javascript_parse_text("{free}");
    $computers = $tpl->javascript_parse_text("{computers}");
    $overloaded_text = $tpl->javascript_parse_text("{overloaded}");
    $orders_text = $tpl->javascript_parse_text("{orders}");
    $policies_text = $tpl->javascript_parse_text("{policies}");
    $directories_monitor = $tpl->javascript_parse_text("{directories_monitor}");
    while ($ligne = mysql_fetch_assoc($results)) {
        $LOGSWHY = array();
        $overloaded = null;
        $loadcolor = "black";
        $StatHourColor = "black";
        $uuid = $ligne["uuid"];
        $hostname = $ligne["hostname"];
        $public_ip = $ligne["public_ip"];
        $updated = $ligne["updated"];
        $version = $ligne["version"];
        $ColorTime = "black";
        $CPU_NUMBER = $ligne["CPU_NUMBER"];
        $CPU_NUMBER_MAX = $ligne["CPU_NUMBER"] + 1.5;
        $load = $ligne["load"];
        $mem_perc = $ligne["mem_perc"];
        $mem_total = FormatBytes($ligne["mem_total"]);
        $proxyversion = null;
        $CountdeComputers_text = null;
        $policies_text_line = null;
        $CountdeComputers = $q->network_hosts_count($uuid);
        $icon_warning_32 = "warning32.png";
        $icon_red_32 = "32-red.png";
        $icon = "ok-32.png";
        $BANDWIDTH = $ligne["BANDWIDTH"];
        $BANDWIDTH_text = null;
        $hostag_switch = null;
        $uuidenc = urlencode($uuid);
        $PING_URI_SWITCH = null;
        if ($ArticaMetaUseSendClient == 1) {
            $PING_URI = "&nbsp;<a href=\"javascript:blur();\" \n\t\t\tOnClick=\"javascript:Loadjs('artica-meta.menus.php?send-ping-js=yes&uuid={$uuidenc}&gpid=0');\"\n\t\t\tstyle='font-size:12px;text-decoration:underline;color:#0021C6'\n\t\t\t>Ping</a>";
        }
        if ($BANDWIDTH > 0) {
            $BANDWIDTH_text = " (" . FormatBytes($BANDWIDTH / 1024) . ")";
        }
        if ($switch == 1) {
            $icon_warning_32 = "22-warn.png";
            $icon_red_32 = "22-red.png";
            $icon = "ok22.png";
        }
        if ($load > $CPU_NUMBER_MAX) {
            $overloaded = "<br><strong style='color:red'>{$overloaded_text}</strong>";
            $icon = $icon_warning_32;
            $loadcolor = "#CC0000";
            $LOGSWHY[] = "{$overloaded_text} {$load}>{$CPU_NUMBER_MAX}";
        }
        $xtime = strtotime($updated);
        $diff = time_diff_min($xtime);
        $Difftext = distanceOfTimeInWords($xtime, time(), true);
        if ($diff > $ArticaMetaPooling) {
            $icon = $icon_warning_32;
            $ColorTime = "#CC0000";
            $LOGSWHY[] = $Difftext . "/{$ArticaMetaPooling}Mn";
        }
        if ($diff > $ArticaMetaPooling * 4) {
            $icon = $icon_red_32;
            $ColorTime = "#CC0000";
            $LOGSWHY[] = $Difftext . "/{$ArticaMetaPooling}Mn";
        }
        $disks = unserialize($ligne["disks"]);
        $SIZE = 0;
        $USED = 0;
        $infodisk = null;
        $DISKS_TEXT = array();
        if ($q->philesight_count($uuid) > 0) {
            $DISKS_TEXT[] = "<a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('artica-meta.hosts.philesight.php?uuid={$uuid}')\"\n\t\t\tstyle='font-size:14px;font-weight:bold;text-decoration:underline'>{$directories_monitor}</a><hr style='margin-bottom:15px;border:0px;'>";
        }
        if (is_array($disks)) {
            $DISKS_TEXT[] = "<ul>";
            while (list($disks, $mainarray) = each($disks)) {
                $SIZE = FormatBytes(intval($mainarray["SIZE"]) / 1024);
                $DISKS_TEXT[] = "<li style='font-weight:bold;font-size:14px'>{$disks} {$SIZE}</li>";
                $DISKS_TEXT[] = "<ul>";
                while (list($part, $partArray) = each($mainarray["PARTS"])) {
                    $color_disk = "black";
                    $POURC = $partArray["POURC"];
                    if ($POURC > 95) {
                        $color_disk = "red";
                        $icon = $icon_red_32;
                        $LOGSWHY[] = "{$part} {used}:{$POURC}%";
                    }
                    $TOT = FormatBytes($partArray["TOT"] / 1024);
                    $AIV = FormatBytes($partArray["AIV"] / 1024);
                    $DISKS_TEXT[] = "<li style='color:{$color_disk}'>{$part} {$TOT} - {used}:{$POURC}% {free}: {$AIV}</li>";
                }
                $DISKS_TEXT[] = "</ul>";
            }
            $DISKS_TEXT[] = "</ul>";
            $infodisk = $tpl->_ENGINE_parse_body(@implode("", $DISKS_TEXT));
        }
        if ($switch == 1) {
            $infodisk = null;
        }
        $info = $tpl->_ENGINE_parse_body("<br>{last_status}:&nbsp;<span style='color:{$ColorTime}'>{$Difftext}</span><br><span style='font-size:12px'>{$CPU_NUMBER} CPU(s), {memory}:{$mem_total}{$overloaded}</span>");
        $cell = array();
        $linkver = "<a href=\"javascript:Loadjs('artica-meta.update.artica.php?uuid={$uuid}');\" \n\t\tstyle='text-decoration:underline'>";
        if ($q->isOrder($uuid, "UPDATE_ARTICA")) {
            $version = "<center style='margin:10px'><img src='img/preloader.gif'></center>";
        }
        if ($ligne["PROXY"] == 1) {
            $proxyuri = "<a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('artica-meta.squid.watchdog-events.php?js=yes&uuid={$uuid}');\"\n\t\tstyle='text-decoration:underline'>";
            $proxyversion = "<br><span style='font-size:12px'>{$proxyuri}Proxy: {$ligne["squidver"]}</a> {$BANDWIDTH_text}</span>";
        }
        if ($CountdeComputers > 0) {
            $CountdeComputers = FormatNumber($CountdeComputers);
            $CountdeComputers_uri = "<a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('artica-meta.networks.hosts.php?js=yes&uuid={$uuid}');\"\n\t\t\tstyle='text-decoration:underline'>";
            $CountdeComputers_text = "<br><span style='font-size:12px'>{$CountdeComputers_uri}{$computers}: <strong>{$CountdeComputers}</strong></a></span>";
        }
        $OrdersText = null;
        $ligneOrders = mysql_fetch_array($q->QUERY_SQL("SELECT COUNT(orderid) as tcount FROM `metaorders` WHERE `uuid`='{$uuid}'"));
        $OrdersCount = $ligneOrders["tcount"];
        if ($OrdersCount > 0) {
            $OrdersText = "<br><a href=\"javascript:blur();\" \n\t\t\tOnClick=\"javascript:Loadjs('artica-meta.hosts.orders.php?uuid={$uuid}');\">\n\t\t\t<strong style='text-decoration:underline;color:#E48407'>{$orders_text}:{$OrdersCount}</strong>";
        }
        $ligneOrders = mysql_fetch_array($q->QUERY_SQL("SELECT COUNT(uuid) as tcount FROM `policies_storage` WHERE `uuid`='{$uuid}'"));
        $OrdersCount = $ligneOrders["tcount"];
        if ($OrdersCount > 0) {
            $policies_text_line = "<br><strong style='text-decoration:underline;color:#E48407'>{$policies_text}:{$OrdersCount}</strong>";
        }
        $events = "<a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('artica-meta.events.php?js=yes&uuid={$uuid}');\"\n\t\tstyle='float:right'><img src='css/images-flexigrid/magnifier.png'></a>";
        $cpus = "<a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('artica-meta.cpustats.php?js=yes&uuid={$uuid}');\"\n\t\tstyle='text-decoration:underline'>";
        $hostsCommands = "<a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('artica-meta.menus.php?js=yes&uuid={$uuid}');\"\n\t\tstyle='text-decoration:underline'>";
        $hostag = utf8_encode($ligne["hostag"]);
        if ($hostag != null) {
            $hostag = "<br><i style='font-size:12px'>{$hostag}</i>";
        }
        if ($switch == 1) {
            $info = null;
            $hostag = null;
            $proxyversion = null;
            $CountdeComputers_text = null;
            $events = null;
            $hostag_switch = utf8_encode($ligne["hostag"]);
            $PING_URI_SWITCH = $PING_URI;
            $PING_URI = null;
            if (count($LOGSWHY) > 0) {
                $infodisk = $tpl->_ENGINE_parse_body("<span style='color:red;font-size:12px'>" . @implode(", ", $LOGSWHY) . "</span>");
            }
        }
        $cell = array();
        $link_ip = "<a href=\"https://{$public_ip}:9000\" style='text-decoration:underline' target=_new>";
        $cell[] = "<img src=\"img/{$icon}\">";
        $cell[] = "{$style}{$hostsCommands}{$hostname}{$hostag}</a>{$PING_URI_SWITCH}{$events} </span>{$info}{$proxyversion}{$CountdeComputers_text}{$OrdersText}{$policies_text_line}";
        $cell[] = "{$style}<span style='color:{$loadcolor}'>{$load}</span></span>";
        $cell[] = "{$style}{$cpus}{$mem_perc}%</a></span>";
        $cell[] = $hostag_switch . "&nbsp;" . $infodisk;
        $cell[] = "{$style}{$link_ip}{$public_ip}</a>{$PING_URI}</span>";
        $cell[] = "{$style}{$linkver}{$version}</a></span>";
        $data['rows'][] = array('id' => $ligne['uuid'], 'cell' => $cell);
    }
    echo json_encode($data);
}
function clean_tables()
{
    $pidTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    $unix = new unix();
    $TImExec = $unix->file_time_min($pidTime);
    if ($TImExec < 1440) {
        return;
    }
    @unlink($pidTime);
    @file_put_contents($pidTime, time());
    $array["squid_admin_mysql"] = true;
    $sock = new sockets();
    $settings = unserialize(base64_decode($sock->GET_INFO("FcronSchedulesParams")));
    if (!is_numeric($settings["max_events"])) {
        $settings["max_events"] = "10000";
    }
    $q = new mysql_meta();
    if ($GLOBALS["VERBOSE"]) {
        echo "Checking {$c} tables\n";
    }
    $c = 0;
    $max = count($array);
    while (list($table, $lib) = each($array)) {
        $c++;
        if (!$q->TABLE_EXISTS($table, "articameta")) {
            if ($GLOBALS["VERBOSE"]) {
                echo "{$table}: No such table\n";
            }
            continue;
        }
        $FileData = "/var/lib/mysql/articameta/{$table}.MYD";
        $NumRows = $q->COUNT_ROWS($table, "articameta");
        $size = @filesize($FileData);
        $size = $size / 1024;
        $size = $size / 1024;
        $size = round($size, 2);
        if ($GLOBALS["VERBOSE"]) {
            echo "{$table}:[{$c}/{$max}] {$NumRows} rows, {$size}MB Max rows:{$settings["max_events"]}\n";
        }
        if ($size > 500) {
            if ($GLOBALS["VERBOSE"]) {
                echo "{$table} is more than 500MB > purge it\n";
            }
            $q->QUERY_SQL("TRUNCATE TABLE `{$table}` ", "articameta");
            continue;
        }
        if ($NumRows > $settings["max_events"]) {
            $toDelete = $NumRows - $settings["max_events"];
            if ($GLOBALS["VERBOSE"]) {
                echo "{$table} DELETING {$toDelete} rows\n";
            }
            $q->QUERY_SQL("DELETE FROM `{$table}` ORDER BY zDate LIMIT {$toDelete}", "articameta");
            continue;
        }
        $q->QUERY_SQL("DELETE FROM `{$table}` WHERE zDate<DATE_SUB(NOW(),INTERVAL 60 DAY)", "articameta");
    }
}
function categories_search()
{
    $MyPage = CurrentPageName();
    $page = CurrentPageName();
    $tpl = new templates();
    $sock = new sockets();
    $q = new mysql_meta();
    $t = $_GET["t"];
    $OnlyPersonal = 0;
    $error_license = null;
    $sql = "SELECT * FROM webfiltering_categories";
    $table = "webfiltering_categories";
    $searchstring = string_to_flexquery();
    $page = 1;
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    if ($searchstring != null) {
        $sql = "SELECT COUNT( * ) AS tcount FROM {$table} WHERE 1 {$searchstring}";
        writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup"));
        if (!$q->ok) {
            json_error_show("Mysql Error [" . __LINE__ . "]: {$q->mysql_error}.<br>{$sql}", 1);
        }
        $total = $ligne["tcount"];
    } else {
        $total = $q->COUNT_ROWS($table);
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    if (!is_numeric($rp)) {
        $rp = 50;
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $sql = "SELECT * FROM {$table} WHERE 1 {$searchstring} {$ORDER} {$limitSql} ";
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        if ($q->mysql_error != null) {
            json_error_show(date("H:i:s") . "<br>SORT:{$_POST["sortname"]}:<br>Mysql Error [L." . __LINE__ . "]: {$q->mysql_error}<br>{$sql}", 0);
        }
    }
    if (mysql_num_rows($results) == 0) {
        json_error_show("Not found...", 1);
    }
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    $enc = new mysql_catz();
    $field = "category";
    $field_description = "category_description";
    $q2 = new mysql_squid_builder();
    while ($ligne = mysql_fetch_assoc($results)) {
        $color = "black";
        $category = $ligne["category"];
        $categoryname = $category;
        $text_category = null;
        $itemsEncTxt = "-";
        $sql = "SELECT COUNT( pattern ) AS tcount FROM webfiltering_categories WHERE category='{$category}'";
        $ligne2 = mysql_fetch_array($q->QUERY_SQL($sql));
        $items = $ligne2["tcount"];
        $text_category = $tpl->_ENGINE_parse_body(utf8_decode($ligne[$field_description]));
        $text_category = trim($text_category);
        $linkcat = "<a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('{$MyPage}?add-perso-cat-js=yes&cat={$categoryname}&t={$t}',true)\"\n\t\t\tstyle='font-size:20px;font-weight:bold;color:{$color};text-decoration:underline'>";
        $categoryname_text = utf8_encode($categoryname);
        $categoryText = $tpl->_ENGINE_parse_body("<span style='font-size:20px';font-weight:bold'>{$linkcat}{$categoryname_text}</span>\n\t\t\t\t\t</a><br><span style='font-size:18px;width:100%;font-weight:normal'><i>{$text_category}</i></span>{$error_license}");
        if ($items > 0) {
            $itemsEncTxt = "<span style='font-size:18px;font-weight:bold'>" . numberFormat($items, 0, "", " ");
            "</span>";
        }
        $compile = imgsimple("compile-distri-48.png", null, "DansGuardianCompileDB('{$categoryname}')");
        $delete = imgsimple("dustbin-48.png", null, "TableCategoryPurge('{$category}')");
        if ($categoryname == "UnkNown") {
            $linkcat = null;
            $delete = imgsimple("delete-48.png", null, "TableCategoryPurge('')");
        }
        $cell = array();
        $cell[] = $categoryText;
        $cell[] = $itemsEncTxt;
        $cell[] = "<center>{$delete}</center>";
        $data['rows'][] = array('id' => $ligne['ID'], 'cell' => $cell);
    }
    echo json_encode($data);
}
예제 #7
0
function search()
{
    $MyPage = CurrentPageName();
    $page = CurrentPageName();
    $tpl = new templates();
    $sock = new sockets();
    $q = new mysql_meta();
    $table = "metagroups";
    if (!$q->TABLE_EXISTS($table)) {
        $sql = "CREATE TABLE IF NOT EXISTS `metagroups` (\n\t\t\t\t`ID` INT(10) NOT NULL AUTO_INCREMENT,\n\t\t\t\t`groupname` varchar(90) NOT NULL,\n\t\t\t\t`CountHosts` smallint(3) NOT NULL DEFAULT 0,\n\t\t\t\tPRIMARY KEY (`ID`),\n\t\t\t\tKEY `groupname` (`groupname`),\n\t\t\t\tKEY `CountHosts` (`CountHosts`)\n\t\t\t\t) ENGINE=MYISAM;";
        $q->QUERY_SQL($sql);
        if (!$q->ok) {
            echo json_error_show($q->mysql_error, 1);
        }
    }
    $searchstring = string_to_flexquery();
    $page = 1;
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY `{$_POST["sortname"]}` {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    if ($searchstring != null) {
        $sql = "SELECT COUNT( * ) AS tcount FROM {$table} WHERE 1 {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql));
        if (!$q->ok) {
            json_error_show("Mysql Error [" . __LINE__ . "]: <br>{$q->mysql_error}.<br>{$sql}", 1);
        }
        $total = $ligne["tcount"];
    } else {
        $total = $q->COUNT_ROWS($table);
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    if (!is_numeric($rp)) {
        $rp = 50;
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $sql = "SELECT * FROM {$table} WHERE 1 {$searchstring} {$ORDER} {$limitSql} ";
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        if ($q->mysql_error != null) {
            json_error_show(date("H:i:s") . "<br>SORT:{$_POST["sortname"]}:<br>Mysql Error [L." . __LINE__ . "]: {$q->mysql_error}<br>{$sql}", 1);
        }
    }
    if (mysql_num_rows($results) == 0) {
        json_error_show("no data", 1);
    }
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    $fontsize = "22";
    $style = " style='font-size:{$fontsize}px'";
    $styleHref = " style='font-size:{$fontsize}px;text-decoration:underline'";
    $free_text = $tpl->javascript_parse_text("{free}");
    $computers = $tpl->javascript_parse_text("{computers}");
    $overloaded_text = $tpl->javascript_parse_text("{overloaded}");
    $orders_text = $tpl->javascript_parse_text("{orders}");
    $directories_monitor = $tpl->javascript_parse_text("{directories_monitor}");
    while ($ligne = mysql_fetch_assoc($results)) {
        $LOGSWHY = array();
        $overloaded = null;
        $loadcolor = "black";
        $StatHourColor = "black";
        $ColorTime = "black";
        $groupname = $ligne["groupname"];
        $icon_warning_32 = "warning32.png";
        $icon_red_32 = "32-red.png";
        $icon = "ok-32.png";
        $urijs = "Loadjs('{$MyPage}?group-js=yes&ID={$ligne["ID"]}')";
        $link = "<a href=\"javascript:blur();\" OnClick=\"javascript:{$urijs}\" {$styleHref}>";
        $orders = imgtootltip("48-settings.png", null, "Loadjs('artica-meta.menus.php?gpid={$ligne["ID"]}');");
        $transparent = imgtootltip("ok-pass-48.png", null, "Loadjs('artica-meta.squidtransparent-white.php?gpid={$ligne["ID"]}');");
        $delete = imgtootltip("delete-32.png", null, "Loadjs('{$MyPage}?delete-group-js={$ligne["ID"]}')");
        $count = $q->group_count($ligne["ID"]);
        $cell = array();
        $cell[] = "<center><img src=\"img/{$icon}\"></center>";
        $cell[] = "<span {$style}>{$link}{$groupname}</a></span>";
        $cell[] = "<center {$style}>{$link}{$count}</a></center>";
        $cell[] = "<center {$style}>{$orders}</a></center>";
        $cell[] = "<center {$style}>{$transparent}</a></center>";
        $cell[] = "<center {$style}>{$delete}</a></center>";
        $data['rows'][] = array('id' => $ligne['uuid'], 'cell' => $cell);
    }
    echo json_encode($data);
}
예제 #8
0
function search()
{
    $MyPage = CurrentPageName();
    $page = CurrentPageName();
    $tpl = new templates();
    $sock = new sockets();
    $q = new mysql_meta();
    $ArticaMetaPooling = intval($sock->GET_INFO("ArticaMetaPooling"));
    $ArticaMetaUseSendClient = intval($sock->GET_INFO("ArticaMetaUseSendClient"));
    $ArticaLinkAutoconnect = intval($sock->GET_INFO("ArticaLinkAutoconnect"));
    $MetaUfdbArticaVer = intval($sock->GET_INFO("MetaUfdbArticaVer"));
    if ($ArticaMetaPooling == 0) {
        $ArticaMetaPooling = 15;
    }
    $table = "metahosts";
    if (isset($_POST["qtype"])) {
        if (preg_match("#prxy([0-9\\.]+)#", $_POST["qtype"], $re)) {
            $_POST["query"] = $re[1];
            $_POST["qtype"] = "squidver";
        }
        if (preg_match("#^([0-9\\.]+)#", $_POST["qtype"])) {
            $_POST["query"] = $_POST["qtype"];
            $_POST["qtype"] = "version";
        }
    }
    $searchstring = string_to_flexquery();
    $page = 1;
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY `{$_POST["sortname"]}` {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    if ($searchstring != null) {
        $sql = "SELECT COUNT( * ) AS tcount FROM {$table} WHERE 1 {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql));
        if (!$q->ok) {
            json_error_show("Mysql Error [" . __LINE__ . "]: <br>{$q->mysql_error}.<br>{$sql}", 1);
        }
        $total = $ligne["tcount"];
    } else {
        $total = $q->COUNT_ROWS($table);
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    if (!is_numeric($rp)) {
        $rp = 50;
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $sql = "SELECT * FROM {$table} WHERE 1 {$searchstring} {$ORDER} {$limitSql} ";
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        if ($q->mysql_error != null) {
            json_error_show(date("H:i:s") . "<br>SORT:{$_POST["sortname"]}:<br>Mysql Error [L." . __LINE__ . "]: {$q->mysql_error}<br>{$sql}", 1);
        }
    }
    if (mysql_num_rows($results) == 0) {
        json_error_show("no data", 1);
    }
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    $fontsize = "18";
    if ($switch == 1) {
        $fontsize = 12;
    }
    $style = "<span style='font-size:18px'>";
    $free_text = $tpl->javascript_parse_text("{free}");
    $computers = $tpl->javascript_parse_text("{computers}");
    $overloaded_text = $tpl->javascript_parse_text("{overloaded}");
    $orders_text = $tpl->javascript_parse_text("{orders}");
    $policies_text = $tpl->javascript_parse_text("{policies}");
    $directories_monitor = $tpl->javascript_parse_text("{directories_monitor}");
    $proxy_statistics = $tpl->javascript_parse_text("{SQUID_STATS1}");
    $cache_rate = $tpl->javascript_parse_text("{cache_rate}");
    $clone_of_text = $tpl->javascript_parse_text("{clone_of}");
    $proxy_in_emergency_mode = $tpl->javascript_parse_text("{proxy_in_emergency_mode}");
    $webfiltering = $tpl->javascript_parse_text("{webfiltering}");
    $activedirectory_emergency_mode = $tpl->javascript_parse_text("{activedirectory_emergency_mode}");
    while ($ligne = mysql_fetch_assoc($results)) {
        $LOGSWHY = array();
        $overloaded = null;
        $cloneFrom = $ligne["cloneFrom"];
        $loadcolor = "black";
        $StatHourColor = "black";
        $uuid = $ligne["uuid"];
        $hostname = $ligne["hostname"];
        $public_ip = $ligne["public_ip"];
        $updated = $ligne["updated"];
        $version = $ligne["version"];
        $ColorTime = "black";
        $CPU_NUMBER = $ligne["CPU_NUMBER"];
        $CPU_NUMBER_MAX = $ligne["CPU_NUMBER"] + 1.5;
        $load = $ligne["load"];
        $mem_perc = $ligne["mem_perc"];
        $mem_total = FormatBytes($ligne["mem_total"]);
        $proxyversion = null;
        $CountdeComputers_text = null;
        $policies_text_line = null;
        $BANDWIDTH = $ligne["BANDWIDTH"];
        $TaskPercent = intval($ligne["TaskPercent"]);
        $BANDWIDTH_text = null;
        $hostag_switch = null;
        $uuidenc = urlencode($uuid);
        $PING_URI_SWITCH = null;
        $PROXY_PERFS = null;
        $END_PROXY = null;
        $PROXY_LINE = null;
        $PROXYEMERG = $ligne["PROXYEMERG"];
        $webfiltering_version = null;
        $UFDBARTICA = intval($ligne["UFDBARTICA"]);
        $UFDB_ENABLED = intval($ligne["UFDB_ENABLED"]);
        $WINDOWSAD = intval($ligne["WINDOWSAD"]);
        $ADEMERG = intval($ligne["ADEMERG"]);
        $PROXYEMERG_ICON = 0;
        $link_ip = null;
        $secondincon = null;
        $icon_warning_32 = "22-warn.png";
        $icon_red_32 = "22-red.png";
        $icon = "ok22.png";
        $icon_panneau_32 = "warning-panneau-24.png";
        $icon_performance = $icon;
        $icon_activedirectory = "ok22-grey.png";
        $icon_ufdb = "ok22-grey.png";
        $icon_disk = $icon;
        if (preg_match("#^([0-9\\.]+)-#", $ligne["squidver"], $rz)) {
            $ligne["squidver"] = $rz[1];
        }
        if ($ArticaMetaUseSendClient == 1) {
            $PING_URI = "&nbsp;<a href=\"javascript:blur();\" \n\t\t\tOnClick=\"javascript:Loadjs('artica-meta.menus.php?send-ping-js=yes&uuid={$uuidenc}&gpid=0');\"\n\t\t\tstyle='font-size:18px;text-decoration:underline;color:#0021C6'\n\t\t\t>Ping</a>";
        }
        if ($UFDB_ENABLED == 1) {
            if ($UFDBARTICA > 0) {
                $UFDBARTICAT = date("Y-m-d H:i:s", $UFDBARTICA);
                $webfiltering_version = "<br>{$webfiltering} {$UFDBARTICAT}";
            }
        }
        if ($BANDWIDTH > 0) {
            $BANDWIDTH_text = " (" . FormatBytes($BANDWIDTH / 1024) . ")";
        }
        if ($load > $CPU_NUMBER_MAX) {
            $icon_performance = $icon_red_32;
        }
        $xtime = strtotime($updated);
        $diff = time_diff_min($xtime);
        $Difftext = distanceOfTimeInWords($xtime, time(), true);
        if ($diff > $ArticaMetaPooling * 1.5) {
            $icon = $icon_warning_32;
            $ColorTime = "#CC0000";
            $LOGSWHY[] = $Difftext . "/{$ArticaMetaPooling}Mn";
        }
        if ($diff > $ArticaMetaPooling * 4) {
            $icon = $icon_red_32;
            $ColorTime = "#CC0000";
        }
        if ($PROXYEMERG == 1) {
            $icon = $icon_panneau_32;
        }
        if ($WINDOWSAD == 1) {
            $icon_activedirectory = $icon;
            if ($ADEMERG == 1) {
                $icon_activedirectory = $icon_warning_32;
                $ColorTime = "#CC0000";
            }
        }
        if ($UFDB_ENABLED == 1) {
            $icon_ufdb = $icon;
            if ($UFDBARTICA < $MetaUfdbArticaVer) {
                $icon_ufdb = $icon_warning_32;
            }
        }
        $disks = unserialize($ligne["disks"]);
        // -------------------------------------------- DISKS INFOS
        if (is_array($disks)) {
            while (@(list($disks, $mainarray) = each($disks))) {
                $SIZE = FormatBytes(intval($mainarray["SIZE"]) / 1024);
                while (list($part, $partArray) = each($mainarray["PARTS"])) {
                    $POURC = $partArray["POURC"];
                    if ($POURC > 95) {
                        $color_disk = "red";
                        $icon = $icon_red_32;
                        $icon_disk = $icon_red_32;
                    }
                }
            }
        }
        // --------------------------------------------	--------------------------------------------------------------------
        $cell = array();
        $linkver = "<a href=\"javascript:Loadjs('artica-meta.update.artica.php?uuid={$uuid}');\" \n\t\tstyle='text-decoration:underline'>";
        $events = "<a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('artica-meta.events.php?js=yes&uuid={$uuid}');\"\n\t\tstyle='float:right'><img src='css/images-flexigrid/magnifier.png'></a>";
        $cpus = "<a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('artica-meta.cpustats.php?js=yes&uuid={$uuid}');\"\n\t\tstyle='text-decoration:underline'>";
        $hostsCommands = "<a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('artica-meta.menus.php?js=yes&uuid={$uuid}');\"\n\t\tstyle='text-decoration:underline'>";
        $hostag = utf8_encode($ligne["hostag"]);
        if ($hostag != null) {
            $hostag = "<br><i style='font-size:12px'>{$hostag}</i>";
        }
        $cell = array();
        if ($ArticaMetaUseSendClient == 1) {
            $uriAdd = null;
            if ($ArticaLinkAutoconnect == 1) {
                if ($ligne["system_adm"] != null) {
                    $uriAdd = "/logon.php?autologmeta=" . md5($ligne["system_adm"] . $ligne["system_password"]);
                }
            }
            $link_ip = "<a href=\"https://{$public_ip}:9000{$uriAdd}\" style='text-decoration:underline;font-size:18px;color:black !important' target=_new>";
        }
        $cell[] = "<center><img src=\"img/{$icon}\"></center>";
        $cell[] = "{$style}{$hostname}{$hostag}</a></span>";
        $cell[] = "{$link_ip}{$public_ip}</a></span>";
        $cell[] = "<center>" . imgsimple($icon_performance, null, null) . "</center>";
        $cell[] = "<center>" . imgsimple($icon_disk, null, null) . "</center>";
        $cell[] = "<center>" . imgsimple($icon_activedirectory, null, null) . "</center>";
        $cell[] = "<center>" . imgsimple($icon_ufdb, null, null) . "</center>";
        $cell[] = "{$style}{$ligne["squidver"]}</span>";
        $cell[] = "{$style}{$linkver}{$version}</a></span>";
        $data['rows'][] = array('id' => $ligne['uuid'], 'cell' => $cell);
    }
    echo json_encode($data);
}
예제 #9
0
function events_table()
{
    $tpl = new templates();
    $MyPage = CurrentPageName();
    $q = new mysql_meta();
    $FORCE2 = "AND uuid='{$_GET["uuid"]}'";
    $FORCE = 1;
    $search = '%';
    $table = "psaux";
    $page = 1;
    $ORDER = "ORDER BY CPU desc";
    if ($_GET["sysalert"] == "yes") {
        $q = new mysql_meta();
    }
    $uuid = $_GET["uuid"];
    $total = 0;
    if ($q->COUNT_ROWS($table, "artica_events") == 0) {
        json_error_show("no data", 1);
    }
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    $severity[0] = "22-red.png";
    $severity[1] = "22-warn.png";
    $severity[2] = "22-infos.png";
    $currentdate = date("Y-m-d");
    $searchstring = string_to_flexquery();
    if ($searchstring != null) {
        $sql = "SELECT COUNT(*) as TCOUNT FROM `{$table}` WHERE {$FORCE} {$FORCE2} {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_events"));
        if (!$q->ok) {
            if (preg_match("#marked as crashed#", $q->mysql_error)) {
                $q->QUERY_SQL("DROP TABLE `{$table}`", "artica_events");
            }
        }
        $total = $ligne["TCOUNT"];
    } else {
        if (strlen($FORCE) > 2) {
            $sql = "SELECT COUNT(*) as TCOUNT FROM `{$table}` WHERE {$FORCE} {$FORCE2}";
            $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_events"));
            if (!$q->ok) {
                if (preg_match("#marked as crashed#", $q->mysql_error)) {
                    $q->QUERY_SQL("DROP TABLE `{$table}`", "artica_events");
                }
            }
            $total = $ligne["TCOUNT"];
        } else {
            $total = $q->COUNT_ROWS($table, "artica_events");
        }
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $sql = "SELECT *  FROM `{$table}` WHERE {$FORCE} {$FORCE2} {$searchstring} {$ORDER} {$limitSql}";
    writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
    $results = $q->QUERY_SQL($sql, "artica_events");
    if (!$q->ok) {
        if (preg_match("#marked as crashed#", $q->mysql_error)) {
            $q->QUERY_SQL("DROP TABLE `{$table}`", "artica_events");
        }
    }
    if (!$q->ok) {
        json_error_show($q->mysql_error, 1);
    }
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    $CurrentPage = CurrentPageName();
    if (mysql_num_rows($results) == 0) {
        json_error_show("no data");
    }
    while ($ligne = mysql_fetch_assoc($results)) {
        // (uuid,user,pid,CPU,MEM,VSZ,RSS,pTIME,pcmd)
        $user = $ligne["user"];
        $pid = $ligne["pid"];
        $CPU = $ligne["CPU"];
        $MEM = $ligne["MEM"];
        $VSZ = FormatBytes($ligne["VSZ"]);
        $RSS = FormatBytes($ligne["RSS"]);
        $pTIME = $ligne["pTIME"];
        if (strlen($CPU) == 1) {
            $CPU = "{$CPU}.0";
        }
        if (strlen($MEM) == 1) {
            $MEM = "{$MEM}.0";
        }
        $pcmd = $ligne["pcmd"];
        $pcmd = str_replace("/usr/bin/php5 /usr/share/artica-postfix/", "", $pcmd);
        $pcmd = str_replace("/bin/sh -c /usr/bin/ionice -c2 -n7 /usr/bin/nice --adjustment=19 ", "", $pcmd);
        $pcmd = str_replace("/usr/bin/php -q /usr/share/artica-postfix/", "", $pcmd);
        $pcmd = str_replace("php5 /usr/share/artica-postfix/", "", $pcmd);
        $pcmd = str_replace("/usr/sbin/apache2 -f /etc/artica-postfix/httpd.conf -k start", "Apache (Web interface)", $pcmd);
        //	$start=imgsimple("24-run.png",null,"Loadjs('$MyPage?service-cmd-js=yes&action=start&cmdline=$service_cmd&uuid=$uuid&app={$ligne["service_name"]}')");
        //	$stop=imgsimple("24-stop.png",null,"Loadjs('$MyPage?service-cmd-js=yes&action=stop&cmdline=$service_cmd&uuid=$uuid&app={$ligne["service_name"]}')");
        //	$restart=imgsimple("restart-24.png",null,"Loadjs('$MyPage?service-cmd-js=yes&action=restart&cmdline=$service_cmd&uuid=$uuid&app={$ligne["service_name"]}')");
        if ($installed == 1) {
            if ($running == 1) {
                $severity_icon = "ok22.png";
                $start = "-";
            } else {
                $severity_icon = "22-red.png";
                $stop = "-";
            }
        }
        $data['rows'][] = array('id' => $ligne['ID'], 'cell' => array($user, $pid, "{$CPU}%", "{$MEM}%", $VSZ, $RSS, $pTIME, $pcmd));
    }
    echo json_encode($data);
}
예제 #10
0
function query()
{
    $category = null;
    $tpl = new templates();
    $also = $tpl->_ENGINE_parse_body("{also}");
    $MyPage = CurrentPageName();
    $q = new mysql_meta();
    $nowebsites = $tpl->_ENGINE_parse_body("{no_saved_web_site_catz}");
    if ($category == null) {
        if ($_GET["category"] != null) {
            $category = $_GET["category"];
        }
    }
    if ($category == null) {
        if ($_POST["qtype"] != null) {
            $category = $_POST["qtype"];
        }
    }
    if ($_POST["query"] != null) {
        if ($_GET["website"] != null) {
            $_POST["query"] = $_GET["website"];
        }
    }
    if ($category == null) {
        json_error_show("Please select a category first");
    }
    if ($_POST["sortname"] == "sitename") {
        $_POST["sortname"] = "zDate";
        $_POST["sortorder"] = "desc";
    }
    $table = "webfiltering_categories_urls";
    $search = '%';
    $page = 1;
    $COUNT_ROWS = $q->COUNT_ROWS($table);
    if ($COUNT_ROWS == 0) {
        json_error_show("no data", 1);
    }
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    $searchstring = string_to_flexquery();
    if ($searchstring != null) {
        $sql = "SELECT COUNT(zmd5) as TCOUNT FROM `{$table}` WHERE category='{$category}' {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup"));
        $total = $ligne["TCOUNT"];
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $sql = "SELECT zDate,zmd5,pattern,enabled  FROM `{$table}` WHERE category='{$category}' {$searchstring} {$ORDER} {$limitSql}";
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        json_error_show($q->mysql_error, 1);
    }
    if (mysql_num_rows($results) == 0) {
        json_error_show("{$nowebsites}", 1);
    }
    $disabled_text = $tpl->_ENGINE_parse_body("{disabled}");
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    while ($ligne = mysql_fetch_assoc($results)) {
        $delete = imgtootltip("delete-24.png", "{delete}", "DeleteCategorizedURI('{$ligne["zmd5"]}','{$table}')");
        $color = "color:black";
        $jscat = "<a href=\"javascript:blur();\" \n\t\t\t\tOnClick=\"javascript:Loadjs('squid.categorize.php?www={$ligne["pattern"]}');\"\n\t\t\t\tstyle='font-size:14px;text-decoration:underline;{$color}'>";
        $data['rows'][] = array('id' => $ligne['zmd5'], 'cell' => array("\n\t\t<span style='font-size:18px;{$color}'>{$ligne['zDate']}</span>", "<span style='font-size:18px;{$color}'>{$ligne['pattern']}</a></span>", "<center>{$delete}</center>"));
    }
    echo json_encode($data);
}
function events_table()
{
    $tpl = new templates();
    $MyPage = CurrentPageName();
    $q = new mysql_meta();
    $FORCE2 = "AND uuid='{$_GET["uuid"]}'";
    $FORCE = 1;
    $search = '%';
    $table = "squid_admin_mysql";
    $page = 1;
    $ORDER = "ORDER BY zDate DESC";
    if (is_numeric($_GET["critical"])) {
        $FORCE = "severity={$_GET["critical"]}";
    }
    if ($_GET["text-filter"] != null) {
        $FORCE = " subject LIKE '%{$_GET["text-filter"]}%'";
        if (is_numeric($_GET["critical"])) {
            $FORCE = $FORCE . " AND severity={$_GET["critical"]}";
        }
    }
    $total = 0;
    if ($q->COUNT_ROWS($table, "artica_events") == 0) {
        json_error_show("no data", 1);
    }
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    $severity[0] = "22-red.png";
    $severity[1] = "22-warn.png";
    $severity[2] = "22-infos.png";
    $currentdate = date("Y-m-d");
    $searchstring = string_to_flexquery();
    if ($searchstring != null) {
        $sql = "SELECT COUNT(*) as TCOUNT FROM `{$table}` WHERE {$FORCE} {$FORCE2} {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_events"));
        if (!$q->ok) {
            if (preg_match("#marked as crashed#", $q->mysql_error)) {
                $q->QUERY_SQL("DROP TABLE `{$table}`", "artica_events");
            }
        }
        $total = $ligne["TCOUNT"];
    } else {
        if (strlen($FORCE) > 2) {
            $sql = "SELECT COUNT(*) as TCOUNT FROM `{$table}` WHERE {$FORCE} {$FORCE2}";
            $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_events"));
            if (!$q->ok) {
                if (preg_match("#marked as crashed#", $q->mysql_error)) {
                    $q->QUERY_SQL("DROP TABLE `{$table}`", "artica_events");
                }
            }
            $total = $ligne["TCOUNT"];
        } else {
            $total = $q->COUNT_ROWS($table, "artica_events");
        }
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    if (!is_numeric($rp)) {
        $rp = 50;
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $sql = "SELECT *  FROM `{$table}` WHERE {$FORCE} {$FORCE2} {$searchstring} {$ORDER} {$limitSql}";
    writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
    $results = $q->QUERY_SQL($sql, "artica_events");
    if (!$q->ok) {
        if (preg_match("#marked as crashed#", $q->mysql_error)) {
            $q->QUERY_SQL("DROP TABLE `{$table}`", "artica_events");
        }
    }
    if (!$q->ok) {
        json_error_show($q->mysql_error, 1);
    }
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    $CurrentPage = CurrentPageName();
    if (mysql_num_rows($results) == 0) {
        json_error_show("no data");
    }
    while ($ligne = mysql_fetch_assoc($results)) {
        $hostname = $ligne["hostname"];
        $ligne["zDate"] = str_replace($currentdate, "", $ligne["zDate"]);
        $severity_icon = $severity[$ligne["severity"]];
        $link = "<a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('{$CurrentPage}?ShowID-js={$ligne["ID"]}')\" style='text-decoration:underline'>";
        $text = $link . $tpl->_ENGINE_parse_body($ligne["subject"] . "</a><div style='font-size:10px'>{host}:{$hostname} {function}:{$ligne["function"]}, {line}:{$ligne["line"]}</div>");
        $data['rows'][] = array('id' => $ligne['ID'], 'cell' => array("<img src='img/{$severity_icon}'>", $ligne["zDate"], $text, $ligne["filename"]));
    }
    echo json_encode($data);
}
예제 #12
0
function search()
{
    $tpl = new templates();
    $MyPage = CurrentPageName();
    $q = new mysql_meta();
    $fontsize = "14px";
    $cs = 0;
    $page = 1;
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $_POST["query"] = trim($_POST["query"]);
    $FORCE = 1;
    if ($_GET["uuid"] != null) {
        $FORCE = "uuid='{$_GET["uuid"]}'";
    }
    $search = '%';
    $table = "metaorders";
    $page = 1;
    $total = 0;
    if ($q->COUNT_ROWS($table) == 0) {
        json_error_show("no data", 1);
    }
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    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'];
    }
    $searchstring = string_to_flexquery();
    if ($searchstring != null) {
        $sql = "SELECT COUNT(*) as TCOUNT FROM `{$table}` WHERE {$FORCE}  {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_events"));
        if (!$q->ok) {
            if (preg_match("#marked as crashed#", $q->mysql_error)) {
                $q->QUERY_SQL("DROP TABLE `{$table}`", "artica_events");
            }
        }
        $total = $ligne["TCOUNT"];
    } else {
        if (strlen($FORCE) > 2) {
            $sql = "SELECT COUNT(*) as TCOUNT FROM `{$table}` WHERE {$FORCE}";
            $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_events"));
            if (!$q->ok) {
                if (preg_match("#marked as crashed#", $q->mysql_error)) {
                    $q->QUERY_SQL("DROP TABLE `{$table}`", "artica_events");
                }
            }
            $total = $ligne["TCOUNT"];
        } else {
            $total = $q->COUNT_ROWS($table, "artica_events");
        }
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    if (!is_numeric($rp)) {
        $rp = 50;
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $sql = "SELECT *  FROM `{$table}` WHERE {$FORCE} {$searchstring} {$ORDER} {$limitSql}";
    $results = $q->QUERY_SQL($sql, "artica_events");
    if (!$q->ok) {
        if (preg_match("#marked as crashed#", $q->mysql_error)) {
            $q->QUERY_SQL("DROP TABLE `{$table}`", "artica_events");
        }
    }
    if (!$q->ok) {
        json_error_show($q->mysql_error . "<br>{$sql}", 0);
    }
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    $CurrentPage = CurrentPageName();
    if (mysql_num_rows($results) == 0) {
        json_error_show("no data");
    }
    $uuid = urlencode($_GET["uuid"]);
    while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) {
        $delete = imgtootltip("delete-32.png", null, "Loadjs('{$MyPage}?delete-js={$ligne["orderid"]}')");
        $cs++;
        $ss = array();
        $ordercontent = unserialize(base64_decode($ligne["ordercontent"]));
        while (list($a, $b) = each($ordercontent)) {
            $ss[] = "<strong>{$a} = &laquo;{$b}&raquo;</strong>";
        }
        //$jslink="<a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('$MyPage?mac-js=$macenc&uuid=$uuid&t={$_GET["t"]}');\" style='font-size:$fontsize;text-decoration:underline'>";
        $data['rows'][] = array('id' => md5(serialize($ligne)), 'cell' => array("<span style='font-size:{$fontsize}'>{$jslink}{$ligne["zDate"]}</a></span>", "<span style='font-size:18px'>{$jslink}{$ligne["ordersubject"]}<br></span><span style='font-size:12px'>" . @implode("<br>", $ss) . "</span>", "<span style='font-size:{$fontsize}'>{$jslink}{$delete}</a></span>"));
    }
    echo json_encode($data);
}
function search()
{
    $MyPage = CurrentPageName();
    $page = CurrentPageName();
    $tpl = new templates();
    $sock = new sockets();
    $q = new mysql_meta();
    $table = "metahosts";
    $searchstring = string_to_flexquery();
    $page = 1;
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY `{$_POST["sortname"]}` {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    if (!is_numeric($rp)) {
        $rp = 50;
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    if ($searchstring != null) {
        $sql = "SELECT COUNT( * ) AS tcount FROM {$table} WHERE 1 {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql));
        if (!$q->ok) {
            json_error_show("Mysql Error [" . __LINE__ . "]: <br>{$q->mysql_error}.<br>{$sql}", 1);
        }
        $total = $ligne["tcount"];
    } else {
        $total = $q->COUNT_ROWS($table);
    }
    $sql = "SELECT * FROM {$table} WHERE 1 {$searchstring} {$ORDER} {$limitSql} ";
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        if ($q->mysql_error != null) {
            json_error_show(date("H:i:s") . "<br>SORT:{$_POST["sortname"]}:<br>Mysql Error [L." . __LINE__ . "]: {$q->mysql_error}<br>{$sql}", 1);
        }
    }
    if (mysql_num_rows($results) == 0) {
        json_error_show("no data", 1);
    }
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    $fontsize = "16";
    $style = " style='font-size:{$fontsize}px'";
    $styleHref = " style='font-size:{$fontsize}px;text-decoration:underline'";
    $t = $_GET["t"];
    while ($ligne = mysql_fetch_assoc($results)) {
        $LOGSWHY = array();
        $overloaded = null;
        $loadcolor = "black";
        $StatHourColor = "black";
        $ColorTime = "black";
        $uuid = $ligne["uuid"];
        $icon_warning_32 = "warning32.png";
        $icon_red_32 = "32-red.png";
        $icon = "ok-32.png";
        $urijs = "Loadjs('{$MyPage}?group-js=yes&ID={$ligne["ID"]}')";
        $link = imgsimple("arrow-right-24.png", null, "LinkHosts{$t}('{$ligne["uuid"]}')");
        $cell = array();
        $hostag = utf8_encode($ligne["hostag"]);
        $cell[] = "<span {$style}>{$ligne["hostname"]}</a></span><br>{$uuid}";
        $cell[] = "<span {$style}>{$hostag}</a></span>";
        $cell[] = "{$link}";
        $data['rows'][] = array('id' => $ligne['uuid'], 'cell' => $cell);
    }
    echo json_encode($data);
}
예제 #14
0
function search()
{
    $MyPage = CurrentPageName();
    $page = CurrentPageName();
    $tpl = new templates();
    $sock = new sockets();
    $q = new mysql_meta();
    $table = "policies";
    $searchstring = string_to_flexquery();
    $page = 1;
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    if ($searchstring != null) {
        $sql = "SELECT COUNT( * ) AS tcount FROM {$table} WHERE 1 {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql));
        if (!$q->ok) {
            json_error_show("Mysql Error [" . __LINE__ . "]: {$q->mysql_error}.<br>{$sql}", 1);
        }
        $total = $ligne["tcount"];
    } else {
        $total = $q->COUNT_ROWS($table);
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    if (!is_numeric($rp)) {
        $rp = 50;
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $sql = "SELECT * FROM {$table} WHERE 1 {$searchstring} {$ORDER} {$limitSql} ";
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        if ($q->mysql_error != null) {
            json_error_show(date("H:i:s") . "<br>SORT:{$_POST["sortname"]}:<br>Mysql Error [L." . __LINE__ . "]: {$q->mysql_error}<br>{$sql}", 1);
        }
    }
    if (mysql_num_rows($results) == 0) {
        json_error_show("no data", 1);
    }
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    $fontsize = "18";
    $style = "<span style='font-size:{$fontsize}px'>";
    $free_text = $tpl->javascript_parse_text("{free}");
    $computers = $tpl->javascript_parse_text("{computers}");
    $overloaded_text = $tpl->javascript_parse_text("{overloaded}");
    while ($ligne = mysql_fetch_assoc($results)) {
        $icon_warning_32 = "warning32.png";
        $icon_red_32 = "32-red.png";
        $icon = "ok-32.png";
        $icon_disabled = "ok32-grey.png";
        if ($switch == 1) {
            $icon_warning_32 = "22-warn.png";
            $icon_red_32 = "22-red.png";
            $icon = "ok22.png";
        }
        $policy_name = utf8_encode($ligne["policy_name"]);
        $policy_type = $tpl->_ENGINE_parse_body($q->policy_type[$ligne["policy_type"]]);
        $delete = imgsimple("delete-32.png", null, "Loadjs('{$MyPage}?delete-js=yes&ID={$ligne["ID"]}')");
        if ($_GET["function"] != null) {
            $delete = imgsimple("arrow-right-32.png", null, "{$_GET["function"]}('{$ligne["ID"]}')");
        }
        if (trim($policy_type) == null) {
            $policy_type = "{policy_type} ID:{$ligne["policy_type"]}";
        }
        $ligneCount = mysql_fetch_array($q->QUERY_SQL("SELECT COUNT(zmd5) as tcount FROM metapolicies_link WHERE `policy-id`='{$ligne["ID"]}'"));
        $CountDeGroup = $ligneCount["tcount"];
        $js = "<a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('{$MyPage}?policy-js=yes&ID={$ligne["ID"]}');\" style='text-decoration:underline'>";
        $cell = array();
        $cell[] = "<img src=\"img/{$icon}\">";
        $cell[] = "{$style}{$js}{$policy_name}</a></span>";
        $cell[] = "{$style}{$policy_type}</span>";
        $cell[] = "{$style}{$CountDeGroup}</span>";
        $cell[] = "{$style}{$delete}</span>";
        $data['rows'][] = array('id' => $ligne['uuid'], 'cell' => $cell);
    }
    echo json_encode($data);
}
예제 #15
0
function events_table()
{
    $tpl = new templates();
    $MyPage = CurrentPageName();
    $q = new mysql_meta();
    $FORCE2 = "AND uuid='{$_GET["uuid"]}'";
    $FORCE = 1;
    $search = '%';
    $table = "global_status";
    $page = 1;
    $ORDER = "ORDER BY service_name asc";
    if (isset($_GET["running"])) {
        if ($_GET["running"] == 0) {
            $FORCE = "running={$_GET["running"]} AND service_disabled=1";
        } else {
            $FORCE = "running={$_GET["running"]}";
        }
    }
    $uuid = $_GET["uuid"];
    $total = 0;
    if ($q->COUNT_ROWS($table, "artica_events") == 0) {
        json_error_show("no data", 1);
    }
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    $severity[0] = "22-red.png";
    $severity[1] = "22-warn.png";
    $severity[2] = "22-infos.png";
    $currentdate = date("Y-m-d");
    $searchstring = string_to_flexquery();
    if ($searchstring != null) {
        $sql = "SELECT COUNT(*) as TCOUNT FROM `{$table}` WHERE {$FORCE} {$FORCE2} {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_events"));
        if (!$q->ok) {
            if (preg_match("#marked as crashed#", $q->mysql_error)) {
                $q->QUERY_SQL("DROP TABLE `{$table}`", "artica_events");
            }
        }
        $total = $ligne["TCOUNT"];
    } else {
        if (strlen($FORCE) > 2) {
            $sql = "SELECT COUNT(*) as TCOUNT FROM `{$table}` WHERE {$FORCE} {$FORCE2}";
            $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_events"));
            if (!$q->ok) {
                if (preg_match("#marked as crashed#", $q->mysql_error)) {
                    $q->QUERY_SQL("DROP TABLE `{$table}`", "artica_events");
                }
            }
            $total = $ligne["TCOUNT"];
        } else {
            $total = $q->COUNT_ROWS($table, "artica_events");
        }
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $sql = "SELECT *  FROM `{$table}` WHERE {$FORCE} {$FORCE2} {$searchstring} {$ORDER} {$limitSql}";
    writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
    $results = $q->QUERY_SQL($sql, "artica_events");
    if (!$q->ok) {
        if (preg_match("#marked as crashed#", $q->mysql_error)) {
            $q->QUERY_SQL("DROP TABLE `{$table}`", "artica_events");
        }
    }
    if (!$q->ok) {
        json_error_show($q->mysql_error, 1);
    }
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    $CurrentPage = CurrentPageName();
    if (mysql_num_rows($results) == 0) {
        json_error_show("no data");
    }
    while ($ligne = mysql_fetch_assoc($results)) {
        $master_cached_memory = 0;
        $service_name = $tpl->javascript_parse_text("{" . $ligne["service_name"] . "}");
        $service_cmd = $ligne["service_cmd"];
        $service_disabled = $ligne["service_disabled"];
        $watchdog_features = $ligne["watchdog_features"];
        $binpath = $ligne["binpath"];
        $explain = $ligne["explain"];
        $running = $ligne["running"];
        $installed = $ligne["installed"];
        $master_pid = $ligne["master_pid"];
        $master_memory = FormatBytes($ligne["master_memory"]);
        $master_cached_memory = $ligne["master_cached_memory"];
        $processes_number = $ligne["processes_number"];
        $uptime = $ligne["uptime"];
        $master_version = $ligne["master_version"];
        if ($master_version != null) {
            $installed = 1;
        }
        $service_cmd = urlencode($service_cmd);
        $start = imgsimple("24-run.png", null, "Loadjs('{$MyPage}?service-cmd-js=yes&action=start&cmdline={$service_cmd}&uuid={$uuid}&app={$ligne["service_name"]}')");
        $stop = imgsimple("24-stop.png", null, "Loadjs('{$MyPage}?service-cmd-js=yes&action=stop&cmdline={$service_cmd}&uuid={$uuid}&app={$ligne["service_name"]}')");
        $restart = imgsimple("restart-24.png", null, "Loadjs('{$MyPage}?service-cmd-js=yes&action=restart&cmdline={$service_cmd}&uuid={$uuid}&app={$ligne["service_name"]}')");
        if ($installed == 1) {
            if ($running == 1) {
                $severity_icon = "ok22.png";
                $start = "-";
            } else {
                $severity_icon = "22-red.png";
                $stop = "-";
            }
        }
        if ($service_disabled == 0) {
            $severity_icon = "22-warn.png";
            if ($master_memory == 0) {
                $master_memory = "-";
            }
            $stop = "-";
            $start = "-";
            $restart = "-";
            if ($uptime == null) {
                $uptime = "-";
            }
        }
        if ($installed == 0) {
            $severity_icon = "ok22-grey.png";
            $master_version = "-";
            $master_memory = "-";
            $uptime = "-";
            $stop = "-";
            $start = "-";
            $restart = "-";
        }
        $data['rows'][] = array('id' => $ligne['ID'], 'cell' => array("<img src='img/{$severity_icon}'>", $service_name, $master_version, $master_memory, $processes_number, $uptime, $stop, $start, $restart));
    }
    echo json_encode($data);
}
예제 #16
0
function search()
{
    $MyPage = CurrentPageName();
    $page = CurrentPageName();
    $tpl = new templates();
    $sock = new sockets();
    $q = new mysql_meta();
    $ArticaMetaPooling = intval($sock->GET_INFO("ArticaMetaPooling"));
    $ArticaMetaUseSendClient = intval($sock->GET_INFO("ArticaMetaUseSendClient"));
    $ArticaLinkAutoconnect = intval($sock->GET_INFO("ArticaLinkAutoconnect"));
    $MetaUfdbArticaVer = intval($sock->GET_INFO("MetaUfdbArticaVer"));
    if ($ArticaMetaPooling == 0) {
        $ArticaMetaPooling = 15;
    }
    $switch = intval($_GET["switch"]);
    $table = "metahosts";
    if (isset($_POST["qtype"])) {
        if (preg_match("#prxy([0-9\\.]+)#", $_POST["qtype"], $re)) {
            $_POST["query"] = $re[1];
            $_POST["qtype"] = "squidver";
        }
        if (preg_match("#^([0-9\\.]+)#", $_POST["qtype"])) {
            $_POST["query"] = $_POST["qtype"];
            $_POST["qtype"] = "version";
        }
    }
    $searchstring = string_to_flexquery();
    $page = 1;
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY `{$_POST["sortname"]}` {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    if ($searchstring != null) {
        $sql = "SELECT COUNT( * ) AS tcount FROM {$table} WHERE 1 {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql));
        if (!$q->ok) {
            json_error_show("Mysql Error [" . __LINE__ . "]: <br>{$q->mysql_error}.<br>{$sql}", 1);
        }
        $total = $ligne["tcount"];
    } else {
        $total = $q->COUNT_ROWS($table);
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    if (!is_numeric($rp)) {
        $rp = 50;
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $sql = "SELECT * FROM {$table} WHERE 1 {$searchstring} {$ORDER} {$limitSql} ";
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        if ($q->mysql_error != null) {
            json_error_show(date("H:i:s") . "<br>SORT:{$_POST["sortname"]}:<br>Mysql Error [L." . __LINE__ . "]: {$q->mysql_error}<br>{$sql}", 1);
        }
    }
    if (mysql_num_rows($results) == 0) {
        json_error_show("no data", 1);
    }
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    $fontsize = "18";
    if ($switch == 1) {
        $fontsize = 12;
    }
    $style = "<span style='font-size:{$fontsize}px'>";
    $free_text = $tpl->javascript_parse_text("{free}");
    $computers = $tpl->javascript_parse_text("{computers}");
    $overloaded_text = $tpl->javascript_parse_text("{overloaded}");
    $orders_text = $tpl->javascript_parse_text("{orders}");
    $policies_text = $tpl->javascript_parse_text("{policies}");
    $directories_monitor = $tpl->javascript_parse_text("{directories_monitor}");
    $proxy_statistics = $tpl->javascript_parse_text("{SQUID_STATS1}");
    $cache_rate = $tpl->javascript_parse_text("{cache_rate}");
    $clone_of_text = $tpl->javascript_parse_text("{clone_of}");
    $proxy_in_emergency_mode = $tpl->javascript_parse_text("{proxy_in_emergency_mode}");
    $webfiltering = $tpl->javascript_parse_text("{webfiltering}");
    $activedirectory_emergency_mode = $tpl->javascript_parse_text("{activedirectory_emergency_mode}");
    $NeCommuniquePlus_text = "<br><span style='font-size:14px;font-weight:bold;color:d32d2d'>" . $tpl->_ENGINE_parse_body("{did_not_talk_with_meta}") . "</span>";
    $memory_exceed_80 = $tpl->javascript_parse_text("{memory_exceed_80}");
    $memory_exceed_90 = $tpl->javascript_parse_text("{memory_exceed_90}");
    while ($ligne = mysql_fetch_assoc($results)) {
        $LOGSWHY = array();
        $overloaded = null;
        $cloneFrom = $ligne["cloneFrom"];
        $loadcolor = "black";
        $StatHourColor = "black";
        $uuid = $ligne["uuid"];
        $hostname = $ligne["hostname"];
        $public_ip = $ligne["public_ip"];
        $updated = $ligne["updated"];
        $version = $ligne["version"];
        $ColorTime = "black";
        $CPU_NUMBER = $ligne["CPU_NUMBER"];
        $CPU_NUMBER_MAX = $ligne["CPU_NUMBER"] + 1.5;
        $load = $ligne["load"];
        $mem_perc = $ligne["mem_perc"];
        $mem_total = FormatBytes($ligne["mem_total"]);
        $proxyversion = null;
        $CountdeComputers_text = null;
        $policies_text_line = null;
        $CountdeComputers = $q->network_hosts_count($uuid);
        $icon_warning_32 = "warning32.png";
        $icon_red_32 = "32-red.png";
        $icon = "ok-32.png";
        $icon_panneau_32 = "warning-panneau-32.png";
        $BANDWIDTH = $ligne["BANDWIDTH"];
        $TaskPercent = intval($ligne["TaskPercent"]);
        $BANDWIDTH_text = null;
        $hostag_switch = null;
        $uuidenc = urlencode($uuid);
        $PING_URI_SWITCH = null;
        $PROXY_PERFS = null;
        $END_PROXY = null;
        $PROXY_LINE = null;
        $PROXYEMERG = $ligne["PROXYEMERG"];
        $webfiltering_version = null;
        $UFDBARTICA = intval($ligne["UFDBARTICA"]);
        $UFDB_ENABLED = intval($ligne["UFDB_ENABLED"]);
        $WINDOWSAD = intval($ligne["WINDOWSAD"]);
        $ADEMERG = intval($ligne["ADEMERG"]);
        $PROXYEMERG_ICON = 0;
        $link_ip = null;
        $secondincon = null;
        $NeCommuniquePlus = null;
        $MemoryColor = null;
        $Loadbr = "<br>";
        $StyleLoad = "font-size:30px;font-weight:bold";
        if (preg_match("#^([0-9\\.]+)-#", $ligne["squidver"], $rz)) {
            $ligne["squidver"] = $rz[1];
        }
        if ($ArticaMetaUseSendClient == 1) {
            $PING_URI = "&nbsp;<a href=\"javascript:blur();\" \n\t\t\tOnClick=\"javascript:Loadjs('artica-meta.menus.php?send-ping-js=yes&uuid={$uuidenc}&gpid=0');\"\n\t\t\tstyle='font-size:12px;text-decoration:underline;color:#0021C6'\n\t\t\t>Ping</a>";
        }
        if ($UFDB_ENABLED == 1) {
            if ($UFDBARTICA > 0) {
                $UFDBARTICAT = date("Y-m-d H:i:s", $UFDBARTICA);
                $webfiltering_version = "<br>{$webfiltering} {$UFDBARTICAT}";
            }
        }
        if ($BANDWIDTH > 0) {
            $BANDWIDTH_text = " (" . FormatBytes($BANDWIDTH / 1024) . ")";
        }
        if ($switch == 1) {
            $icon_warning_32 = "22-warn.png";
            $icon_red_32 = "22-red.png";
            $icon = "ok22.png";
            $icon_panneau_32 = "warning-panneau-24.png";
            $StyleLoad = "font-size:14px;";
            $Loadbr = null;
        }
        if ($load > $CPU_NUMBER_MAX) {
            $overloaded = "<br><strong style='color:#d32d2d'>{$overloaded_text}</strong>";
            $icon = $icon_warning_32;
            $loadcolor = "#d32d2d";
            $LOGSWHY[] = "{$overloaded_text} {$load}>{$CPU_NUMBER_MAX}";
        }
        $xtime = strtotime($updated);
        $diff = time_diff_min($xtime);
        $Difftext = distanceOfTimeInWords($xtime, time(), true);
        if ($diff > $ArticaMetaPooling * 1.5) {
            $icon = $icon_warning_32;
            $ColorTime = "#d32d2d";
            $LOGSWHY[] = $Difftext . "/{$ArticaMetaPooling}Mn";
            $loadcolor = $ColorTime;
        }
        if ($diff > $ArticaMetaPooling * 4) {
            $icon = $icon_red_32;
            $ColorTime = "#d32d2d";
            $LOGSWHY[] = $Difftext . "/{$ArticaMetaPooling}Mn";
            $NeCommuniquePlus = $NeCommuniquePlus_text;
        }
        if ($PROXYEMERG == 1) {
            $icon = $icon_panneau_32;
            $ColorTime = "#d32d2d";
            $loadcolor = $ColorTime;
            $LOGSWHY[] = "<a href=\"javascript:blur();\" \n\t\t\tOnClick=\"javascript:Loadjs('artica-meta.urgency.php?uuid={$uuid}');\" style='color:{$ColorTime};text-decoration:underline'>{$proxy_in_emergency_mode}</a>";
        }
        if ($WINDOWSAD == 1) {
            $secondincon = "windows-server-32.png";
            if ($ADEMERG == 1) {
                $icon = $icon_warning_32;
                $ColorTime = "#d32d2d";
                $secondincon = "windows-server-32-red.png";
                $LOGSWHY[] = $activedirectory_emergency_mode;
                $loadcolor = $ColorTime;
            }
        }
        if ($MetaUfdbArticaVer > 0) {
            if ($UFDB_ENABLED == 1) {
                if ($UFDBARTICA < $MetaUfdbArticaVer) {
                    $LOGSWHY[] = "{$webfiltering} < " . date("Y-m-d H:i:s", $MetaUfdbArticaVer);
                }
            }
        }
        if ($mem_perc > 80) {
            $MemoryColor = "#f59c44";
            $icon = $icon_panneau_32;
            $LOGSWHY[] = "<span style='color:{$MemoryColor}'>{$memory_exceed_80}</span>";
        }
        if ($mem_perc > 90) {
            $icon = $icon_red_32;
            $MemoryColor = "#d32d2d";
            $icon = $icon_panneau_32;
            $LOGSWHY[] = "{$memory_exceed_90}";
        }
        $disks = unserialize($ligne["disks"]);
        $SIZE = 0;
        $USED = 0;
        $infodisk = null;
        $DISKS_TEXT = array();
        $squid_db = "squid_{$uuid}";
        if ($q->DATABASE_EXISTS($squid_db)) {
            $DISKS_TEXT[] = "<ul><li><a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('artica-meta.hosts.squid.stats.php?uuid={$uuid}')\"\n\t\t\tstyle='font-size:14px;font-weight:bold;text-decoration:underline'>{$proxy_statistics}</a></li>";
        }
        if ($q->philesight_count($uuid) > 0) {
            if (count($DISKS_TEXT) == 0) {
                $DISKS_TEXT[] = "<ul>";
            }
            $DISKS_TEXT[] = "<li><a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('artica-meta.hosts.philesight.php?uuid={$uuid}')\"\n\t\t\tstyle='font-size:14px;font-weight:bold;text-decoration:underline'>{$directories_monitor}</a></li>";
        }
        if (count($DISKS_TEXT) > 0) {
            $DISKS_TEXT[] = "</ul>";
        }
        // -------------------------------------------- DISKS INFOS
        if (is_array($disks)) {
            if (count($disks) > 0) {
                $DISKS_TEXT[] = "<ul>";
                while (@(list($disks, $mainarray) = each($disks))) {
                    $SIZE = FormatBytes(intval($mainarray["SIZE"]) / 1024);
                    $DISKS_TEXT[] = "<li style='font-weight:bold;font-size:14px'>{$disks} {$SIZE}</li>";
                    $DISKS_TEXT[] = "<ul>";
                    while (list($part, $partArray) = each($mainarray["PARTS"])) {
                        $color_disk = "black";
                        $POURC = $partArray["POURC"];
                        if ($POURC > 95) {
                            $color_disk = "red";
                            $icon = $icon_red_32;
                            $LOGSWHY[] = "{$part} {used}:{$POURC}%";
                        }
                        $TOT = FormatBytes($partArray["TOT"] / 1024);
                        $AIV = FormatBytes($partArray["AIV"] / 1024);
                        $DISKS_TEXT[] = "<li style='color:{$color_disk}'>{$part} {$TOT} - {used}:{$POURC}% {free}: {$AIV}</li>";
                    }
                    $DISKS_TEXT[] = "</ul>";
                }
                $DISKS_TEXT[] = "</ul>";
                $infodisk = $tpl->_ENGINE_parse_body(@implode("", $DISKS_TEXT));
            }
        }
        // --------------------------------------------	--------------------------------------------------------------------
        if ($switch == 1) {
            $infodisk = null;
        }
        $info = $tpl->_ENGINE_parse_body("<br>{last_status}:&nbsp;<span style='color:{$ColorTime}'>{$Difftext}</span><br><span style='font-size:12px'>{$CPU_NUMBER} CPU(s), {memory}:{$mem_total}{$overloaded}</span>");
        $cell = array();
        $linkver = "<a href=\"javascript:Loadjs('artica-meta.update.artica.php?uuid={$uuid}');\" \n\t\tstyle='text-decoration:underline'>";
        if ($q->isOrder($uuid, "UPDATE_ARTICA")) {
            $version = "<center style='margin:10px'><img src='img/preloader.gif'></center>";
        }
        if ($ligne["PROXY"] == 1) {
            $proxyuri = "<br><a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('artica-meta.squid.watchdog-events.php?js=yes&uuid={$uuid}');\"\n\t\tstyle='text-decoration:underline'>";
            $proxyversion = "<br><span style='font-size:12px'>{$proxyuri}Proxy: {$ligne["squidver"]}</a>{$webfiltering_version} {$BANDWIDTH_text}</span>";
            $ligne2 = mysql_fetch_array($q->QUERY_SQL("SELECT * FROM squid_perfs_gb WHERE uuid='{$uuid}'"));
            $client_http_hits = $ligne2["client_http_hits"];
            $client_http_requests = round($ligne2["client_http_requests"], 2);
            $client_http_kbytes_out = round($ligne2["client_http_kbytes_out"]);
            $TOTALS_NOT_CACHED = $ligne2["TOTALS_NOT_CACHED"];
            $TOTALS_CACHED = $ligne2["TOTALS_CACHED"];
            $TOTALS_CACHED_AVG = round($ligne2["TOTALS_CACHED_AVG"], 2);
            $END_PROXY = "</span><br>";
            if ($ligne2["uuid"] != null) {
                $PROXY_PERFS = "<br><span style='font-size:12px'>{$client_http_requests}Req/s, {$client_http_kbytes_out}KB/s\n\t\t\t\t<br>{$cache_rate}: {$TOTALS_CACHED_AVG}%";
                $PROXY_LINE = "<span style='font-size:12px'>{$client_http_requests}Req/s&nbsp;|&nbsp;{$client_http_kbytes_out}KB/s&nbsp;|&nbsp;{$cache_rate}: {$TOTALS_CACHED_AVG}%</span>";
            }
        }
        if ($CountdeComputers > 0) {
            $CountdeComputers = FormatNumber($CountdeComputers);
            $CountdeComputers_uri = "<a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('artica-meta.networks.hosts.php?js=yes&uuid={$uuid}');\"\n\t\t\tstyle='text-decoration:underline'>";
            $CountdeComputers_text = "<br><span style='font-size:12px'>{$CountdeComputers_uri}{$computers}: <strong>{$CountdeComputers}</strong></a></span>";
        }
        $OrdersText = null;
        $ligneOrders = mysql_fetch_array($q->QUERY_SQL("SELECT COUNT(orderid) as tcount FROM `metaorders` WHERE `uuid`='{$uuid}'"));
        $OrdersCount = $ligneOrders["tcount"];
        if ($OrdersCount > 0) {
            $OrdersText = "<br><a href=\"javascript:blur();\" \n\t\t\tOnClick=\"javascript:Loadjs('artica-meta.hosts.orders.php?uuid={$uuid}');\">\n\t\t\t<strong style='text-decoration:underline;color:#E48407'>{$orders_text}:{$OrdersCount} ({$TaskPercent}%)</strong>";
        }
        $ligneOrders = mysql_fetch_array($q->QUERY_SQL("SELECT COUNT(uuid) as tcount FROM `policies_storage` WHERE `uuid`='{$uuid}'"));
        $OrdersCount = $ligneOrders["tcount"];
        if ($OrdersCount > 0) {
            $policies_text_line = "<br><strong style='text-decoration:underline;color:#E48407'>{$policies_text}:{$OrdersCount}</strong>";
        }
        $events = "<a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('artica-meta.events.php?js=yes&uuid={$uuid}');\"\n\t\tstyle='float:right'><img src='css/images-flexigrid/magnifier.png'></a>";
        $cpus = "<a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('artica-meta.cpustats.php?js=yes&uuid={$uuid}');\"\n\t\tstyle='text-decoration:underline'>";
        $hostsCommands = "<a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('artica-meta.menus.php?js=yes&uuid={$uuid}');\"\n\t\tstyle='text-decoration:underline'>";
        $hostag = utf8_encode($ligne["hostag"]);
        if ($hostag != null) {
            $hostag = "<br><i style='font-size:12px'>{$hostag}</i>";
        }
        if ($cloneFrom != null) {
            $cloneFrom = "<br><i style='font-weight:bold;font-size:12px'>{$clone_of_text}:&nbsp;" . $q->uuid_to_host($cloneFrom) . "</i>";
        }
        if ($secondincon != null) {
            $secondincon = "<br><img src='img/{$secondincon}' style='margin-top:10px'>";
        }
        $LicenseJs = "OnClick=\"javascript:Loadjs('artica-meta.host.license.php?uuid={$uuid}')\"";
        $LicenseInfos = $q->LicenseInfos($uuid);
        $LICT = "Community Edition";
        if ($LicenseInfos["CORP_LICENSE"]) {
            $LICT = "Entreprise Edition";
        }
        if ($LicenseInfos["ExpiresSoon"] > 0) {
            if ($LicenseInfos["ExpiresSoon"] < 31) {
                $LICT = "<span style='color:red'>{trial_mode}</span>";
            }
        }
        $LicenseText = "<br><a href=\"javascript:blur();\" {$LicenseJs} style='font-size:12px;text-decoration:underline'>" . $tpl->_ENGINE_parse_body($LICT) . "</a>";
        if ($switch == 1) {
            $info = null;
            $secondincon = null;
            $hostag = null;
            $cloneFrom = null;
            $proxyversion = null;
            $CountdeComputers_text = null;
            $events = null;
            $hostag_switch = utf8_encode($ligne["hostag"]);
            $PING_URI_SWITCH = $PING_URI;
            $PING_URI = null;
            $PROXY_PERFS = null;
            $END_PROXY = null;
            $LicenseText = null;
            if (count($LOGSWHY) > 0) {
                $infodisk = $tpl->_ENGINE_parse_body("<span style='color:#d32d2d;font-size:14px'>" . @implode("<br>", $LOGSWHY) . "</span>");
            }
        } else {
            $GroupsList = GetGroups($uuid);
            $PROXY_LINE = null;
            if (count($LOGSWHY) > 0) {
                $infodisk = $tpl->_ENGINE_parse_body("<span style='color:#d32d2d;font-size:14px'>" . @implode("<br>", $LOGSWHY) . "</span>") . "<hr>" . $infodisk;
            }
        }
        $cell = array();
        if ($ArticaMetaUseSendClient == 1) {
            $uriAdd = null;
            if ($ArticaLinkAutoconnect == 1) {
                if ($ligne["system_adm"] != null) {
                    $uriAdd = "/logon.php?autologmeta=" . md5($ligne["system_adm"] . $ligne["system_password"]);
                }
            }
            $link_ip = "<a href=\"https://{$public_ip}:9000{$uriAdd}\" style='text-decoration:underline;color:{$loadcolor}' target=_new>";
        }
        if ($MemoryColor == null) {
            $MemoryColor = $loadcolor;
        }
        $cell[] = "{$Loadbr}<center><img src=\"img/{$icon}\">{$secondincon}</center>";
        $cell[] = "{$style}{$hostsCommands}{$hostname}{$hostag}</a>{$LicenseText}{$NeCommuniquePlus}{$cloneFrom}{$PING_URI_SWITCH}{$events} </span>{$info}\n\t\t{$proxyversion}{$PROXY_PERFS}{$END_PROXY}\n\t\t{$CountdeComputers_text}{$OrdersText}{$policies_text_line}";
        $cell[] = "<span style='color:{$loadcolor};{$StyleLoad}'>{$Loadbr}{$load}</span></span>";
        $cell[] = "{$style}{$cpus}<span style='{$StyleLoad};color:{$MemoryColor}'>{$Loadbr}{$mem_perc}%</a></span>";
        $cell[] = $hostag_switch . "&nbsp;" . $infodisk . $PROXY_LINE;
        $cell[] = "{$style}<span style='color:{$loadcolor} !important'>{$link_ip}{$public_ip}</span></a>{$PING_URI}</span>{$GroupsList}";
        $cell[] = "{$style}{$ligne["squidver"]}</span>";
        $cell[] = "{$style}{$linkver}{$version}</a></span>";
        $data['rows'][] = array('id' => $ligne['uuid'], 'cell' => $cell);
    }
    echo json_encode($data);
}
function query()
{
    $tpl = new templates();
    $also = $tpl->_ENGINE_parse_body("{also}");
    $MyPage = CurrentPageName();
    $q = new mysql_meta();
    $nowebsites = $tpl->_ENGINE_parse_body("{no_saved_web_site_catz}");
    $category = null;
    if ($category == null) {
        if ($_GET["category"] != null) {
            $category = $_GET["category"];
            $_POST["qtype"] = "pattern";
        }
    }
    if ($category == null) {
        if ($_POST["qtype"] != null) {
            $category = $_POST["qtype"];
            $_POST["qtype"] = "pattern";
        }
    }
    if ($_POST["query"] != null) {
        if ($_GET["website"] != null) {
            $_POST["query"] = $_GET["website"];
        }
    }
    if ($category == null) {
        json_error_show("Please select a category first");
    }
    if ($_POST["sortname"] == "sitename") {
        $_POST["sortname"] = "zDate";
        $_POST["sortorder"] = "desc";
    }
    $search = '%';
    $page = 1;
    $COUNT_ROWS = $q->COUNT_ROWS("webfiltering_categories_items");
    if ($COUNT_ROWS == 0) {
        json_error_show("category/COUNT_ROWS:{$category} ,{$nowebsites}", 1);
    }
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    $_POST["query"] = trim($_POST["query"]);
    $searchstring = string_to_flexquery();
    if ($searchstring != null) {
        $orgQuery = $_POST["query"];
        $sql = "SELECT COUNT(zmd5) as TCOUNT FROM `webfiltering_categories_items` WHERE category='{$category}' {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup"));
        $total = $ligne["TCOUNT"];
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $sql = "SELECT zDate,zmd5,pattern,enabled  FROM `webfiltering_categories_items` WHERE 1 {$searchstring} {$ORDER} {$limitSql}";
    writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        json_error_show($q->mysql_error, 1);
    }
    if (mysql_num_rows($results) == 0) {
        json_error_show("{$nowebsites}", 1);
    }
    $disabled_text = $tpl->_ENGINE_parse_body("{disabled}");
    $CategoriesCheckRightsWrite = CategoriesCheckRightsWrite();
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    if ($orgQuery != null) {
        $moveAll = imgtootltip("arrow-multiple-right-24.png", "{move}", "MoveAllCategorizedWebsite2('{$category}','{$table}','{$orgQuery}')");
    }
    while ($ligne = mysql_fetch_assoc($results)) {
        $delete = imgtootltip("delete-24.png", "{delete}", "DeleteCategorizedWebsite('{$ligne["zmd5"]}','{$table}')");
        $move = imgtootltip("arrow-right-24.png", "{move}", "MoveCategorizedWebsite('{$ligne["zmd5"]}','{$ligne["pattern"]}','{$category}','{$table}')");
        $added = null;
        $enabled = $ligne["enabled"];
        $color = "color:black";
        $moveAll = "&nbsp;";
        $move = "&nbsp;";
        $delete = imgtootltip("delete-24.png", "{delete}", "ReallyDeleteCategorizedWebsite('{$ligne["zmd5"]}')");
        $jscat = "<a href=\"javascript:blur();\" \n\t\tOnClick=\"javascript:Loadjs('squid.categorize.php?www={$ligne["pattern"]}');\"\n\t\tstyle='font-size:14px;text-decoration:underline;{$color}'>";
        if (!$CategoriesCheckRightsWrite) {
            $jscat = null;
            $moveAll = null;
            $move = null;
            $delete = null;
        }
        $data['rows'][] = array('id' => $ligne['zmd5'], 'cell' => array("\n\t\t<span style='font-size:18px;{$color}'>{$ligne['zDate']}</span>", "<span style='font-size:18px;{$color}'>{$ligne['pattern']}</a></span>", "<center>{$delete}</center>"));
    }
    echo json_encode($data);
    return;
    $page = CurrentPageName();
    $tpl = new templates();
    $category = $_GET["category"];
    if ($category == null) {
        return;
    }
    $q = new mysql_squid_builder();
    $tableN = "category_" . $q->category_transform_name($category);
    $strictSearch = $_GET["strictSearch"];
    if (!is_numeric($strictSearch)) {
        $strictSearch = 0;
    }
    $searchOrg = $_GET["search"];
    if ($_GET["search"] != null) {
        $search = $_GET["search"];
        if ($strictSearch == 0) {
            $search = "*{$search}*";
        }
        $search = str_replace("**", "*", $search);
        $search = str_replace("**", "*", $search);
        $search = str_replace("*", "%", $search);
        $search = " AND pattern LIKE '{$search}'";
    }
    $sql = "SELECT * FROM {$tableN} WHERE enabled=1 {$search} ORDER BY pattern LIMIT 0,25 ";
    $table = "<center>\n<table cellspacing='0' cellpadding='0' border='0' class='tableView' style='width:350px'>\n<thead class='thead'>\n\t<tr>\n\t<th width=1%>{website} {$category}</th>\n\t<th>{date}</th>\n\t<th>{$moveall}</th>\n\t<th>&nbsp;</th>\n\t</tr>\n</thead>\n<tbody>";
    $results = $q->QUERY_SQL($sql);
    $number = mysql_num_rows($results);
    if ($number == 0) {
        if ($searchOrg != null) {
            if (strpos($searchOrg, "*") == 0) {
                $html = "\n\t\t<center style='margin:30px'>\n\t\t<div style='font-size:16px;margin-bottom:15px'><code>&laquo;http://{$searchOrg}&raquo; {in} &laquo;{$category}&raquo;</code></div>\n\t\t<div style='font-size:14px'><a href=\"javascript:blur();\" \n\t\tOnClick=\"javascript:Loadjs('squid.visited.php?add-www=yes&websitetoadd={$searchOrg}')\"\n\t\tstyle='font-size:14px;font-weight:bold;text-decoration:underline'\n\t\t>{webiste_notfound_additask}</a>\n\t\t</div>\n\t\t</center>\n\t\t<script>LoadAjaxTiny('subtitles-categories','{$page}?subtitles-categories=yes');</script>\n\t\t";
                echo $tpl->_ENGINE_parse_body($html);
                return;
            }
        }
    }
    if (!$q->ok) {
        echo "<H2>{$q->mysql_error}</H2><center style='font-size:11px'><code>{$sql}</code></center>";
    }
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        if ($classtr == "oddRow") {
            $classtr = null;
        } else {
            $classtr = "oddRow";
        }
        if ($ligne["pattern"] == null) {
            $q->QUERY_SQL("DELETE FROM {$tableN} WHERE zmd5='{$ligne["zmd5"]}'");
            continue;
        }
        $jscat = "<a href=\"javascript:blur();\" \n\t\tOnClick=\"javascript:Loadjs('squid.categorize.php?www={$ligne["pattern"]}');\"\n\t\tstyle='font-size:14px;text-decoration:underline'>";
        $table = $table . "\n\t\t<tr class={$classtr}>\n\t\t<td style='width:1%;font-size:14px' nowrap>{$ligne["zDate"]}</td>\n\t\t<td style='width:1%;font-size:14px' nowrap>{$jscat}{$ligne["pattern"]}</a></td>\n\t\t<td>{$move}</td>\n\t\t<td>{$delete}</td>\n\t\t</tr>\n\t\t";
    }
    $table = $table . "</tbody></table>\n\t<script>\n\t\n\t\n\n\t\n\n\t\n\tLoadAjaxTiny('subtitles-categories','{$page}?subtitles-categories=yes');\n\t\n</script>\t\n\t";
    echo $tpl->_ENGINE_parse_body($table);
}