]> git.mxchange.org Git - friendica.git/blob - include/gprobe.php
Issue-#3873
[friendica.git] / include / gprobe.php
1 <?php
2
3 use Friendica\Core\Config;
4 use Friendica\Network\Probe;
5
6 require_once 'include/probe.php';
7 require_once 'include/socgraph.php';
8 require_once 'include/datetime.php';
9
10 function gprobe_run(&$argv, &$argc){
11         if ($argc != 2) {
12                 return;
13         }
14         $url = $argv[1];
15
16         $r = q("SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1",
17                 dbesc(normalise_link($url))
18         );
19
20         logger("gprobe start for ".normalise_link($url), LOGGER_DEBUG);
21
22         if (!dbm::is_result($r)) {
23
24                 // Is it a DDoS attempt?
25                 $urlparts = parse_url($url);
26
27                 $result = Cache::get("gprobe:".$urlparts["host"]);
28                 if (!is_null($result)) {
29                         if (in_array($result["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) {
30                                 logger("DDoS attempt detected for ".$urlparts["host"]." by ".$_SERVER["REMOTE_ADDR"].". server data: ".print_r($_SERVER, true), LOGGER_DEBUG);
31                                 return;
32                         }
33                 }
34
35                 $arr = Probe::uri($url);
36
37                 if (is_null($result)) {
38                         Cache::set("gprobe:".$urlparts["host"], $arr);
39                 }
40
41                 if (!in_array($arr["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) {
42                         update_gcontact($arr);
43                 }
44
45                 $r = q("SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1",
46                         dbesc(normalise_link($url))
47                 );
48         }
49         if (dbm::is_result($r)) {
50                 // Check for accessibility and do a poco discovery
51                 if (poco_last_updated($r[0]['url'], true) && ($r[0]["network"] == NETWORK_DFRN))
52                         poco_load(0,0,$r[0]['id'], str_replace('/profile/','/poco/',$r[0]['url']));
53         }
54
55         logger("gprobe end for ".normalise_link($url), LOGGER_DEBUG);
56         return;
57 }