From f4038a2160d55a7f519a3b42be1aa96e29e9a908 Mon Sep 17 00:00:00 2001 From: ftimme <ft@falkotimme.com> Date: Wed, 27 Feb 2013 09:01:40 -0500 Subject: [PATCH] - Fixed "FUNCTION databasename.CONCAT does not exist" error for older MySQL versions. --- server/mods-available/monitor_core_module.inc.php | 127 +++++++++++++++++++++++++++++++++--------- 1 files changed, 99 insertions(+), 28 deletions(-) diff --git a/server/mods-available/monitor_core_module.inc.php b/server/mods-available/monitor_core_module.inc.php index 185702a..63a813c 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(); in process + $this->_monitorEmailQuota(); $this->_monitorHDQuota(); $this->_monitorServer(); $this->_monitorOsVer(); @@ -112,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; @@ -126,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']) . "', " . @@ -151,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']) . "', " . @@ -176,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']) . "', " . @@ -201,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']) . "', " . @@ -226,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']) . "', " . @@ -250,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']) . "', " . @@ -274,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']) . "', " . @@ -299,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']) . "', " . @@ -324,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']) . "', " . @@ -349,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']) . "', " . @@ -380,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']) . "', " . @@ -409,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']) . "', " . @@ -434,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']) . "', " . @@ -469,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']) . "', " . @@ -484,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']) . "', " . @@ -519,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']) . "', " . @@ -544,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']) . "', " . @@ -569,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']) . "', " . @@ -594,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']) . "', " . @@ -619,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']) . "', " . @@ -640,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']) . "', " . @@ -669,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']) . "', " . @@ -694,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']) . "', " . @@ -719,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']) . "', " . @@ -742,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 -- Gitblit v1.9.1