From 8e38755040c6c2073f92f0ffb087da530d0e7a0a Mon Sep 17 00:00:00 2001
From: ftimme <ft@falkotimme.com>
Date: Mon, 12 Nov 2012 11:49:26 -0500
Subject: [PATCH] - Changed a German translation. - Extended SEO redirect check for subdomains/alias domains.

---
 server/mods-available/monitor_core_module.inc.php |  128 +++++++++++++++++++++++++++++++++---------
 1 files changed, 100 insertions(+), 28 deletions(-)

diff --git a/server/mods-available/monitor_core_module.inc.php b/server/mods-available/monitor_core_module.inc.php
index 70df7fd..63a813c 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 = 'REPLACE 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;
@@ -125,7 +163,7 @@
 		/*
 		 * Insert the data into the database
 		 */
-		$sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' .
+		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
@@ -150,7 +188,7 @@
 		/*
 		 * Insert the data into the database
 		 */
-		$sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' .
+		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
@@ -175,7 +213,7 @@
 		/*
 		 * Insert the data into the database
 		 */
-		$sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' .
+		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
@@ -200,7 +238,7 @@
 		/*
 		 * Insert the data into the database
 		 */
-		$sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' .
+		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
@@ -225,7 +263,7 @@
 		/*
 		 * Insert the data into the database
 		 */
-		$sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' .
+		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
@@ -249,7 +287,7 @@
 		/*
 		 * Insert the data into the database
 		 */
-		$sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' .
+		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
@@ -273,7 +311,7 @@
 		/*
 		 * Insert the data into the database
 		 */
-		$sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' .
+		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
@@ -298,7 +336,7 @@
 		/*
 		 * Insert the data into the database
 		 */
-		$sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' .
+		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
@@ -323,7 +361,7 @@
 		/*
 		 * Insert the data into the database
 		 */
-		$sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' .
+		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
@@ -348,7 +386,7 @@
 		/*
 		 * Insert the data into the database
 		 */
-		$sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' .
+		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
@@ -379,11 +417,14 @@
 		 * 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
 		 */
-		$sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' .
+		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
@@ -408,7 +449,7 @@
 		/*
 		 * Insert the data into the database
 		 */
-		$sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' .
+		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
@@ -433,7 +474,7 @@
 		/*
 		 * Insert the data into the database
 		 */
-		$sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' .
+		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
@@ -468,7 +509,7 @@
 		/*
 		 * Insert the data into the database
 		 */
-		$sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' .
+		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
@@ -483,17 +524,43 @@
 	}
 
 	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 = 'REPLACE 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
 		 */
-		$sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' .
+		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
@@ -518,7 +585,7 @@
 		/*
 		 * Insert the data into the database
 		 */
-		$sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' .
+		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
@@ -543,7 +610,7 @@
 		/*
 		 * Insert the data into the database
 		 */
-		$sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' .
+		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
@@ -568,7 +635,7 @@
 		/*
 		 * Insert the data into the database
 		 */
-		$sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' .
+		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
@@ -593,7 +660,7 @@
 		/*
 		 * Insert the data into the database
 		 */
-		$sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' .
+		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
@@ -618,7 +685,7 @@
 		/*
 		 * Insert the data into the database
 		 */
-		$sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' .
+		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
@@ -639,11 +706,14 @@
 		 * 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
+		if(is_array($res) && isset($res['data'])) $res['data'] = htmlentities($res['data']);
 
 		/*
 		 * Insert the data into the database
 		 */
-		$sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' .
+		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
@@ -668,7 +738,7 @@
 		/*
 		 * Insert the data into the database
 		 */
-		$sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' .
+		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
@@ -693,7 +763,7 @@
 		/*
 		 * Insert the data into the database
 		 */
-		$sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' .
+		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
@@ -718,7 +788,7 @@
 		/*
 		 * Insert the data into the database
 		 */
-		$sql = 'INSERT INTO monitor_data (server_id, type, created, data, state) ' .
+		$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
 				'VALUES (' .
 				$res['server_id'] . ', ' .
 				"'" . $app->dbmaster->quote($res['type']) . "', " .
@@ -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