/** * This will check and see how many 404 requests there have been recently. * * @return bool */ public static function Check404Pages() { // How long back do I want to check the logs? $time = new DateTime(); $time->modify('-30 seconds'); $ds = Dataset::Init()->table('user_activity')->where(['status = 404', 'ip_addr = ' . REMOTE_IP, 'datetime > ' . $time->format('U')])->count()->execute(); if ($ds->num_rows > 30) { // CHILL THAR F****R! $time->modify('+6 minutes'); $blacklist = new \IpBlacklistModel(); $blacklist->setFromArray(['ip_addr' => REMOTE_IP . '/24', 'expires' => $time->format('U'), 'message' => 'You have requested too many "404" pages recently, please go get some coffee and wait for a short bit. If you are a bot and/or spammer, please bugger off.', 'comment' => '5-minute auto-ban for too many 404 requests in 30 seconds']); $blacklist->save(); \SystemLogModel::LogSecurityEvent('/security/blocked', 'Blocking IP due to too many 404 requests in 30 seconds.'); die($blacklist->get('message')); } }