Merge pull request #12909 from annando/server-detection

Simplified Nomad detection
This commit is contained in:
Hypolite Petovan 2023-03-18 08:59:29 -04:00 committed by GitHub
commit bbb5440144
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 6 deletions

View File

@ -1503,7 +1503,7 @@ class GServer
$generator = explode(' ', JsonLD::fetchElement($actor['as:generator'], 'as:name', '@value')); $generator = explode(' ', JsonLD::fetchElement($actor['as:generator'], 'as:name', '@value'));
$serverdata['platform'] = strtolower(array_shift($generator)); $serverdata['platform'] = strtolower(array_shift($generator));
$serverdata['detection-method'] = self::DETECT_SYSTEM_ACTOR; $serverdata['detection-method'] = self::DETECT_SYSTEM_ACTOR;
if (self::isNomad($actor['@id'])) { if (self::isNomad($actor)) {
$serverdata['version'] = $serverdata['platform']; $serverdata['version'] = $serverdata['platform'];
$serverdata['platform'] = 'nomad'; $serverdata['platform'] = 'nomad';
} }
@ -1530,15 +1530,20 @@ class GServer
} }
/** /**
* 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 * @return boolean
*/ */
private static function isNomad(string $url): bool private static function isNomad(array $actor): bool
{ {
foreach (Probe::lrdd($url) as $attribute) { $tags = JsonLD::fetchElementArray($actor, 'as:tag');
if ((($attribute['@attributes']['rel'] ?? '') == 'http://purl.org/nomad') && (($attribute['@attributes']['type'] ?? '') == 'application/x-nomad+json')) { if (empty($tags)) {
return false;
}
foreach ($tags as $tag) {
if ((($tag['as:name'] ?? '') == 'Protocol') && (($tag['sc:value'] ?? '') == 'nomad')) {
return true; return true;
} }
} }