From b5715fb4a82d6494e6fba5ffcc1b0af3c9d2421c Mon Sep 17 00:00:00 2001
From: cfoe <cfoe@ispconfig3>
Date: Sat, 07 Jul 2012 13:12:41 -0400
Subject: [PATCH] removed hardcoded width for list search_limit select-element -> css defined

---
 server/mods-available/monitor_core_module.inc.php |  134 ++++++++++++++++++++++++++++++++++----------
 1 files changed, 103 insertions(+), 31 deletions(-)

diff --git a/server/mods-available/monitor_core_module.inc.php b/server/mods-available/monitor_core_module.inc.php
index 584d6d6..2bc95d8 100644
--- a/server/mods-available/monitor_core_module.inc.php
+++ b/server/mods-available/monitor_core_module.inc.php
@@ -86,6 +86,7 @@
 		/*
 		 * Calls the single Monitoring steps 
 		 */
+		$this->_monitorEmailQuota();
 		$this->_monitorHDQuota();
 		$this->_monitorServer();
 		$this->_monitorOsVer();
@@ -111,8 +112,45 @@
 		$this->_monitorRaid();
 		$this->_monitorRkHunter();
 		$this->_monitorFail2ban();
+		$this->_monitorIPTables();
 		$this->_monitorSysLog();
 	}
+
+    private function _monitorEmailQuota() {
+        global $app, $conf;
+
+        /*
+		 *  This monitoring is expensive, so do it only every 15 minutes
+		 */
+		$min = @date('i');
+		if ($min % 15 != 0) return;
+		
+		$app->uses('getconf');
+		$mail_config = $app->getconf->get_server_config($conf['server_id'], 'mail');
+		if($mail_config['mailbox_quota_stats'] == 'n') return;
+		
+		
+		/*
+         * First we get the Monitoring-data from the tools
+         */
+        $res = $this->_tools->monitorEmailQuota();
+
+        /*
+         * Insert the data into the database
+         */
+        $sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' .
+                'VALUES (' .
+                $res['server_id'] . ', ' .
+                "'" . $app->dbmaster->quote($res['type']) . "', " .
+                'UNIX_TIMESTAMP(), ' .
+                "'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
+                "'" . $res['state'] . "'" .
+                ')';
+        $app->dbmaster->query($sql);
+
+        /* The new data is written, now we can delete the old one */
+        $this->_delOldRecords($res['type'], $res['server_id']);
+    }
 
 	private function _monitorHDQuota() {
 		global $app;
@@ -129,7 +167,7 @@
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
-				time() . ', ' .
+				'UNIX_TIMESTAMP(), ' .
 				"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
 				"'" . $res['state'] . "'" .
 				')';
@@ -154,7 +192,7 @@
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
-				time() . ', ' .
+				'UNIX_TIMESTAMP(), ' .
 				"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
 				"'" . $res['state'] . "'" .
 				')';
@@ -179,7 +217,7 @@
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
-				time() . ', ' .
+				'UNIX_TIMESTAMP(), ' .
 				"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
 				"'" . $res['state'] . "'" .
 				')';
@@ -204,7 +242,7 @@
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
-				time() . ', ' .
+				'UNIX_TIMESTAMP(), ' .
 				"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
 				"'" . $res['state'] . "'" .
 				')';
@@ -229,7 +267,7 @@
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
-				time() . ', ' .
+				'UNIX_TIMESTAMP(), ' .
 				"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
 				"'" . $res['state'] . "'" .
 				')';
@@ -253,7 +291,7 @@
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
-				time() . ', ' .
+				'UNIX_TIMESTAMP(), ' .
 				"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
 				"'" . $res['state'] . "'" .
 				')';
@@ -277,7 +315,7 @@
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
-				time() . ', ' .
+				'UNIX_TIMESTAMP(), ' .
 				"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
 				"'" . $res['state'] . "'" .
 				')';
@@ -302,7 +340,7 @@
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
-				time() . ', ' .
+				'UNIX_TIMESTAMP(), ' .
 				"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
 				"'" . $res['state'] . "'" .
 				')';
@@ -327,7 +365,7 @@
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
-				time() . ', ' .
+				'UNIX_TIMESTAMP(), ' .
 				"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
 				"'" . $res['state'] . "'" .
 				')';
@@ -352,7 +390,7 @@
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
-				time() . ', ' .
+				'UNIX_TIMESTAMP(), ' .
 				"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
 				"'" . $res['state'] . "'" .
 				')';
@@ -366,7 +404,7 @@
 		/*
 		 *  This monitoring is expensive, so do it only once an hour
 		 */
-		$min = date('i');
+		$min = @date('i');
 		if ($min != 0)
 			return;
 
@@ -379,6 +417,9 @@
 		 * First we get the Monitoring-data from the tools
 		 */
 		$res = $this->_tools->monitorSystemUpdate();
+		
+		//* Ensure that output is encoded so that it does not break the serialize
+		$res['data']['output'] = htmlentities($res['data']['output']);
 
 		/*
 		 * Insert the data into the database
@@ -387,7 +428,7 @@
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
-				time() . ', ' .
+				'UNIX_TIMESTAMP(), ' .
 				"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
 				"'" . $res['state'] . "'" .
 				')';
@@ -412,7 +453,7 @@
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
-				time() . ', ' .
+				'UNIX_TIMESTAMP(), ' .
 				"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
 				"'" . $res['state'] . "'" .
 				')';
@@ -437,7 +478,7 @@
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
-				time() . ', ' .
+				'UNIX_TIMESTAMP(), ' .
 				"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
 				"'" . $res['state'] . "'" .
 				')';
@@ -451,8 +492,8 @@
 		/*
 		 *  This monitoring is expensive, so do it only once a day
 		 */
-		$min = date('i');
-		$hour = date('H');
+		$min = @date('i');
+		$hour = @date('H');
 		if (!($min == 0 && $hour == 23))
 			return;
 		/*
@@ -472,7 +513,7 @@
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
-				time() . ', ' .
+				'UNIX_TIMESTAMP(), ' .
 				"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
 				"'" . $res['state'] . "'" .
 				')';
@@ -483,12 +524,38 @@
 	}
 
 	private function _monitorFail2ban() {
+        global $app;
+
+        /*
+         * First we get the Monitoring-data from the tools
+         */
+        $res = $this->_tools->monitorFail2ban();
+
+        /*
+         * Insert the data into the database
+         */
+        $sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' .
+                'VALUES (' .
+                $res['server_id'] . ', ' .
+                "'" . $app->dbmaster->quote($res['type']) . "', " .
+                'UNIX_TIMESTAMP(), ' .
+                "'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
+                "'" . $res['state'] . "'" .
+                ')';
+        $app->dbmaster->query($sql);
+
+        /* The new data is written, now we can delete the old one */
+        $this->_delOldRecords($res['type'], $res['server_id']);
+    }
+
+
+	private function _monitorIPTables() {
 		global $app;
 
 		/*
 		 * First we get the Monitoring-data from the tools
 		 */
-		$res = $this->_tools->monitorFail2ban();
+		$res = $this->_tools->monitorIPTables();
 
 		/*
 		 * Insert the data into the database
@@ -497,7 +564,7 @@
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
-				time() . ', ' .
+				'UNIX_TIMESTAMP(), ' .
 				"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
 				"'" . $res['state'] . "'" .
 				')';
@@ -522,7 +589,7 @@
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
-				time() . ', ' .
+				'UNIX_TIMESTAMP(), ' .
 				"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
 				"'" . $res['state'] . "'" .
 				')';
@@ -547,7 +614,7 @@
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
-				time() . ', ' .
+				'UNIX_TIMESTAMP(), ' .
 				"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
 				"'" . $res['state'] . "'" .
 				')';
@@ -572,7 +639,7 @@
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
-				time() . ', ' .
+				'UNIX_TIMESTAMP(), ' .
 				"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
 				"'" . $res['state'] . "'" .
 				')';
@@ -597,7 +664,7 @@
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
-				time() . ', ' .
+				'UNIX_TIMESTAMP(), ' .
 				"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
 				"'" . $res['state'] . "'" .
 				')';
@@ -622,7 +689,7 @@
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
-				time() . ', ' .
+				'UNIX_TIMESTAMP(), ' .
 				"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
 				"'" . $res['state'] . "'" .
 				')';
@@ -639,6 +706,9 @@
 		 * First we get the Monitoring-data from the tools
 		 */
 		$res = $this->_tools->monitorISPCCronLog();
+		
+		//* Ensure that output is encoded so that it does not break the serialize
+		$res['data']['output'] = htmlentities($res['data']['output']);
 
 		/*
 		 * Insert the data into the database
@@ -647,7 +717,7 @@
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
-				time() . ', ' .
+				'UNIX_TIMESTAMP(), ' .
 				"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
 				"'" . $res['state'] . "'" .
 				')';
@@ -672,7 +742,7 @@
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
-				time() . ', ' .
+				'UNIX_TIMESTAMP(), ' .
 				"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
 				"'" . $res['state'] . "'" .
 				')';
@@ -697,7 +767,7 @@
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
-				time() . ', ' .
+				'UNIX_TIMESTAMP(), ' .
 				"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
 				"'" . $res['state'] . "'" .
 				')';
@@ -722,7 +792,7 @@
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
-				time() . ', ' .
+				'UNIX_TIMESTAMP(), ' .
 				"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
 				"'" . $res['state'] . "'" .
 				')';
@@ -741,8 +811,10 @@
 	private function _delOldRecords($type, $serverId) {
 		global $app;
 
-		$now = time();
-		$old = $now - (4 * 60); // 4 minutes
+		// $now = time();
+		// $old = $now - (4 * 60); // 4 minutes
+		$old = 'UNIX_TIMESTAMP() - 240';
+		
 		/*
 		 * ATTENTION if i do NOT pay attention of the server id, i delete all data (of the type)
 		 * of ALL servers. This means, if i have a multiserver-environment and a server has a 
@@ -763,4 +835,4 @@
 
 }
 
-?>
+?>
\ No newline at end of file

--
Gitblit v1.9.1