3 * @copyright Copyright (C) 2010-2023, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Module;
25 use Friendica\BaseModule;
26 use Friendica\Core\Addon;
27 use Friendica\Core\Config\Capability\IManageConfigValues;
28 use Friendica\Core\Hook;
29 use Friendica\Core\KeyValueStorage\Capability\IManageKeyValuePairs;
30 use Friendica\Core\L10n;
31 use Friendica\Core\Renderer;
32 use Friendica\Core\Session\Capability\IHandleUserSessions;
33 use Friendica\Core\System;
34 use Friendica\Database\PostUpdate;
35 use Friendica\Model\User;
36 use Friendica\Network\HTTPException;
37 use Friendica\Protocol\ActivityPub;
38 use Friendica\Util\Profiler;
39 use Psr\Log\LoggerInterface;
42 * Prints information about the current node
43 * Either in human-readable form or in JSON
45 class Friendica extends BaseModule
47 /** @var IManageConfigValues */
49 /** @var IManageKeyValuePairs */
51 /** @var IHandleUserSessions */
54 public function __construct(IHandleUserSessions $session, IManageKeyValuePairs $keyValue, IManageConfigValues $config, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
56 parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
58 $this->config = $config;
59 $this->keyValue = $keyValue;
60 $this->session = $session;
63 protected function content(array $request = []): string
65 $visibleAddonList = Addon::getVisibleList();
66 if (!empty($visibleAddonList)) {
68 $sorted = $visibleAddonList;
71 $sortedAddonList = '';
73 foreach ($sorted as $addon) {
75 if (strlen($sortedAddonList)) {
76 $sortedAddonList .= ', ';
78 $sortedAddonList .= $addon;
82 'title' => $this->t('Installed addons/apps:'),
83 'list' => $sortedAddonList,
87 'title' => $this->t('No installed addons/apps'),
91 $tos = ($this->config->get('system', 'tosdisplay')) ?
92 $this->t('Read about the <a href="%1$s/tos">Terms of Service</a> of this node.', $this->baseUrl) :
95 $blockList = $this->config->get('system', 'blocklist') ?? [];
97 $register_policy_int = $this->config->get('config', 'register_policy');
98 if (!empty($blockList) && ($register_policy_int !== Register::CLOSED || $this->session->isAuthenticated())) {
100 'title' => $this->t('On this server the following remote servers are blocked.'),
102 $this->t('Blocked domain'),
103 $this->t('Reason for the block'),
105 'download' => $this->t('Download this list in CSV format'),
106 'list' => $blockList,
114 Hook::callAll('about_hook', $hooked);
116 $tpl = Renderer::getMarkupTemplate('friendica.tpl');
118 return Renderer::replaceMacros($tpl, [
119 'about' => $this->t('This is Friendica, version %s that is running at the web location %s. The database version is %s, the post update version is %s.',
120 '<strong>' . App::VERSION . '</strong>',
122 '<strong>' . $this->config->get('system', 'build') . '/' . DB_UPDATE_VERSION . '</strong>',
123 '<strong>' . $this->keyValue->get('post_update_version') . '/' . PostUpdate::VERSION . '</strong>'),
124 'friendica' => $this->t('Please visit <a href="https://friendi.ca">Friendi.ca</a> to learn more about the Friendica project.'),
125 'bugs' => $this->t('Bug reports and issues: please visit') . ' ' . '<a href="https://github.com/friendica/friendica/issues?state=open">' . $this->t('the bugtracker at github') . '</a>',
126 'info' => $this->t('Suggestions, praise, etc. - please email "info" at "friendi - dot - ca'),
128 'visible_addons' => $addon,
130 'block_list' => $blocked,
135 protected function rawContent(array $request = [])
137 if (empty($this->parameters['format']) || $this->parameters['format'] !== 'json') {
138 if (!ActivityPub::isRequest()) {
143 $data = ActivityPub\Transmitter::getProfile(0);
144 header('Access-Control-Allow-Origin: *');
145 header('Cache-Control: max-age=23200, stale-while-revalidate=23200');
146 System::jsonExit($data, 'application/activity+json');
147 } catch (HTTPException\NotFoundException $e) {
148 System::jsonError(404, ['error' => 'Record not found']);
152 $register_policies = [
153 Register::CLOSED => 'REGISTER_CLOSED',
154 Register::APPROVE => 'REGISTER_APPROVE',
155 Register::OPEN => 'REGISTER_OPEN'
158 $register_policy_int = $this->config->get('config', 'register_policy');
159 if ($register_policy_int !== Register::CLOSED && $this->config->get('config', 'invitation_only')) {
160 $register_policy = 'REGISTER_INVITATION';
162 $register_policy = $register_policies[$register_policy_int];
166 $administrator = User::getFirstAdmin(['username', 'nickname']);
167 if (!empty($administrator)) {
169 'name' => $administrator['username'],
170 'profile' => $this->baseUrl . '/profile/' . $administrator['nickname'],
174 $visible_addons = Addon::getVisibleList();
176 $this->config->reload();
177 $locked_features = [];
178 $featureLocks = $this->config->get('config', 'feature_lock');
179 if (isset($featureLocks)) {
180 foreach ($featureLocks as $feature => $lock) {
181 if ($feature === 'config_loaded') {
185 $locked_features[$feature] = intval($lock);
190 'version' => App::VERSION,
191 'url' => (string)$this->baseUrl,
192 'addons' => $visible_addons,
193 'locked_features' => $locked_features,
194 'explicit_content' => intval($this->config->get('system', 'explicit_content', 0)),
195 'language' => $this->config->get('system', 'language'),
196 'register_policy' => $register_policy,
198 'site_name' => $this->config->get('config', 'sitename'),
199 'platform' => strtolower(App::PLATFORM),
200 'info' => $this->config->get('config', 'info'),
201 'no_scrape_url' => $this->baseUrl . '/noscrape',
204 System::jsonExit($data);