function squid_cache_status()
{
    $page = CurrentPageName();
    $squid = new squidnodes($_GET["nodeid"]);
    $tpl = new templates();
    $q = new mysql_blackbox();
    $t = $_GET["t"];
    $sql = "SELECT * FROM cachestatus WHERE nodeid='{$_GET["nodeid"]}'";
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        echo "<H3>Error: {$q->mysql_error}</H3>";
        return;
    }
    //$squid->
    $tr[] = "\n\t\t\t<table style='width:99%' class=form>\n\t\t\t<tbody>\n\t\t\t<tr>\n\t\t\t\t<td width=1%><img src='img/parameters2-64.png'></td>\n\t\t\t\t<td valign='top'>\n\t\t\t\t\t<table style='width:100%'>\n\t\t\t\t\t<tbody>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td valign=top><strong style='font-size:14px'>\n\t\t\t\t\t\t\t<a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('nodes.squid.caches32.parms.php?hostid={$_GET["hostid"]}&nodeid={$_GET["nodeid"]}');\"\n\t\t\t\t\t\t\tstyle='font-size:14px;text-decoration:underline;font-weight:bold'>\n\t\t\t\t\t\t\t{caches_parameters}</a></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td valign='top'><span style='font-size:14px'>{cache_parameters_node_explain}</span></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t</tbody>\n\t\t\t\t\t</table>\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t\t</tbody>\n\t\t\t</table>";
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $tr[] = "\n\t\t\t<table style='width:99%' class=form>\n\t\t\t<tbody>\n\t\t\t<tr>\n\t\t\t\t<td width=1%><img src='img/disk-64.png'></td>\n\t\t\t\t<td valign='top'>\n\t\t\t\t\t<table style='width:100%'>\n\t\t\t\t\t<tbody>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td valign=top><strong style='font-size:14px'>" . basename($ligne["cachedir"]) . "</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td valign='top'><strong style='font-size:14px'>" . FormatBytes($ligne["currentsize"]) . "/" . FormatBytes($ligne["maxsize"]) . "</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td valign='top'>" . pourcentage($ligne["pourc"]) . "</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t</tbody>\n\t\t\t\t\t</table>\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t\t</tbody>\n\t\t\t</table>";
    }
    $html = CompileTr2($tr);
    $html = $html . "<div style='width:100%;text-align:right'>" . imgtootltip("refresh-32.png", "{refresh}", "LoadAjax('squid-caches-status{$t}','{$page}?squid-caches-status=yes&nodeid={$_GET["nodeid"]}');") . "</div>";
    echo $tpl->_ENGINE_parse_body($html);
}
Example #2
0
function delete_node_perform()
{
    $f = new mysql_blackbox();
    $f->CheckTables();
    $q = new blackboxes($_POST["delete-node"]);
    $q->delete_node();
}
function DELETE_FROM_CACHE()
{
    $sock = new sockets();
    $delete_enc = urlencode($_POST["DELETE"]);
    $sock->getFrameWork("squid.php?purge-site={$delete_enc}");
    $sql = "DELETE FROM cacheitems_{$_POST["hostid"]} WHERE sitename='{$_POST["DELETE"]}'";
    $q = new mysql_blackbox();
    $q->QUERY_SQL($sql);
}
Example #4
0
function inject_stored_items($nopid = false)
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    if (system_is_overloaded(basename(__FILE__))) {
        $php = $unix->LOCATE_PHP5_BIN();
        ufdbguard_admin_events("Overloaded system... ask to run this task later...", __FUNCTION__, __FILE__, __LINE__, "proxy");
        $unix->THREAD_COMMAND_SET("{$php} " . __FILE__ . " --inject");
    }
    if (!$nopid) {
        $pid = @file_get_contents($pidfile);
        $myfile = basename(__FILE__);
        if ($unix->process_exists($pid, $myfile)) {
            ufdbguard_admin_events("Task already running PID: {$pid}, aborting current task", __FUNCTION__, __FILE__, __LINE__, "proxy");
            return;
        }
    }
    $mypid = getmypid();
    @file_put_contents($pidfile, $mypid);
    $t1 = time();
    $file = "/var/cache/purge.calculated.db";
    if (!is_file($file)) {
        echo "{$file} no such file\n";
        return;
    }
    $q = new mysql_blackbox();
    if (!$q->TABLE_EXISTS("cacheitems_localhost")) {
        $q->build_cached_items_table("localhost");
    }
    $BIGARRAY = inject_stored_array();
    $prefix = "INSERT IGNORE INTO cacheitems_localhost(sitename,familysite,size,items) VALUES ";
    $q->QUERY_SQL("TRUNCATE TABLE cacheitems_localhost");
    $f = array();
    $c = 0;
    while (list($sitename, $array) = each($BIGARRAY)) {
        $c++;
        $f[] = "('{$sitename}','{$array["FAMILY"]}','{$array["SIZE"]}','{$array["ITEMS"]}')";
        if (count($f) > 500) {
            $q->QUERY_SQL($prefix . @implode(",", $f));
            if (!$q->ok) {
                squid_admin_mysql(0, "MySQL error!", $q->mysql_error, __FILE__, __LINE__);
                return;
            }
        }
    }
    if (count($f) > 0) {
        $q->QUERY_SQL($prefix . @implode(",", $f));
        if (!$q->ok) {
            squid_admin_mysql(0, "MySQL error!", $q->mysql_error, __FILE__, __LINE__);
            return;
        }
    }
    $took = $unix->distanceOfTimeInWords($t1, time());
    if ($c > 0) {
        squid_admin_mysql(2, "Sucess adding {$c} cached websites took:{$took}", null, __FILE__, __LINE__);
    }
    @unlink($file);
}
function rows_table()
{
    $tpl = new templates();
    $MyPage = CurrentPageName();
    $q = new mysql_blackbox();
    $nodeid = $_GET["nodeid"];
    $search = '%';
    $table = "cachelogs{$nodeid}";
    $page = 1;
    $ORDER = "ORDER BY zDate DESC";
    if (!$q->TABLE_EXISTS($table)) {
        writelogs("`{$table}` no such table", __FUNCTION__, __FILE__, __LINE__);
    }
    writelogs("`{$table}` " . $q->COUNT_ROWS($table) . " items", __FUNCTION__, __FILE__, __LINE__);
    $total = 0;
    if ($q->COUNT_ROWS($table) == 0) {
        $data['page'] = $page;
        $data['total'] = $total;
        $data['rows'] = array();
        echo json_encode($data);
        return;
    }
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    if ($_POST["query"] != null) {
        $_POST["query"] = "*" . $_POST["query"] . "*";
        $_POST["query"] = str_replace("**", "*", $_POST["query"]);
        $_POST["query"] = str_replace("**", "*", $_POST["query"]);
        $_POST["query"] = str_replace("*", "%", $_POST["query"]);
        $search = $_POST["query"];
        $searchstring = "AND (`{$_POST["qtype"]}` LIKE '{$search}')";
        $sql = "SELECT COUNT(*) as TCOUNT FROM `{$table}` WHERE 1 {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql));
        $total = $ligne["TCOUNT"];
    } else {
        $total = $q->COUNT_ROWS($table);
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $sql = "SELECT *  FROM `{$table}` WHERE 1 {$searchstring} {$ORDER} {$limitSql}";
    writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        writelogs("`{$table}` {$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__);
    }
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    if (!$q->ok) {
        $data['rows'][] = array('id' => $ligne[time() + 1], 'cell' => array($q->mysql_error, "", "", ""));
        $data['rows'][] = array('id' => $ligne[time()], 'cell' => array($sql, "", "", ""));
        echo json_encode($data);
        return;
    }
    //if(mysql_num_rows($results)==0){$data['rows'][] = array('id' => $ligne[time()],'cell' => array($sql,"", "",""));}
    writelogs("`{$sql}` " . mysql_num_rows($results), __FUNCTION__, __FILE__, __LINE__);
    while ($ligne = mysql_fetch_assoc($results)) {
        $color = "black";
        if (preg_match("#(crashing|failed|No such|FATAL|abnormally|WARNING|refused)#", $ligne["line"])) {
            $color = "red";
        }
        $data['rows'][] = array('id' => $ligne['mac'], 'cell' => array("<span style='font-size:14px;color:{$color}'>{$ligne["zDate"]}</span>", "<span style='font-size:14px;color:{$color}'>{$ligne["line"]}</span>"));
    }
    echo json_encode($data);
}
Example #6
0
function main_tabs()
{
    $tpl = new templates();
    $page = CurrentPageName();
    $squid = new squidbee();
    $sock = new sockets();
    $DisableAnyCache = $sock->GET_INFO("DisableAnyCache");
    if (!is_numeric($DisableAnyCache)) {
        $DisableAnyCache = 0;
    }
    $SquidCacheLevel = $sock->GET_INFO("SquidCacheLevel");
    if (!is_numeric($SquidCacheLevel)) {
        $SquidCacheLevel = 4;
    }
    if ($SquidCacheLevel == 0) {
        $DisableAnyCache = 1;
    }
    $UseSimplifiedCachePattern = $sock->GET_INFO("UseSimplifiedCachePattern");
    if (!is_numeric($UseSimplifiedCachePattern)) {
        $UseSimplifiedCachePattern = 1;
    }
    $realsquidversion = @file_get_contents("/etc/artica-postfix/settings/Daemons/SquidVersion");
    $ID = $_GET["ID"];
    $t = $_GET["t"];
    $array["caches-level"] = '{cache_level}';
    $array["caches-status"] = '{caches_status}';
    if ($DisableAnyCache == 0) {
        if (preg_match("#^3\\.(4|5|6|7|8)\\.#", $realsquidversion)) {
            $array["rock"] = '{rock_store}';
        }
    }
    $array["caches-center"] = '{caches_center}';
    $array["artica-cache"] = "{enforce_rules}";
    if ($UseSimplifiedCachePattern == 0) {
        if ($SquidCacheLevel > 2) {
            //$array["dyn-section"]="{dynamic_enforce_rules}";
        }
    }
    if ($SquidCacheLevel > 1) {
        //$array["main-section"]="{cache_rules}";
    }
    $array["parameters"] = "{global_parameters}";
    if ($DisableAnyCache == 0) {
        $q = new mysql_blackbox();
        if ($q->TABLE_EXISTS("cacheitems_localhost")) {
            $ct = $q->COUNT_ROWS("cacheitems_localhost");
            if ($ct > 0) {
                $array["cached_items"] = "{$ct} {cached_items}";
            }
        }
    }
    if (count($array) >= 4) {
        $fontsize = 18;
    }
    if (count($array) >= 8) {
        $fontsize = 14;
    }
    while (list($num, $ligne) = each($array)) {
        if ($num == "artica-cache") {
            $html[] = $tpl->_ENGINE_parse_body("<li><a href=\"squid.artica-rules.php\">\n\t\t\t<span style='font-size:{$fontsize}px'>{$ligne}</span></a></li>\n");
            continue;
        }
        if ($num == "rock") {
            $html[] = $tpl->_ENGINE_parse_body("<li><a href=\"squid.rock.php\">\n\t\t\t<span style='font-size:{$fontsize}px'>{$ligne}</span></a></li>\n");
            continue;
        }
        if ($num == "caches-level") {
            $html[] = $tpl->_ENGINE_parse_body("<li><a href=\"squid.caches.level.php\">\n\t\t\t\t\t<span style='font-size:{$fontsize}px'>{$ligne}</span></a></li>\n");
            continue;
        }
        if ($num == "caches-status") {
            $html[] = $tpl->_ENGINE_parse_body("<li><a href=\"squid.caches.status.php\">\n\t\t\t\t\t <span style='font-size:{$fontsize}px'>{$ligne}</span></a></li>\n");
            continue;
        }
        if ($num == "caches") {
            $html[] = $tpl->_ENGINE_parse_body("<li>\n\t\t\t\t\t<a href=\"squid.caches32.php?uuid={$squid->uuid}\"><span style='font-size:{$fontsize}px'>{$ligne}</span></a></li>\n");
            continue;
        }
        if ($num == "caches-params") {
            $html[] = $tpl->_ENGINE_parse_body("<li>\n\t\t\t\t\t<a href=\"squid.caches.php?parameters=yes\">\n\t\t\t\t\t\t<span style='font-size:{$fontsize}px'>{$ligne}</span></a></li>\n");
            continue;
        }
        if ($num == "caches-center") {
            $html[] = $tpl->_ENGINE_parse_body("<li><a href=\"squid.caches.center.php\" ><span style='font-size:{$fontsize}px'>{$ligne}</span></a></li>\n");
            continue;
        }
        if ($num == "cached_items") {
            $html[] = $tpl->_ENGINE_parse_body("<li ><a href=\"squid.cached.itemps.php?hostid=localhost\"><span style='font-size:{$fontsize}px'>{$ligne}</span></a></li>\n");
            continue;
        }
        if ($num == "dyn-section") {
            $html[] = $tpl->_ENGINE_parse_body("<li><a href=\"squid.cache.dynamic.rules.php\"><span style='font-size:{$fontsize}px'>{$ligne}</span></a></li>\n");
            continue;
        }
        $html[] = $tpl->_ENGINE_parse_body("<li>\n\t\t\t\t\t<a href=\"{$page}?{$num}=yes&t={$t}&ID={$ID}&tt={$_GET["tt"]}&SourceT={$_GET["SourceT"]}\"><span style='font-size:{$fontsize}px'>{$ligne}</span></a></li>\n");
    }
    echo build_artica_tabs($html, "main_cache_rules_main_tabs") . "<script>LeftDesign('caches-center-white-256-opac20.png');</script>";
}
Example #7
0
function serverlist()
{
    $tpl = new templates();
    $users = new usersMenus();
    $page = CurrentPageName();
    $q = new mysql_blackbox();
    $add_artica_agent_explain = $tpl->javascript_parse_text("{add_artica_agent_explain}");
    $t = time();
    $sql = "SELECT * FROM nodes";
    $results = $q->QUERY_SQL($sql);
    $classtr = null;
    while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) {
        $nodeid = $ligne["nodeid"];
        $server = $ligne["ipaddress"];
        $port = $ligne["port"];
        $hostname = $ligne["hostname"];
        $laststatus = distanceOfTimeInWords(time(), strtotime($ligne["laststatus"]));
        $perfs = unserialize(base64_decode($ligne["perfs"]));
        $perftext = "&nbsp;";
        $settings = unserialize(base64_decode($ligne["settingsinc"]));
        $fqdn_hostname = $settings["fqdn_hostname"];
        if ($fqdn_hostname == null) {
            $fqdn_hostname = $server;
        }
        if (is_array($perfs["MEMORY"])) {
            $hash_mem = $perfs["MEMORY"];
            $Hash_real_mem = $perfs["REALMEM"];
            if (is_array($Hash_real_mem)) {
                $hash_mem["ram"]["percent"] = $Hash_real_mem["ram"]["percent"];
                $hash_mem["ram"]["used"] = $Hash_real_mem["ram"]["used"];
                $hash_mem["ram"]["total"] = $Hash_real_mem["ram"]["total"];
            }
            $mem_used_p = $hash_mem["ram"]["percent"];
            $mem_used_kb = FormatBytes($hash_mem["ram"]["used"]);
            $total = FormatBytes($hash_mem["ram"]["total"]);
            $color = "#5DD13D";
            $swapar_perc = $hash_mem['swap']['percent'];
            $swap_color = "rgb(93, 209, 61)";
            $swap_text = "<br><span style='font-size:9px'>swap: {$swapar_perc}% {used}</span>";
            if ($swapar_perc > 30) {
                $swap_color = "#F59C44";
            }
            if ($swapar_perc > 50) {
                $swap_color = "#D32D2D";
            }
            $swap = "<div style=\"border: 1px solid {$swap_color}; width: 100px; background-color: white; padding-left: 0px; margin-top: 3px;\" " . CellRollOver($swap_js) . ">\n\t\t\t\t\t\t<div style=\"width: {$swapar_perc}px; text-align: center; color: white; padding-top: 3px; padding-bottom: 3px; background-color:{$swap_color};\"> </div>\n\t\t\t\t</div>";
            if ($mem_used_p > 70) {
                $color = "#F59C44";
            }
            if ($mem_used_p > 79) {
                $color = "#D32D2D";
            }
            $memtext = "<div style='width:100px;background-color:white;padding-left:0px;border:1px solid {$color}'>\n\t\t\t\t<div style='width:{$mem_used_p}px;text-align:center;color:white;padding-top:3px;padding-bottom:3px;background-color:{$color}'><strong>{$mem_used_p}%</strong></div>\n\t\t\t\t</div>{$swap}";
            //print_r($perfs["MEMORY"]);
        }
        if (is_numeric($perfs["LOAD_POURC"])) {
            $perfsColor = "white";
            if ($perfs["LOAD_POURC"] == 0) {
                $perfsColor = "black";
            }
            $perftext = "\n\t\t<table style='width:100%' margin=0 padding=0>\n\t\t<tr style='background-color:transparent'>\n\t\t<td padding=0px style='border:0px'><span style='font-size:11px'>{load}:</span></td>\n\t\t<td padding=0px style='border:0px'>\n\t\t<div style='width:100px;background-color:white;padding-left:0px;border:1px solid {$perfs["LOAD_COLOR"]};margin-top:3px'>\n\t\t\t<div style='width:{$perfs["LOAD_POURC"]}px;text-align:center;color:white;padding-top:3px;padding-bottom:3px;background-color:{$perfs["LOAD_COLOR"]}'>\n\t\t\t\t<span style='color:{$perfsColor};font-size:11px;font-weight:bold'>{$perfs["LOAD_POURC"]}%</span>\n\t\t\t</div>\n\t\t</div>\n\t\t</td >\n\t\t</tr'>\n\t\t<tr padding=0px style='background-color:transparent'>\n\t\t\t<td style='border:0px'><span style='font-size:11px'>{memory}:</span></td>\n\t\t\t<td style='border:0px'>{$memtext}</td>\n\t\t</tr>\n\t\t</table>";
        }
        $fqdn_hostnameAR = explode(".", $fqdn_hostname);
        if (strpos($hostname, ".") > 0) {
            $hostnameTR = explode(".", $hostname);
            $hostname = $hostnameTR[0];
        }
        $ipZ = array();
        $ipsT = null;
        $results2 = $q->QUERY_SQL("SELECT ipaddr  FROM `nics` WHERE nodeid={$nodeid}");
        while ($ligne2 = mysql_fetch_array($results2, MYSQL_ASSOC)) {
            if ($ligne2["ipaddr"] == "127.0.0.1") {
                continue;
            }
            $ipZ[] = $ligne2["ipaddr"];
        }
        if (count($ipZ) > 0) {
            $ipsT = "<div style='font-size:11px'><i>" . @implode(", ", $ipZ) . "</i></div>";
        }
        $hostTXT = $hostname;
        $NODES[] = "<table style='width:90%' class=form>\n\t\t<tbody>\n\t\t<tr>\n\t\t\t<td width=1%>" . imgtootltip("64-idisk-server.png", "{$fqdn_hostname}", "Loadjs('nodes.php?nodeid={$nodeid}')") . "</td>\n\t\t\t<td width=99%>\n\t\t\t\t<strong style='font-size:12px'>\n\t\t\t\t\t<a href=\"javascript:blur();\"\n\t\t\t\t\tstyle='font-size:14px;text-decoration:underline'\n\t\t\t\t\tOnClick=\"javascript:Loadjs('nodes.php?nodeid={$nodeid}')\"\n\t\t\t\t\t>{$hostTXT}</a></strong>{$ipsT}\n\t\t\t\t{$perftext}\n\t\t\t</td>\n\t\t</tr>\n\t\t</tbody>\n\t\t</table>";
    }
    $html = CompileTr2($NODES);
    echo $tpl->_ENGINE_parse_body($html);
}
function section_status()
{
    $page = CurrentPageName();
    $sock = new sockets();
    $users = new usersMenus();
    $q = new mysql_blackbox();
    $tpl = new templates();
    $language = $tpl->language;
    $array["status"] = "{services_status}";
    $array["events-squidaccess"] = '{realtime_requests}';
    if ($q->TABLE_EXISTS("cacheitems_localhost")) {
        $ct = $q->COUNT_ROWS("cacheitems_localhost");
        if ($ct > 0) {
            $array["cached_items"] = "{$ct} {cached_items}";
        }
    }
    $EnableRemoteStatisticsAppliance = $sock->GET_INFO("EnableRemoteStatisticsAppliance");
    if (!is_numeric($EnableRemoteStatisticsAppliance)) {
        $EnableRemoteStatisticsAppliance = 0;
    }
    $array["remote-web-appliances"] = "{appliances}";
    $fontsize = 14;
    if ($language == "fr") {
        $fontsize = "12.5";
    }
    while (list($num, $ligne) = each($array)) {
        if ($num == "software-update") {
            $html[] = $tpl->_ENGINE_parse_body("<li><a href=\"squid.softwares.php\">\n\t\t\t\t<span style='font-size:{$fontsize}px'>{$ligne}</span></a></li>\n");
            continue;
        }
        if ($num == "events-squidaccess") {
            $html[] = $tpl->_ENGINE_parse_body("<li><a href=\"squid.accesslogs.php?table-size=898&url-row=433\">\n\t\t\t\t\t<span style='font-size:{$fontsize}px'>{$ligne}</span></a></li>\n");
            continue;
        }
        if ($num == "remote-web-appliances") {
            $html[] = $tpl->_ENGINE_parse_body("<li ><a href=\"squid.statsappliance.clients.php\">\n\t\t\t\t\t<span style='font-size:{$fontsize}px'>{$ligne}</span></a></li>\n", null, "310", null, 1);
            continue;
        }
        if ($num == "cached_items") {
            $html[] = $tpl->_ENGINE_parse_body("<li><a href=\"squid.cached.itemps.php?hostid=localhost\"><span style='font-size:{$fontsize}px'>{$ligne}</span></a></li>\n");
            continue;
        }
        if ($num == "graphs") {
            $html[] = $tpl->_ENGINE_parse_body("<li><a href=\"squid.graphs.php\" style='font-size:{$fontsize}px'><span>{$ligne}</span></a></li>\n");
            continue;
        }
        if ($num == "events-squidcache") {
            $html[] = $tpl->_ENGINE_parse_body("<li><a href=\"squid.cachelogs.php\"><span style='font-size:{$fontsize}px'>{$ligne}</span></a></li>\n");
            continue;
        }
        $html[] = $tpl->_ENGINE_parse_body("<li><a href=\"{$page}?{$num}=yes\"><span style='font-size:{$fontsize}px'>{$ligne}</span></a></li>\n");
        //$html=$html . "<li><a href=\"javascript:LoadAjax('squid_main_config','$page?main=$num&hostname={$_GET["hostname"]}')\" $class>$ligne</a></li>\n";
    }
    echo build_artica_tabs($html, "squid_main_svc", 950) . "\n\t\t<script>QuickLinkShow('quicklinks-services_status');</script>";
}
function AddArticaAgent(){
	$tpl=new templates();
	$sock=new sockets();
	$pattern=$_POST["AddArticaAgent"];
	$ip=$pattern;
	if(preg_match("#(.+?):([0-9]+)#", $pattern,$re)){$ip=$re[1];$port=$re[2];}
	if(!is_numeric($port)){$port=9001;}
	include_once(dirname(__FILE__)."/ressources/class.ccurl.inc");
	
	
	$ArticaHttpsPort=$sock->GET_INFO("ArticaHttpsPort");
	$ArticaHttpUseSSL=$sock->GET_INFO("ArticaHttpUseSSL");
	if(!is_numeric($ArticaHttpUseSSL)){$ArticaHttpUseSSL=1;}
	if(!is_numeric($ArticaHttpsPort)){$ArticaHttpsPort="9000";}	
	
	
	$time=date('Y-m-d H:i:s');
	if(preg_match("#^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+#", $ip)){
		$hostname=gethostbyaddr($ip);
	}else{
		$hostname=$ip;
		$ip=gethostbyname($hostname);
	}

	$q=new mysql_blackbox();
	$q->CheckTables();
	$sql="INSERT IGNORE INTO `nodes` (ipaddress,hostname,port,laststatus) VALUES ('$ip','$hostname','$port','$time')";
	$q->QUERY_SQL($sql);
	if(!$q->ok){echo $q->mysql_error;return;}
	if($q->last_id==0){
		echo "Unable to get Last ID\n";return;
	}
	$curl=new ccurl("http://$ip:$port/listener.php");
	$curl->parms["REGISTER"]="yes";
	$curl->parms["SSL"]=$ArticaHttpUseSSL;
	$curl->parms["PORT"]=$ArticaHttpsPort;
	$curl->parms["NODE_ID"]=$q->last_id;
	if(!$curl->get()){echo $tpl->javascript_parse_text("{$curl->error}")."\nhttp://$ip:$port";return;}
	if(!preg_match("#<SUCCESS>#is", $curl->data)){echo $tpl->javascript_parse_text("{failed} `http://$ip:$port`");return;}	
	
}	
function rows_table()
{
    $tpl = new templates();
    $MyPage = CurrentPageName();
    $q = new mysql_blackbox();
    $nodeid = $_GET["nodeid"];
    $hostid = $_GET["hostid"];
    $q = new mysql_blackbox();
    $sql = "SELECT UfdbClientLogs FROM nodes WHERE hostid='{$hostid}'";
    $ligne = mysql_fetch_array($q->QUERY_SQL($sql));
    if (!$q->ok) {
        json_error_show("{$q->mysql_error}", 1);
    }
    if (strlen($ligne["UfdbClientLogs"]) == 0) {
        json_error_show("UfdbClientLogs No content...", 1);
    }
    $base = base64_decode($ligne["UfdbClientLogs"]);
    $array = unserialize($base);
    if (!is_array($array)) {
        json_error_show(strlen($ligne["UfdbClientLogs"]) . " bytes...Not an array...", 1);
    }
    $page = 1;
    if (count($array) == 0) {
        json_error_show("No rows", 1);
    }
    krsort($array);
    $total = count($array);
    $search = string_to_regex($_POST["query"]);
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    $c = 0;
    while (list($index, $ligne) = each($array)) {
        if (trim($ligne) == null) {
            continue;
        }
        $md5 = md5($ligne);
        $color = "black";
        if (preg_match("#([0-9\\-\\s\\:]+)\\s+\\[#", $ligne, $re)) {
            $date = $re[1];
            $ligne = str_replace($date, "", $ligne);
        }
        if ($search != null) {
            if (!preg_match("#{$search}#", $ligne)) {
                continue;
            }
        }
        if (preg_match("#(crashing|failed|No such|FATAL|abnormally|WARNING)#", $ligne["line"])) {
            $color = "red";
        }
        $c++;
        $data['rows'][] = array('id' => $md5, 'cell' => array("<span style='font-size:14px;color:{$color}'>{$date}</span>", "<span style='font-size:14px;color:{$color}'>{$ligne}</span>"));
    }
    $data['total'] = $c;
    echo json_encode($data);
}
Example #11
0
function REGISTER()
{
    $q = new mysql_blackbox();
    if (!isset($_POST["nets"])) {
        die("No network sended");
    }
    $EncodedDatas = $_POST["nets"];
    $array = unserialize(base64_decode($EncodedDatas));
    $nodeid = $_POST["nodeid"];
    $hostid = $_POST["hostid"];
    $ISARTICA = $_POST["ISARTICA"];
    $usessl = $_POST["usessl"];
    if (!is_numeric($ISARTICA)) {
        $ISARTICA = 0;
    }
    if (!is_numeric($nodeid)) {
        $nodeid = 0;
    }
    if (!is_array($array)) {
        echo "<ERROR>No an Array</ERROR>\n";
        writelogs("Not an array... ", __CLASS__ . "/" . __FUNCTION__, __FILE__, __LINE__);
        return;
    }
    if (count($array) == 0) {
        echo "<ERROR>No item sended</ERROR>\n";
        writelogs("No item... ", __CLASS__ . "/" . __FUNCTION__, __FILE__, __LINE__);
        return;
    }
    $sql = "SELECT nodeid FROM nodes WHERE `hostid`='{$hostid}'";
    $ligne = mysql_fetch_array($q->QUERY_SQL($sql));
    $nodeid = $ligne["nodeid"];
    if (!is_numeric($nodeid)) {
        $nodeid = 0;
    }
    $ME = $_SERVER["SERVER_NAME"];
    $q = new mysql_blackbox();
    $q->CheckTables();
    if ($nodeid > 0) {
        writelogs("item already exists", __CLASS__ . "/" . __FUNCTION__, __FILE__, __LINE__);
        $sql = "UPDATE nodes SET hostname='{$_POST["hostname"]}',\n\t\tipaddress='{$_SERVER["REMOTE_ADDR"]}',\n\t\tport='{$_POST["port"]}',\n\t\thostid='{$hostid}' WHERE nodeid='{$nodeid}'";
        if ($GLOBALS["VERBOSE"]) {
            echo "{$ME}:{$sql}\n";
        }
        $q->QUERY_SQL($sql);
        if (preg_match("#Unknown column 'hostid'#", $q->mysql_error)) {
            $q->QUERY_SQL("DROP TABLE nodes");
            $q->CheckTables();
            $sql = "INSERT INTO nodes (`hostname`,`ipaddress`,`port`,`hostid`,`BigArtica`,`ssl`) \n\t\t\tVALUES ('{$_POST["hostname"]}','{$_SERVER["REMOTE_ADDR"]}','{$_POST["port"]}','{$hostid}','{$ISARTICA}','{$usessl}')";
            $q->QUERY_SQL($sql);
            if (!$q->ok) {
                echo "<ERROR>{$ME}: Statisics appliance: {$q->mysql_error}:\n{$sql}\n line:" . __LINE__ . "</ERROR>\n";
                return;
            }
            $sql = "SELECT nodeid FROM nodes WHERE `hostid`='{$hostid}'";
            $ligne = mysql_fetch_array($q->QUERY_SQL($sql));
            if (!$q->ok) {
                echo "<ERROR>{$ME}: Statisics appliance: {$q->mysql_error}:\n{$sql}\n line:" . __LINE__ . "</ERROR>\n";
                return;
            }
            $nodeid = $ligne["nodeid"];
        }
        if (!$q->ok) {
            echo "<ERROR>{$ME}: Statisics appliance: {$q->mysql_error}:\n{$sql}\n line:" . __LINE__ . "</ERROR>\n";
            return;
        }
        echo "<SUCCESS>{$nodeid}</SUCCESS>";
    } else {
        echo "Adding new item\n...";
        writelogs("Adding new item", __CLASS__ . "/" . __FUNCTION__, __FILE__, __LINE__);
        $sql = "INSERT INTO nodes (`hostname`,`ipaddress`,`port`,`hostid`,`BigArtica`,`ssl`) \n\t\tVALUES ('{$_POST["hostname"]}','{$_SERVER["REMOTE_ADDR"]}','{$_POST["port"]}','{$hostid}','{$ISARTICA}','{$usessl}')";
        $q->QUERY_SQL($sql);
        if ($GLOBALS["VERBOSE"]) {
            if (!$q->ok) {
                echo "<ERROR>{$ME}: Statisics appliance: {$q->mysql_error}: line:" . __LINE__ . "</ERROR>\n";
            }
        }
        if (preg_match("#Unknown column 'hostid'#", $q->mysql_error)) {
            $q->QUERY_SQL("DROP TABLE nodes");
            $q->CheckTables();
            $q->QUERY_SQL($sql);
        }
        if (!$q->ok) {
            echo "<ERROR>{$ME}:Statisics appliance: {$q->mysql_error}: line:" . __LINE__ . "</ERROR>\n";
            return;
        }
        $sql = "SELECT nodeid FROM nodes WHERE `hostid`='{$hostid}'";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql));
        echo "{$ME}:Success adding new item in the central server\n";
        echo "<SUCCESS>{$ligne["nodeid"]}</SUCCESS>";
    }
}
<?php 
include_once dirname(__FILE__) . '/ressources/class.templates.inc';
include_once dirname(__FILE__) . '/ressources/class.ldap.inc';
include_once dirname(__FILE__) . '/ressources/class.users.menus.inc';
include_once dirname(__FILE__) . '/ressources/class.mysql.inc';
include_once dirname(__FILE__) . '/ressources/class.os.system.inc';
include_once dirname(__FILE__) . '/ressources/class.mysql.blackboxes.inc';
include_once dirname(__FILE__) . '/framework/frame.class.inc';
include_once dirname(__FILE__) . '/framework/class.unix.inc';
if (posix_getuid() != 0) {
    die("Cannot be used in web server mode\n\n");
}
$GLOBALS["AS_ROOT"] = true;
$GLOBALS["VERBOSE"] = true;
ini_set('display_errors', 1);
ini_set('error_reporting', E_ALL);
ini_set('error_prepend_string', null);
ini_set('error_append_string', null);
echo "Starting initalization....\n";
$q = new mysql_blackbox();
$q->CheckTables();
if ($q->TABLE_EXISTS("nodes")) {
    echo "Starting nodes......: OK\n";
}
if ($q->TABLE_EXISTS("squidconf")) {
    echo "Starting squidconf..: OK\n";
}
Example #13
0
function rows_table()
{
    $tpl = new templates();
    $MyPage = CurrentPageName();
    $q = new mysql_blackbox();
    $nodeid = $_GET["nodeid"];
    $search = '%';
    $table = "nics";
    $page = 1;
    $ORDER = "ORDER BY nics ASC";
    $total = 0;
    if ($q->COUNT_ROWS($table) == 0) {
        $data['page'] = $page;
        $data['total'] = $total;
        $data['rows'] = array();
        echo json_encode($data);
        return;
    }
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    if ($_POST["query"] != null) {
        $_POST["query"] = "*" . $_POST["query"] . "*";
        $_POST["query"] = str_replace("**", "*", $_POST["query"]);
        $_POST["query"] = str_replace("**", "*", $_POST["query"]);
        $_POST["query"] = str_replace("*", "%", $_POST["query"]);
        $search = $_POST["query"];
        $searchstring = "AND ((`{$_POST["qtype"]}` LIKE '{$search}' AND nodeid={$nodeid}) OR (`mac` LIKE '{$search}' AND nodeid={$nodeid}))";
        $sql = "SELECT COUNT(*) as TCOUNT FROM `{$table}` WHERE 1 {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql));
        $total = $ligne["TCOUNT"];
    } else {
        $sql = "SELECT COUNT(*) as TCOUNT FROM `{$table}` WHERE nodeid={$nodeid}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql));
        $total = $ligne["TCOUNT"];
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $sql = "SELECT *  FROM `{$table}` WHERE nodeid={$nodeid} {$searchstring} {$ORDER} {$limitSql}";
    writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
    }
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    if (!$q->ok) {
        $data['rows'][] = array('id' => $ligne[time() + 1], 'cell' => array($q->mysql_error, "", "", ""));
        $data['rows'][] = array('id' => $ligne[time()], 'cell' => array($sql, "", "", ""));
        echo json_encode($data);
        return;
    }
    //if(mysql_num_rows($results)==0){$data['rows'][] = array('id' => $ligne[time()],'cell' => array($sql,"", "",""));}
    while ($ligne = mysql_fetch_assoc($results)) {
        $data['rows'][] = array('id' => $ligne['mac'], 'cell' => array("<img src='img/folder-network-24.png'>", "<span style='font-size:16px'>{$ligne["ipaddr"]}</span>", "<span style='font-size:16px'>{$ligne["netmask"]}</span>", "<span style='font-size:16px'>{$ligne["gateway"]}</span>", "<span style='font-size:16px'>{$ligne["mac"]}</span>"));
    }
    echo json_encode($data);
}
Example #14
0
function rows_table()
{
    $tpl = new templates();
    $MyPage = CurrentPageName();
    $q = new mysql_blackbox();
    $nodeid = $_GET["nodeid"];
    $search = '%';
    $table = "softwares";
    $page = 1;
    $ORDER = "ORDER BY software ASC";
    $total = 0;
    if ($q->COUNT_ROWS($table) == 0) {
        $data['page'] = $page;
        $data['total'] = $total;
        $data['rows'] = array();
        echo json_encode($data);
        return;
    }
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    if ($_POST["query"] != null) {
        $_POST["query"] = "*" . $_POST["query"] . "*";
        $_POST["query"] = str_replace("**", "*", $_POST["query"]);
        $_POST["query"] = str_replace("**", "*", $_POST["query"]);
        $_POST["query"] = str_replace("*", "%", $_POST["query"]);
        $search = $_POST["query"];
        $searchstring = "AND ((`{$_POST["qtype"]}` LIKE '{$search}' AND nodeid={$nodeid}) OR (`software` LIKE '{$search}' AND nodeid={$nodeid}))";
        $sql = "SELECT COUNT(*) as TCOUNT FROM `{$table}` WHERE 1 {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql));
        $total = $ligne["TCOUNT"];
    } else {
        $sql = "SELECT COUNT(*) as TCOUNT FROM `{$table}` WHERE nodeid={$nodeid}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql));
        $total = $ligne["TCOUNT"];
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $sql = "SELECT *  FROM `{$table}` WHERE nodeid={$nodeid} {$searchstring} {$ORDER} {$limitSql}";
    writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
    }
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    if (!$q->ok) {
        $data['rows'][] = array('id' => $ligne[time() + 1], 'cell' => array($q->mysql_error, "", "", ""));
        $data['rows'][] = array('id' => $ligne[time()], 'cell' => array($sql, "", "", ""));
        echo json_encode($data);
        return;
    }
    //if(mysql_num_rows($results)==0){$data['rows'][] = array('id' => $ligne[time()],'cell' => array($sql,"", "",""));}
    while ($ligne = mysql_fetch_assoc($results)) {
        $software_name = $tpl->_ENGINE_parse_body("{{$ligne['software']}}");
        if (strpos($software_name, "}") > 0) {
            $software_name = $ligne['software'];
        }
        if (preg_match("#.+?\\((.+?)\\)\$#", trim($software_name), $re)) {
            $software_name = str_replace($re[1], "<span style='font-size:11px'>{$re[1]}</span>", $software_name);
        }
        $ligne['software'] = $software_name;
        $data['rows'][] = array('id' => $ligne['software'], 'cell' => array("<span style='font-size:16px'>{$ligne["software"]}</span>", "<span style='font-size:16px'>{$ligne["version"]}</span>"));
    }
    echo json_encode($data);
}
Example #15
0
function main_tabs(){
	$tpl=new templates();
	$page=CurrentPageName();
	$squid=new squidbee();
	$sock=new sockets();
	$DisableAnyCache=$sock->GET_INFO("DisableAnyCache");
	if(!is_numeric($DisableAnyCache)){$DisableAnyCache=0;}
	$CacheManagement2=$sock->GET_INFO("CacheManagement2");
	if(!is_numeric($CacheManagement2)){$CacheManagement2=0;}
	$SquidCacheLevel=$sock->GET_INFO("SquidCacheLevel");
	if(!is_numeric($SquidCacheLevel)){$SquidCacheLevel=4;}
	if($SquidCacheLevel==0){$DisableAnyCache=1;}
	$UseSimplifiedCachePattern=$sock->GET_INFO("UseSimplifiedCachePattern");
	if(!is_numeric($UseSimplifiedCachePattern)){$UseSimplifiedCachePattern=1;}
	
	$ID=$_GET["ID"];
	$t=$_GET["t"];
	
	
	$array["caches-level"]='{cache_level}';
	$array["caches-status"]='{caches_status}';
	
	if($CacheManagement2==1){
		$array["caches-center"]='{caches_center}';
	}
	
	
	$array["artica-cache"]="{enforce_rules}";
	
	
	
	
	
	
	if($UseSimplifiedCachePattern==0){
		if($SquidCacheLevel>2){
			$array["dyn-section"]="{dynamic_enforce_rules}";
		}
		
	}
	
	if($SquidCacheLevel>1){
		$array["main-section"]="{cache_rules}";
	}
	

	
	$array["parameters"]='{global_parameters}';
	if($CacheManagement2==0){
		$array["caches"]='{caches}';
		$array["caches-params"]='{caches_parameters}';
	}
	

	if($DisableAnyCache==0){
		$q=new mysql_blackbox();
		if($q->TABLE_EXISTS("cacheitems_localhost")){
			$ct=$q->COUNT_ROWS("cacheitems_localhost");
			if($ct>0){
				if($CacheManagement2==1){$array["cached_items"]="$ct {cached_items}";}
	
			}
		}
	}

	if(count($array)>=4){
		$fontsize=18;
	}
	
	if(count($array)>=7){
		$fontsize=14;
	}
	while (list ($num, $ligne) = each ($array) ){
		
		
		if($num=="artica-cache"){
			$html[]= $tpl->_ENGINE_parse_body("<li><a href=\"squid.artica-rules.php\">
			<span style='font-size:{$fontsize}px'>$ligne</span></a></li>\n");
			continue;
		}
		
		
		if($num=="caches-level"){
			$html[]= $tpl->_ENGINE_parse_body("<li><a href=\"squid.caches.level.php\">
					<span style='font-size:{$fontsize}px'>$ligne</span></a></li>\n");
			continue;
		}
		
		
		if($num=="caches-status"){
			$html[]= $tpl->_ENGINE_parse_body("<li><a href=\"squid.caches.status.php\">
					 <span style='font-size:{$fontsize}px'>$ligne</span></a></li>\n");
			continue;
		}		
		
		if($num=="caches"){
			$html[]= $tpl->_ENGINE_parse_body("<li>
					<a href=\"squid.caches32.php?uuid=$squid->uuid\"><span style='font-size:{$fontsize}px'>$ligne</span></a></li>\n");
			continue;
		}		
		if($num=="caches-params"){
			$html[]= $tpl->_ENGINE_parse_body("<li>
					<a href=\"squid.caches.php?parameters=yes\">
						<span style='font-size:{$fontsize}px'>$ligne</span></a></li>\n");
			continue;
		}
		
		if($num=="caches-center"){
			$html[]= $tpl->_ENGINE_parse_body("<li><a href=\"squid.caches.center.php\" ><span style='font-size:{$fontsize}px'>$ligne</span></a></li>\n");
			continue;
		}	

		if($num=="cached_items"){
			$html[]= $tpl->_ENGINE_parse_body("<li ><a href=\"squid.cached.itemps.php?hostid=localhost\"><span style='font-size:{$fontsize}px'>$ligne</span></a></li>\n");
			continue;
		}
		
		if($num=="dyn-section"){
			$html[]= $tpl->_ENGINE_parse_body("<li><a href=\"squid.cache.dynamic.rules.php\"><span style='font-size:{$fontsize}px'>$ligne</span></a></li>\n");
			continue;			
		}
						
		$html[]= $tpl->_ENGINE_parse_body("<li>
					<a href=\"$page?$num=yes&t=$t&ID=$ID&tt={$_GET["tt"]}&SourceT={$_GET["SourceT"]}\"><span style='font-size:{$fontsize}px'>$ligne</span></a></li>\n");
	}
	echo build_artica_tabs($html, "main_cache_rules_main_tabs")."<script>LeftDesign('caches-center-white-256-opac20.png');</script>";
	
}
Example #16
0
function rows_table()
{
    $tpl = new templates();
    $MyPage = CurrentPageName();
    $q = new mysql_blackbox();
    $nodeid = $_GET["nodeid"];
    $mountedon = $tpl->_ENGINE_parse_body("{mounted}");
    $search = '%';
    $table = "harddrives";
    $page = 1;
    $ORDER = "ORDER BY path desc";
    $total = 0;
    if ($q->COUNT_ROWS($table) == 0) {
        $data['page'] = $page;
        $data['total'] = $total;
        $data['rows'] = array();
        echo json_encode($data);
        return;
    }
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    if ($_POST["query"] != null) {
        $_POST["query"] = "*" . $_POST["query"] . "*";
        $_POST["query"] = str_replace("**", "*", $_POST["query"]);
        $_POST["query"] = str_replace("**", "*", $_POST["query"]);
        $_POST["query"] = str_replace("*", "%", $_POST["query"]);
        $search = $_POST["query"];
        $searchstring = "AND ((`{$_POST["qtype"]}` LIKE '{$search}' AND nodeid={$nodeid}) OR (`mac` LIKE '{$search}' AND nodeid={$nodeid}))";
        $sql = "SELECT COUNT(*) as TCOUNT FROM `{$table}` WHERE 1 {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql));
        $total = $ligne["TCOUNT"];
    } else {
        $sql = "SELECT COUNT(*) as TCOUNT FROM `{$table}` WHERE nodeid={$nodeid}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql));
        $total = $ligne["TCOUNT"];
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $sql = "SELECT *  FROM `{$table}` WHERE nodeid={$nodeid} {$searchstring} {$ORDER} {$limitSql}";
    writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
    }
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    if (!$q->ok) {
        $data['rows'][] = array('id' => $ligne[time() + 1], 'cell' => array($q->mysql_error, "", "", ""));
        $data['rows'][] = array('id' => $ligne[time()], 'cell' => array($sql, "", "", ""));
        echo json_encode($data);
        return;
    }
    //if(mysql_num_rows($results)==0){$data['rows'][] = array('id' => $ligne[time()],'cell' => array($sql,"", "",""));}
    $usb = new usb();
    while ($ligne = mysql_fetch_assoc($results)) {
        $model = $ligne["ID_MODEL_1"] . " " . $ligne["ID_MODEL_2"] . " " . $ligne["ID_VENDOR"] . " " . $ligne["ID_FS_LABEL"];
        $partitions = unserialize(base64_decode($ligne["PARTITIONS"]));
        $ppp = array();
        if (count($partitions) > 0) {
            while (list($num, $line) = each($partitions)) {
                $MOUNTED = $line["MOUNTED"];
                $free_size = explode(";", $line["free_size"]);
                $bigsize = $free_size[0];
                $used = $free_size[1];
                $free = $free_size[2];
                $pourcent = $free_size[3];
                $perc = pourcentage($pourcent);
                if ($used == null) {
                    $line["USED"] = 0;
                }
                if ($bigsize == null) {
                    $bigsize = 0;
                }
                if ($line["TYPE"] == 5) {
                    $perc = "-";
                }
                if ($line["TYPE"] == 82) {
                    $perc = "-";
                }
                $ppp[] = "<tr style='border:0px'>\n\t\t\t\t\t<td  style='border:0px'><span style='font-size:12px'>" . basename($num) . "&nbsp;{$label}</td>\n\t\t\t\t\t<td valign='middle' style='width:99%'>{$perc}\n\t\t\t\t\t<div style='margin-top:-10px'>{$used}/{$bigsize} <span style='font-size:12px' >{$usb->getPartypename($line["TYPE"])} ({$line["TYPE"]}) {$mountedon} {$MOUNTED}</div>\n\t\t\t\t\t\n\t\t\t\t\t</td>\n\t\t\t\t\t\n\t\t\t\t\t";
            }
        }
        $ligne["size"] = FormatBytes($ligne["size"] * 1000);
        $data['rows'][] = array('id' => $ligne['mac'], 'cell' => array("<img src='img/disk-64.png'>", "<span style='font-size:16px'>{$ligne["path"]}</span>", "<span style='font-size:16px'>{$ligne["size"]}</span>", "<span style='font-size:16px'>{$model}</span>", "<table style='border:0px'>" . @implode("", $ppp) . "</table>"));
    }
    echo json_encode($data);
}