]> git.mxchange.org Git - friendica.git/blob - GProbe.php
55da28f914eaec004360d5cfe7cf06846508a64b
[friendica.git] / GProbe.php
1 <?php
2 /**
3  * @file src/Worker/GProbe.php
4  */
5
6 namespace Friendica\Worker;
7
8 use Friendica\Core\Cache;
9 use Friendica\Core\Logger;
10 use Friendica\Core\Protocol;
11 use Friendica\Database\DBA;
12 use Friendica\Model\GContact;
13 use Friendica\Network\Probe;
14 use Friendica\Protocol\PortableContact;
15
16 class GProbe {
17         public static function execute($url = '')
18         {
19                 if (empty($url)) {
20                         return;
21                 }
22
23                 $r = q(
24                         "SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1",
25                         DBA::escape(normalise_link($url))
26                 );
27
28                 Logger::log("gprobe start for ".normalise_link($url), Logger::DEBUG);
29
30                 if (!DBA::isResult($r)) {
31                         // Is it a DDoS attempt?
32                         $urlparts = parse_url($url);
33
34                         $result = Cache::get("gprobe:".$urlparts["host"]);
35                         if (!is_null($result)) {
36                                 if (in_array($result["network"], [Protocol::FEED, Protocol::PHANTOM])) {
37                                         Logger::log("DDoS attempt detected for ".$urlparts["host"]." by ".$_SERVER["REMOTE_ADDR"].". server data: ".print_r($_SERVER, true), Logger::DEBUG);
38                                         return;
39                                 }
40                         }
41
42                         $arr = Probe::uri($url);
43
44                         if (is_null($result)) {
45                                 Cache::set("gprobe:".$urlparts["host"], $arr);
46                         }
47
48                         if (!in_array($arr["network"], [Protocol::FEED, Protocol::PHANTOM])) {
49                                 GContact::update($arr);
50                         }
51
52                         $r = q(
53                                 "SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1",
54                                 DBA::escape(normalise_link($url))
55                         );
56                 }
57                 if (DBA::isResult($r)) {
58                         // Check for accessibility and do a poco discovery
59                         if (PortableContact::lastUpdated($r[0]['url'], true) && ($r[0]["network"] == Protocol::DFRN)) {
60                                 PortableContact::loadWorker(0, 0, $r[0]['id'], str_replace('/profile/', '/poco/', $r[0]['url']));
61                         }
62                 }
63
64                 Logger::log("gprobe end for ".normalise_link($url), Logger::DEBUG);
65                 return;
66         }
67 }