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);
}
Beispiel #2
0
function status_list()
{
    //ini_set('html_errors',0);ini_set('display_errors', 1);ini_set('error_reporting', E_ALL);ini_set('error_prepend_string','');ini_set('error_append_string','');
    $tpl = new templates();
    $MyPage = CurrentPageName();
    $q = new mysql_blackbox();
    $search = '%';
    $table = "nodesstatus";
    $page = 1;
    $ORDER = "ORDER BY category ASC";
    $FORCE_FILTER = "nodeid={$_GET["nodeid"]}";
    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"] = str_replace("*", "%", $_POST["query"]);
        $search = $_POST["query"];
        $searchstring = "AND (`{$_POST["qtype"]}` LIKE '{$search}')";
        $sql = "SELECT COUNT(*) as TCOUNT FROM `{$table}` WHERE {$FORCE_FILTER} {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, $database));
        $total = $ligne["TCOUNT"];
    } else {
        $sql = "SELECT COUNT(*) as TCOUNT FROM `{$table}` WHERE {$FORCE_FILTER}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, $database));
        $total = $ligne["TCOUNT"];
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    if ($OnlyEnabled) {
        $limitSql = null;
    }
    $sql = "SELECT *  FROM `{$table}` WHERE {$FORCE_FILTER} {$ORDER} {$limitSql}";
    writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
    $results = $q->QUERY_SQL($sql);
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    if (mysql_num_rows($results) == 0) {
        $data['rows'][] = array('id' => $ligne[time()], 'cell' => array($sql, "", "", ""));
    }
    while ($ligne = mysql_fetch_assoc($results)) {
        $color = "black";
        $service = $tpl->_ENGINE_parse_body("{{$ligne["service_name"]}}");
        $master_memory = FormatBytes($ligne["master_memory"]);
        $master_cached_memory = FormatBytes($ligne["master_cached_memory"]);
        $master_version = $ligne["master_version"];
        $master_pid = $ligne["master_pid"];
        $img = "img/ok24-grey.png";
        if ($master_pid > 0) {
            $img = "img/ok24.png";
        } else {
            $img = "img/danger24.png";
        }
        $data['rows'][] = array('id' => $ligne['ID'], 'cell' => array("<span style='font-size:14px;color:{$color}'>{$service}</span>", "<span style='font-size:14px;color:{$color}'>{$master_memory}</span>", "<span style='font-size:14px;color:{$color}'>{$master_cached_memory}</a></span>", "<span style='font-size:14px;color:{$color}'>{$master_version}</span>", "<img src='{$img}'>", "<span style='font-size:14px;color:{$color}'>{$master_pid}</span>", $delete));
    }
    echo json_encode($data);
}
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);
}
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);
}
Beispiel #6
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 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;}	
	
}	
Beispiel #8
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>";
    }
}
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);
}
Beispiel #10
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);
}
Beispiel #11
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);
}
Beispiel #12
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);
}