Store the "authredirect" path of a server

This commit is contained in:
Michael 2024-05-26 00:07:06 +00:00
parent c432924d27
commit 1853f00a12
4 changed files with 88 additions and 7 deletions

View file

@ -1,6 +1,6 @@
-- ------------------------------------------
-- Friendica 2024.06-dev (Yellow Archangel)
-- DB_UPDATE_VERSION 1561
-- DB_UPDATE_VERSION 1562
-- ------------------------------------------
@ -24,6 +24,7 @@ CREATE TABLE IF NOT EXISTS `gserver` (
`directory-type` tinyint DEFAULT 0 COMMENT 'Type of directory service (Poco, Mastodon)',
`poco` varbinary(383) NOT NULL DEFAULT '' COMMENT '',
`openwebauth` varbinary(383) COMMENT 'Path to the OpenWebAuth endpoint',
`authredirect` varbinary(383) COMMENT 'Path to the authRedirect endpoint',
`noscrape` varbinary(383) NOT NULL DEFAULT '' COMMENT '',
`network` char(4) NOT NULL DEFAULT '' COMMENT '',
`protocol` tinyint unsigned COMMENT 'The protocol of the server',

View file

@ -24,6 +24,7 @@ Fields
| directory-type | Type of directory service (Poco, Mastodon) | tinyint | YES | | 0 | |
| poco | | varbinary(383) | NO | | | |
| openwebauth | Path to the OpenWebAuth endpoint | varbinary(383) | YES | | NULL | |
| authredirect | Path to the authRedirect endpoint | varbinary(383) | YES | | NULL | |
| noscrape | | varbinary(383) | NO | | | |
| network | | char(4) | NO | | | |
| protocol | The protocol of the server | tinyint unsigned | YES | | NULL | |

View file

@ -737,6 +737,10 @@ class GServer
}
}
if (in_array($serverdata['platform'] ?? '', ['hubzilla', 'streams', 'osada', 'mistpark', 'roadhouse', 'zap'])) {
$serverdata = self::getZotData($url, $serverdata);
}
// When we hadn't been able to detect the network type, we use the hint from the parameter
if (($serverdata['network'] == Protocol::PHANTOM) && !empty($network)) {
$serverdata['network'] = $network;
@ -1623,6 +1627,80 @@ class GServer
return $data ?? '';
}
private static function getZotData(string $url, array $serverdata): array
{
$curlResult = DI::httpClient()->get($url, 'application/x-zot+json');
if (!$curlResult->isSuccess()) {
return $serverdata;
}
$json = $curlResult->getBodyString();
$data = json_decode($json, true);
if (empty($data)) {
return $serverdata;
}
if (!empty($data['site'])) {
$serverdata = self::getFromZotData($data['site'], $serverdata);
} else {
$serverdata = self::getFromZotData($data, $serverdata);
}
return $serverdata;
}
private static function getFromZotData(array $data, array $serverdata): array
{
if (!empty($data['version'])) {
$serverdata['version'] = $data['version'];
}
if (!empty($data['openWebAuth'])) {
$serverdata['openwebauth'] = $data['openWebAuth'];
}
if (!empty($data['authRedirect'])) {
$serverdata['authredirect'] = $data['authRedirect'];
}
if (!empty($data['sitename'])) {
$serverdata['site_name'] = $data['sitename'];
}
if (!empty($data['about'])) {
$serverdata['info'] = $data['about'];
}
if (empty($serverdata['info']) && !empty($data['location'])) {
$serverdata['info'] = $data['location'];
}
if (!empty($data['project']) && in_array($data['project'], ['hubzilla', 'streams', 'osada', 'mistpark', 'roadhouse', 'zap'])) {
$serverdata['platform'] = $data['project'];
}
if (!empty($data['accounts'])) {
$serverdata['registered-users'] = $data['accounts'];
}
if (!empty($data['register_policy'])) {
switch ($data['register_policy']) {
case 'open':
$serverdata['register_policy'] = Register::OPEN;
break;
case 'closed':
$serverdata['register_policy'] = Register::CLOSED;
break;
case 'approve':
$serverdata['register_policy'] = Register::APPROVE;
break;
default:
echo $data['register_policy'] . "\n";
break;
}
}
return $serverdata;
}
/**
* Checks if the server contains a valid host meta file
*
@ -2105,7 +2183,7 @@ class GServer
($curlResult->getBodyString() != '') && (strlen($curlResult->getBodyString()) < 30)) {
// Remove junk that some GNU Social servers return
$serverdata['version'] = str_replace(chr(239).chr(187).chr(191), '', $curlResult->getBodyString());
$serverdata['version'] = str_replace(chr(239) . chr(187) . chr(191), '', $curlResult->getBodyString());
$serverdata['version'] = str_replace(["\r", "\n", "\t"], '', $serverdata['version']);
$serverdata['version'] = trim($serverdata['version'], '"');

View file

@ -56,7 +56,7 @@ use Friendica\Database\DBA;
// This file is required several times during the test in DbaDefinition which justifies this condition
if (!defined('DB_UPDATE_VERSION')) {
define('DB_UPDATE_VERSION', 1561);
define('DB_UPDATE_VERSION', 1562);
}
return [
@ -80,6 +80,7 @@ return [
"directory-type" => ["type" => "tinyint", "default" => "0", "comment" => "Type of directory service (Poco, Mastodon)"],
"poco" => ["type" => "varbinary(383)", "not null" => "1", "default" => "", "comment" => ""],
"openwebauth" => ["type" => "varbinary(383)", "comment" => "Path to the OpenWebAuth endpoint"],
"authredirect" => ["type" => "varbinary(383)", "comment" => "Path to the authRedirect endpoint"],
"noscrape" => ["type" => "varbinary(383)", "not null" => "1", "default" => "", "comment" => ""],
"network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => ""],
"protocol" => ["type" => "tinyint unsigned", "comment" => "The protocol of the server"],