X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FGServer.php;h=f68851af6826b945cdc25f392a7381a5636c7db8;hb=feb74b4d9aeecbcac2b81cd6f0e0c8cfde1464f3;hp=7e4b055d10900981cde793fad20b5f0f6c038d10;hpb=018858934b0423efb7dd07e660f621f1e8eb75cd;p=friendica.git diff --git a/src/Model/GServer.php b/src/Model/GServer.php index 7e4b055d10..f68851af68 100644 --- a/src/Model/GServer.php +++ b/src/Model/GServer.php @@ -70,6 +70,7 @@ class GServer const DETECT_UNSPECIFIC = [self::DETECT_MANUAL, self::DETECT_HEADER, self::DETECT_BODY, self::DETECT_HOST_META, self::DETECT_CONTACTS, self::DETECT_AP_ACTOR]; // Implementation specific endpoints + // @todo Possibly add Lemmy detection via the endpoint /api/v3/site const DETECT_FRIENDIKA = 10; const DETECT_FRIENDICA = 11; const DETECT_STATUSNET = 12; @@ -115,12 +116,12 @@ class GServer */ public static function getID(string $url, bool $no_check = false): ?int { + $url = self::cleanURL($url); + if (empty($url)) { return null; } - $url = self::cleanURL($url); - $gserver = DBA::selectFirst('gserver', ['id'], ['nurl' => Strings::normaliseLink($url)]); if (DBA::isResult($gserver)) { Logger::debug('Got ID for URL', ['id' => $gserver['id'], 'url' => $url, 'callstack' => System::callstack(20)]); @@ -176,9 +177,13 @@ class GServer public static function reachable(string $profile, string $server = '', string $network = '', bool $force = false): bool { if ($server == '') { - $contact = Contact::getByURL($profile, null, ['baseurl']); + $contact = Contact::getByURL($profile, null, ['baseurl', 'network']); if (!empty($contact['baseurl'])) { $server = $contact['baseurl']; + } elseif ($contact['network'] == Protocol::DIASPORA) { + $parts = parse_url($profile); + unset($parts['path']); + $server = (string)Uri::fromParts($parts); } } @@ -313,21 +318,20 @@ class GServer /** * Remove unwanted content from the given URL * - * @param string $url + * @param string $dirtyUrl * * @return string cleaned URL + * @throws Exception */ - public static function cleanURL(string $url): string + public static function cleanURL(string $dirtyUrl): string { - $url = trim($url, '/'); - $url = str_replace('/index.php', '', $url); - - $urlparts = parse_url($url); - unset($urlparts['user']); - unset($urlparts['pass']); - unset($urlparts['query']); - unset($urlparts['fragment']); - return (string)Uri::fromParts($urlparts); + try { + $url = str_replace('/index.php', '', trim($dirtyUrl, '/')); + return (string)(new Uri($url))->withUserInfo('')->withQuery('')->withFragment(''); + } catch (\Throwable $e) { + Logger::warning('Invalid URL', ['dirtyUrl' => $dirtyUrl, 'url' => $url]); + return ''; + } } /** @@ -1209,7 +1213,7 @@ class GServer if (!empty($data['url'])) { $serverdata['platform'] = strtolower($data['platform']); - $serverdata['version'] = $data['version']; + $serverdata['version'] = $data['version'] ?? 'N/A'; } if (!empty($data['plugins'])) { @@ -1325,7 +1329,7 @@ class GServer private static function validHostMeta(string $url): bool { $xrd_timeout = DI::config()->get('system', 'xrd_timeout'); - $curlResult = DI::httpClient()->get($url . '/.well-known/host-meta', HttpClientAccept::XRD_XML, [HttpClientOptions::TIMEOUT => $xrd_timeout]); + $curlResult = DI::httpClient()->get($url . Probe::HOST_META, HttpClientAccept::XRD_XML, [HttpClientOptions::TIMEOUT => $xrd_timeout]); if (!$curlResult->isSuccess()) { return false; } @@ -2168,7 +2172,7 @@ class GServer foreach ($servers['instances'] as $server) { $url = (is_null($server['https_score']) ? 'http' : 'https') . '://' . $server['name']; self::add($url); - } + } } } }