From c1fcaed2ee8f05a5030fe4e8e211ca4eae7a9489 Mon Sep 17 00:00:00 2001
From: ftimme <ft@falkotimme.com>
Date: Tue, 11 Jun 2013 11:44:57 -0400
Subject: [PATCH] - Fixed FS#2921 - RBL list field in server config can not be empty.
---
server/mods-available/monitor_core_module.inc.php | 107 ++++++++++++++++++++++++++++++++++++++---------------
1 files changed, 77 insertions(+), 30 deletions(-)
diff --git a/server/mods-available/monitor_core_module.inc.php b/server/mods-available/monitor_core_module.inc.php
index a0410c8..917e089 100644
--- a/server/mods-available/monitor_core_module.inc.php
+++ b/server/mods-available/monitor_core_module.inc.php
@@ -86,7 +86,7 @@
/*
* Calls the single Monitoring steps
*/
-// $this->_monitorEmailQuota();
+ $this->_monitorEmailQuota();
$this->_monitorHDQuota();
$this->_monitorServer();
$this->_monitorOsVer();
@@ -112,13 +112,25 @@
$this->_monitorRaid();
$this->_monitorRkHunter();
$this->_monitorFail2ban();
+ $this->_monitorIPTables();
$this->_monitorSysLog();
}
private function _monitorEmailQuota() {
- global $app;
+ 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();
@@ -126,7 +138,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']) . "', " .
@@ -151,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']) . "', " .
@@ -176,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']) . "', " .
@@ -201,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']) . "', " .
@@ -226,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']) . "', " .
@@ -251,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']) . "', " .
@@ -275,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']) . "', " .
@@ -299,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']) . "', " .
@@ -324,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']) . "', " .
@@ -349,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']) . "', " .
@@ -374,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']) . "', " .
@@ -405,11 +417,15 @@
* 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']);
+ $res['data']['output'] = htmlentities($res['data']['output'],ENT_QUOTES,'UTF-8');
/*
* 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']) . "', " .
@@ -434,7 +450,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']) . "', " .
@@ -459,7 +475,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']) . "', " .
@@ -494,7 +510,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']) . "', " .
@@ -509,17 +525,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']) . "', " .
@@ -544,7 +586,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']) . "', " .
@@ -569,7 +611,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']) . "', " .
@@ -594,7 +636,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']) . "', " .
@@ -619,7 +661,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']) . "', " .
@@ -644,7 +686,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']) . "', " .
@@ -665,11 +707,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']) . "', " .
@@ -694,7 +739,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']) . "', " .
@@ -719,7 +764,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']) . "', " .
@@ -744,7 +789,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']) . "', " .
@@ -767,8 +812,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
--
Gitblit v1.9.1