From 1564447b8cda1974fef73a6eed0e49db0801f6b1 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 5 Feb 2022 11:25:06 +0000 Subject: [PATCH 1/2] Detect pump.io servers --- src/Model/GServer.php | 57 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/src/Model/GServer.php b/src/Model/GServer.php index bf6672962..b9efae804 100644 --- a/src/Model/GServer.php +++ b/src/Model/GServer.php @@ -67,6 +67,7 @@ class GServer const DETECT_MASTODON_API = 16; const DETECT_STATUS_PHP = 17; // Nextcloud const DETECT_V1_CONFIG = 18; + const DETECT_PUMPIO = 19; // Standardized endpoints const DETECT_STATISTICS_JSON = 100; @@ -468,6 +469,10 @@ class GServer $serverdata = self::detectGNUSocial($url, $serverdata); } + if (empty($serverdata['network'])) { + $serverdata = self::detectPumpIO($url, $serverdata); + } + $serverdata = array_merge($nodeinfo, $serverdata); } else { $serverdata = $nodeinfo; @@ -1366,7 +1371,57 @@ class GServer } return $val; - } + } + + /** + * Detect if the URL belongs to a pump.io server + * + * @param string $url URL of the given server + * @param array $serverdata array with server data + * + * @return array server data + */ + private static function detectPumpIO(string $url, array $serverdata) + { + $curlResult = DI::httpClient()->get($url . '/.well-known/host-meta.json'); + if (!$curlResult->isSuccess()) { + return $serverdata; + } + + $data = json_decode($curlResult->getBody(), true); + if (empty($data['links'])) { + return $serverdata; + + } + + // We are looking for some endpoints that are typical for pump.io + $trust = 0; + foreach ($data['links'] as $link) { + if (empty($link['rel'])) { + continue; + } + if (in_array($link['rel'], ['registration_endpoint', 'dialback', 'http://apinamespace.org/activitypub/whoami'])) { + ++$trust; + } + } + + if ($trust == 3) { + $serverdata['detection-method'] = self::DETECT_PUMPIO; + + $serverdata['platform'] = 'pumpio'; + $serverdata['version'] = ''; + $serverdata['network'] = Protocol::PUMPIO; + + $servers = $curlResult->getHeader('Server'); + foreach ($servers as $server) { + if (preg_match("#pump.io/(.*)\s#U", $server, $matches)) { + $serverdata['version'] = $matches[1]; + } + } + } + + return $serverdata; + } /** * Detect if the URL belongs to a GNU Social server From 3a96a971890d822bc43519c83c1fa7d27592bfce Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sat, 5 Feb 2022 16:01:04 +0100 Subject: [PATCH 2/2] Update src/Model/GServer.php Co-authored-by: Hypolite Petovan --- src/Model/GServer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Model/GServer.php b/src/Model/GServer.php index b9efae804..8cc1b5d01 100644 --- a/src/Model/GServer.php +++ b/src/Model/GServer.php @@ -1371,7 +1371,7 @@ class GServer } return $val; - } + } /** * Detect if the URL belongs to a pump.io server