return false;
}
+ if (empty($serverdata['version']) && in_array($serverdata['platform'], ['osada']) && in_array($serverdata['detection-method'], [self::DETECT_CONTACTS, self::DETECT_BODY])) {
+ $serverdata['version'] = self::getNomadVersion($url);
+ }
+
// Detect the directory type
$serverdata['directory-type'] = self::DT_NONE;
Logger::info('Invalid nodeinfo format', ['url' => $url]);
continue;
}
+
if ($link['rel'] == 'http://nodeinfo.diaspora.software/ns/schema/1.0') {
- $nodeinfo1_url = $link['href'];
+ $nodeinfo1_url = Network::addBasePath($link['href'], $httpResult->getUrl());
} elseif ($link['rel'] == 'http://nodeinfo.diaspora.software/ns/schema/2.0') {
- $nodeinfo2_url = $link['href'];
+ $nodeinfo2_url = Network::addBasePath($link['href'], $httpResult->getUrl());
}
}
$serverdata['network'] = Protocol::ACTIVITYPUB;
$serverdata['site_name'] = JsonLD::fetchElement($actor, 'as:name', '@value');
$serverdata['info'] = JsonLD::fetchElement($actor, 'as:summary', '@value');
- if (!empty($actor['as:generator'])) {
+ if (self::isNomad($actor)) {
+ $serverdata['platform'] = self::getNomadName($actor['@id']);
+ $serverdata['version'] = self::getNomadVersion($actor['@id']);
+ $serverdata['detection-method'] = self::DETECT_SYSTEM_ACTOR;
+ } elseif (!empty($actor['as:generator'])) {
$generator = explode(' ', JsonLD::fetchElement($actor['as:generator'], 'as:name', '@value'));
$serverdata['platform'] = strtolower(array_shift($generator));
+ $serverdata['version'] = self::getNomadVersion($actor['@id']);
$serverdata['detection-method'] = self::DETECT_SYSTEM_ACTOR;
} else {
$serverdata['detection-method'] = self::DETECT_AP_ACTOR;
return ['server' => $serverdata, 'actor' => ''];
}
+ /**
+ * Detect if the given actor is a nomad account
+ *
+ * @param array $actor
+ * @return boolean
+ */
+ private static function isNomad(array $actor): bool
+ {
+ $tags = JsonLD::fetchElementArray($actor, 'as:tag');
+ if (empty($tags)) {
+ return false;
+ }
+
+ foreach ($tags as $tag) {
+ if ((($tag['as:name'] ?? '') == 'Protocol') && (($tag['sc:value'] ?? '') == 'nomad')) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Fetch the name of Nomad implementation
+ *
+ * @param string $url
+ * @return string
+ */
+ private static function getNomadName(string $url): string
+ {
+ $name = 'nomad';
+ $curlResult = DI::httpClient()->get($url . '/manifest', 'application/manifest+json');
+ if (!$curlResult->isSuccess() || ($curlResult->getBody() == '')) {
+ return $name;
+ }
+
+ $data = json_decode($curlResult->getBody(), true);
+ if (empty($data)) {
+ return $name;
+ }
+
+ return $data['name'] ?? $name;
+ }
+
+ /**
+ * Fetch the version of the Nomad installation
+ *
+ * @param string $url
+ * @return string
+ */
+ private static function getNomadVersion(string $url): string
+ {
+ $curlResult = DI::httpClient()->get($url . '/api/z/1.0/version', HttpClientAccept::JSON);
+ if (!$curlResult->isSuccess() || ($curlResult->getBody() == '')) {
+ return '';
+ }
+
+ $data = json_decode($curlResult->getBody(), true);
+ if (empty($data)) {
+ return '';
+ }
+ return $data ?? '';
+ }
+
/**
* Checks if the server contains a valid host meta file
*