const DETECT_NODEINFO_210 = 103;
/**
- * Check for the existance of a server and adds it in the background if not existant
+ * Check for the existence of a server and adds it in the background if not existant
*
* @param string $url
* @param boolean $only_nodeinfo
return DateTimeFormat::utc('now +1 month');
}
- // The system hadn't been successul contacted for more than a month, so try again in three months
+ // The system hadn't been successful contacted for more than a month, so try again in three months
return DateTimeFormat::utc('now +3 month');
}
return false;
}
- // If the URL missmatches, then we mark the old entry as failure
+ // If the URL mismatches, then we mark the old entry as failure
if (!Strings::compareLink($url, $original_url)) {
self::setFailureByUrl($original_url);
if (!self::getID($url, true) && !Network::isUrlBlocked($url)) {
}
// All following checks are done for systems that always have got a "host-meta" endpoint.
- // With this check we don't have to waste time and ressources for dead systems.
+ // With this check we don't have to waste time and resources for dead systems.
// Also this hopefully prevents us from receiving abuse messages.
if (($serverdata['network'] == Protocol::PHANTOM) || in_array($serverdata['detection-method'], self::DETECT_UNSPECIFIC)) {
$validHostMeta = self::validHostMeta($url);
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;
}
// Sanitize incoming data, see https://github.com/friendica/friendica/issues/8565
- $data['subscribe'] = (bool)$data['subscribe'] ?? false;
+ $data['subscribe'] = (bool)($data['subscribe'] ?? false);
if (!$data['subscribe'] || empty($data['scope']) || !in_array(strtolower($data['scope']), ['all', 'tags'])) {
$data['scope'] = '';
$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;
- if (self::isNomad($actor['@id'])) {
- $serverdata['version'] = $serverdata['platform'];
- $serverdata['platform'] = 'nomad';
- }
} else {
$serverdata['detection-method'] = self::DETECT_AP_ACTOR;
}
}
/**
- * Detect if the given url belongs to a nomad account
+ * Detect if the given actor is a nomad account
*
- * @param string $url
+ * @param array $actor
* @return boolean
*/
- private static function isNomad(string $url): bool
+ private static function isNomad(array $actor): bool
{
- foreach (Probe::lrdd($url) as $attribute) {
- if ((($attribute['@attributes']['rel'] ?? '') == 'http://purl.org/nomad') && (($attribute['@attributes']['type'] ?? '') == 'application/x-nomad+json')) {
+ $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
*
}
}
- // Disvover Mastodon servers
+ // Discover Mastodon servers
$accesstoken = DI::config()->get('system', 'instances_social_key');
if (!empty($accesstoken)) {