2012-05-01 08:07:52 +02:00
|
|
|
<?php
|
2017-11-15 15:47:28 +01:00
|
|
|
/**
|
|
|
|
* @file include/gprobe.php
|
|
|
|
*/
|
2017-11-09 17:05:18 +01:00
|
|
|
use Friendica\Core\Cache;
|
2017-04-30 06:29:14 +02:00
|
|
|
use Friendica\Core\Config;
|
2017-11-08 04:57:46 +01:00
|
|
|
use Friendica\Database\DBM;
|
2017-11-15 15:47:28 +01:00
|
|
|
use Friendica\Model\GlobalContact;
|
2017-11-07 03:22:52 +01:00
|
|
|
use Friendica\Network\Probe;
|
2017-11-15 15:47:28 +01:00
|
|
|
use Friendica\Protocol\PortableContact;
|
2017-01-18 22:45:32 +01:00
|
|
|
|
2017-05-07 20:40:23 +02:00
|
|
|
require_once 'include/datetime.php';
|
2012-05-01 08:07:52 +02:00
|
|
|
|
2017-11-15 15:47:28 +01:00
|
|
|
function gprobe_run(&$argv, &$argc)
|
|
|
|
{
|
2017-03-14 16:17:21 +01:00
|
|
|
if ($argc != 2) {
|
2012-05-01 08:07:52 +02:00
|
|
|
return;
|
2017-03-14 16:17:21 +01:00
|
|
|
}
|
2017-07-06 07:48:02 +02:00
|
|
|
$url = $argv[1];
|
2012-05-01 08:07:52 +02:00
|
|
|
|
2017-11-15 15:47:28 +01:00
|
|
|
$r = q(
|
|
|
|
"SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1",
|
2012-05-01 08:07:52 +02:00
|
|
|
dbesc(normalise_link($url))
|
|
|
|
);
|
|
|
|
|
2014-12-08 11:02:03 +01:00
|
|
|
logger("gprobe start for ".normalise_link($url), LOGGER_DEBUG);
|
|
|
|
|
2017-11-08 04:57:46 +01:00
|
|
|
if (!DBM::is_result($r)) {
|
2015-03-28 08:29:01 +01:00
|
|
|
// Is it a DDoS attempt?
|
|
|
|
$urlparts = parse_url($url);
|
|
|
|
|
|
|
|
$result = Cache::get("gprobe:".$urlparts["host"]);
|
|
|
|
if (!is_null($result)) {
|
2015-10-04 00:28:15 +02:00
|
|
|
if (in_array($result["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) {
|
2015-03-28 08:49:24 +01:00
|
|
|
logger("DDoS attempt detected for ".$urlparts["host"]." by ".$_SERVER["REMOTE_ADDR"].". server data: ".print_r($_SERVER, true), LOGGER_DEBUG);
|
2015-03-28 08:29:01 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-07 03:22:52 +01:00
|
|
|
$arr = Probe::uri($url);
|
2015-03-28 08:29:01 +01:00
|
|
|
|
2017-04-04 19:47:45 +02:00
|
|
|
if (is_null($result)) {
|
2016-11-04 16:44:49 +01:00
|
|
|
Cache::set("gprobe:".$urlparts["host"], $arr);
|
2017-04-04 19:47:45 +02:00
|
|
|
}
|
2015-03-28 08:29:01 +01:00
|
|
|
|
2017-04-04 19:47:45 +02:00
|
|
|
if (!in_array($arr["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) {
|
2017-11-15 15:47:28 +01:00
|
|
|
GlobalContact::update($arr);
|
2017-04-04 19:47:45 +02:00
|
|
|
}
|
2016-01-23 22:36:15 +01:00
|
|
|
|
2017-11-15 15:47:28 +01:00
|
|
|
$r = q(
|
|
|
|
"SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1",
|
2012-05-01 10:34:47 +02:00
|
|
|
dbesc(normalise_link($url))
|
2012-05-01 08:07:52 +02:00
|
|
|
);
|
|
|
|
}
|
2017-11-08 04:57:46 +01:00
|
|
|
if (DBM::is_result($r)) {
|
2016-04-23 10:46:16 +02:00
|
|
|
// Check for accessibility and do a poco discovery
|
2017-11-15 16:53:16 +01:00
|
|
|
if (PortableContact::lastUpdated($r[0]['url'], true) && ($r[0]["network"] == NETWORK_DFRN)) {
|
2017-11-15 15:47:28 +01:00
|
|
|
PortableContact::loadWorker(0, 0, $r[0]['id'], str_replace('/profile/', '/poco/', $r[0]['url']));
|
|
|
|
}
|
2016-04-23 10:46:16 +02:00
|
|
|
}
|
2014-12-08 11:02:03 +01:00
|
|
|
|
|
|
|
logger("gprobe end for ".normalise_link($url), LOGGER_DEBUG);
|
2012-05-01 08:07:52 +02:00
|
|
|
return;
|
|
|
|
}
|