]> git.mxchange.org Git - friendica.git/blob - src/Worker/GProbe.php
bd209b5782f3e5873ae8b81b6bd7defb5959932c
[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\Database\DBM;
10 use Friendica\Model\GContact;
11 use Friendica\Network\Probe;
12 use Friendica\Protocol\PortableContact;
13
14 require_once 'include/datetime.php';
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                         dbesc(normalise_link($url))
26                 );
27
28                 logger("gprobe start for ".normalise_link($url), LOGGER_DEBUG);
29
30                 if (!DBM::is_result($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"], [NETWORK_FEED, NETWORK_PHANTOM])) {
37                                         logger("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"], [NETWORK_FEED, NETWORK_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                                 dbesc(normalise_link($url))
55                         );
56                 }
57                 if (DBM::is_result($r)) {
58                         // Check for accessibility and do a poco discovery
59                         if (PortableContact::lastUpdated($r[0]['url'], true) && ($r[0]["network"] == NETWORK_DFRN)) {
60                                 PortableContact::loadWorker(0, 0, $r[0]['id'], str_replace('/profile/', '/poco/', $r[0]['url']));
61                         }
62                 }
63
64                 logger("gprobe end for ".normalise_link($url), LOGGER_DEBUG);
65                 return;
66         }
67 }