Merge branch '2020.06-rc' into stable
[friendica.git/.git] / src / Module / BaseAdmin.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
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.
11  *
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.
16  *
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/>.
19  *
20  */
21
22 namespace Friendica\Module;
23
24 use Friendica\BaseModule;
25 use Friendica\Core\Addon;
26 use Friendica\Core\Renderer;
27 use Friendica\Core\Session;
28 use Friendica\DI;
29 use Friendica\Network\HTTPException\ForbiddenException;
30
31 require_once 'boot.php';
32
33 /**
34  * This abstract module is meant to be extended by all modules that are reserved to administrator users.
35  *
36  * It performs a blanket permission check in all the module methods as long as the relevant `parent::method()` is
37  * called in the inheriting module.
38  *
39  * Additionally, it puts together the administration page aside with all the administration links.
40  *
41  * @package Friendica\Module
42  */
43 abstract class BaseAdmin extends BaseModule
44 {
45         public static function post(array $parameters = [])
46         {
47                 if (!is_site_admin()) {
48                         return;
49                 }
50
51                 // do not allow a page manager to access the admin panel at all.
52                 if (!empty($_SESSION['submanage'])) {
53                         return;
54                 }
55         }
56
57         public static function rawContent(array $parameters = [])
58         {
59                 if (!is_site_admin()) {
60                         return '';
61                 }
62
63                 if (!empty($_SESSION['submanage'])) {
64                         return '';
65                 }
66
67                 return '';
68         }
69
70         public static function content(array $parameters = [])
71         {
72                 if (!is_site_admin()) {
73                         notice(DI::l10n()->t('Please login to continue.'));
74                         Session::set('return_path', DI::args()->getQueryString());
75                         DI::baseUrl()->redirect('login');
76                 }
77
78                 if (!empty($_SESSION['submanage'])) {
79                         throw new ForbiddenException(DI::l10n()->t('Submanaged account can\'t access the administation pages. Please log back in as the main account.'));
80                 }
81
82                 // Header stuff
83                 DI::page()['htmlhead'] .= Renderer::replaceMacros(Renderer::getMarkupTemplate('admin/settings_head.tpl'), []);
84
85                 /*
86                  * Side bar links
87                  */
88
89                 // array(url, name, extra css classes)
90                 // not part of $aside to make the template more adjustable
91                 $aside_sub = [
92                         'information' => [DI::l10n()->t('Information'), [
93                                 'overview'     => ['admin'             , DI::l10n()->t('Overview')                , 'overview'],
94                                 'federation'   => ['admin/federation'  , DI::l10n()->t('Federation Statistics')   , 'federation']
95                         ]],
96                         'configuration' => [DI::l10n()->t('Configuration'), [
97                                 'site'         => ['admin/site'        , DI::l10n()->t('Site')                    , 'site'],
98                                 'users'        => ['admin/users'       , DI::l10n()->t('Users')                   , 'users'],
99                                 'addons'       => ['admin/addons'      , DI::l10n()->t('Addons')                  , 'addons'],
100                                 'themes'       => ['admin/themes'      , DI::l10n()->t('Themes')                  , 'themes'],
101                                 'features'     => ['admin/features'    , DI::l10n()->t('Additional features')     , 'features'],
102                                 'tos'          => ['admin/tos'         , DI::l10n()->t('Terms of Service')        , 'tos'],
103                         ]],
104                         'database' => [DI::l10n()->t('Database'), [
105                                 'dbsync'       => ['admin/dbsync'      , DI::l10n()->t('DB updates')              , 'dbsync'],
106                                 'deferred'     => ['admin/queue/deferred', DI::l10n()->t('Inspect Deferred Workers'), 'deferred'],
107                                 'workerqueue'  => ['admin/queue'       , DI::l10n()->t('Inspect worker Queue')    , 'workerqueue'],
108                         ]],
109                         'tools' => [DI::l10n()->t('Tools'), [
110                                 'contactblock' => ['admin/blocklist/contact', DI::l10n()->t('Contact Blocklist')  , 'contactblock'],
111                                 'blocklist'    => ['admin/blocklist/server' , DI::l10n()->t('Server Blocklist')   , 'blocklist'],
112                                 'deleteitem'   => ['admin/item/delete' , DI::l10n()->t('Delete Item')             , 'deleteitem'],
113                         ]],
114                         'logs' => [DI::l10n()->t('Logs'), [
115                                 'logsconfig'   => ['admin/logs/', DI::l10n()->t('Logs')                           , 'logs'],
116                                 'logsview'     => ['admin/logs/view'    , DI::l10n()->t('View Logs')              , 'viewlogs'],
117                         ]],
118                         'diagnostics' => [DI::l10n()->t('Diagnostics'), [
119                                 'phpinfo'      => ['admin/phpinfo'           , DI::l10n()->t('PHP Info')          , 'phpinfo'],
120                                 'probe'        => ['probe'             , DI::l10n()->t('probe address')           , 'probe'],
121                                 'webfinger'    => ['webfinger'         , DI::l10n()->t('check webfinger')         , 'webfinger'],
122                                 'itemsource'   => ['admin/item/source' , DI::l10n()->t('Item Source')             , 'itemsource'],
123                                 'babel'        => ['babel'             , DI::l10n()->t('Babel')                   , 'babel'],
124                         ]],
125                 ];
126
127                 $t = Renderer::getMarkupTemplate('admin/aside.tpl');
128                 DI::page()['aside'] .= Renderer::replaceMacros($t, [
129                         '$admin' => ['addons_admin' => Addon::getAdminList()],
130                         '$subpages' => $aside_sub,
131                         '$admtxt' => DI::l10n()->t('Admin'),
132                         '$plugadmtxt' => DI::l10n()->t('Addon Features'),
133                         '$h_pending' => DI::l10n()->t('User registrations waiting for confirmation'),
134                         '$admurl' => 'admin/'
135                 ]);
136
137                 return '';
138         }
139 }