X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=WEB-INF%2Flib%2FttRegistrator.class.php;h=e054fe001c730576ad3f1d867ce6cfdc49692cf9;hb=97bc3daf3d32a73d2b614eecacfe1abc0639a271;hp=b122d015f5a4622108b621ff9fdfccbf44469701;hpb=c5461f26c2b9b04044747c9f78fd710627067c83;p=timetracker.git diff --git a/WEB-INF/lib/ttRegistrator.class.php b/WEB-INF/lib/ttRegistrator.class.php index b122d015..e054fe00 100644 --- a/WEB-INF/lib/ttRegistrator.class.php +++ b/WEB-INF/lib/ttRegistrator.class.php @@ -149,11 +149,12 @@ class ttRegistrator { $name = $mdb2->quote($this->group_name); $currency = $mdb2->quote($this->currency); $lang = $mdb2->quote($this->lang); + $plugins = $mdb2->quote(defined('DEFAULT_PLUGINS') ? DEFAULT_PLUGINS : null); $created = 'now()'; $created_ip = $mdb2->quote($_SERVER['REMOTE_ADDR']); - $sql = "insert into tt_groups (group_key, name, currency, lang, created, created_ip)". - " values($group_key, $name, $currency, $lang, $created, $created_ip)"; + $sql = "insert into tt_groups (group_key, name, currency, lang, plugins, created, created_ip)". + " values($group_key, $name, $currency, $lang, $plugins, $created, $created_ip)"; $affected = $mdb2->exec($sql); if (is_a($affected, 'PEAR_Error')) return false; @@ -214,13 +215,28 @@ class ttRegistrator { return true; } - // registeredRecently determines if we already have a successful recent registration from user IP. - // "recent" means "within the last minute" and is set in a query by the following condition: - // "and created > now() - interval 1 minute". Change if necessary. + // registeredRecently determines if we already have successful recent registration(s) from user IP. + // "recent" means the following: + // - 2 or more registrations during last 10 minutes, or + // - 1 registration during last minute. + // + // This offers some level of protection from bot registrations. function registeredRecently() { $mdb2 = getConnection(); $ip_part = ' created_ip = '.$mdb2->quote($_SERVER['REMOTE_ADDR']); + $sql = 'select count(*) as cnt from tt_groups where '.$ip_part.' and created > now() - interval 10 minute'; + $res = $mdb2->query($sql); + if (is_a($res, 'PEAR_Error')) + return false; + $val = $res->fetchRow(); + if ($val['cnt'] == 0) + return false; // No registrations in last 10 minutes. + if ($val['cnt'] >= 2) + return true; // 2 or more registrations in last 10 mintes. + + // If we are here, there was exactly one registration during last 10 minutes. + // Determine if it occurred within the last minute in a separate query. $sql = 'select created from tt_groups where '.$ip_part.' and created > now() - interval 1 minute'; $res = $mdb2->query($sql); if (is_a($res, 'PEAR_Error'))