1
1
Fork 0

Merge pull request #8102 from annando/servertest

Improved test for invalid systems
This commit is contained in:
Tobias Diekershoff 2020-01-12 14:59:48 +01:00 committed by GitHub
commit d45575e0fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -217,7 +217,7 @@ class GServer
$serverdata = self::analyseRootBody($curlResult, $serverdata, $url);
}
if (!$curlResult->isSuccess() || empty($curlResult->getBody())) {
if (!$curlResult->isSuccess() || empty($curlResult->getBody()) || self::invalidBody($curlResult->getBody())) {
DBA::update('gserver', ['last_failure' => DateTimeFormat::utcNow()], ['nurl' => Strings::normaliseLink($url)]);
return false;
}
@ -1061,6 +1061,7 @@ class GServer
$serverdata['platform'] = 'gnusocial';
// Remove junk that some GNU Social servers return
$serverdata['version'] = str_replace(chr(239) . chr(187) . chr(191), '', $curlResult->getBody());
$serverdata['version'] = str_replace(["\r", "\n", "\t"], '', $serverdata['version']);
$serverdata['version'] = trim($serverdata['version'], '"');
$serverdata['network'] = Protocol::OSTATUS;
return $serverdata;
@ -1070,11 +1071,20 @@ class GServer
$curlResult = Network::curl($url . '/api/statusnet/version.json');
if ($curlResult->isSuccess() && ($curlResult->getBody() != '{"error":"not implemented"}') &&
($curlResult->getBody() != '') && (strlen($curlResult->getBody()) < 30)) {
$serverdata['platform'] = 'statusnet';
// Remove junk that some GNU Social servers return
$serverdata['version'] = str_replace(chr(239).chr(187).chr(191), '', $curlResult->getBody());
$serverdata['version'] = str_replace(["\r", "\n", "\t"], '', $serverdata['version']);
$serverdata['version'] = trim($serverdata['version'], '"');
$serverdata['network'] = Protocol::OSTATUS;
if (!empty($serverdata['version']) && strtolower(substr($serverdata['version'], 0, 7)) == 'pleroma') {
$serverdata['platform'] = 'pleroma';
$serverdata['version'] = trim(str_ireplace('pleroma', '', $serverdata['version']));
$serverdata['network'] = Protocol::ACTIVITYPUB;
} else {
$serverdata['platform'] = 'statusnet';
$serverdata['network'] = Protocol::OSTATUS;
}
}
return $serverdata;
@ -1285,7 +1295,6 @@ class GServer
$serverdata['platform'] = 'diaspora';
$serverdata['network'] = $network = Protocol::DIASPORA;
$serverdata['version'] = $curlResult->getHeader('x-diaspora-version');
} elseif ($curlResult->inHeader('x-friendica-version')) {
$serverdata['platform'] = 'friendica';
$serverdata['network'] = $network = Protocol::DFRN;
@ -1294,6 +1303,19 @@ class GServer
return $serverdata;
}
/**
* Test if the body contains valid content
*
* @param string $body
* @return boolean
*/
private static function invalidBody(string $body)
{
// Currently we only test for a HTML element.
// Possibly we enhance this in the future.
return !strpos($body, '>');
}
/**
* Update the user directory of a given gserver record
*