]> git.mxchange.org Git - friendica.git/blob - include/gprobe.php
a6b46afc563d02cbf29550cc9a85d355dfff383a
[friendica.git] / include / gprobe.php
1 <?php
2 /**
3  * @file include/gprobe.php
4  */
5 use Friendica\Core\Cache;
6 use Friendica\Core\Config;
7 use Friendica\Database\DBM;
8 use Friendica\Model\GlobalContact;
9 use Friendica\Network\Probe;
10 use Friendica\Protocol\PortableContact;
11
12 require_once 'include/datetime.php';
13
14 function gprobe_run(&$argv, &$argc)
15 {
16         if ($argc != 2) {
17                 return;
18         }
19         $url = $argv[1];
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"], array(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"], array(NETWORK_FEED, NETWORK_PHANTOM))) {
47                         GlobalContact::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 }