friendica/src/Module/BaseAdmin.php

140 lines
5.3 KiB
PHP
Raw Normal View History

2019-05-02 06:01:43 +02:00
<?php
2020-02-09 15:45:36 +01:00
/**
* @copyright Copyright (C) 2020, Friendica
*
* @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 06:01:43 +02:00
namespace Friendica\Module;
use Friendica\BaseModule;
use Friendica\Core\Addon;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\DI;
use Friendica\Network\HTTPException\ForbiddenException;
require_once 'boot.php';
2019-05-02 06:01:43 +02: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-23 05:14:14 +01:00
abstract class BaseAdmin extends BaseModule
2019-05-02 06:01:43 +02:00
{
public static function post(array $parameters = [])
2019-05-02 06:01:43 +02:00
{
if (!is_site_admin()) {
return;
}
// do not allow a page manager to access the admin panel at all.
if (!empty($_SESSION['submanage'])) {
return;
}
}
public static function rawContent(array $parameters = [])
2019-05-02 06:01:43 +02:00
{
if (!is_site_admin()) {
return '';
2019-05-02 06:01:43 +02:00
}
if (!empty($_SESSION['submanage'])) {
return '';
2019-05-02 06:01:43 +02:00
}
return '';
}
public static function content(array $parameters = [])
2019-05-02 06:01:43 +02:00
{
if (!is_site_admin()) {
notice(DI::l10n()->t('Please login to continue.'));
Session::set('return_path', DI::args()->getQueryString());
DI::baseUrl()->redirect('login');
2019-05-02 06:01:43 +02:00
}
if (!empty($_SESSION['submanage'])) {
throw new ForbiddenException(DI::l10n()->t('Submanaged account can\'t access the administation pages. Please log back in as the master account.'));
2019-05-02 06:01:43 +02:00
}
// Header stuff
DI::page()['htmlhead'] .= Renderer::replaceMacros(Renderer::getMarkupTemplate('admin/settings_head.tpl'), []);
2019-05-02 06:01:43 +02:00
/*
* Side bar links
*/
// array(url, name, extra css classes)
// not part of $aside to make the template more adjustable
$aside_sub = [
'information' => [DI::l10n()->t('Information'), [
'overview' => ['admin' , DI::l10n()->t('Overview') , 'overview'],
'federation' => ['admin/federation' , DI::l10n()->t('Federation Statistics') , 'federation']
2019-05-02 06:01:43 +02:00
]],
'configuration' => [DI::l10n()->t('Configuration'), [
'site' => ['admin/site' , DI::l10n()->t('Site') , 'site'],
'users' => ['admin/users' , DI::l10n()->t('Users') , 'users'],
'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 06:01:43 +02: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 06:01:43 +02:00
]],
'tools' => [DI::l10n()->t('Tools'), [
'contactblock' => ['admin/blocklist/contact', DI::l10n()->t('Contact Blocklist') , 'contactblock'],
'blocklist' => ['admin/blocklist/server' , DI::l10n()->t('Server Blocklist') , 'blocklist'],
'deleteitem' => ['admin/item/delete' , DI::l10n()->t('Delete Item') , 'deleteitem'],
2019-05-02 06:01:43 +02: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 06:01:43 +02: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'],
'itemsource' => ['admin/item/source' , DI::l10n()->t('Item Source') , 'itemsource'],
'babel' => ['babel' , DI::l10n()->t('Babel') , 'babel'],
2019-05-02 06:01:43 +02:00
]],
];
$t = Renderer::getMarkupTemplate('admin/aside.tpl');
DI::page()['aside'] .= Renderer::replaceMacros($t, [
2019-05-02 06:01:43 +02:00
'$admin' => ['addons_admin' => Addon::getAdminList()],
'$subpages' => $aside_sub,
'$admtxt' => DI::l10n()->t('Admin'),
'$plugadmtxt' => DI::l10n()->t('Addon Features'),
'$h_pending' => DI::l10n()->t('User registrations waiting for confirmation'),
2019-05-02 06:01:43 +02:00
'$admurl' => 'admin/'
]);
return '';
}
}