Example #1
0
function vlan_list_list()
{
    $page = CurrentPageName();
    $tpl = new templates();
    $sock = new sockets();
    $q = new mysql();
    $table = "nics_vlan";
    $database = "artica_backup";
    $search = '%';
    $page = 1;
    $sock = new sockets();
    $net = new networking();
    $ip = new IP();
    $interfaces = unserialize(base64_decode($sock->getFrameWork("cmd.php?ifconfig-interfaces=yes")));
    $ERROR_NO_PRIVS = $tpl->javascript_parse_text("{ERROR_NO_PRIVS}");
    $DisableNetworksManagement = $sock->GET_INFO("DisableNetworksManagement");
    if ($DisableNetworksManagement == null) {
        $DisableNetworksManagement = 0;
    }
    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) {
        $search = string_to_sql_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, $database));
        if (!$q->ok) {
            json_error_show($q->mysql_error . "<hr>" . $sql, 1);
        }
        $total = $ligne["tcount"];
    } else {
        $total = $q->COUNT_ROWS($table, $database);
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $sql = "SELECT * FROM `{$table}` WHERE 1 {$searchstring} {$ORDER} {$limitSql}";
    $results = $q->QUERY_SQL($sql, $database);
    if (!$q->ok) {
        json_error_show($q->mysql_error . "<hr>" . $sql, 1);
    }
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    if (mysql_num_rows($results) == 0) {
        json_error_show("No VLAN interface set...", 1);
    }
    while ($ligne = mysql_fetch_assoc($results)) {
        $ip = new IP();
        $cdir = $ligne["cdir"];
        $eth = "{$ligne["nic"]}.{$ligne["ID"]}/{$ligne["nic"]}";
        if ($ligne["cdir"] == null) {
            $ligne["cdir"] = $net->array_TCP[$ligne["nic"]];
            $eth = $ligne["nic"];
        }
        $img = "22-win-nic-off.png";
        if ($interfaces["{$ligne["nic"]}.{$ligne["ID"]}"] != null) {
            $img = "22-win-nic.png";
        }
        if (trim($ligne["org"]) == null) {
            $ligne["org"] = $tpl->_ENGINE_parse_body("<strong style='color:#d32d2d'>{no_organization}</strong>");
        }
        $edit = imgsimple("24-administrative-tools.png", "{apply}", "VLANEdit({$ligne["ID"]})");
        $delete = imgsimple("delete-24.png", "{delete}", "VLANDelete({$ligne["ID"]})");
        if ($DisableNetworksManagement == 1) {
            $edit = "&nbsp;";
            $delete = "&nbsp;";
        }
        $a = $ip->parseCIDR($cdir);
        if ($a[0] == 0) {
            $img = "warning-panneau-24.png";
            $cdir = "<span style='color:#d32d2d'>{$cdir}</span>";
        }
        $data['rows'][] = array('id' => $ligne['ID'], 'cell' => array("<img src='img/{$img}'>", "<div style='font-size:14px;font-weight:normal'>{$ligne["vlanid"]}</div>", "<div style='font-size:14px;font-weight:normal'>{$ligne["org"]}</div>", "<div style='font-size:14px;font-weight:normal'>{$eth}</div>", "<div style='font-size:14px;font-weight:normal'>{$ligne["ipaddr"]}</div>", "<div style='font-size:14px;font-weight:normal'>{$ligne["netmask"]}<div style='font-size:11px'>{$cdir}</div></div>", $edit, $delete));
    }
    echo json_encode($data);
}
function artica_search()
{
    $tpl = new templates();
    $MyPage = CurrentPageName();
    $sock = new sockets();
    $title = $tpl->_ENGINE_parse_body("{event}");
    $q = new mysql();
    $searchstring = string_to_flexquery("search");
    $today = $tpl->_ENGINE_parse_body("{today}");
    $contextQ = "1";
    if ($_GET["context"] != null) {
        $contextQ = " category='{$_GET["context"]}'";
    }
    if ($q->TABLE_EXISTS("Taskev0", "artica_events")) {
        $sql = "SELECT *  FROM `Taskev0` WHERE {$contextQ} AND \n\tdescription LIKE '%" . string_to_sql_search($_GET["search"]) . "%' ORDER BY zDate DESC LIMIT 0,500";
    }
    writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
    $results = $q->QUERY_SQL($sql, "artica_events");
    if (!$q->ok) {
        senderror($q->mysql_error . "<br>{$sql}");
    }
    $tt = date("Y-m-d");
    while ($ligne = mysql_fetch_assoc($results)) {
        $original_date = $ligne["zDate"];
        $ligne["zDate"] = str_replace($tt, $today, $ligne["zDate"]);
        $affiche_text = $ligne["description"];
        $trClass = LineToClass($affiche_text);
        $tooltip = "\n\t\t<div style='font-size:11px'>\n\t\t<strong>{date}:&nbsp;{$original_date}&nbsp;|&nbsp;\n\t\t<strong>{function}:&nbsp;{$ligne["function"]} in line {$ligne["line"]}</strong>&nbsp;|&nbsp;\n\t\t<strong>{process}:&nbsp;{$ligne["filename"]}</strong>";
        $tooltip = $tpl->_ENGINE_parse_body($tooltip);
        $tr[] = "\n\t\t<tr class={$trClass}>\n\t\t<td width=1% nowrap>{$ligne["zDate"]}</td>\n\t\t<td width=1% nowrap>{$ligne["category"]}</td>\n\t\t<td width=1% nowrap>{$affiche_text}{$tooltip}</td>\n\t\t</tr>\n\t\t";
    }
    $contextQ = "1";
    if ($_GET["context"] != null) {
        $contextQ = " context='{$_GET["context"]}'";
    }
    $sql = "SELECT *  FROM `events` WHERE {$contextQ} {$searchstring} ORDER BY zDate DESC LIMIT 0,1000";
    writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
    $results = $q->QUERY_SQL($sql, "artica_events");
    if (!$q->ok) {
        senderror($q->mysql_error . "<br>{$sql}");
    }
    $tt = date("Y-m-d");
    while ($ligne = mysql_fetch_assoc($results)) {
        if ($ligne["process"] == null) {
            $ligne["process"] = "{unknown}";
        }
        $original_date = $ligne["zDate"];
        $ligne["zDate"] = str_replace($tt, $today, $ligne["zDate"]);
        if ($ligne["process"] == null) {
            $ligne["process"] = "{unknown}";
        }
        $ligne["context"] = $tpl->_ENGINE_parse_body($ligne["context"]);
        $ligne["content"] = $tpl->_ENGINE_parse_body($ligne["content"]);
        if (preg_match("#\\[.+?\\]:\\s+\\[.+?\\]:\\s+\\((.+?)\\)\\s+:(.+)#", $ligne["text"], $re)) {
            $ligne["text"] = $re[2];
            $computer = $re[1];
        }
        if (preg_match("#\\[.+?\\]:\\s+\\[.+?\\]:\\s+\\((.+?)\\)\\:\\s+(.+)#", $ligne["text"], $re)) {
            $ligne["text"] = $re[2];
            $computer = $re[1];
        }
        if (preg_match("#\\[.+?\\]:\\s+\\[.+?\\]:\\s+\\((.+?)\\)\\s+(.+)#", $ligne["text"], $re)) {
            $ligne["text"] = $re[2];
            $computer = $re[1];
        }
        if (preg_match("#\\[.+?\\]:\\s+\\[.+?\\]:\\((.+?)\\)\\s+(.+)#", $ligne["text"], $re)) {
            $ligne["text"] = $re[2];
            $computer = $re[1];
        }
        if (preg_match("#\\[.+?\\]:\\s+\\[.+?\\]:\\s+(.+)#", $ligne["text"], $re)) {
            $ligne["text"] = $re[1];
        }
        $affiche_text = $ligne["text"];
        $trClass = LineToClass($affiche_text);
        $tooltip = "\n\t\t<div style='font-size:11px'>\n\t\t\t<strong>{date}:&nbsp;{$original_date}&nbsp;|&nbsp;\n\t\t\t<strong>{computer}:&nbsp;{$computer}</strong>&nbsp;|&nbsp;\n\t\t\t<strong>{process}:&nbsp;{$ligne["process"]}</strong>";
        if (preg_match("#<body>(.+?)</body>#is", $ligne["content"], $re)) {
            $content = strip_tags($re[1]);
        } else {
            $content = strip_tags($ligne["content"]);
        }
        if (strlen($content) > 300) {
            $content = substr($content, 0, 290) . "...";
        }
        $ID = $ligne["ID"];
        $js = "articaShowEvent({$ID});";
        $color = "5C81A7";
        if (preg_match("#(error|fatal|unable)#i", $affiche_text)) {
            $color = "B50113";
        }
        $time = strtotime($original_date . " 00:00:00");
        $tooltip = $tpl->_ENGINE_parse_body($tooltip);
        $OBS = "<div style='font-weight:bold;margin:0px;padding:0px'>{$affiche_text}</div><div>{$content}</div>\n\t\t";
        $ligne["zDate"] = $tpl->_ENGINE_parse_body($ligne["zDate"]);
        $tr[] = "\n\t\t<tr class={$trClass}>\n\t\t<td width=1% nowrap>{$ligne["zDate"]}</td>\n\t\t<td width=1% nowrap>{$ligne["context"]}</td>\n\t\t<td width=1% nowrap>{$OBS}{$tooltip}</td>\n\t\t</tr>\n\t\t";
    }
    echo $tpl->_ENGINE_parse_body("\n\t\n\t\t<table class='table table-bordered'>\n\t\n\t\t\t<thead>\n\t\t\t\t<tr>\n\t\t\t\t\t<th>{date}</th>\n\t\t\t\t\t<th>{context}</th>\n\t\t\t\t\t<th>{event}</th>\n\t\t\t\t</tr>\n\t\t\t</thead>\n\t\t\t <tbody>") . @implode("", $tr) . "</tbody>\n\t\t\t </table>\n<script>\n\t\t\t \t\t\nfunction articaShowEvent(ID){\n\t\t YahooWin6('900','artica.events.php?ShowID='+ID,'{$title}::'+ID);\n\t}\t\t\t\n\n</script>\n";
}
function rules_list(){
	$q=new mysql();
	$tpl=new templates();
	$database="artica_backup";
	$table="pnic_bridges";
	$MyPage=CurrentPageName();
	$t=$_GET["t"];
	
	if(!$q->TABLE_EXISTS("pnic_bridges", "artica_backup")){
		$sql="CREATE TABLE IF NOT EXISTS `pnic_bridges` (
		`ID` INT(10) NOT NULL AUTO_INCREMENT,
		`zMD5` varchar(90) NOT NULL,
		`nic_from` varchar(50) NOT NULL,
		`nic_to` varchar(50) NOT NULL,
		`enabled` smallint(1) NOT NULL DEFAULT 1,
		`DenyDHCP` smallint(1) NOT NULL DEFAULT 1,
		PRIMARY KEY (`ID`),
		UNIQUE KEY (`zMD5`),
		KEY `nic_from` (`nic_from`),
		KEY `nic_to` (`nic_to`),
		KEY `DenyDHCP` (`DenyDHCP`),
		KEY `enabled` (`enabled`)
		) ENGINE=MYISAM;";
		$q->QUERY_SQL($sql,$database);
	}
	
	if(!$q->FIELD_EXISTS("pnic_bridges", "DenyDHCP", "artica_backup")){
		$q->QUERY_SQL("ALTER TABLE pnic_bridges ADD DenyDHCP smallint(1) DEFAULT 1","artica_backup");
		if(!$q->ok){echo "ALTER TABLE DenyDHCP failed\n$q->mysql_error\n";return;}
	}
	
	if(!$q->TABLE_EXISTS("pnic_bridges", "artica_backup")){
		json_error_show("Unable to create table...",1);
	}
	
	$sock=new sockets();
	$net=new networking();
	$ip=new IP();
	$interfaces=unserialize(base64_decode($sock->getFrameWork("cmd.php?ifconfig-interfaces=yes")));
	$ERROR_NO_PRIVS=$tpl->javascript_parse_text("{ERROR_NO_PRIVS}");
	$DisableNetworksManagement=$sock->GET_INFO("DisableNetworksManagement");
	if($DisableNetworksManagement==null){$DisableNetworksManagement=0;}
	
	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){
		$search=string_to_sql_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,$database));
		if(!$q->ok){json_error_show($q->mysql_error."<hr>".$sql,1);}
		$total = $ligne["tcount"];
	
	}else{
	
		$total = $q->COUNT_ROWS($table, $database);
	}
	
	if (isset($_POST['rp'])) {$rp = $_POST['rp'];}
	$pageStart = ($page-1)*$rp;
	$limitSql = "LIMIT $pageStart, $rp";
	
	
	$deny_dhcp_requests=$tpl->_ENGINE_parse_body("<br><span style='font-size:18px'><i>{deny_dhcp_requests}</i></span>");
	$sql="SELECT * FROM `$table` WHERE 1 $searchstring $ORDER $limitSql";
	$results = $q->QUERY_SQL($sql,$database);
	if(!$q->ok){json_error_show($q->mysql_error."<hr>".$sql,1);}
	
	
	$data = array();
	$data['page'] = $page;
	$data['total'] = $total;
	$data['rows'] = array();
	if(mysql_num_rows($results)==0){json_error_show("No rule set...",1);}
	
	
	while ($ligne = mysql_fetch_assoc($results)) {
		$color="black";
		$deny_dhcp_requeststxt=null;
		$arrow="arrow-right-32.png";
		if($ligne["enabled"]==0){$color="#ABABAB";$arrow="arrow-right-32-grey.png";}
		$ip=new IP();
		$nic_from=$ligne["nic_from"];
		$nic_to=$ligne["nic_to"];
		
		
		if($ligne["DenyDHCP"]==1){
			$deny_dhcp_requeststxt=$deny_dhcp_requests;
		}
		
		$nic=new system_nic($nic_from);
		$nic_from_text="<strong style='color:$color'>$nic_from</strong> $nic->IPADDR/$nic->NETMASK $nic->NICNAME";
		
		$nic=new system_nic($nic_to);
		$nic_to_text="<strong style='color:$color'>$nic_to</strong> $nic->IPADDR/$nic->NETMASK $nic->NICNAME";
	
		$delete=imgsimple("delete-32.png",null,"Loadjs('$MyPage?network-bridge-delete-js={$ligne['ID']}&t=$t',true)");
		
		$js="Loadjs('$MyPage?network-bridge-js=yes&ID={$ligne['ID']}&t=$t',true);";
		$href="<a href=\"javascript:blur();\" OnClick=\"javascript:$js\" style='font-size:18px;color:$color;font-weight:normal;text-decoration:underline'>";
	
		$data['rows'][] = array(
				'id' => $ligne['ID'],
				'cell' => array(
						"<div style='font-size:18px;font-weight:bold;color:$color'>{$ligne['ID']}</div>",
						"<div style='font-size:18px;font-weight:normal;color:$color'>$href{$nic_from_text}</a></div>",
						"<div style='font-size:18px;font-weight:normal;color:$color'><img src=\"img/$arrow\"></div>",
						"<div style='font-size:18px;font-weight:normal;color:$color'>$nic_to_text$deny_dhcp_requests</div>",
						$delete
				)
		);
	}
	
	
	echo json_encode($data);	
	
	
}
Example #4
0
function search()
{
    $page = CurrentPageName();
    $tpl = new templates();
    $sock = new sockets();
    $q = new mysql_squid_builder();
    $table = "webstats_backup";
    $search = '%';
    $page = 1;
    $WHERE = 1;
    if (!$q->TABLE_EXISTS($table)) {
        $q->BuildTables();
    }
    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) {
        $search = string_to_sql_search($_POST["query"]);
        $searchstring = "AND (`{$_POST["qtype"]}` LIKE '{$search}')";
        $sql = "SELECT COUNT( * ) AS tcount FROM {$table} WHERE {$WHERE} {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_events"));
        if (!$q->ok) {
            json_error_show($q->mysql_error);
        }
        $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 {$WHERE} {$searchstring} {$ORDER} {$limitSql}";
    writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
    $results = $q->QUERY_SQL($sql, "artica_events");
    if (!$q->ok) {
        json_error_show($q->mysql_error);
    }
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    if (mysql_num_rows($results) == 0) {
        json_error_show("No data...", 1);
    }
    while ($ligne = mysql_fetch_assoc($results)) {
        $subtext = null;
        $ligne["filesize"] = FormatBytes($ligne["filesize"] / 1024);
        if (preg_match("#^dansguardian_events_([0-9]+)#", $ligne["tablename"], $re)) {
            $timestr = $re[1];
            $year = substr($timestr, 0, 4);
            $month = substr($timestr, 4, 2);
            $day = substr($timestr, 6, 2);
            $dateToStr = strtotime("{$year}-{$month}-{$day} 00:00:00");
            $subtext = "{day_events_of} " . date('{l} d {F} Y', $dateToStr);
            $subtext = $tpl->_ENGINE_parse_body($subtext);
            $subtext = "<div style='font-size:11px'><i>{$subtext}</i></div>";
        }
        if (preg_match("#^([0-9]+)_([a-z]+)#", $ligne["tablename"], $re)) {
            $timestr = $re[1];
            $length = strlen($timestr);
            if ($length > 7) {
                $year = substr($timestr, 0, 4);
                $month = substr($timestr, 4, 2);
                $day = substr($timestr, 6, 2);
                $dateToStr = strtotime("{$year}-{$month}-{$day} 00:00:00");
                $subtext = "{$re[2]} " . date('{l} d {F} Y', $dateToStr);
            }
            if ($length == 6) {
                $year = substr($timestr, 0, 4);
                $month = substr($timestr, 4, 2);
                $day = "01";
                $dateToStr = strtotime("{$year}-{$month}-{$day} 00:00:00");
                $subtext = "{month}/{$re[2]} " . date('{F} Y', $dateToStr);
            }
            $subtext = $tpl->_ENGINE_parse_body($subtext);
            $subtext = "<div style='font-size:11px'><i>{$subtext}</i></div>";
        }
        $data['rows'][] = array('id' => $ligne['zDate'], 'cell' => array("<strong style='font-size:13px'>{$ligne["tablename"]}</strong>", "<strong style='font-size:13px'>{$ligne["filesize"]}</strong>", "<strong style='font-size:13px'>{$ligne["filepath"]}{$subtext}</strong>"));
    }
    echo json_encode($data);
}