Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib/mysql.php
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2019-07-26 09:56:55 +0200
committerErich Eckner <git@eckner.net>2019-07-26 09:56:55 +0200
commit14703b9448125a2901bc6e54823ab5d00df22d8e (patch)
tree1b1f9ecbac868d5cbe8b5a1163a542aae250b8d8 /lib/mysql.php
parentc89681bb369d9ec000efbdd1f68b640418d7ba30 (diff)
lib/mysql.php: actually forbid access for bots
Diffstat (limited to 'lib/mysql.php')
-rw-r--r--lib/mysql.php19
1 files changed, 18 insertions, 1 deletions
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');
+ }
}