Merge branch 'develop' into Art4/fix-code-style-for-pr-14688

# Conflicts:
#	src/Model/GServer.php
#	src/Util/HTTPSignature.php
This commit is contained in:
Hypolite Petovan 2025-01-22 21:05:24 -05:00
commit 822b4429f3
26 changed files with 924 additions and 732 deletions

View file

@ -52,4 +52,4 @@ $container = \Friendica\Core\DiceContainer::fromBasePath(dirname(__DIR__));
$app = \Friendica\App::fromContainer($container);
$app->processEjabberd();
$app->processEjabberd($_SERVER);

View file

@ -19,4 +19,4 @@ $container = \Friendica\Core\DiceContainer::fromBasePath(dirname(__DIR__));
$app = \Friendica\App::fromContainer($container);
$app->processConsole($_SERVER['argv'] ?? []);
$app->processConsole($_SERVER);

View file

@ -6,7 +6,7 @@
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*
* @deprecated 2025.02 use bin/console.php daemon instead
* @deprecated 2025.02 use `bin/console.php daemon` instead
*/
/**
@ -24,11 +24,15 @@ chdir(dirname(__DIR__));
require dirname(__DIR__) . '/vendor/autoload.php';
fwrite(STDOUT, '`bin/daemon.php` is deprecated since 2024.02 and will be removed in 5 months, please use `bin/console.php daemon` instead.' . \PHP_EOL);
// BC: Add console command as second argument
$argv = $_SERVER['argv'] ?? [];
array_splice($argv, 1, 0, "daemon");
$_SERVER['argv'] = $argv;
$container = \Friendica\Core\DiceContainer::fromBasePath(dirname(__DIR__));
$app = \Friendica\App::fromContainer($container);
$app->processConsole($argv);
$app->processConsole($_SERVER);

View file

@ -6,7 +6,7 @@
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*
* @deprecated 2025.02 use bin/console.php jetstream instead
* @deprecated 2025.02 use `bin/console.php jetstream` instead
*/
if (php_sapi_name() !== 'cli') {
@ -19,11 +19,15 @@ chdir(dirname(__DIR__));
require dirname(__DIR__) . '/vendor/autoload.php';
fwrite(STDOUT, '`bin/jetstream.php` is deprecated since 2024.02 and will be removed in 5 months, please use `bin/console.php jetstream` instead.' . \PHP_EOL);
// BC: Add console command as second argument
$argv = $_SERVER['argv'] ?? [];
array_splice($argv, 1, 0, "jetstream");
$_SERVER['argv'] = $argv;
$container = \Friendica\Core\DiceContainer::fromBasePath(dirname(__DIR__));
$app = \Friendica\App::fromContainer($container);
$app->processConsole($argv);
$app->processConsole($_SERVER);

View file

@ -8,7 +8,7 @@
*
* Starts the background processing
*
* @deprecated 2025.02 use bin/console.php worker instead
* @deprecated 2025.02 use `bin/console.php worker` instead
*/
if (php_sapi_name() !== 'cli') {
@ -21,11 +21,15 @@ chdir(dirname(__DIR__));
require dirname(__DIR__) . '/vendor/autoload.php';
fwrite(STDOUT, '`bin/worker.php` is deprecated since 2024.02 and will be removed in 5 months, please use `bin/console.php worker` instead.' . \PHP_EOL);
// BC: Add console command as second argument
$argv = $_SERVER['argv'] ?? [];
array_splice($argv, 1, 0, "worker");
$_SERVER['argv'] = $argv;
$container = \Friendica\Core\DiceContainer::fromBasePath(dirname(__DIR__));
$app = \Friendica\App::fromContainer($container);
$app->processConsole($argv);
$app->processConsole($_SERVER);

View file

@ -156,3 +156,97 @@ If you are interested in improving those clients, please contact the developers
* iOS: *currently no client*
* SailfishOS: **Friendiy** [src](https://kirgroup.com/projects/fabrixxm/harbour-friendly) - developed by [Fabio](https://kirgroup.com/profile/fabrixxm/profile)
* Windows: **Friendica Mobile** for Windows versions [before 8.1](http://windowsphone.com/s?appid=e3257730-c9cf-4935-9620-5261e3505c67) and [Windows 10](https://www.microsoft.com/store/apps/9nblggh0fhmn) - developed by [Gerhard Seeber](http://mozartweg.dyndns.org/friendica/profile/gerhard/profile)
## Backward compatibility
### Backward Compatibility Promise
Friendica can be extended by addons.
These addons relies on many classes and conventions from Friendica.
As developers our work on Friendica should not break things in the addons without giving the addon maintainers a chance to fix their addons.
Our goal is to build trust for the addon maintainers but also allow Friendica developers to move on.
This is called the Backward Compatibility Promise.
Inspired by the [Symonfy BC promise](https://symfony.com/doc/current/contributing/code/bc.html) we promise BC for every class, interface, trait, enum, function, constant, etc., but with the exception of:
- Classes, interfaces, traits, enums, functions, methods, properties and constants marked as `@internal` or `@private`
- Extending or modifying a `final` class or method in any way
- Calling `private` methods (via Reflection)
- Accessing `private` properties (via Reflection)
- Accessing `private` methods (via Reflection)
- Accessing `private` constants (via Reflection)
- New properties on overridden `protected` methods
- Possible name collisions with new methods in an extended class (addon developers should prefix their custom methods in the extending classes in an appropriate way)
- Dropping support for every PHP version that has reached end of life
### Deprecation and removing features
As the development goes by Friendica needs to get rid of old code and concepts.
This will be done in 3 steps to give addon maintainers a chance to adjust their addons.
**1. Label deprecation**
If we as the Friendica maintainers decide to remove some functions, classes, interface, etc. we start this by adding a `@deprecated` PHPDoc note on the code.
For instance the class `Friendica\Core\Logger` should be removed, so we add the following note with a possible replacement:
```php
/**
* Logger functions
*
* @deprecated 2025.02 Use constructor injection or `DI::logger()` instead
*/
class Logger {/* ... */}
```
This way addon developers might be notified early by their IDE or other tools that the usage of the class is deprecated.
In Friendica we can now start to replace all occurrences and usage of this class with the alternative.
The deprecation label COULD be remain over multiple releases.
As long as the code that is labeled with `@deprecated` is used inside Friendica or the official addon repository, it SHOULD NOT be hard deprecated.
**2. Hard deprecation**
If the deprecated code is no longer used inside Friendica or the official addons it MUST be hard deprecated.
The code MUST NOT be deleted.
Starting from the next release, it MUST be stay for at least 5 months.
Hard deprecated code COULD remain longer than 5 months, depending on when a release appears.
Addon developer MUST NOT consider that they have more than 5 months to adjust their code.
Hard deprecation code means that the code triggers an `E_USER_DEPRECATION` error if it is called.
For instance with the deprecated class `Friendica\Core\Logger` the call of every method should trigger an error:
```php
/**
* Logger functions
*
* @deprecated 2025.02 Use constructor injection or `DI::logger()` instead
*/
class Logger {
public static function info(string $message, array $context = [])
{
trigger_error('Class `' . __CLASS__ . '` is deprecated since 2025.05 and will be removed after 5 months, use constructor injection or `DI::logger()` instead.', E_USER_DEPRECATED);
self::getInstance()->info($message, $context);
}
/* ... */
}
```
This way the maintainer or users of addons will be notified that the addon will stop working in one of the next releases.
The addon maintainer now has at least 5 months or at least one release to fix the deprecations.
Please note that the deprecation message contains the release that will be released next.
In the example the code was hard deprecated with release `2025.05`, so it COULD be removed earliest with the `2025.11` release.
**3. Code Removing**
We promise BC for deprecated code for at least 5 months, starting from the release the deprecation was announced.
After this time the deprecated code COULD be remove within the next release.
Breaking changes MUST be happen only in a new release but MUST be hard deprecated first.
The BC promise refers only to releases, respective the `stable` branch.
Deprecated code on other branches like `develop` or RC branches could be removed earlier.
This is not a BC break as long as the release will be published 5 months after the hard deprecation.
If a release breaks BC without deprecation or earlier than 5 months, this SHOULD considered as a bug and BC SHOULD be restored in a bugfix release.

View file

@ -57,6 +57,7 @@ use Psr\Log\LoggerInterface;
* and anything else that might need to be passed around
* before we spit the page out.
*
* @final
*/
class App
{
@ -64,6 +65,9 @@ class App
const CODENAME = 'Interrupted Fern';
const VERSION = '2025.02-dev';
/**
* @internal
*/
public static function fromContainer(Container $container): self
{
return new self($container);
@ -130,6 +134,9 @@ class App
$this->container = $container;
}
/**
* @internal
*/
public function processRequest(ServerRequestInterface $request, float $start_time): void
{
$this->container->addRule(Mode::class, [
@ -158,16 +165,18 @@ class App
$this->session = $this->container->create(IHandleUserSessions::class);
$this->appHelper = $this->container->create(AppHelper::class);
$this->loadSetupForFrontend(
$request,
$this->load(
$request->getServerParams(),
$this->container->create(DbaDefinition::class),
$this->container->create(ViewDefinition::class),
$this->mode,
$this->config,
$this->profiler,
$this->appHelper,
);
$this->registerTemplateEngine();
$this->mode->setExecutor(Mode::INDEX);
$this->runFrontend(
$this->container->create(IManagePersonalConfigValues::class),
$this->container->create(Page::class),
@ -178,8 +187,13 @@ class App
);
}
public function processConsole(array $argv): void
/**
* @internal
*/
public function processConsole(array $serverParams): void
{
$argv = $serverParams['argv'] ?? [];
$this->setupContainerForAddons();
$this->setupLogChannel($this->determineLogChannel($argv));
@ -188,12 +202,25 @@ class App
$this->registerErrorHandler();
$this->load(
$serverParams,
$this->container->create(DbaDefinition::class),
$this->container->create(ViewDefinition::class),
$this->container->create(Mode::class),
$this->container->create(IManageConfigValues::class),
$this->container->create(Profiler::class),
$this->container->create(AppHelper::class),
);
$this->registerTemplateEngine();
(\Friendica\Core\Console::create($this->container, $argv))->execute();
}
public function processEjabberd(): void
/**
* @internal
*/
public function processEjabberd(array $serverParams): void
{
$this->setupContainerForAddons();
@ -203,6 +230,16 @@ class App
$this->registerErrorHandler();
$this->load(
$serverParams,
$this->container->create(DbaDefinition::class),
$this->container->create(ViewDefinition::class),
$this->container->create(Mode::class),
$this->container->create(IManageConfigValues::class),
$this->container->create(Profiler::class),
$this->container->create(AppHelper::class),
);
/** @var BasePath */
$basePath = $this->container->create(BasePath::class);
@ -272,14 +309,21 @@ class App
/**
* Load the whole app instance
*/
private function loadSetupForFrontend(ServerRequestInterface $request, DbaDefinition $dbaDefinition, ViewDefinition $viewDefinition)
{
if ($this->config->get('system', 'ini_max_execution_time') !== false) {
set_time_limit((int)$this->config->get('system', 'ini_max_execution_time'));
private function load(
array $serverParams,
DbaDefinition $dbaDefinition,
ViewDefinition $viewDefinition,
Mode $mode,
IManageConfigValues $config,
Profiler $profiler,
AppHelper $appHelper
): void {
if ($config->get('system', 'ini_max_execution_time') !== false) {
set_time_limit((int) $config->get('system', 'ini_max_execution_time'));
}
if ($this->config->get('system', 'ini_pcre_backtrack_limit') !== false) {
ini_set('pcre.backtrack_limit', (int)$this->config->get('system', 'ini_pcre_backtrack_limit'));
if ($config->get('system', 'ini_pcre_backtrack_limit') !== false) {
ini_set('pcre.backtrack_limit', (int) $config->get('system', 'ini_pcre_backtrack_limit'));
}
// Normally this constant is defined - but not if "pcntl" isn't installed
@ -290,11 +334,11 @@ class App
// Ensure that all "strtotime" operations do run timezone independent
date_default_timezone_set('UTC');
$this->profiler->reset();
$profiler->reset();
if ($this->mode->has(Mode::DBAVAILABLE)) {
if ($mode->has(Mode::DBAVAILABLE)) {
Core\Hook::loadHooks();
$loader = (new Config())->createConfigFileManager($this->appHelper->getBasePath(), $request->getServerParams());
$loader = (new Config())->createConfigFileManager($appHelper->getBasePath(), $serverParams);
Core\Hook::callAll('load_config', $loader);
// Hooks are now working, reload the whole definitions with hook enabled
@ -302,7 +346,7 @@ class App
$viewDefinition->load(true);
}
$this->loadDefaultTimezone();
$this->loadDefaultTimezone($config, $appHelper);
}
/**
@ -312,16 +356,16 @@ class App
*
* @global string $default_timezone
*/
private function loadDefaultTimezone()
private function loadDefaultTimezone(IManageConfigValues $config, AppHelper $appHelper)
{
if ($this->config->get('system', 'default_timezone')) {
$timezone = $this->config->get('system', 'default_timezone', 'UTC');
if ($config->get('system', 'default_timezone')) {
$timezone = $config->get('system', 'default_timezone', 'UTC');
} else {
global $default_timezone;
$timezone = $default_timezone ?? '' ?: 'UTC';
}
$this->appHelper->setTimeZone($timezone);
$appHelper->setTimeZone($timezone);
}
/**
@ -348,6 +392,8 @@ class App
float $start_time,
ServerRequestInterface $request
) {
$this->mode->setExecutor(Mode::INDEX);
$httpInput = new HTTPInputData($request->getServerParams());
$serverVars = $request->getServerParams();
$queryVars = $request->getQueryParams();

View file

@ -32,6 +32,7 @@ use Friendica\Util\Strings;
* and anything else that might need to be passed around
* before we spit the page out.
*
* @internal
*/
final class AppLegacy implements AppHelper
{

View file

@ -1,39 +0,0 @@
<?php
// Copyright (C) 2010-2024, the Friendica project
// SPDX-FileCopyrightText: 2010-2024 the Friendica project
//
// SPDX-License-Identifier: AGPL-3.0-or-later
declare(strict_types=1);
namespace Friendica\Console;
use Asika\SimpleConsole\Console;
use Friendica\Core\Console as CoreConsole;
use Friendica\Core\Logger\Capability\LogChannel;
/**
* Abstract Console class for common settings
*/
abstract class AbstractConsole extends Console
{
/**
* Overwrite this const in case you want to switch the LogChannel for this console command
*
* @var string
*/
public const LOG_CHANNEL = LogChannel::CONSOLE;
/**
* Checks, if the Console command was executed outside `bin/console.php` and prints the correct execution
*
* @param string $command the current command
*/
protected function checkDeprecated(string $command): void
{
if (substr($this->executable, -strlen(CoreConsole::getDefaultExecutable())) !== CoreConsole::getDefaultExecutable()) {
$this->out(sprintf("'%s' is deprecated and will removed. Please use 'bin/console.php %s' instead", $this->executable, $command));
}
}
}

View file

@ -10,10 +10,10 @@ declare(strict_types=1);
namespace Friendica\Console;
use Asika\SimpleConsole\CommandArgsException;
use Asika\SimpleConsole\Console;
use Friendica\App\Mode;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\KeyValueStorage\Capability\IManageKeyValuePairs;
use Friendica\Core\Logger\Capability\LogChannel;
use Friendica\Core\System;
use Friendica\Core\Update;
use Friendica\Core\Worker;
@ -27,10 +27,8 @@ use RuntimeException;
/**
* Console command for interacting with the daemon
*/
final class Daemon extends AbstractConsole
final class Daemon extends Console
{
public const LOG_CHANNEL = LogChannel::DAEMON;
private Mode $mode;
private IManageConfigValues $config;
private IManageKeyValuePairs $keyValue;
@ -93,8 +91,6 @@ HELP;
protected function doExecute()
{
$this->checkDeprecated('daemon');
if ($this->mode->isInstall()) {
throw new RuntimeException("Friendica isn't properly installed yet");
}

View file

@ -9,12 +9,12 @@ declare(strict_types=1);
namespace Friendica\Console;
use Asika\SimpleConsole\Console;
use Friendica\App\Mode;
use Friendica\Core\Addon;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\Hook;
use Friendica\Core\KeyValueStorage\Capability\IManageKeyValuePairs;
use Friendica\Core\Logger\Capability\LogChannel;
use Friendica\Protocol\ATProtocol\Jetstream;
use Friendica\System\Daemon as SysDaemon;
use RuntimeException;
@ -22,10 +22,8 @@ use RuntimeException;
/**
* Console command for interacting with the daemon
*/
final class JetstreamDaemon extends AbstractConsole
final class JetstreamDaemon extends Console
{
public const LOG_CHANNEL = LogChannel::DAEMON;
private Mode $mode;
private IManageConfigValues $config;
private IManageKeyValuePairs $keyValue;
@ -79,8 +77,6 @@ HELP;
protected function doExecute()
{
$this->checkDeprecated('jetstream');
if ($this->mode->isInstall()) {
throw new RuntimeException("Friendica isn't properly installed yet");
}

View file

@ -9,8 +9,8 @@ declare(strict_types=1);
namespace Friendica\Console;
use Asika\SimpleConsole\Console;
use Friendica\App\Mode;
use Friendica\Core\Logger\Capability\LogChannel;
use Friendica\Core\Update;
use Friendica\Core\Worker as CoreWorker;
use Friendica\Core\Worker\Repository\Process as ProcessRepository;
@ -19,10 +19,8 @@ use Friendica\Util\BasePath;
/**
* Console command for starting worker
*/
final class Worker extends AbstractConsole
final class Worker extends Console
{
public const LOG_CHANNEL = LogChannel::WORKER;
private Mode $mode;
private BasePath $basePath;
private ProcessRepository $processRepo;
@ -69,8 +67,6 @@ HELP;
protected function doExecute()
{
$this->checkDeprecated('worker');
$this->mode->setExecutor(Mode::WORKER);
// Check the database structure and possibly fixes it

View file

@ -11,6 +11,8 @@ namespace Friendica\Core;
/**
* Dependency Injection Container
*
* @internal
*/
interface Container
{

View file

@ -13,6 +13,8 @@ use Dice\Dice;
/**
* Wrapper for the Dice class to make some basic setups
*
* @internal
*/
final class DiceContainer implements Container
{

View file

@ -26,6 +26,8 @@ use Psr\Log\LoggerInterface;
*
* @see \Friendica\Core\Logger\Factory\StreamLogger
* @see \Friendica\Core\Logger\Factory\SyslogLogger
*
* @internal
*/
final class LegacyLoggerFactory implements LoggerFactory
{

View file

@ -21,6 +21,8 @@ use Psr\Log\NullLogger;
/**
* Manager for the core logging instances
*
* @internal
*/
final class LoggerManager
{

View file

@ -60,7 +60,8 @@ abstract class DI
/**
* Returns a clone of the current dice instance
* This useful for overloading the current instance with mocked methods during tests
*
* @internal This useful for overloading the current instance with mocked methods during tests
*
* @return Dice
*/

View file

@ -362,10 +362,8 @@ class Contact
return [];
}
$background_update = DI::config()->get('system', 'update_active_contacts') ? $contact['local-data'] : true;
// Update the contact in the background if needed
if ($background_update && !self::isLocal($url) && Protocol::supportsProbe($contact['network']) && ($contact['next-update'] < DateTimeFormat::utcNow())) {
if (UpdateContact::isUpdatable($contact['id'])) {
try {
UpdateContact::add(['priority' => Worker::PRIORITY_LOW, 'dont_fork' => true], $contact['id']);
} catch (\InvalidArgumentException $e) {
@ -537,6 +535,17 @@ class Contact
return DBA::exists('account-user-view', ["`pid` = ? AND `uid` != ? AND `rel` IN (?, ?)", $cid, 0, self::SHARING, self::FRIEND]);
}
/**
* Checks if the provided public contact id has got relations with someone on this system
*
* @param integer $cid Public Contact Id
* @return boolean Contact has followers or sharers on this system
*/
public static function hasRelations(int $cid): bool
{
return DBA::exists('account-user-view', ["`pid` = ? AND `uid` != ? AND `rel` IN (?, ?, ?)", $cid, 0, self::FOLLOWER, self::SHARING, self::FRIEND]);
}
/**
* Get the basepath for a given contact link
*
@ -1318,9 +1327,7 @@ class Contact
if (!empty($contact)) {
$contact_id = $contact['id'];
$background_update = DI::config()->get('system', 'update_active_contacts') ? $contact['local-data'] : true;
if ($background_update && !self::isLocal($url) && Protocol::supportsProbe($contact['network']) && ($contact['next-update'] < DateTimeFormat::utcNow())) {
if (UpdateContact::isUpdatable($contact['id'])) {
try {
UpdateContact::add(['priority' => Worker::PRIORITY_LOW, 'dont_fork' => true], $contact['id']);
} catch (\InvalidArgumentException $e) {

View file

@ -805,6 +805,7 @@ class GServer
$gserver = DBA::selectFirst('gserver', ['network'], ['nurl' => Strings::normaliseLink($url)]);
if (!DBA::isResult($gserver)) {
$serverdata['created'] = DateTimeFormat::utcNow();
$ret = self::insert($serverdata);
$id = DBA::lastInsertId();
} else {
@ -984,6 +985,7 @@ class GServer
if (!empty($data['version'])) {
$valid = true;
$serverdata['version'] = $data['version'];
// Version numbers on statistics.json are presented with additional info, e.g.:
// 0.6.3.0-p1702cc1c, 0.6.99.0-p1b9ab160 or 3.4.3-2-1191.
@ -992,11 +994,13 @@ class GServer
if (!empty($data['name'])) {
$valid = true;
$serverdata['site_name'] = $data['name'];
}
if (!empty($data['network'])) {
$valid = true;
$serverdata['platform'] = strtolower($data['network']);
if ($serverdata['platform'] == 'diaspora') {
@ -1012,21 +1016,25 @@ class GServer
if (!empty($data['total_users'])) {
$valid = true;
$serverdata['registered-users'] = max($data['total_users'], 1);
}
if (!empty($data['active_users_monthly'])) {
$valid = true;
$serverdata['active-month-users'] = max($data['active_users_monthly'], 0);
}
if (!empty($data['active_users_halfyear'])) {
$valid = true;
$serverdata['active-halfyear-users'] = max($data['active_users_halfyear'], 0);
}
if (!empty($data['local_posts'])) {
$valid = true;
$serverdata['local-posts'] = max($data['local_posts'], 0);
}
@ -1830,8 +1838,7 @@ class GServer
}
if (!empty($data['totalResults'])) {
$registeredUsers = $serverdata['registered-users'] ?? 0;
$serverdata['registered-users'] = max($data['totalResults'], $registeredUsers, 1);
$serverdata['registered-users'] = max($data['totalResults'], $serverdata['registered-users'] ?? 0, 1);
$serverdata['directory-type'] = self::DT_POCO;
$serverdata['poco'] = $url . '/poco';
}
@ -2016,6 +2023,7 @@ class GServer
$serverdata['platform'] = 'mastodon';
$serverdata['version'] = $data['version'] ?? '';
$serverdata['network'] = Protocol::ACTIVITYPUB;
$valid = true;
}
@ -2026,6 +2034,7 @@ class GServer
if (!empty($data['title']) && empty($serverdata['platform']) && ($serverdata['network'] == Protocol::PHANTOM)) {
$serverdata['platform'] = 'mastodon';
$serverdata['network'] = Protocol::ACTIVITYPUB;
$valid = true;
}
@ -2040,18 +2049,21 @@ class GServer
if (!empty($serverdata['version']) && preg_match('/.*?\(compatible;\s(.*)\s(.*)\)/ism', $serverdata['version'], $matches)) {
$serverdata['platform'] = strtolower($matches[1]);
$serverdata['version'] = $matches[2];
$valid = true;
}
if (!empty($serverdata['version']) && strstr(strtolower($serverdata['version']), 'pleroma')) {
$serverdata['platform'] = 'pleroma';
$serverdata['version'] = trim(str_ireplace('pleroma', '', $serverdata['version']));
$valid = true;
}
if (!empty($serverdata['platform']) && strstr($serverdata['platform'], 'pleroma')) {
$serverdata['version'] = trim(str_ireplace('pleroma', '', $serverdata['platform']));
$serverdata['platform'] = 'pleroma';
$valid = true;
}
@ -2319,12 +2331,14 @@ class GServer
$doc = new DOMDocument();
@$doc->loadHTML($curlResult->getBodyString());
$xpath = new DOMXPath($doc);
$assigned = false;
// We can only detect honk via some HTML element on their page
if ($xpath->query('//div[@id="honksonpage"]')->count() == 1) {
$serverdata['platform'] = 'honk';
$serverdata['network'] = Protocol::ACTIVITYPUB;
$assigned = true;
}
@ -2360,9 +2374,11 @@ class GServer
'twitter:app:name:googleplay', 'twitter:app:name:iphone', 'twitter:app:name:ipad', 'generator'])) {
$platform = str_ireplace(array_keys($platforms), array_values($platforms), $attr['content']);
$platform = str_replace('/', ' ', $platform);
$platform_parts = explode(' ', $platform);
if ((count($platform_parts) >= 2) && in_array(strtolower($platform_parts[0]), array_values($platforms))) {
$platform = $platform_parts[0];
$serverdata['version'] = $platform_parts[1];
}
if (in_array($platform, array_values($grouped_platforms['dfrn_platforms']))) {
@ -2374,6 +2390,7 @@ class GServer
}
if (in_array($platform, array_values($platforms))) {
$serverdata['platform'] = $platform;
$assigned = true;
}
}
@ -2409,6 +2426,7 @@ class GServer
if (in_array($attr['property'], ['og:platform', 'generator'])) {
if (in_array($attr['content'], array_keys($platforms))) {
$serverdata['platform'] = $platforms[$attr['content']];
$assigned = true;
}
@ -2427,6 +2445,7 @@ class GServer
$serverdata['version'] = trim($serverdata['platform'] . ' ' . $serverdata['version']);
$serverdata['platform'] = 'microblog';
$serverdata['network'] = Protocol::ACTIVITYPUB;
$assigned = true;
}
}
@ -2440,6 +2459,7 @@ class GServer
$serverdata['version'] = trim($serverdata['platform'] . ' ' . $serverdata['version']);
$serverdata['platform'] = 'microblog';
$serverdata['network'] = Protocol::ACTIVITYPUB;
$assigned = true;
}
}
@ -2490,10 +2510,6 @@ class GServer
*/
public static function discover()
{
if (!DI::config()->get('system', 'discover_servers')) {
return;
}
// Update the server list
self::discoverFederation();

View file

@ -7,7 +7,6 @@
namespace Friendica\Module\Admin;
use Friendica\App;
use Friendica\Core\Renderer;
use Friendica\Core\Search;
use Friendica\Core\System;
@ -20,7 +19,6 @@ use Friendica\Model\User;
use Friendica\Module\BaseAdmin;
use Friendica\Module\Conversation\Community;
use Friendica\Module\Register;
use Friendica\Navigation\SystemMessages;
use Friendica\Protocol\Relay;
use Friendica\Util\BasePath;
use Friendica\Util\EMailer\MailBuilder;
@ -105,6 +103,7 @@ class Site extends BaseAdmin
$optimize_tables = (!empty($_POST['optimize_tables']) ? intval(trim($_POST['optimize_tables'])) : false);
$contact_discovery = (!empty($_POST['contact_discovery']) ? intval(trim($_POST['contact_discovery'])) : Contact\Relation::DISCOVERY_NONE);
$update_active_contacts = (!empty($_POST['update_active_contacts']) ? intval(trim($_POST['update_active_contacts'])) : false);
$update_known_contacts = (!empty($_POST['update_known_contacts']) ? intval(trim($_POST['update_known_contacts'])) : false);
$synchronize_directory = (!empty($_POST['synchronize_directory']) ? intval(trim($_POST['synchronize_directory'])) : false);
$poco_requery_days = (!empty($_POST['poco_requery_days']) ? intval(trim($_POST['poco_requery_days'])) : 7);
$poco_discovery = (!empty($_POST['poco_discovery']) ? intval(trim($_POST['poco_discovery'])) : false);
@ -141,7 +140,6 @@ class Site extends BaseAdmin
$worker_defer_limit = (!empty($_POST['worker_defer_limit']) ? intval($_POST['worker_defer_limit']) : 15);
$worker_fetch_limit = (!empty($_POST['worker_fetch_limit']) ? intval($_POST['worker_fetch_limit']) : 1);
$relay_directly = !empty($_POST['relay_directly']);
$relay_scope = (!empty($_POST['relay_scope']) ? trim($_POST['relay_scope']) : '');
$relay_server_tags = (!empty($_POST['relay_server_tags']) ? trim($_POST['relay_server_tags']) : '');
@ -178,6 +176,7 @@ class Site extends BaseAdmin
$transactionConfig->set('system', 'optimize_tables', $optimize_tables);
$transactionConfig->set('system', 'contact_discovery', $contact_discovery);
$transactionConfig->set('system', 'update_active_contacts', $update_active_contacts);
$transactionConfig->set('system', 'update_known_contacts', $update_known_contacts);
$transactionConfig->set('system', 'synchronize_directory', $synchronize_directory);
$transactionConfig->set('system', 'poco_requery_days', $poco_requery_days);
$transactionConfig->set('system', 'poco_discovery', $poco_discovery);
@ -546,6 +545,7 @@ class Site extends BaseAdmin
'<li>' . DI::l10n()->t('Interactors - contacts of our local contacts and contacts who interacted on locally visible postings are discovered for their followers/followings.') . '</li></ul>',
$discovery_choices],
'$update_active_contacts' => ['update_active_contacts', DI::l10n()->t('Only update contacts/servers with local data'), DI::config()->get('system', 'update_active_contacts'), DI::l10n()->t('If enabled, the system will only look for changes in contacts and servers that engaged on this system by either being in a contact list of a user or when posts or comments exists from the contact on this system.')],
'$update_known_contacts' => ['update_known_contacts', DI::l10n()->t('Only update contacts with relations'), DI::config()->get('system', 'update_known_contacts'), DI::l10n()->t('If enabled, the system will only look for changes in contacts that are in a contact list of a user on this system.')],
'$synchronize_directory' => ['synchronize_directory', DI::l10n()->t('Synchronize the contacts with the directory server'), DI::config()->get('system', 'synchronize_directory'), DI::l10n()->t('if enabled, the system will check periodically for new contacts on the defined directory server.')],
'$poco_discovery' => ['poco_discovery', DI::l10n()->t('Discover contacts from other servers'), DI::config()->get('system', 'poco_discovery'), DI::l10n()->t('Periodically query other servers for contacts and servers that they know of. The system queries Friendica, Mastodon and Hubzilla servers. Keep it deactivated on small machines to decrease the database size and load.')],

View file

@ -57,11 +57,13 @@ class HTTPSignature
// Decide if $data arrived via controller submission or curl.
$headers = [];
$headers['(request-target)'] = strtolower(DI::args()->getMethod()) . ' ' . $_SERVER['REQUEST_URI'];
foreach ($_SERVER as $k => $v) {
if (strpos($k, 'HTTP_') === 0) {
$field = str_replace('_', '-', strtolower(substr($k, 5)));
$headers[$field] = $v;
}
}
@ -98,6 +100,7 @@ class HTTPSignature
if ($key && function_exists($key)) {
$result['signer'] = $sig_block['keyId'];
$key = $key($sig_block['keyId']);
}
@ -604,13 +607,14 @@ class HTTPSignature
/**
* Gets a signer from a given HTTP request
*
* @param string $content
* @param array $http_headers
* @param string $content Body of the request
* @param array $http_headers array containing the HTTP headers
* @param ?boolean $update true = always update, false = never update, null = update when not found or outdated
*
* @return string|null|false Signer
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function getSigner(string $content, array $http_headers)
public static function getSigner(string $content, array $http_headers, ?bool $update = null)
{
if (empty($http_headers['HTTP_SIGNATURE'])) {
DI::logger()->debug('No HTTP_SIGNATURE header');
@ -630,11 +634,13 @@ class HTTPSignature
}
$headers = [];
$headers['(request-target)'] = strtolower(DI::args()->getMethod()) . ' ' . parse_url($http_headers['REQUEST_URI'], PHP_URL_PATH);
// First take every header
foreach ($http_headers as $k => $v) {
$field = str_replace('_', '-', strtolower($k));
$headers[$field] = $v;
}
@ -642,6 +648,7 @@ class HTTPSignature
foreach ($http_headers as $k => $v) {
if (strpos($k, 'HTTP_') === 0) {
$field = str_replace('_', '-', strtolower(substr($k, 5)));
$headers[$field] = $v;
}
}
@ -700,7 +707,7 @@ class HTTPSignature
return false;
}
$key = self::fetchKey($sig_block['keyId'], $actor);
$key = self::fetchKey($sig_block['keyId'], $actor, $update);
if (empty($key)) {
DI::logger()->info('Empty key');
return false;
@ -802,17 +809,18 @@ class HTTPSignature
/**
* fetches a key for a given id and actor
*
* @param string $id
* @param string $actor
* @param string $id keyId of the signature block
* @param string $actor Actor URI
* @param ?boolean $update true = always update, false = never update, null = update when not found or outdated
*
* @return array with actor url and public key
* @throws \Exception
*/
private static function fetchKey(string $id, string $actor): array
private static function fetchKey(string $id, string $actor, ?bool $update = null): array
{
$url = (strpos($id, '#') ? substr($id, 0, strpos($id, '#')) : $id);
$profile = APContact::getByURL($url);
$profile = APContact::getByURL($url, $update);
if (!empty($profile)) {
DI::logger()->info('Taking key from id', ['id' => $id]);
return ['url' => $url, 'pubkey' => $profile['pubkey'], 'type' => $profile['type']];

View file

@ -7,10 +7,12 @@
namespace Friendica\Worker;
use Friendica\Core\Protocol;
use Friendica\Core\Worker;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Network\HTTPException\InternalServerErrorException;
use Friendica\Util\DateTimeFormat;
class UpdateContact
{
@ -54,4 +56,38 @@ class UpdateContact
DI::logger()->debug('Update contact', ['id' => $contact_id]);
return Worker::add($run_parameters, 'UpdateContact', $contact_id);
}
public static function isUpdatable(int $contact_id): bool
{
$contact = Contact::selectFirst(['next-update', 'local-data', 'url', 'network', 'uid'], ['id' => $contact_id]);
if (empty($contact)) {
return false;
}
if ($contact['next-update'] > DateTimeFormat::utcNow()) {
return false;
}
if (DI::config()->get('system', 'update_known_contacts') && ($contact['uid'] == 0) && !Contact::hasRelations($contact_id)) {
DI::logger()->debug('No local relations, contact will not be updated', ['id' => $contact_id, 'url' => $contact['url'], 'network' => $contact['network']]);
return false;
}
if (DI::config()->get('system', 'update_active_contacts') && $contact['local-data']) {
DI::logger()->debug('No local data, contact will not be updated', ['id' => $contact_id, 'url' => $contact['url'], 'network' => $contact['network']]);
return false;
}
if (Contact::isLocal($contact['url'])) {
DI::logger()->debug('Local contact will not be updated', ['id' => $contact_id, 'url' => $contact['url'], 'network' => $contact['network']]);
return false;
}
if (!Protocol::supportsProbe($contact['network'])) {
DI::logger()->debug('Contact does not support probe, it will not be updated', ['id' => $contact_id, 'url' => $contact['url'], 'network' => $contact['network']]);
return false;
}
return true;
}
}

View file

@ -257,6 +257,10 @@ return [
// When activated, only public contacts will be activated regularly that are used for example in items or tags.
'update_active_contacts' => false,
// update_known_contacts (Boolean)
// When activated, only public contacts will be activated regularly that are in a contact list of a local user.
'update_known_contacts' => false,
// url (String)
// The fully-qualified URL of this Friendica node.
// Used by the worker in a non-HTTP execution environment.

File diff suppressed because it is too large Load diff

View file

@ -112,6 +112,7 @@
<h2>{{$portable_contacts}}</h2>
{{include file="field_select.tpl" field=$contact_discovery}}
{{include file="field_checkbox.tpl" field=$update_active_contacts}}
{{include file="field_checkbox.tpl" field=$update_known_contacts}}
{{include file="field_checkbox.tpl" field=$synchronize_directory}}
{{include file="field_checkbox.tpl" field=$poco_discovery}}
{{include file="field_input.tpl" field=$poco_requery_days}}

View file

@ -228,6 +228,7 @@
<div class="panel-body">
{{include file="field_select.tpl" field=$contact_discovery}}
{{include file="field_checkbox.tpl" field=$update_active_contacts}}
{{include file="field_checkbox.tpl" field=$update_known_contacts}}
{{include file="field_checkbox.tpl" field=$synchronize_directory}}
{{include file="field_checkbox.tpl" field=$poco_discovery}}
{{include file="field_input.tpl" field=$poco_requery_days}}