]> git.mxchange.org Git - friendica.git/blob - include/gprobe.php
New process table for a better detection of running workers
[friendica.git] / include / gprobe.php
1 <?php
2
3 require_once("boot.php");
4 require_once('include/Scrape.php');
5 require_once('include/socgraph.php');
6
7 function gprobe_run(&$argv, &$argc){
8         global $a, $db;
9
10         if(is_null($a)) {
11                 $a = new App;
12         }
13
14         if(is_null($db)) {
15             @include(".htconfig.php");
16         require_once("include/dba.php");
17             $db = new dba($db_host, $db_user, $db_pass, $db_data);
18         unset($db_host, $db_user, $db_pass, $db_data);
19         };
20
21         $a->start_process();
22
23         require_once('include/session.php');
24         require_once('include/datetime.php');
25
26         load_config('config');
27         load_config('system');
28
29         $a->set_baseurl(get_config('system','url'));
30
31         load_hooks();
32
33         if($argc != 2)
34                 return;
35
36         $url = hex2bin($argv[1]);
37
38         $r = q("SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1",
39                 dbesc(normalise_link($url))
40         );
41
42         logger("gprobe start for ".normalise_link($url), LOGGER_DEBUG);
43
44         if (!count($r)) {
45
46                 // Is it a DDoS attempt?
47                 $urlparts = parse_url($url);
48
49                 $result = Cache::get("gprobe:".$urlparts["host"]);
50                 if (!is_null($result)) {
51                         $result = unserialize($result);
52                         if (in_array($result["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) {
53                                 logger("DDoS attempt detected for ".$urlparts["host"]." by ".$_SERVER["REMOTE_ADDR"].". server data: ".print_r($_SERVER, true), LOGGER_DEBUG);
54                                 return;
55                         }
56                 }
57
58                 $arr = probe_url($url);
59
60                 if (is_null($result))
61                         Cache::set("gprobe:".$urlparts["host"],serialize($arr));
62
63                 if (!in_array($arr["network"], array(NETWORK_FEED, NETWORK_PHANTOM)))
64                         update_gcontact($arr);
65
66                 $r = q("SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1",
67                         dbesc(normalise_link($url))
68                 );
69         }
70         if(count($r)) {
71                 // Check for accessibility and do a poco discovery
72                 if (poco_last_updated($r[0]['url'], true) AND ($r[0]["network"] == NETWORK_DFRN))
73                         poco_load(0,0,$r[0]['id'], str_replace('/profile/','/poco/',$r[0]['url']));
74         }
75
76         logger("gprobe end for ".normalise_link($url), LOGGER_DEBUG);
77         return;
78 }
79
80 if (array_search(__file__,get_included_files())===0){
81   gprobe_run($_SERVER["argv"],$_SERVER["argc"]);
82   killme();
83 }