From c3673d3bcf4eef3fab2b6c7ff12fee6501080a67 Mon Sep 17 00:00:00 2001 From: Hani Rouatbi Date: Tue, 17 Jan 2023 12:58:25 +0100 Subject: [PATCH] Add custom admin feature --- go.php | 4 ++-- includes/common.php | 29 ++++++++++++++++++++++++----- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/go.php b/go.php index f4c5dd4..36a5071 100755 --- a/go.php +++ b/go.php @@ -573,7 +573,7 @@ switch ($current_go_case) { delete_cache('data_stats'); $text = $title = sprintf($lang['SYNCING_DONE'], $lang['ALL_FILES']); - $link_to_go = './admin/?cp=r_repair#!cp=r_repair'; + $link_to_go = './'.$customadminpath.'/?cp=r_repair#!cp=r_repair'; } else { @@ -604,7 +604,7 @@ switch ($current_go_case) { delete_cache('data_stats'); $text = $title = sprintf($lang['SYNCING_DONE'], $lang['ALL_IMAGES']) . ' (' . (! $start ? 0 : $start) . '->' . (! $end ? '?' : $end) . ')'; - $link_to_go = './admin/?cp=r_repair#!cp=r_repair'; + $link_to_go = './'.$customadminpath.'/?cp=r_repair#!cp=r_repair'; } else { diff --git a/includes/common.php b/includes/common.php index 2a7a533..5092e4f 100755 --- a/includes/common.php +++ b/includes/common.php @@ -47,6 +47,7 @@ if (! file_exists(PATH . KLEEJA_CONFIG_FILE)) //there is a config require_once PATH . KLEEJA_CONFIG_FILE; +$customadminpath = $customadminpath ?? 'admin'; //admin files path @@ -191,6 +192,24 @@ include PATH . 'includes/FetchFile.php'; if (defined('IN_ADMIN')) { + $currentDirectoryPath = dirname($_SERVER['PHP_SELF']); + $currentDirectoryPathParts = explode('/', $currentDirectoryPath); + $currentDir = array_pop($currentDirectoryPathParts); + $adminDirErrorMsg = ''; + if ($customadminpath == 'admin' && $currentDir != $customadminpath) { + $adminDirErrorMsg = 'You are trying to access the admin area through a directory that is not configured. Please either revert to the default admin directory name, or see our documentation for customizing the admin directory.'; + } else { + if ($currentDir != $customadminpath) { + $adminDirErrorMsg = 'You are trying to access the admin area through a directory different from the one configured. Please refer to the Customize Administrator\'s Guide documentation for instructions on how to update it.'; + } else { + if ($customadminpath != 'admin' && is_dir(PATH . 'admin')) { + $adminDirErrorMsg = 'You are trying to access the admin area through a custom directory, but we also detected that there is a default directory \'admin\'. This may indicate that files from a recent update were uploaded to the default admin path location instead of the custom location, resulting in these files becoming outdated. Please make sure your custom admin folder contains the latest files, and delete the default admin directory to continue.'; + } + } + } + if ($adminDirErrorMsg) { + kleeja_show_error('', 'Critical Error', $adminDirErrorMsg); + } include PATH . 'includes/functions_adm.php'; } @@ -239,7 +258,7 @@ $config = array_merge($config, (array) $d_groups[$usrcp->group_id()]['configs']) //admin path -define('ADMIN_PATH', rtrim($config['siteurl'], '/') . '/admin/index.php'); +define('ADMIN_PATH', rtrim($config['siteurl'], '/') . '/'. $customadminpath .'/index.php'); //no tpl caching in dev stage @@ -330,10 +349,10 @@ define('ACP_STYLE_NAME', 'Masmak'); $STYLE_PATH = $config['siteurl'] . 'styles/' . (trim($config['style_depend_on']) == '' ? $config['style'] : $config['style_depend_on']) . '/'; $THIS_STYLE_PATH = $config['siteurl'] . 'styles/' . $config['style'] . '/'; $THIS_STYLE_PATH_ABS = PATH . 'styles/' . $config['style'] . '/'; -$STYLE_PATH_ADMIN = $config['siteurl'] . 'admin/' . (is_browser('mobile') || defined('IN_MOBILE') ? ACP_STYLE_NAME : ACP_STYLE_NAME) . '/'; -$STYLE_PATH_ADMIN_ABS = PATH . 'admin/' . (is_browser('mobile') || defined('IN_MOBILE') ? ACP_STYLE_NAME . '/' : ACP_STYLE_NAME . '/'); -$DEFAULT_PATH_ADMIN_ABS = PATH . 'admin/' . ACP_STYLE_NAME . '/'; -$DEFAULT_PATH_ADMIN = $config['siteurl'] . 'admin/' . ACP_STYLE_NAME . '/'; +$STYLE_PATH_ADMIN = $config['siteurl'] . $customadminpath . '/' . (is_browser('mobile') || defined('IN_MOBILE') ? ACP_STYLE_NAME : ACP_STYLE_NAME) . '/'; +$STYLE_PATH_ADMIN_ABS = PATH . $customadminpath . '/' . (is_browser('mobile') || defined('IN_MOBILE') ? ACP_STYLE_NAME . '/' : ACP_STYLE_NAME . '/'); +$DEFAULT_PATH_ADMIN_ABS = PATH . $customadminpath . '/' . ACP_STYLE_NAME . '/'; +$DEFAULT_PATH_ADMIN = $config['siteurl'] . $customadminpath . '/' . ACP_STYLE_NAME . '/'; //get languge of common