]> git.mxchange.org Git - friendica.git/blob - src/Worker/GProbe.php
Revert "Move Objects to Model"
[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\Config;
10 use Friendica\Database\DBM;
11 use Friendica\Model\GlobalContact;
12 use Friendica\Network\Probe;
13 use Friendica\Protocol\PortableContact;
14
15 require_once 'include/datetime.php';
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                         dbesc(normalise_link($url))
27                 );
28
29                 logger("gprobe start for ".normalise_link($url), LOGGER_DEBUG);
30
31                 if (!DBM::is_result($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"], array(NETWORK_FEED, NETWORK_PHANTOM))) {
38                                         logger("DDoS attempt detected for ".$urlparts["host"]." by ".$_SERVER["REMOTE_ADDR"].". server data: ".print_r($_SERVER, true), LOGGER_DEBUG);
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"], array(NETWORK_FEED, NETWORK_PHANTOM))) {
50                                 GlobalContact::update($arr);
51                         }
52
53                         $r = q(
54                                 "SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1",
55                                 dbesc(normalise_link($url))
56                         );
57                 }
58                 if (DBM::is_result($r)) {
59                         // Check for accessibility and do a poco discovery
60                         if (PortableContact::lastUpdated($r[0]['url'], true) && ($r[0]["network"] == NETWORK_DFRN)) {
61                                 PortableContact::loadWorker(0, 0, $r[0]['id'], str_replace('/profile/', '/poco/', $r[0]['url']));
62                         }
63                 }
64
65                 logger("gprobe end for ".normalise_link($url), LOGGER_DEBUG);
66                 return;
67         }
68 }