Merge branch '2019.06-rc'
[friendica-addons.git/.git] / blockbot / blockbot.php
1 <?php
2 /**
3  * Name: blockbot
4  * Description: Blocking bots based on detecting bots/crawlers/spiders via the user agent and http_from header.
5  * Version: 0.1
6  * Author: Philipp Holzer <admin@philipp.info>
7  *
8  */
9
10 use Friendica\App;
11 use Friendica\Core\Hook;
12 use Friendica\Core\System;
13 use Jaybizzle\CrawlerDetect\CrawlerDetect;
14
15 require_once __DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
16
17 function blockbot_install() {
18         Hook::register('init_1', __FILE__, 'blockbot_init_1');
19 }
20
21
22 function blockbot_uninstall() {
23         Hook::unregister('init_1', __FILE__, 'blockbot_init_1');
24 }
25
26 function blockbot_init_1(App $a) {
27         $crawlerDetect = new CrawlerDetect();
28
29         if ($crawlerDetect->isCrawler()) {
30                 System::httpExit(403, 'Bots are not allowed');
31         }
32 }