From ebd0e986ed11f2a34fb58cdd33efbfab192083ad Mon Sep 17 00:00:00 2001
From: Till Brehm <tbrehm@ispconfig.org>
Date: Fri, 22 Apr 2016 05:26:17 -0400
Subject: [PATCH] Added PHP 7 check in installer and updater.
---
server/mods-available/monitor_core_module.inc.php | 527 +++++++++++++++++++++++++++++++++-------------------------
1 files changed, 301 insertions(+), 226 deletions(-)
diff --git a/server/mods-available/monitor_core_module.inc.php b/server/mods-available/monitor_core_module.inc.php
index a0410c8..fc5dd79 100644
--- a/server/mods-available/monitor_core_module.inc.php
+++ b/server/mods-available/monitor_core_module.inc.php
@@ -36,7 +36,11 @@
/* No actions at this time. maybe later... */
var $actions_available = array();
/** The Tools */
+
+
private $_tools = null;
+ //** time the script was called
+ private $_run_time = null;
/**
* This function is called during ispconfig installation to determine
@@ -53,10 +57,13 @@
public function onLoad() {
global $app;
+ //* store the running time
+ $this->_run_time = time();
+
/*
* Do the monitor every n minutes and write the result to the db
*/
- $min = @date('i');
+ $min = @date('i', $this->_run_time);
if (($min % $this->interval) == 0) {
$this->_doMonitor();
}
@@ -84,9 +91,9 @@
$this->_tools = new monitor_tools();
/*
- * Calls the single Monitoring steps
+ * Calls the single Monitoring steps
*/
-// $this->_monitorEmailQuota();
+ $this->_monitorEmailQuota();
$this->_monitorHDQuota();
$this->_monitorServer();
$this->_monitorOsVer();
@@ -112,33 +119,46 @@
$this->_monitorRaid();
$this->_monitorRkHunter();
$this->_monitorFail2ban();
+ $this->_monitorIPTables();
$this->_monitorSysLog();
+ $this->_cleanupAPS();
}
- private function _monitorEmailQuota() {
- global $app;
+ private function _monitorEmailQuota() {
+ global $app, $conf;
- /*
+ /*
+ * This monitoring is expensive, so do it only every 15 minutes
+ */
+ $min = @date('i', $this->_run_time);
+ 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();
+ $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);
+ $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']);
- }
+ /* The new data is written, now we can delete the old one */
+ $this->_delOldRecords($res['type'], $res['server_id']);
+ }
private function _monitorHDQuota() {
global $app;
@@ -151,14 +171,14 @@
/*
* 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'] . "'" .
- ')';
+ $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 */
@@ -176,14 +196,14 @@
/*
* 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'] . "'" .
- ')';
+ $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 */
@@ -201,14 +221,14 @@
/*
* 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'] . "'" .
- ')';
+ $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 */
@@ -226,14 +246,14 @@
/*
* 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'] . "'" .
- ')';
+ $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 */
@@ -251,14 +271,14 @@
/*
* 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'] . "'" .
- ')';
+ $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 */
@@ -275,14 +295,14 @@
/*
* 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'] . "'" .
- ')';
+ $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 */
@@ -299,14 +319,14 @@
/*
* 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'] . "'" .
- ')';
+ $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 */
@@ -324,14 +344,14 @@
/*
* 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'] . "'" .
- ')';
+ $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 */
@@ -349,14 +369,14 @@
/*
* 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'] . "'" .
- ')';
+ $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 */
@@ -374,14 +394,14 @@
/*
* 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'] . "'" .
- ')';
+ $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 */
@@ -392,7 +412,7 @@
/*
* This monitoring is expensive, so do it only once an hour
*/
- $min = @date('i');
+ $min = @date('i', $this->_run_time);
if ($min != 0)
return;
@@ -400,23 +420,31 @@
* OK - here we go...
*/
global $app;
+
+ $app->uses('getconf');
+ $server_config = $app->getconf->get_server_config($conf['server_id'], 'server');
+ if($server_config['monitor_system_updates'] == 'n') return;
/*
* 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) ' .
- 'VALUES (' .
- $res['server_id'] . ', ' .
- "'" . $app->dbmaster->quote($res['type']) . "', " .
- 'UNIX_TIMESTAMP(), ' .
- "'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
- "'" . $res['state'] . "'" .
- ')';
+ $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 */
@@ -434,14 +462,14 @@
/*
* 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'] . "'" .
- ')';
+ $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 */
@@ -459,14 +487,14 @@
/*
* 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'] . "'" .
- ')';
+ $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 */
@@ -477,8 +505,8 @@
/*
* This monitoring is expensive, so do it only once a day
*/
- $min = @date('i');
- $hour = @date('H');
+ $min = @date('i', $this->_run_time);
+ $hour = @date('H', $this->_run_time);
if (!($min == 0 && $hour == 23))
return;
/*
@@ -494,14 +522,14 @@
/*
* 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'] . "'" .
- ')';
+ $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 */
@@ -512,21 +540,47 @@
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) ' .
- 'VALUES (' .
- $res['server_id'] . ', ' .
- "'" . $app->dbmaster->quote($res['type']) . "', " .
- 'UNIX_TIMESTAMP(), ' .
- "'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
- "'" . $res['state'] . "'" .
- ')';
+ $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 */
@@ -544,14 +598,14 @@
/*
* 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'] . "'" .
- ')';
+ $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 */
@@ -569,14 +623,14 @@
/*
* 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'] . "'" .
- ')';
+ $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 */
@@ -594,14 +648,14 @@
/*
* 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'] . "'" .
- ')';
+ $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 */
@@ -619,14 +673,14 @@
/*
* 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'] . "'" .
- ')';
+ $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 */
@@ -644,14 +698,14 @@
/*
* 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'] . "'" .
- ')';
+ $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 */
@@ -666,17 +720,20 @@
*/
$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) ' .
- 'VALUES (' .
- $res['server_id'] . ', ' .
- "'" . $app->dbmaster->quote($res['type']) . "', " .
- 'UNIX_TIMESTAMP(), ' .
- "'" . $app->dbmaster->quote(serialize($res['data'])) . "', " .
- "'" . $res['state'] . "'" .
- ')';
+ $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 */
@@ -694,14 +751,14 @@
/*
* 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'] . "'" .
- ')';
+ $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 */
@@ -719,14 +776,14 @@
/*
* 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'] . "'" .
- ')';
+ $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 */
@@ -744,14 +801,14 @@
/*
* 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'] . "'" .
- ')';
+ $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 */
@@ -767,26 +824,44 @@
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
+ * of ALL servers. This means, if i have a multiserver-environment and a server has a
* time not synced with the others (for example, all server has 11:00 and ONE server has
* 10:45) then the actual data of this server (with the time-stamp 10:45) get lost
* even though it is the NEWEST data of this server. To avoid this i HAVE to include
* the server-id!
*/
$sql = 'DELETE FROM monitor_data ' .
- 'WHERE ' .
- ' type =' . "'" . $app->dbmaster->quote($type) . "' " .
- 'AND ' .
- ' created < ' . $old . ' ' .
- 'AND ' .
- ' server_id = ' . $serverId;
+ 'WHERE ' .
+ ' type =' . "'" . $app->dbmaster->quote($type) . "' " .
+ 'AND ' .
+ ' created < ' . $old . ' ' .
+ 'AND ' .
+ ' server_id = ' . $serverId;
$app->dbmaster->query($sql);
+ }
+
+ private function _cleanupAPS() {
+ global $app, $conf;
+
+ // run this only on the master
+ if($conf['server_id'] == 1) {
+ $records = $app->db->queryAllRecords("SELECT s.instance_id, s.name, s.value FROM `aps_instances_settings` as s INNER JOIN `aps_instances` as i ON (i.id = s.instance_id) WHERE s.value != '' AND s.name IN ('main_database_password', 'admin_password') AND i.instance_status > 1");
+ if(is_array($records)) {
+ foreach($records as $rec) {
+ $tmp = $app->db->queryOneRecord("SELECT id FROM aps_instances_settings WHERE instance_id = '".$app->db->quote($rec['instance_id'])."' AND name = '".$app->db->quote($rec['name'])."'");
+ $app->db->datalogUpdate('aps_instances_settings', "value = ''", 'id', $tmp['id']);
+ }
+ }
+ }
+
}
}
-?>
\ No newline at end of file
+?>
--
Gitblit v1.9.1