3 * @file src/Worker/GProbe.php
6 namespace Friendica\Worker;
8 use Friendica\Core\Cache;
9 use Friendica\Core\Logger;
10 use Friendica\Core\Protocol;
11 use Friendica\Database\DBA;
12 use Friendica\Model\GContact;
13 use Friendica\Network\Probe;
14 use Friendica\Protocol\PortableContact;
17 public static function execute($url = '')
24 "SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1",
25 DBA::escape(normalise_link($url))
28 Logger::log("gprobe start for ".normalise_link($url), Logger::DEBUG);
30 if (!DBA::isResult($r)) {
31 // Is it a DDoS attempt?
32 $urlparts = parse_url($url);
34 $result = Cache::get("gprobe:".$urlparts["host"]);
35 if (!is_null($result)) {
36 if (in_array($result["network"], [Protocol::FEED, Protocol::PHANTOM])) {
37 Logger::log("DDoS attempt detected for ".$urlparts["host"]." by ".$_SERVER["REMOTE_ADDR"].". server data: ".print_r($_SERVER, true), Logger::DEBUG);
42 $arr = Probe::uri($url);
44 if (is_null($result)) {
45 Cache::set("gprobe:".$urlparts["host"], $arr);
48 if (!in_array($arr["network"], [Protocol::FEED, Protocol::PHANTOM])) {
49 GContact::update($arr);
53 "SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1",
54 DBA::escape(normalise_link($url))
57 if (DBA::isResult($r)) {
58 // Check for accessibility and do a poco discovery
59 if (PortableContact::lastUpdated($r[0]['url'], true) && ($r[0]["network"] == Protocol::DFRN)) {
60 PortableContact::loadWorker(0, 0, $r[0]['id'], str_replace('/profile/', '/poco/', $r[0]['url']));
64 Logger::log("gprobe end for ".normalise_link($url), Logger::DEBUG);