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