Improved block check for redirects

This commit is contained in:
Michael 2023-01-22 12:33:38 +00:00
parent ced77ccbce
commit edf3e9c4b6
2 changed files with 4 additions and 15 deletions

View file

@ -474,14 +474,6 @@ class GServer
return; return;
} }
if (Network::isUrlBlocked($url)) {
Logger::info('Server domain is blocked', ['url' => $url]);
return;
} elseif (Network::isUrlBlocked($nurl)) {
Logger::info('Server domain is blocked', ['nurl' => $nurl]);
return;
}
self::insert(['url' => $url, 'nurl' => $nurl, self::insert(['url' => $url, 'nurl' => $nurl,
'network' => Protocol::PHANTOM, 'created' => DateTimeFormat::utcNow(), 'network' => Protocol::PHANTOM, 'created' => DateTimeFormat::utcNow(),
'failed' => true, 'last_failure' => DateTimeFormat::utcNow()]); 'failed' => true, 'last_failure' => DateTimeFormat::utcNow()]);
@ -568,13 +560,10 @@ class GServer
// If the URL missmatches, then we mark the old entry as failure // If the URL missmatches, then we mark the old entry as failure
if (!Strings::compareLink($url, $original_url)) { if (!Strings::compareLink($url, $original_url)) {
self::setFailureByUrl($original_url); self::setFailureByUrl($original_url);
if (!self::getID($url, true)) { if (!self::getID($url, true) && !Network::isUrlBlocked($url)) {
self::detect($url, $network, $only_nodeinfo); self::detect($url, $network, $only_nodeinfo);
} }
return false; return false;
} elseif (Network::isUrlBlocked($url)) {
Logger::info('Server domain is blocked', ['url' => $url]);
return false;
} }
$valid_url = Network::isUrlValid($url); $valid_url = Network::isUrlValid($url);
@ -592,7 +581,7 @@ class GServer
(((parse_url($url, PHP_URL_HOST) != parse_url($valid_url, PHP_URL_HOST)) || (parse_url($url, PHP_URL_PATH) != parse_url($valid_url, PHP_URL_PATH))) && empty(parse_url($valid_url, PHP_URL_PATH)))) { (((parse_url($url, PHP_URL_HOST) != parse_url($valid_url, PHP_URL_HOST)) || (parse_url($url, PHP_URL_PATH) != parse_url($valid_url, PHP_URL_PATH))) && empty(parse_url($valid_url, PHP_URL_PATH)))) {
Logger::debug('Found redirect. Mark old entry as failure', ['old' => $url, 'new' => $valid_url]); Logger::debug('Found redirect. Mark old entry as failure', ['old' => $url, 'new' => $valid_url]);
self::setFailureByUrl($url); self::setFailureByUrl($url);
if (!self::getID($valid_url, true)) { if (!self::getID($valid_url, true) && !Network::isUrlBlocked($valid_url)) {
self::detect($valid_url, $network, $only_nodeinfo); self::detect($valid_url, $network, $only_nodeinfo);
} }
return false; return false;
@ -606,7 +595,7 @@ class GServer
$valid_url = (string)Uri::fromParts($parts); $valid_url = (string)Uri::fromParts($parts);
self::setFailureByUrl($url); self::setFailureByUrl($url);
if (!self::getID($valid_url, true)) { if (!self::getID($valid_url, true) && !Network::isUrlBlocked($valid_url)) {
self::detect($valid_url, $network, $only_nodeinfo); self::detect($valid_url, $network, $only_nodeinfo);
} }
return false; return false;

View file

@ -63,7 +63,7 @@ class UpdateServerPeers
} }
++$total; ++$total;
if (DBA::exists('gserver', ['nurl' => 'http://' . $peer])) { if (DBA::exists('gserver', ['nurl' => Strings::normaliseLink('http://' . $peer)])) {
// We already know this server // We already know this server
continue; continue;
} }