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\Capabilities\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 if (!empty($blockList) && ($this->config->get('blocklist', 'published') || $this->session->isAuthenticated())) {
99 'title' => $this->t('On this server the following remote servers are blocked.'),
101 $this->t('Blocked domain'),
102 $this->t('Reason for the block'),
104 'download' => $this->t('Download this list in CSV format'),
105 'list' => $blockList,
113 Hook::callAll('about_hook', $hooked);
115 $tpl = Renderer::getMarkupTemplate('friendica.tpl');
117 return Renderer::replaceMacros($tpl, [
118 '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.',
119 '<strong>' . App::VERSION . '</strong>',
121 '<strong>' . $this->config->get('system', 'build') . '/' . DB_UPDATE_VERSION . '</strong>',
122 '<strong>' . $this->keyValue->get('post_update_version') . '/' . PostUpdate::VERSION . '</strong>'),
123 'friendica' => $this->t('Please visit <a href="https://friendi.ca">Friendi.ca</a> to learn more about the Friendica project.'),
124 '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>',
125 'info' => $this->t('Suggestions, praise, etc. - please email "info" at "friendi - dot - ca'),
127 'visible_addons' => $addon,
129 'block_list' => $blocked,
134 protected function rawContent(array $request = [])
136 if (empty($this->parameters['format']) || $this->parameters['format'] !== 'json') {
137 if (!ActivityPub::isRequest()) {
142 $data = ActivityPub\Transmitter::getProfile(0);
143 header('Access-Control-Allow-Origin: *');
144 header('Cache-Control: max-age=23200, stale-while-revalidate=23200');
145 System::jsonExit($data, 'application/activity+json');
146 } catch (HTTPException\NotFoundException $e) {
147 System::jsonError(404, ['error' => 'Record not found']);
151 $register_policies = [
152 Register::CLOSED => 'REGISTER_CLOSED',
153 Register::APPROVE => 'REGISTER_APPROVE',
154 Register::OPEN => 'REGISTER_OPEN'
157 $register_policy_int = $this->config->get('config', 'register_policy');
158 if ($register_policy_int !== Register::CLOSED && $this->config->get('config', 'invitation_only')) {
159 $register_policy = 'REGISTER_INVITATION';
161 $register_policy = $register_policies[$register_policy_int];
165 $administrator = User::getFirstAdmin(['username', 'nickname']);
166 if (!empty($administrator)) {
168 'name' => $administrator['username'],
169 'profile' => $this->baseUrl . '/profile/' . $administrator['nickname'],
173 $visible_addons = Addon::getVisibleList();
175 $this->config->reload();
176 $locked_features = [];
177 $featureLocks = $this->config->get('config', 'feature_lock');
178 if (isset($featureLocks)) {
179 foreach ($featureLocks as $feature => $lock) {
180 if ($feature === 'config_loaded') {
184 $locked_features[$feature] = intval($lock);
189 'version' => App::VERSION,
190 'url' => (string)$this->baseUrl,
191 'addons' => $visible_addons,
192 'locked_features' => $locked_features,
193 'explicit_content' => intval($this->config->get('system', 'explicit_content', 0)),
194 'language' => $this->config->get('system', 'language'),
195 'register_policy' => $register_policy,
197 'site_name' => $this->config->get('config', 'sitename'),
198 'platform' => strtolower(App::PLATFORM),
199 'info' => $this->config->get('config', 'info'),
200 'no_scrape_url' => $this->baseUrl . '/noscrape',
203 System::jsonExit($data);