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