2019-05-02 00:01:43 -04:00
< ? php
2020-02-09 09:45:36 -05:00
/**
2023-01-01 09:36:24 -05:00
* @ copyright Copyright ( C ) 2010 - 2023 , the Friendica project
2020-02-09 09:45:36 -05:00
*
* @ license GNU AGPL version 3 or any later version
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation , either version 3 of the
* License , or ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU Affero General Public License for more details .
*
* You should have received a copy of the GNU Affero General Public License
* along with this program . If not , see < https :// www . gnu . org / licenses />.
*
*/
2019-05-02 00:01:43 -04:00
namespace Friendica\Module ;
use Friendica\BaseModule ;
use Friendica\Core\Addon ;
use Friendica\Core\Renderer ;
2019-12-15 16:34:11 -05:00
use Friendica\DI ;
2020-09-08 10:44:27 -04:00
use Friendica\Network\HTTPException ;
2019-05-31 00:16:07 -04:00
2019-05-02 00:01:43 -04:00
/**
* This abstract module is meant to be extended by all modules that are reserved to administrator users .
*
* It performs a blanket permission check in all the module methods as long as the relevant `parent::method()` is
* called in the inheriting module .
*
* Additionally , it puts together the administration page aside with all the administration links .
*
* @ package Friendica\Module
*/
2020-01-22 23:14:14 -05:00
abstract class BaseAdmin extends BaseModule
2019-05-02 00:01:43 -04:00
{
2020-09-08 10:44:27 -04:00
/**
2022-06-21 23:03:30 -04:00
* Checks admin access and throws exceptions if not logged - in administrator
*
2020-09-08 10:44:27 -04:00
* @ param bool $interactive
2022-06-21 23:03:30 -04:00
* @ return void
2020-09-08 10:44:27 -04:00
* @ throws HTTPException\ForbiddenException
* @ throws HTTPException\InternalServerErrorException
*/
public static function checkAdminAccess ( bool $interactive = false )
2019-05-02 00:01:43 -04:00
{
2022-10-20 16:59:12 -04:00
if ( ! DI :: userSession () -> getLocalUserId ()) {
2020-09-08 10:44:27 -04:00
if ( $interactive ) {
2022-10-17 14:55:22 -04:00
DI :: sysmsg () -> addNotice ( DI :: l10n () -> t ( 'Please login to continue.' ));
2022-10-19 09:00:43 -04:00
DI :: session () -> set ( 'return_path' , DI :: args () -> getQueryString ());
2020-09-08 10:44:27 -04:00
DI :: baseUrl () -> redirect ( 'login' );
} else {
throw new HTTPException\UnauthorizedException ( DI :: l10n () -> t ( 'Please login to continue.' ));
}
2019-05-02 00:01:43 -04:00
}
2021-11-04 16:29:59 -04:00
if ( ! DI :: app () -> isSiteAdmin ()) {
2020-09-08 10:44:27 -04:00
throw new HTTPException\ForbiddenException ( DI :: l10n () -> t ( 'You don\'t have access to administration pages.' ));
2019-05-02 00:01:43 -04:00
}
2022-10-21 13:33:28 -04:00
if ( DI :: userSession () -> getSubManagedUserId ()) {
2020-09-15 09:38:31 -04:00
throw new HTTPException\ForbiddenException ( DI :: l10n () -> t ( 'Submanaged account can\'t access the administration pages. Please log back in as the main account.' ));
2019-05-02 00:01:43 -04:00
}
}
2021-11-20 09:38:03 -05:00
protected function content ( array $request = []) : string
2019-05-02 00:01:43 -04:00
{
2020-09-08 10:44:27 -04:00
self :: checkAdminAccess ( true );
2019-05-02 00:01:43 -04:00
// Header stuff
2019-12-30 14:02:09 -05:00
DI :: page ()[ 'htmlhead' ] .= Renderer :: replaceMacros ( Renderer :: getMarkupTemplate ( 'admin/settings_head.tpl' ), []);
2019-05-02 00:01:43 -04:00
/*
* Side bar links
*/
// array(url, name, extra css classes)
// not part of $aside to make the template more adjustable
$aside_sub = [
2020-01-18 14:52:34 -05:00
'information' => [ DI :: l10n () -> t ( 'Information' ), [
'overview' => [ 'admin' , DI :: l10n () -> t ( 'Overview' ) , 'overview' ],
'federation' => [ 'admin/federation' , DI :: l10n () -> t ( 'Federation Statistics' ) , 'federation' ]
2019-05-02 00:01:43 -04:00
]],
2020-01-18 14:52:34 -05:00
'configuration' => [ DI :: l10n () -> t ( 'Configuration' ), [
'site' => [ 'admin/site' , DI :: l10n () -> t ( 'Site' ) , 'site' ],
2021-07-18 16:09:11 -04:00
'storage' => [ 'admin/storage' , DI :: l10n () -> t ( 'Storage' ) , 'storage' ],
2020-01-18 14:52:34 -05:00
'addons' => [ 'admin/addons' , DI :: l10n () -> t ( 'Addons' ) , 'addons' ],
'themes' => [ 'admin/themes' , DI :: l10n () -> t ( 'Themes' ) , 'themes' ],
'features' => [ 'admin/features' , DI :: l10n () -> t ( 'Additional features' ) , 'features' ],
'tos' => [ 'admin/tos' , DI :: l10n () -> t ( 'Terms of Service' ) , 'tos' ],
2019-05-02 00:01:43 -04:00
]],
2020-01-18 14:52:34 -05:00
'database' => [ DI :: l10n () -> t ( 'Database' ), [
'dbsync' => [ 'admin/dbsync' , DI :: l10n () -> t ( 'DB updates' ) , 'dbsync' ],
'deferred' => [ 'admin/queue/deferred' , DI :: l10n () -> t ( 'Inspect Deferred Workers' ), 'deferred' ],
'workerqueue' => [ 'admin/queue' , DI :: l10n () -> t ( 'Inspect worker Queue' ) , 'workerqueue' ],
2019-05-02 00:01:43 -04:00
]],
2020-01-18 14:52:34 -05:00
'logs' => [ DI :: l10n () -> t ( 'Logs' ), [
'logsconfig' => [ 'admin/logs/' , DI :: l10n () -> t ( 'Logs' ) , 'logs' ],
'logsview' => [ 'admin/logs/view' , DI :: l10n () -> t ( 'View Logs' ) , 'viewlogs' ],
2019-05-02 00:01:43 -04:00
]],
2020-01-18 14:52:34 -05:00
'diagnostics' => [ DI :: l10n () -> t ( 'Diagnostics' ), [
'phpinfo' => [ 'admin/phpinfo' , DI :: l10n () -> t ( 'PHP Info' ) , 'phpinfo' ],
'probe' => [ 'probe' , DI :: l10n () -> t ( 'probe address' ) , 'probe' ],
'webfinger' => [ 'webfinger' , DI :: l10n () -> t ( 'check webfinger' ) , 'webfinger' ],
'babel' => [ 'babel' , DI :: l10n () -> t ( 'Babel' ) , 'babel' ],
2020-07-20 00:39:17 -04:00
'debug/ap' => [ 'debug/ap' , DI :: l10n () -> t ( 'ActivityPub Conversion' ) , 'debug/ap' ],
2019-05-02 00:01:43 -04:00
]],
];
$t = Renderer :: getMarkupTemplate ( 'admin/aside.tpl' );
2019-12-30 14:02:09 -05:00
DI :: page ()[ 'aside' ] .= Renderer :: replaceMacros ( $t , [
2019-05-02 00:01:43 -04:00
'$admin' => [ 'addons_admin' => Addon :: getAdminList ()],
'$subpages' => $aside_sub ,
2020-01-18 14:52:34 -05:00
'$admtxt' => DI :: l10n () -> t ( 'Admin' ),
'$plugadmtxt' => DI :: l10n () -> t ( 'Addon Features' ),
'$h_pending' => DI :: l10n () -> t ( 'User registrations waiting for confirmation' ),
2019-05-02 00:01:43 -04:00
'$admurl' => 'admin/'
]);
return '' ;
}
}