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) -- 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)', `directory-type` tinyint DEFAULT 0 COMMENT 'Type of directory service (Poco, Mastodon)',
`poco` varbinary(383) NOT NULL DEFAULT '' COMMENT '', `poco` varbinary(383) NOT NULL DEFAULT '' COMMENT '',
`openwebauth` varbinary(383) COMMENT 'Path to the OpenWebAuth endpoint', `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 '', `noscrape` varbinary(383) NOT NULL DEFAULT '' COMMENT '',
`network` char(4) NOT NULL DEFAULT '' COMMENT '', `network` char(4) NOT NULL DEFAULT '' COMMENT '',
`protocol` tinyint unsigned COMMENT 'The protocol of the server', `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 | | | directory-type | Type of directory service (Poco, Mastodon) | tinyint | YES | | 0 | |
| poco | | varbinary(383) | NO | | | | | poco | | varbinary(383) | NO | | | |
| openwebauth | Path to the OpenWebAuth endpoint | varbinary(383) | YES | | NULL | | | openwebauth | Path to the OpenWebAuth endpoint | varbinary(383) | YES | | NULL | |
| authredirect | Path to the authRedirect endpoint | varbinary(383) | YES | | NULL | |
| noscrape | | varbinary(383) | NO | | | | | noscrape | | varbinary(383) | NO | | | |
| network | | char(4) | NO | | | | | network | | char(4) | NO | | | |
| protocol | The protocol of the server | tinyint unsigned | YES | | NULL | | | protocol | The protocol of the server | tinyint unsigned | YES | | NULL | |

View file

@ -578,7 +578,7 @@ class GServer
// We only follow redirects when the path stays the same or the target url has no path. // We only follow redirects when the path stays the same or the target url has no path.
// Some systems have got redirects on their landing page to a single account page. This check handles it. // Some systems have got redirects on their landing page to a single account page. This check handles it.
if (((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))) || if (((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))) ||
(((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)))) { (((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]); Logger::debug('Found redirect. Mark old entry as failure', ['old' => $url, 'new' => $valid_url]);
self::setFailureByUrl($url); self::setFailureByUrl($url);
if (!self::getID($valid_url, true) && !Network::isUrlBlocked($valid_url)) { if (!self::getID($valid_url, true) && !Network::isUrlBlocked($valid_url)) {
@ -588,7 +588,7 @@ class GServer
} }
if ((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)) && if ((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)) &&
(parse_url($url, PHP_URL_PATH) == '')) { (parse_url($url, PHP_URL_PATH) == '')) {
Logger::debug('Found redirect. Mark old entry as failure and redirect to the basepath.', ['old' => $url, 'new' => $valid_url]); Logger::debug('Found redirect. Mark old entry as failure and redirect to the basepath.', ['old' => $url, 'new' => $valid_url]);
$parts = (array)parse_url($valid_url); $parts = (array)parse_url($valid_url);
unset($parts['path']); unset($parts['path']);
@ -606,7 +606,7 @@ class GServer
if ((parse_url($url, PHP_URL_HOST) == parse_url($valid_url, PHP_URL_HOST)) && if ((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)) && (parse_url($url, PHP_URL_PATH) == parse_url($valid_url, PHP_URL_PATH)) &&
(parse_url($url, PHP_URL_SCHEME) != parse_url($valid_url, PHP_URL_SCHEME))) { (parse_url($url, PHP_URL_SCHEME) != parse_url($valid_url, PHP_URL_SCHEME))) {
$url = $valid_url; $url = $valid_url;
} }
$in_webroot = empty(parse_url($url, PHP_URL_PATH)); $in_webroot = empty(parse_url($url, PHP_URL_PATH));
@ -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 // 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)) { if (($serverdata['network'] == Protocol::PHANTOM) && !empty($network)) {
$serverdata['network'] = $network; $serverdata['network'] = $network;
@ -1623,6 +1627,80 @@ class GServer
return $data ?? ''; 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 * Checks if the server contains a valid host meta file
* *
@ -2105,7 +2183,7 @@ class GServer
($curlResult->getBodyString() != '') && (strlen($curlResult->getBodyString()) < 30)) { ($curlResult->getBodyString() != '') && (strlen($curlResult->getBodyString()) < 30)) {
// 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->getBodyString()); $serverdata['version'] = str_replace(chr(239) . chr(187) . chr(191), '', $curlResult->getBodyString());
$serverdata['version'] = str_replace(["\r", "\n", "\t"], '', $serverdata['version']); $serverdata['version'] = str_replace(["\r", "\n", "\t"], '', $serverdata['version']);
$serverdata['version'] = trim($serverdata['version'], '"'); $serverdata['version'] = trim($serverdata['version'], '"');
@ -2192,7 +2270,7 @@ class GServer
break; break;
default: default:
Logger::info('Register policy is invalid', ['policy' => $register_policy, 'server' => $url]); Logger::info('Register policy is invalid', ['policy' => $register_policy, 'server' => $url]);
$serverdata['register_policy'] = Register::CLOSED; $serverdata['register_policy'] = Register::CLOSED;
break; break;
} }

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