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