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;
15 use Friendica\Util\Strings;
18 public static function execute($url = '')
25 "SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1",
26 DBA::escape(Strings::normaliseLink($url))
29 Logger::log("gprobe start for ".Strings::normaliseLink($url), Logger::DEBUG);
31 if (!DBA::isResult($r)) {
32 // Is it a DDoS attempt?
33 $urlparts = parse_url($url);
35 $result = Cache::get("gprobe:".$urlparts["host"]);
36 if (!is_null($result)) {
37 if (in_array($result["network"], [Protocol::FEED, Protocol::PHANTOM])) {
38 Logger::log("DDoS attempt detected for ".$urlparts["host"]." by ".defaults($_SERVER, "REMOTE_ADDR", '').". server data: ".print_r($_SERVER, true), Logger::DEBUG);
43 $arr = Probe::uri($url);
45 if (is_null($result)) {
46 Cache::set("gprobe:".$urlparts["host"], $arr);
49 if (!in_array($arr["network"], [Protocol::FEED, Protocol::PHANTOM])) {
50 GContact::update($arr);
54 "SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1",
55 DBA::escape(Strings::normaliseLink($url))
58 if (DBA::isResult($r)) {
59 // Check for accessibility and do a poco discovery
60 if (PortableContact::lastUpdated($r[0]['url'], true) && ($r[0]["network"] == Protocol::DFRN)) {
61 PortableContact::loadWorker(0, 0, $r[0]['id'], str_replace('/profile/', '/poco/', $r[0]['url']));
65 Logger::log("gprobe end for ".Strings::normaliseLink($url), Logger::DEBUG);