]> git.mxchange.org Git - friendica.git/blob - src/Worker/GProbe.php
Add support for legacy $lang config in App->loadConfig
[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 class GProbe {
15         public static function execute($url = '')
16         {
17                 if (empty($url)) {
18                         return;
19                 }
20
21                 $r = q(
22                         "SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1",
23                         dbesc(normalise_link($url))
24                 );
25
26                 logger("gprobe start for ".normalise_link($url), LOGGER_DEBUG);
27
28                 if (!DBM::is_result($r)) {
29                         // Is it a DDoS attempt?
30                         $urlparts = parse_url($url);
31
32                         $result = Cache::get("gprobe:".$urlparts["host"]);
33                         if (!is_null($result)) {
34                                 if (in_array($result["network"], [NETWORK_FEED, NETWORK_PHANTOM])) {
35                                         logger("DDoS attempt detected for ".$urlparts["host"]." by ".$_SERVER["REMOTE_ADDR"].". server data: ".print_r($_SERVER, true), LOGGER_DEBUG);
36                                         return;
37                                 }
38                         }
39
40                         $arr = Probe::uri($url);
41
42                         if (is_null($result)) {
43                                 Cache::set("gprobe:".$urlparts["host"], $arr);
44                         }
45
46                         if (!in_array($arr["network"], [NETWORK_FEED, NETWORK_PHANTOM])) {
47                                 GContact::update($arr);
48                         }
49
50                         $r = q(
51                                 "SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1",
52                                 dbesc(normalise_link($url))
53                         );
54                 }
55                 if (DBM::is_result($r)) {
56                         // Check for accessibility and do a poco discovery
57                         if (PortableContact::lastUpdated($r[0]['url'], true) && ($r[0]["network"] == NETWORK_DFRN)) {
58                                 PortableContact::loadWorker(0, 0, $r[0]['id'], str_replace('/profile/', '/poco/', $r[0]['url']));
59                         }
60                 }
61
62                 logger("gprobe end for ".normalise_link($url), LOGGER_DEBUG);
63                 return;
64         }
65 }