mirror of
https://github.com/friendica/friendica
synced 2024-11-13 05:02:54 +00:00
Merge pull request #8102 from annando/servertest
Improved test for invalid systems
This commit is contained in:
commit
d45575e0fa
1 changed files with 26 additions and 4 deletions
|
@ -217,7 +217,7 @@ class GServer
|
||||||
$serverdata = self::analyseRootBody($curlResult, $serverdata, $url);
|
$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)]);
|
DBA::update('gserver', ['last_failure' => DateTimeFormat::utcNow()], ['nurl' => Strings::normaliseLink($url)]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1061,6 +1061,7 @@ class GServer
|
||||||
$serverdata['platform'] = 'gnusocial';
|
$serverdata['platform'] = 'gnusocial';
|
||||||
// Remove junk that some GNU Social servers return
|
// Remove junk that some GNU Social servers return
|
||||||
$serverdata['version'] = str_replace(chr(239) . chr(187) . chr(191), '', $curlResult->getBody());
|
$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['version'] = trim($serverdata['version'], '"');
|
||||||
$serverdata['network'] = Protocol::OSTATUS;
|
$serverdata['network'] = Protocol::OSTATUS;
|
||||||
return $serverdata;
|
return $serverdata;
|
||||||
|
@ -1070,11 +1071,20 @@ class GServer
|
||||||
$curlResult = Network::curl($url . '/api/statusnet/version.json');
|
$curlResult = Network::curl($url . '/api/statusnet/version.json');
|
||||||
if ($curlResult->isSuccess() && ($curlResult->getBody() != '{"error":"not implemented"}') &&
|
if ($curlResult->isSuccess() && ($curlResult->getBody() != '{"error":"not implemented"}') &&
|
||||||
($curlResult->getBody() != '') && (strlen($curlResult->getBody()) < 30)) {
|
($curlResult->getBody() != '') && (strlen($curlResult->getBody()) < 30)) {
|
||||||
$serverdata['platform'] = 'statusnet';
|
|
||||||
// Remove junk that some GNU Social servers return
|
// Remove junk that some GNU Social servers return
|
||||||
$serverdata['version'] = str_replace(chr(239).chr(187).chr(191), '', $curlResult->getBody());
|
$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['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;
|
return $serverdata;
|
||||||
|
@ -1285,7 +1295,6 @@ class GServer
|
||||||
$serverdata['platform'] = 'diaspora';
|
$serverdata['platform'] = 'diaspora';
|
||||||
$serverdata['network'] = $network = Protocol::DIASPORA;
|
$serverdata['network'] = $network = Protocol::DIASPORA;
|
||||||
$serverdata['version'] = $curlResult->getHeader('x-diaspora-version');
|
$serverdata['version'] = $curlResult->getHeader('x-diaspora-version');
|
||||||
|
|
||||||
} elseif ($curlResult->inHeader('x-friendica-version')) {
|
} elseif ($curlResult->inHeader('x-friendica-version')) {
|
||||||
$serverdata['platform'] = 'friendica';
|
$serverdata['platform'] = 'friendica';
|
||||||
$serverdata['network'] = $network = Protocol::DFRN;
|
$serverdata['network'] = $network = Protocol::DFRN;
|
||||||
|
@ -1294,6 +1303,19 @@ class GServer
|
||||||
return $serverdata;
|
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
|
* Update the user directory of a given gserver record
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue