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;
24 use Friendica\BaseModule;
25 use Friendica\Core\Addon;
26 use Friendica\Core\Renderer;
28 use Friendica\Network\HTTPException;
31 * This abstract module is meant to be extended by all modules that are reserved to administrator users.
33 * It performs a blanket permission check in all the module methods as long as the relevant `parent::method()` is
34 * called in the inheriting module.
36 * Additionally, it puts together the administration page aside with all the administration links.
38 * @package Friendica\Module
40 abstract class BaseAdmin extends BaseModule
43 * Checks admin access and throws exceptions if not logged-in administrator
45 * @param bool $interactive
47 * @throws HTTPException\ForbiddenException
48 * @throws HTTPException\InternalServerErrorException
50 public static function checkAdminAccess(bool $interactive = false)
52 if (!DI::userSession()->getLocalUserId()) {
54 DI::sysmsg()->addNotice(DI::l10n()->t('Please login to continue.'));
55 DI::session()->set('return_path', DI::args()->getQueryString());
56 DI::baseUrl()->redirect('login');
58 throw new HTTPException\UnauthorizedException(DI::l10n()->t('Please login to continue.'));
62 if (!DI::app()->isSiteAdmin()) {
63 throw new HTTPException\ForbiddenException(DI::l10n()->t('You don\'t have access to administration pages.'));
66 if (DI::userSession()->getSubManagedUserId()) {
67 throw new HTTPException\ForbiddenException(DI::l10n()->t('Submanaged account can\'t access the administration pages. Please log back in as the main account.'));
71 protected function content(array $request = []): string
73 self::checkAdminAccess(true);
76 DI::page()['htmlhead'] .= Renderer::replaceMacros(Renderer::getMarkupTemplate('admin/settings_head.tpl'), []);
82 // array(url, name, extra css classes)
83 // not part of $aside to make the template more adjustable
85 'information' => [DI::l10n()->t('Information'), [
86 'overview' => ['admin' , DI::l10n()->t('Overview') , 'overview'],
87 'federation' => ['admin/federation' , DI::l10n()->t('Federation Statistics') , 'federation']
89 'configuration' => [DI::l10n()->t('Configuration'), [
90 'site' => ['admin/site' , DI::l10n()->t('Site') , 'site'],
91 'storage' => ['admin/storage' , DI::l10n()->t('Storage') , 'storage'],
92 'addons' => ['admin/addons' , DI::l10n()->t('Addons') , 'addons'],
93 'themes' => ['admin/themes' , DI::l10n()->t('Themes') , 'themes'],
94 'features' => ['admin/features' , DI::l10n()->t('Additional features') , 'features'],
95 'tos' => ['admin/tos' , DI::l10n()->t('Terms of Service') , 'tos'],
97 'database' => [DI::l10n()->t('Database'), [
98 'dbsync' => ['admin/dbsync' , DI::l10n()->t('DB updates') , 'dbsync'],
99 'deferred' => ['admin/queue/deferred', DI::l10n()->t('Inspect Deferred Workers'), 'deferred'],
100 'workerqueue' => ['admin/queue' , DI::l10n()->t('Inspect worker Queue') , 'workerqueue'],
102 'logs' => [DI::l10n()->t('Logs'), [
103 'logsconfig' => ['admin/logs/', DI::l10n()->t('Logs') , 'logs'],
104 'logsview' => ['admin/logs/view' , DI::l10n()->t('View Logs') , 'viewlogs'],
106 'diagnostics' => [DI::l10n()->t('Diagnostics'), [
107 'phpinfo' => ['admin/phpinfo' , DI::l10n()->t('PHP Info') , 'phpinfo'],
108 'probe' => ['probe' , DI::l10n()->t('probe address') , 'probe'],
109 'webfinger' => ['webfinger' , DI::l10n()->t('check webfinger') , 'webfinger'],
110 'babel' => ['babel' , DI::l10n()->t('Babel') , 'babel'],
111 'debug/ap' => ['debug/ap' , DI::l10n()->t('ActivityPub Conversion') , 'debug/ap'],
115 $t = Renderer::getMarkupTemplate('admin/aside.tpl');
116 DI::page()['aside'] .= Renderer::replaceMacros($t, [
117 '$admin' => ['addons_admin' => Addon::getAdminList()],
118 '$subpages' => $aside_sub,
119 '$admtxt' => DI::l10n()->t('Admin'),
120 '$plugadmtxt' => DI::l10n()->t('Addon Features'),
121 '$h_pending' => DI::l10n()->t('User registrations waiting for confirmation'),
122 '$admurl' => 'admin/'