]> git.mxchange.org Git - friendica.git/blob - include/gprobe.php
Rename include/Scrape to include/probe
[friendica.git] / include / gprobe.php
1 <?php
2
3 use Friendica\Core\Config;
4
5 require_once 'include/probe.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
40                 if (!in_array($arr["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) {
41                         update_gcontact($arr);
42                 }
43
44                 $r = q("SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1",
45                         dbesc(normalise_link($url))
46                 );
47         }
48         if (dbm::is_result($r)) {
49                 // Check for accessibility and do a poco discovery
50                 if (poco_last_updated($r[0]['url'], true) AND ($r[0]["network"] == NETWORK_DFRN))
51                         poco_load(0,0,$r[0]['id'], str_replace('/profile/','/poco/',$r[0]['url']));
52         }
53
54         logger("gprobe end for ".normalise_link($url), LOGGER_DEBUG);
55         return;
56 }