]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/GServer.php
Merge pull request #12909 from annando/server-detection
[friendica.git] / src / Model / GServer.php
index 41edb6c8d271568e47b5647809d9b80649fc28c7..13dd13af446efc85752ef12b0e5f28648096865d 100644 (file)
@@ -474,14 +474,6 @@ class GServer
                        return;
                }
 
-               if (Network::isUrlBlocked($url)) {
-                       Logger::info('Server domain is blocked', ['url' => $url]);
-                       return;
-               } elseif (Network::isUrlBlocked($nurl)) {
-                       Logger::info('Server domain is blocked', ['nurl' => $nurl]);
-                       return;
-               }
-
                self::insert(['url' => $url, 'nurl' => $nurl,
                        'network' => Protocol::PHANTOM, 'created' => DateTimeFormat::utcNow(),
                        'failed' => true, 'last_failure' => DateTimeFormat::utcNow()]);
@@ -568,13 +560,10 @@ class GServer
                // If the URL missmatches, then we mark the old entry as failure
                if (!Strings::compareLink($url, $original_url)) {
                        self::setFailureByUrl($original_url);
-                       if (!self::getID($url, true)) {
+                       if (!self::getID($url, true) && !Network::isUrlBlocked($url)) {
                                self::detect($url, $network, $only_nodeinfo);
                        }
                        return false;
-               } elseif (Network::isUrlBlocked($url)) {
-                       Logger::info('Server domain is blocked', ['url' => $url]);
-                       return false;
                }
 
                $valid_url = Network::isUrlValid($url);
@@ -592,7 +581,7 @@ class GServer
                                (((parse_url($url, PHP_URL_HOST) != parse_url($valid_url, PHP_URL_HOST)) || (parse_url($url, PHP_URL_PATH) != parse_url($valid_url, PHP_URL_PATH))) && empty(parse_url($valid_url, PHP_URL_PATH)))) {
                                Logger::debug('Found redirect. Mark old entry as failure', ['old' => $url, 'new' => $valid_url]);
                                self::setFailureByUrl($url);
-                               if (!self::getID($valid_url, true)) {
+                               if (!self::getID($valid_url, true) && !Network::isUrlBlocked($valid_url)) {
                                        self::detect($valid_url, $network, $only_nodeinfo);
                                }
                                return false;
@@ -606,7 +595,7 @@ class GServer
                                $valid_url = (string)Uri::fromParts($parts);
 
                                self::setFailureByUrl($url);
-                               if (!self::getID($valid_url, true)) {
+                               if (!self::getID($valid_url, true) && !Network::isUrlBlocked($valid_url)) {
                                        self::detect($valid_url, $network, $only_nodeinfo);
                                }
                                return false;
@@ -1071,10 +1060,11 @@ class GServer
                                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());
                        }
                }
 
@@ -1427,7 +1417,7 @@ class GServer
                        $serverdata['detection-method'] = self::DETECT_SITEINFO_JSON;
                }
 
-               if (!empty($data['url'])) {
+               if (!empty($data['platform'])) {
                        $serverdata['platform'] = strtolower($data['platform']);
                        $serverdata['version'] = $data['version'] ?? 'N/A';
                }
@@ -1513,6 +1503,10 @@ class GServer
                                $generator = explode(' ', JsonLD::fetchElement($actor['as:generator'], 'as:name', '@value'));
                                $serverdata['platform'] = strtolower(array_shift($generator));
                                $serverdata['detection-method'] = self::DETECT_SYSTEM_ACTOR;
+                               if (self::isNomad($actor)) {
+                                       $serverdata['version']  = $serverdata['platform'];
+                                       $serverdata['platform'] = 'nomad';
+                               }
                        } else {
                                $serverdata['detection-method'] = self::DETECT_AP_ACTOR;
                        }
@@ -1535,6 +1529,27 @@ class GServer
                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;
+       }
+
        /**
         * Checks if the server contains a valid host meta file
         *