Skip to content

Commit 5a68dc7

Browse files
committed
Merge remote-tracking branch 'origin/2019.06-rc'
2 parents 1acfd0b + 796ef5d commit 5a68dc7

File tree

2 files changed

+61
-3
lines changed

2 files changed

+61
-3
lines changed

blockbot/blockbot.php

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
*/
99

1010
use Friendica\App;
11+
use Friendica\Core\Config;
1112
use Friendica\Core\Hook;
1213
use Friendica\Core\System;
1314
use Jaybizzle\CrawlerDetect\CrawlerDetect;
15+
use Friendica\Core\Logger;
1416

1517
require_once __DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
1618

@@ -24,9 +26,64 @@ function blockbot_uninstall() {
2426
}
2527

2628
function blockbot_init_1(App $a) {
29+
if (empty($_SERVER['HTTP_USER_AGENT'])) {
30+
return;
31+
}
32+
33+
$logdata = ['agent' => $_SERVER['HTTP_USER_AGENT'], 'uri' => $_SERVER['REQUEST_URI']];
34+
35+
// List of known crawlers.
36+
$agents = ['SemrushBot', 's~feedly-nikon3', 'Qwantify/Bleriot/', 'ltx71', 'Sogou web spider/',
37+
'Diffbot/', 'Twitterbot/', 'YisouSpider', 'evc-batch/', 'LivelapBot/', 'TrendsmapResolver/',
38+
'PaperLiBot/', 'Nuzzel', 'um-LN/', 'Google Favicon', 'Datanyze', 'BLEXBot/', '360Spider',
39+
'adscanner/', 'HeadlessChrome', 'wpif', 'startmebot/', 'Googlebot/', 'Applebot/',
40+
'facebookexternalhit/', 'GoogleImageProxy', 'bingbot/', 'heritrix/', 'ldspider',
41+
'AwarioRssBot/', 'Zabbix', 'TweetmemeBot/', 'dcrawl/', 'PhantomJS/', 'Googlebot-Image/',
42+
'CrowdTanglebot/', 'Mediapartners-Google', 'Baiduspider/', 'datagnionbot',
43+
'MegaIndex.ru/', 'SMUrlExpander', 'Hatena-Favicon/', 'Wappalyzer', 'FlipboardProxy/',
44+
'NetcraftSurveyAgent/', 'Dataprovider.com', 'SMTBot/', 'Nimbostratus-Bot/',
45+
'DuckDuckGo-Favicons-Bot/', 'IndieWebCards/', 'proximic', 'netEstate NE Crawler',
46+
'AhrefsBot/', 'YandexBot/', 'Exabot/', 'Mediumbot-MetaTagFetcher/', 'WhatsApp/',
47+
'TelegramBot', 'SurdotlyBot/', 'BingPreview/', 'SabsimBot/', 'CCBot/', 'WbSrch/',
48+
'DuckDuckBot-Https/', 'HTTP Banner Detection', 'YandexImages/', 'archive.org_bot',
49+
'ArchiveTeam ArchiveBot/', 'yacybot', 'https://developers.google.com/+/web/snippet/',
50+
'Scrapy/', 'github-camo', 'MJ12bot/', 'DotBot/', 'Pinterestbot/', 'Jooblebot/',
51+
'Cliqzbot/', 'YaK/', 'Mediatoolkitbot'];
52+
53+
foreach ($agents as $agent) {
54+
if (stristr($_SERVER['HTTP_USER_AGENT'], $agent)) {
55+
System::httpExit(403, 'Bots are not allowed');
56+
}
57+
}
58+
59+
// This switch here is only meant for developers who want to add more bots to the list above, it is not safe for production.
60+
if (!Config::get('blockbot', 'training')) {
61+
return;
62+
}
63+
2764
$crawlerDetect = new CrawlerDetect();
2865

29-
if ($crawlerDetect->isCrawler()) {
30-
System::httpExit(403, 'Bots are not allowed');
66+
if (!$crawlerDetect->isCrawler()) {
67+
logger::debug('Good user agent detected', $logdata);
68+
return;
69+
}
70+
71+
// List of false positives' strings of known "good" agents.
72+
$agents = ['fediverse.network crawler', 'Active_Pods_CheckBot_3.0', 'Social-Relay/',
73+
'curl', 'zgrab', 'Go-http-client', 'curb', 'github.com', 'reqwest', 'Feedly/',
74+
'Python-urllib/', 'Liferea/', 'aiohttp/', 'WordPress.com Reader', 'hackney/',
75+
'Faraday v', 'okhttp', 'UniversalFeedParser', 'PixelFedBot', 'python-requests',
76+
'WordPress/', 'http.rb/', 'Apache-HttpClient/', 'WordPress.com;', 'Pleroma',
77+
'Dispatch/', 'Ruby', 'Uptimebot/', 'Java/', 'libwww-perl/', 'Mastodon/',
78+
'lua-resty-http/', 'Test Certificate Info'];
79+
80+
foreach ($agents as $agent) {
81+
if (stristr($_SERVER['HTTP_USER_AGENT'], $agent)) {
82+
logger::notice('False positive', $logdata);
83+
return;
84+
}
3185
}
86+
87+
logger::info('Blocked bot', $logdata);
88+
System::httpExit(403, 'Bots are not allowed');
3289
}

twitter/twitter.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ function twitter_post_hook(App $a, array &$b)
575575
return;
576576
}
577577

578-
Logger::log('twitter post invoked');
578+
Logger::notice('twitter post invoked', ['id' => $b['id'], 'guid' => $b['guid']]);
579579

580580
PConfig::load($b['uid'], 'twitter');
581581

@@ -610,6 +610,7 @@ function (array $attributes, array $author_contact, $content, $is_quote_share) {
610610
$b['body'] = twitter_update_mentions($b['body']);
611611

612612
$msgarr = ItemContent::getPlaintextPost($b, $max_char, true, 8);
613+
Logger::info('Got plaintext', $msgarr);
613614
$msg = $msgarr["text"];
614615

615616
if (($msg == "") && isset($msgarr["title"])) {

0 commit comments

Comments
 (0)