Bugfix in admin area: Requesting a non-existant panel will not result in error message any more. Instead: Redirection to main panel.

This commit is contained in:
azett 2021-02-24 18:37:26 +01:00
parent 8ddd5a448f
commit 25eacf6ccc

View File

@ -1,60 +1,55 @@
<?php <?php
// aggiungere nuovo protocollo per template
include (ADMIN_DIR . 'panels/admin.defaultpanels.php');
include (ADMIN_DIR . 'includes/panels.prototypes.php');
require (SMARTY_DIR . 'SmartyValidate.class.php');
// aggiungere nuovo protocollo per template utils_nocache_headers();
define('MOD_ADMIN_PANEL', 1);
include(ADMIN_DIR.'panels/admin.defaultpanels.php'); function wp_nonce_ays() {
include(ADMIN_DIR.'includes/panels.prototypes.php');
require(SMARTY_DIR . 'SmartyValidate.class.php');
utils_nocache_headers();
define('MOD_ADMIN_PANEL',1);
function wp_nonce_ays() {
die('We apologize, an error occurred.'); die('We apologize, an error occurred.');
} }
/* /*
function admin_is_user_loggedin() { * function admin_is_user_loggedin() {
return ($u=user_loggedin()) && utils_checkreferer() ; * return ($u=user_loggedin()) && utils_checkreferer() ;
} * }
*/ */
function main() {
function main() {
// general setup // general setup
global $panel, $action, $lang, $smarty, $fp_admin, $fp_admin_action; global $panel, $action, $lang, $smarty, $fp_admin, $fp_admin_action;
$panels = admin_getpanels(); $panels = admin_getpanels();
$panel = (isset($_GET['p']))? $_GET['p'] : $panels[0]; $panel = (isset($_GET ['p'])) ? $_GET ['p'] : $panels [0];
define('ADMIN_PANEL', $panel); define('ADMIN_PANEL', $panel);
$smarty->assign('panel', $panel); $smarty->assign('panel', $panel);
if (!admin_panelexists($panel)) // redirect to admin main page if requested panel does not exist
trigger_error('Requested panel does not exists!', E_USER_ERROR); if (!admin_panelexists($panel)) {
// will lead to login if not logged in already
utils_redirect("admin.php");
die();
}
$panelprefix = "admin.$panel"; $panelprefix = "admin.$panel";
$panelpath = ADMIN_DIR."panels/$panel/$panelprefix.php"; $panelpath = ADMIN_DIR . "panels/$panel/$panelprefix.php";
$fp_admin = null; $fp_admin = null;
if (file_exists($panelpath)) { if (file_exists($panelpath)) {
include($panelpath); include ($panelpath);
$panelclass = "admin_$panel"; $panelclass = "admin_$panel";
if (!class_exists($panelclass)) if (!class_exists($panelclass))
trigger_error("No class defined for requested panel", E_USER_ERROR); trigger_error("No class defined for requested panel", E_USER_ERROR);
$fp_admin = new $panelclass($smarty); $fp_admin = new $panelclass($smarty);
} }
/* check if user is loggedin */ /* check if user is loggedin */
@ -64,14 +59,12 @@
die(); die();
} }
$action = isset($_GET ['action']) ? $_GET ['action'] : 'default';
$action = isset($_GET['action'])? $_GET['action'] : 'default';
if (!$fp_admin) if (!$fp_admin)
return; return;
$fp_admin_action = $fp_admin->get_action($action); $fp_admin_action = $fp_admin->get_action($action);
define('ADMIN_PANEL_ACTION', $action); define('ADMIN_PANEL_ACTION', $action);
$smarty->assign('action', $action); $smarty->assign('action', $action);
$panel_url = BLOG_BASEURL . "admin.php?p={$panel}"; $panel_url = BLOG_BASEURL . "admin.php?p={$panel}";
@ -79,13 +72,9 @@
$smarty->assign('panel_url', $panel_url); $smarty->assign('panel_url', $panel_url);
$smarty->assign('action_url', $action_url); $smarty->assign('action_url', $action_url);
if (!empty($_POST)) if (!empty($_POST))
check_admin_referer("admin_{$panel}_{$action}"); check_admin_referer("admin_{$panel}_{$action}");
$smarty->assign('success', sess_remove("success_{$panel}")); $smarty->assign('success', sess_remove("success_{$panel}"));
$retval = $fp_admin_action->exec(); $retval = $fp_admin_action->exec();
@ -96,119 +85,102 @@
$smarty->get_template_vars('success'); $smarty->get_template_vars('success');
$to_action = $retval > 1 ? ('&action=' . $action) : ''; $to_action = $retval > 1 ? ('&action=' . $action) : '';
$with_mod = isset($_GET['mod'])? ('&mod=' . $_GET['mod']) : ''; $with_mod = isset($_GET ['mod']) ? ('&mod=' . $_GET ['mod']) : '';
$with_arguments = ''; $with_arguments = '';
if ($retval == PANEL_REDIRECT_CURRENT) { if ($retval == PANEL_REDIRECT_CURRENT) {
foreach ($fp_admin_action->args as $mandatory_argument) { foreach ($fp_admin_action->args as $mandatory_argument) {
$with_arguments .= '&' . $mandatory_argument . $with_arguments .= '&' . $mandatory_argument . '=' . $_REQUEST [$mandatory_argument];
'=' . $_REQUEST[$mandatory_argument];
} }
} }
$url = "admin.php?p={$panel}{$to_action}{$with_mod}{$with_arguments}"; $url = "admin.php?p={$panel}{$to_action}{$with_mod}{$with_arguments}";
utils_redirect($url); utils_redirect($url);
} }
$smarty->register_modifier('action_link', 'admin_filter_action'); $smarty->register_modifier('action_link', 'admin_filter_action');
$smarty->register_modifier('cmd_link', 'admin_filter_command'); $smarty->register_modifier('cmd_link', 'admin_filter_command');
}
} // smarty tag
function admin_filter_action($string, $action) {
// smarty tag if (strpos($string, '?') === false)
function admin_filter_action($string, $action) {
if (strpos($string, '?')===false)
return $string .= "?action={$action}"; return $string .= "?action={$action}";
else else
return $string .= wp_specialchars("&action={$action}"); return $string .= wp_specialchars("&action={$action}");
} }
// smarty tag
function admin_filter_command($string, $cmd, $val) {
// smarty tag
function admin_filter_command($string, $cmd, $val) {
global $panel, $action; global $panel, $action;
$arg = $cmd? "&{$cmd}" : $cmd; $arg = $cmd ? "&{$cmd}" : $cmd;
return wp_nonce_url("{$string}{$arg}={$val}", "admin_{$panel}_{$action}_{$cmd}_{$val}"); return wp_nonce_url("{$string}{$arg}={$val}", "admin_{$panel}_{$action}_{$cmd}_{$val}");
}
} function admin_panelstrings($panelprefix) {
function admin_panelstrings($panelprefix) {
global $lang, $smarty; global $lang, $smarty;
lang_load('admin'); lang_load('admin');
lang_load($panelprefix); lang_load($panelprefix);
$smarty->assign('subject', $lang['admin']['head']); $smarty->assign('subject', $lang ['admin'] ['head']);
$smarty->assign('menubar', admin_getpanels()); $smarty->assign('menubar', admin_getpanels());
add_filter('wp_title', 'admin_panel_title', 10, 2); add_filter('wp_title', 'admin_panel_title', 10, 2);
} }
function admin_panel_title($title, $sep) {
function admin_panel_title($title, $sep) {
global $lang, $panel; global $lang, $panel;
$t = @$lang['admin']['panels'][$panel]; $t = @$lang ['admin'] ['panels'] [$panel];
$title = "$title $sep $t"; $title = "$title $sep $t";
return $title; return $title;
} }
function showcontrolpanel($params, &$smarty) {
$smarty->display(ABS_PATH . ADMIN_DIR . 'main.tpl');
}
// html header
function showcontrolpanel($params, &$smarty) { function admin_title($title, $sep) {
$smarty->display(ABS_PATH. ADMIN_DIR . 'main.tpl');
}
// html header
function admin_title($title, $sep) {
global $lang; global $lang;
return $title = "$title $sep {$lang['admin']['head']}"; return $title = "$title $sep {$lang['admin']['head']}";
} }
add_filter('wp_title', 'admin_title', 10, 2); add_filter('wp_title', 'admin_title', 10, 2);
// setup admin_header
// setup admin_header function admin_header_default_action() {
function admin_header_default_action() {
global $panel, $action; global $panel, $action;
do_action("admin_{$panel}_{$action}_head"); do_action("admin_{$panel}_{$action}_head");
} }
add_filter('admin_head', 'admin_header_default_action'); add_filter('admin_head', 'admin_header_default_action');
$fp_config = config_load();
system_init();
main();
admin_panelstrings('admin.' . ADMIN_PANEL);
theme_init($smarty);
$smarty->register_function('controlpanel', 'showcontrolpanel');
$fp_config = config_load(); $v = $lang ['admin'] [$panel] [$action];
system_init();
main();
admin_panelstrings('admin.'.ADMIN_PANEL);
theme_init($smarty);
$smarty->register_function('controlpanel', 'showcontrolpanel');
$v = $lang['admin'][$panel][$action]; $smarty->assign_by_ref('panelstrings', $v);
$smarty->assign_by_ref('plang', $v);
if (isset($_GET ['mod'])) {
$smarty->assign_by_ref('panelstrings', $v); switch ($_GET ['mod']) {
$smarty->assign_by_ref('plang', $v); case 'inline':
if (isset($_GET['mod'])) {
switch ($_GET['mod']) {
case 'inline' :
$smarty->display(ABS_PATH . ADMIN_DIR . 'admin-inline.tpl'); $smarty->display(ABS_PATH . ADMIN_DIR . 'admin-inline.tpl');
break; break;
case 'ajax' : case 'ajax':
echo $smarty->get_template_vars('success'); echo $smarty->get_template_vars('success');
} }
} else {
} else {
$smarty->display('admin.tpl'); $smarty->display('admin.tpl');
} }
?> ?>