]> git.mxchange.org Git - friendica-addons.git/blob - botdetection/botdetection.php
New Addon Bot detection
[friendica-addons.git] / botdetection / botdetection.php
1 <?php
2 /**
3  * Name: botdetection
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 function botdetection_install() {
16         Hook::register('init_1', 'addon/botdetection/botdetection.php', 'botdetection_init_1');
17 }
18
19
20 function botdetection_uninstall() {
21         Hook::unregister('init_1', 'addon/botdetection/botdetection.php', 'botdetection_init_1');
22 }
23
24 function botdetection_init_1(App $a) {
25         $crawlerDetect = new CrawlerDetect();
26
27         if ($crawlerDetect->isCrawler()) {
28                 System::httpExit(404, 'Bots are not allowed');
29         }
30 }