From 14703b9448125a2901bc6e54823ab5d00df22d8e Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Fri, 26 Jul 2019 09:56:55 +0200 Subject: lib/mysql.php: actually forbid access for bots --- lib/mysql.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'lib/mysql.php') diff --git a/lib/mysql.php b/lib/mysql.php index 7564a3d..d3b210f 100644 --- a/lib/mysql.php +++ b/lib/mysql.php @@ -100,13 +100,30 @@ function arch_filter_query($table) { } function abort_iff_webspider() { + $is_a_bot = in_array( + $_SERVER['HTTP_USER_AGENT'], + array( + 'Mozilla/5.0 (compatible; AhrefsBot/6.1; +http://ahrefs.com/robot/)', + 'Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)', + "'Mozilla/5.0 (compatible; DuckDuckBot-Https/1.1; https://duckduckgo.com/duckduckbot)'", + 'Mozilla/5.0 (compatible; SeznamBot/3.2; +http://napoveda.seznam.cz/en/seznambot-intro/)', + 'Mozilla/5.0 (Compatible; Supybot 2019.02.23)', + 'Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)', + 'Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.96 Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)', + 'ZoominfoBot (zoominfobot at zoominfo dot com)' + ) + ); if (($fp = fopen(BASE . '/user-agent-log', 'a')) !== false) { flock($fp, LOCK_EX); fwrite($fp, - date('Y-m-d H:i:s') . " " . + date('Y-m-d H:i:s') . " " . ($is_a_bot ? 'bot' : 'human') . " " . $_SERVER['HTTP_USER_AGENT'] . "\n" ); flock($fp, LOCK_UN); fclose($fp); } + if ($is_a_bot) { + include_once BASE . "/lib/http.php"; + throw_http_error(403, 'Forbidden', 'Access forbidden for bots'); + } } -- cgit v1.2.3-70-g09d2