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