3 * @copyright Copyright (C) 2010-2021, 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;
24 use Friendica\BaseModule;
25 use Friendica\Core\Addon;
26 use Friendica\Core\Hook;
27 use Friendica\Core\Renderer;
28 use Friendica\Core\System;
29 use Friendica\Database\PostUpdate;
31 use Friendica\Model\User;
32 use Friendica\Network\HTTPException;
33 use Friendica\Network\HTTPException\ImATeapotException;
34 use Friendica\Protocol\ActivityPub;
37 * Prints information about the current node
38 * Either in human readable form or in JSON
40 class Friendica extends BaseModule
42 public static function content(array $parameters = [])
44 $config = DI::config();
46 $visibleAddonList = Addon::getVisibleList();
47 if (!empty($visibleAddonList)) {
49 $sorted = $visibleAddonList;
52 $sortedAddonList = '';
54 foreach ($sorted as $addon) {
56 if (strlen($sortedAddonList)) {
57 $sortedAddonList .= ', ';
59 $sortedAddonList .= $addon;
63 'title' => DI::l10n()->t('Installed addons/apps:'),
64 'list' => $sortedAddonList,
68 'title' => DI::l10n()->t('No installed addons/apps'),
72 $tos = ($config->get('system', 'tosdisplay')) ?
73 DI::l10n()->t('Read about the <a href="%1$s/tos">Terms of Service</a> of this node.', DI::baseUrl()->get()) :
76 $blockList = $config->get('system', 'blocklist');
78 if (!empty($blockList)) {
80 'title' => DI::l10n()->t('On this server the following remote servers are blocked.'),
82 DI::l10n()->t('Blocked domain'),
83 DI::l10n()->t('Reason for the block'),
93 Hook::callAll('about_hook', $hooked);
95 $tpl = Renderer::getMarkupTemplate('friendica.tpl');
97 return Renderer::replaceMacros($tpl, [
98 'about' => DI::l10n()->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.',
99 '<strong>' . FRIENDICA_VERSION . '</strong>',
100 DI::baseUrl()->get(),
101 '<strong>' . DB_UPDATE_VERSION . '/' . $config->get('system', 'build') .'</strong>',
102 '<strong>' . PostUpdate::VERSION . '/' . $config->get('system', 'post_update_version') . '</strong>'),
103 'friendica' => DI::l10n()->t('Please visit <a href="https://friendi.ca">Friendi.ca</a> to learn more about the Friendica project.'),
104 'bugs' => DI::l10n()->t('Bug reports and issues: please visit') . ' ' . '<a href="https://github.com/friendica/friendica/issues?state=open">' . DI::l10n()->t('the bugtracker at github') . '</a>',
105 'info' => DI::l10n()->t('Suggestions, praise, etc. - please email "info" at "friendi - dot - ca'),
107 'visible_addons' => $addon,
109 'block_list' => $blocked,
114 public static function rawContent(array $parameters = [])
116 if (ActivityPub::isRequest()) {
118 $data = ActivityPub\Transmitter::getProfile(0);
119 header('Access-Control-Allow-Origin: *');
120 header('Cache-Control: max-age=23200, stale-while-revalidate=23200');
121 System::jsonExit($data, 'application/activity+json');
122 } catch (HTTPException\NotFoundException $e) {
123 System::jsonError(404, ['error' => 'Record not found']);
127 // @TODO: Replace with parameter from router
128 if (DI::args()->getArgc() <= 1 || (DI::args()->getArgv()[1] !== 'json')) {
132 $config = DI::config();
134 $register_policies = [
135 Register::CLOSED => 'REGISTER_CLOSED',
136 Register::APPROVE => 'REGISTER_APPROVE',
137 Register::OPEN => 'REGISTER_OPEN'
140 $register_policy_int = intval($config->get('config', 'register_policy'));
141 if ($register_policy_int !== Register::CLOSED && $config->get('config', 'invitation_only')) {
142 $register_policy = 'REGISTER_INVITATION';
144 $register_policy = $register_policies[$register_policy_int];
148 $administrator = User::getFirstAdmin(['username', 'nickname']);
149 if (!empty($administrator)) {
151 'name' => $administrator['username'],
152 'profile' => DI::baseUrl()->get() . '/profile/' . $administrator['nickname'],
156 $visible_addons = Addon::getVisibleList();
158 $config->load('feature_lock');
159 $locked_features = [];
160 $featureLocks = $config->get('config', 'feature_lock');
161 if (isset($featureLocks)) {
162 foreach ($featureLocks as $feature => $lock) {
163 if ($feature === 'config_loaded') {
167 $locked_features[$feature] = intval($lock);
172 'version' => FRIENDICA_VERSION,
173 'url' => DI::baseUrl()->get(),
174 'addons' => $visible_addons,
175 'locked_features' => $locked_features,
176 'explicit_content' => intval($config->get('system', 'explicit_content', 0)),
177 'language' => $config->get('system', 'language'),
178 'register_policy' => $register_policy,
180 'site_name' => $config->get('config', 'sitename'),
181 'platform' => strtolower(FRIENDICA_PLATFORM),
182 'info' => $config->get('config', 'info'),
183 'no_scrape_url' => DI::baseUrl()->get() . '/noscrape',
186 header('Content-type: application/json; charset=utf-8');
187 echo json_encode($data);