admin.php

来自「基于PHP的一套网络管理系统代码,对接口流量等可以进行详细的统计分析,很不错.」· PHP 代码 · 共 159 行

PHP
159
字号
<?php
/*
*/
class CNetwork {
	function CNetwork() {
	}

	function DoEvents(){
		global $base, $_CONF, $_TSM , $_VARS , $_USER , $_BASE;

		$_CONF["forms"]["adminpath"]  .= "level" . ((int) $_USER["user_level"]) . "/";

		if ($_GET["mod"] != "network") {
			return false;
		}
		

		switch ($_GET["sub"]) {

			case "export":
				$_types = $this->db->QFetchRowArray("SELECT * FROM {$this->private->tables[types]}");
				$status = array("0" => "Inactive", "1"=> "Active");
				if (is_array($_types)) {
					foreach ($_types as $key => $val) {
						$types[$val["type_id"]] = $val["type_name"];
					}					
				}

				if ($_GET[device_name])
					$cond[] = 'device_name LIKE \'%' . $_GET[device_name] .'%\'';

				if ($_GET[device_type])
					$cond[] = 'device_type=\'' . $_GET[device_type] .'\'';

				if ($_GET[device_mfg])
					$cond[] = 'device_mfg=\'' . $_GET[device_mfg] .'\'';

				if (is_array($cond))
					$sql_vars['sql_condition'] = 'WHERE ' .  implode(' AND ' , $cond);
				else
					$sql_vars['sql_condition'] = '';

				$devices = $this->db->QFetchRowArray("SELECT * FROM `{$this->private->tables[interfaces]}` {$sql_vars['sql_condition']} ORDER BY device_name ASC ");

				header("Content-Type: text/x-csv");
				header("Content-Disposition: inline; filename=devices.csv");
				header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
				header("Pragma: public");

				echo putcsv(array(
					"Name",
					"Serial Number",
					"Other Number",
					"Location",
					"Ports Used",
					"Firmware Version",
					"Operating System",
					"Device Speed",
					"MFG Name",
					"MFG Phone",
					"MFG Web Site",
					"MFG Other Link",
					"Device Type",
					"Description",
					"Purchase Date",
					"Vendor",
					"Warranty",
					"Network Name",
					"Status",
					"Date placed online",
					"Date taken offline",
					"Other"
				));


				if (is_array($devices)) {
					foreach ($devices as $key => $val) {						
						unset($val["device_id"]);
						$val["device_type"] = $types[$val["device_type"]];
						$val["device_location"] = $types[$val["device_location"]];
						$val["device_mfg"] = $types[$val["device_mfg"]];
						$val["device_vendor"] = $types[$val["device_vendor"]];
						$val["device_network"] = $types[$val["device_network"]];
						$val["device_status"] = $status[$val["device_status"]];
						$val["device_date_online"] = $val["device_date_online"] > 1000 ? date("m/d/Y", $val["device_date_online"]) : "not available";
						$val["device_date_offline"] = $val["device_date_offline"] > 1000 ? date("m/d/Y", $val["device_date_offline"]) : "not available";
						$val["device_purchase"] = $val["device_purchase"] > 1000 ? date("m/d/Y", $val["device_purchase"]) : "not available";
						$val["device_ports"] = str_replace("\n","", str_replace("\r\n","", $val["device_ports"]));
						$val["device_other2"] = str_replace("\n","", str_replace("\r\n","", $val["device_other2"]));
						$val["device_description"] = str_replace("\n","", str_replace("\r\n","", $val["device_description"]));

						echo putcsv($val);
					}					
				}

				die;
								
			break;

			case "type":
			case "interfaces":
			case "notes":
			case "ip":
			case "log":

				if (is_subaction("interfaces","interfacedetails")) {
					switch ($_GET["section"]) {
						case 1:
							$data = new CSQLAdmin("notes", $_CONF["forms"]["admintemplate"],$this->db,$this->private->tables);					
							$extra["details"]["after"] = $data->DoEvents();
						break;
						
						case 2:
							$data = new CSQLAdmin("ip", $_CONF["forms"]["admintemplate"],$this->db,$this->private->tables);					
							$extra["details"]["after"] = $data->DoEvents();
						break;

						case 3:
							$data = new CSQLAdmin("log", $_CONF["forms"]["admintemplate"],$this->db,$this->private->tables);					
							$extra["details"]["after"] = $data->DoEvents();
						break;
							
					}					
				}



				$data = new CSQLAdmin($_GET["sub"], $_CONF["forms"]["admintemplate"],$this->db,$this->private->tables,$extra);
				if (is_subaction("interfaces","interfacedetails") && ($_GET["section"])) {
					$found = false;
					foreach ($data->forms["forms"]["details"]["fields"] as $key => $val) {
						if ($key == "subtitle")
							$found = true;

						//remove details fields for a better view
						if ($found)
							unset($data->forms["forms"]["details"]["fields"][$key]);
					}
					
				}				

				if (is_subaction("interfaces" , "")) {
					$file = $_CONF["forms"]["adminpath"] . "interfaces/search.xml" ;
					$search = new CForm($_CONF["forms"]["admintemplate"],$this->db,$this->private->tables);
					$extra2["after"] = $data->DoEvents();
					return $search->Show($file , array("values"=>$_GET) , $extra2);
				}


				return $data->DoEvents();

			break;
		}
		
	}
}

?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?