From 78e604444fe0314942edb2d88194f76e67588725 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 3 Nov 2017 13:30:13 +0100 Subject: [syslog] api: Relax spam protection --- modules-available/syslog/api.inc.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'modules-available/syslog') diff --git a/modules-available/syslog/api.inc.php b/modules-available/syslog/api.inc.php index 156bc35c..18c42c31 100644 --- a/modules-available/syslog/api.inc.php +++ b/modules-available/syslog/api.inc.php @@ -26,8 +26,10 @@ $longdesc = Request::post('longdesc', '', 'string'); if ($type{0} !== '.' && $type{0} !== '~') { // Spam from IP - $row = Database::queryFirst('SELECT Count(*) AS cnt FROM clientlog WHERE clientip = :client AND dateline + 3600 > UNIX_TIMESTAMP()', array(':client' => $ip)); - if ($row !== false && $row['cnt'] > 150) exit(0); + $row = Database::queryFirst('SELECT Count(*) AS cnt FROM clientlog WHERE clientip = :client AND dateline + 1800 > UNIX_TIMESTAMP()', array(':client' => $ip)); + if ($row !== false && $row['cnt'] > 250) { + exit(0); + } Database::exec('INSERT INTO clientlog (dateline, logtypeid, clientip, machineuuid, description, extra) VALUES (UNIX_TIMESTAMP(), :type, :client, :uuid, :description, :longdesc)', array( 'type' => $type, -- cgit v1.2.3-55-g7522 From fb60fb0cd595a20fa3d09a854abeffb33b8b45dc Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 3 Nov 2017 17:56:06 +0100 Subject: [syslog] Tweak machineuuid index in installer --- modules-available/syslog/install.inc.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'modules-available/syslog') diff --git a/modules-available/syslog/install.inc.php b/modules-available/syslog/install.inc.php index 539f2449..406a6cc6 100644 --- a/modules-available/syslog/install.inc.php +++ b/modules-available/syslog/install.inc.php @@ -2,7 +2,7 @@ $res = array(); -$res[] = tableCreate('clientlog', " +$res[] = $tc = tableCreate('clientlog', " `logid` int(10) unsigned NOT NULL AUTO_INCREMENT, `dateline` int(10) unsigned NOT NULL, `logtypeid` varchar(30) NOT NULL, @@ -14,7 +14,7 @@ $res[] = tableCreate('clientlog', " KEY `dateline` (`dateline`), KEY `logtypeid` (`logtypeid`,`dateline`), KEY `clientip` (`clientip`,`dateline`), - KEY `machineuuid` (`machineuuid`,`dateline`) + KEY `machineuuid` (`machineuuid`,`logid`) "); // Update path @@ -29,6 +29,12 @@ if (!tableHasColumn('clientlog', 'machineuuid')) { $res[] = UPDATE_DONE; } +// 2017-11-03: Create proper index for query in statistics module +if ($tc !== UPDATE_DONE) { + Database::exec("ALTER TABLE `openslx`.`clientlog` DROP INDEX `machineuuid` , + ADD INDEX `machineuuid` ( `machineuuid` , `logid` )"); +} + // Create response for browser if (in_array(UPDATE_DONE, $res)) { -- cgit v1.2.3-55-g7522 From 9f7e2c4c794495f2a32410fd373cc313e0b0d4cf Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 15 Nov 2017 15:16:51 +0100 Subject: [statistics&syslog] Fix possible cron delete query overflow --- modules-available/statistics/hooks/cron.inc.php | 17 ++++++++++++++--- modules-available/syslog/hooks/cron.inc.php | 5 ++++- 2 files changed, 18 insertions(+), 4 deletions(-) (limited to 'modules-available/syslog') diff --git a/modules-available/statistics/hooks/cron.inc.php b/modules-available/statistics/hooks/cron.inc.php index 94c65248..575ab6ba 100644 --- a/modules-available/statistics/hooks/cron.inc.php +++ b/modules-available/statistics/hooks/cron.inc.php @@ -1,8 +1,5 @@ 86400 * 190"); -Database::exec("DELETE FROM machine WHERE (UNIX_TIMESTAMP() - lastseen) > 86400 * 365"); - function logstats() { $NOW = time(); $cutoff = $NOW - 86400 * 30; @@ -15,4 +12,18 @@ function logstats() { 'vals' => $known['val'] . '#' . $on['val'] . '#' . $used['val'], )); } + logstats(); + +if (mt_rand(1, 10) === 1) { + Database::exec("DELETE FROM statistic WHERE (UNIX_TIMESTAMP() - 86400 * 190) > dateline"); + if (mt_rand(1, 100) === 1) { + Database::exec("OPTIMIZE TABLE statistic"); + } +} +if (mt_rand(1, 10) === 1) { + Database::exec("DELETE FROM machine WHERE (UNIX_TIMESTAMP() - 86400 * 365) > lastseen"); + if (mt_rand(1, 100) === 1) { + Database::exec("OPTIMIZE TABLE machine"); + } +} diff --git a/modules-available/syslog/hooks/cron.inc.php b/modules-available/syslog/hooks/cron.inc.php index c796675f..bae882a9 100644 --- a/modules-available/syslog/hooks/cron.inc.php +++ b/modules-available/syslog/hooks/cron.inc.php @@ -1,5 +1,8 @@ 86400 * 190"); + Database::exec("DELETE FROM clientlog WHERE (UNIX_TIMESTAMP() - 86400 * 190) > dateline"); + if (mt_rand(1, 100) === 1) { + Database::exec("OPTIMIZE TABLE clientlog"); + } } \ No newline at end of file -- cgit v1.2.3-55-g7522