diff --git a/ajax.php b/ajax.php index 3d5d522a0..d78beb3d2 100644 --- a/ajax.php +++ b/ajax.php @@ -13,21 +13,11 @@ define('IN_AJAX', true); require __DIR__ . '/common.php'; $ajax = new TorrentPier\Legacy\Ajax(); - $ajax->init(); // Init userdata $user->session_start(); -// Exit if board is disabled via ON/OFF trigger or by admin -if ($ajax->action != 'manage_admin') { - if ($bb_cfg['board_disable']) { - $ajax->ajax_die($lang['BOARD_DISABLE']); - } elseif (file_exists(BB_DISABLED)) { - $ajax->ajax_die($lang['BOARD_DISABLE_CRON']); - } -} - // Load actions required modules switch ($ajax->action) { case 'view_post': @@ -45,9 +35,6 @@ switch ($ajax->action) { break; } -// Position in $ajax->valid_actions['xxx'] -define('AJAX_AUTH', 0); // 'guest', 'user', 'mod', 'admin', 'super_admin' - $ajax->exec(); /** diff --git a/src/Legacy/Ajax.php b/src/Legacy/Ajax.php index 501f40b42..a674a7151 100644 --- a/src/Legacy/Ajax.php +++ b/src/Legacy/Ajax.php @@ -19,13 +19,13 @@ class Ajax public $response = []; public $valid_actions = [ - // ACTION NAME AJAX_AUTH + // ACTION NAME => [AJAX_AUTH, IN_ADMIN_CP (optional)] 'edit_user_profile' => ['admin'], 'change_user_rank' => ['admin'], 'change_user_opt' => ['admin'], 'manage_user' => ['admin'], - 'manage_admin' => ['admin'], - 'sitemap' => ['admin'], + 'manage_admin' => ['admin', true], + 'sitemap' => ['admin', true], 'mod_action' => ['mod'], 'topic_tpl' => ['mod'], @@ -61,7 +61,7 @@ class Ajax */ public function exec() { - global $lang; + global $lang, $bb_cfg; // Exit if we already have errors if (!empty($this->response['error_code'])) { @@ -71,14 +71,26 @@ class Ajax // Check that requested action is valid $action = $this->action; + // Action params + $action_params = null; + if (!$action || !\is_string($action)) { $this->ajax_die('no action specified'); } elseif (!$action_params =& $this->valid_actions[$action]) { $this->ajax_die('invalid action: ' . $action); } + // Exit if board is disabled via ON/OFF trigger or by admin + if ($action_params[1] !== true) { + if ($bb_cfg['board_disable']) { + $this->ajax_die($lang['BOARD_DISABLE']); + } elseif (file_exists(BB_DISABLED)) { + $this->ajax_die($lang['BOARD_DISABLE_CRON']); + } + } + // Auth check - switch ($action_params[AJAX_AUTH]) { + switch ($action_params[0]) { // GUEST case 'guest': break;