From 33e2c95c69b405f36caf9013ff9a256e6edf9500 Mon Sep 17 00:00:00 2001 From: tbrehm <t.brehm@ispconfig.org> Date: Mon, 11 Feb 2013 08:15:44 -0500 Subject: [PATCH] - htpasswd_stats file was not readable for apache user. --- server/mods-available/monitor_core_module.inc.php | 230 +++++++++++++++++++++++++++++++++++++------------------- 1 files changed, 151 insertions(+), 79 deletions(-) diff --git a/server/mods-available/monitor_core_module.inc.php b/server/mods-available/monitor_core_module.inc.php index 9244b05..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,18 +163,18 @@ /* * 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']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorServer() { @@ -150,18 +188,18 @@ /* * 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']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorOsVer() { @@ -175,18 +213,18 @@ /* * 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']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorIspcVer() { @@ -200,18 +238,18 @@ /* * 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']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorDiskUsage() { @@ -225,18 +263,18 @@ /* * 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']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorMemUsage() { @@ -249,18 +287,18 @@ /* * 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']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorCpu() { @@ -273,18 +311,18 @@ /* * 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']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorServices() { @@ -298,18 +336,18 @@ /* * 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']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorOpenVzHost() { @@ -323,18 +361,18 @@ /* * 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']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorOpenVzUserBeancounter() { @@ -348,25 +386,25 @@ /* * 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']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorSystemUpdate() { /* * This monitoring is expensive, so do it only once an hour */ - $min = date('i'); + $min = @date('i'); if ($min != 0) return; @@ -379,22 +417,25 @@ * 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']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorMailQueue() { @@ -408,18 +449,18 @@ /* * 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']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorRaid() { @@ -433,26 +474,26 @@ /* * 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']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorRkHunter() { /* * 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; /* @@ -468,43 +509,69 @@ /* * 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']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } 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']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorSysLog() { @@ -518,18 +585,18 @@ /* * 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']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorMailLog() { @@ -543,18 +610,18 @@ /* * 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']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorMailWarnLog() { @@ -568,18 +635,18 @@ /* * 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']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorMailErrLog() { @@ -593,18 +660,18 @@ /* * 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']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorMessagesLog() { @@ -618,18 +685,18 @@ /* * 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']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorISPCCronLog() { @@ -639,22 +706,25 @@ * 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']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorFreshClamLog() { @@ -668,18 +738,18 @@ /* * 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']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorClamAvLog() { @@ -693,18 +763,18 @@ /* * 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']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } private function _monitorIspConfigLog() { @@ -718,18 +788,18 @@ /* * 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']) . "', " . - time() . ', ' . + '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($type, $res['server_id']); + $this->_delOldRecords($res['type'], $res['server_id']); } /** @@ -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