diff --git a/home.php b/home.php index fb802669..ef69567a 100644 --- a/home.php +++ b/home.php @@ -59,6 +59,11 @@ $settings = $db->getSettings(); @$GLOBALS['panel_language'] = $settings['panel_language']; ogpLang(); +// Apply debug level from panel settings (overrides the DEBUG_LEVEL constant) +if (defined('DEBUG_MODE') && DEBUG_MODE && function_exists('gsp_apply_debug_level')) { + gsp_apply_debug_level((int)($settings['debug_level'] ?? DEBUG_LEVEL)); +} + require_once("includes/view.php"); $view = new OGPView(); $view->setCharset(get_lang('lang_charset')); diff --git a/includes/database_mysqli.php b/includes/database_mysqli.php index 2a2b2886..11f5f068 100644 --- a/includes/database_mysqli.php +++ b/includes/database_mysqli.php @@ -2191,7 +2191,7 @@ class OGPDatabaseMySQL extends OGPDatabase return $this->listQuery($query); } - public function getIpPorts_limit($ip_id = 0,$page_dashboardlist,$limit_dashboardlist) { + public function getIpPorts_limit($ip_id = 0, $page_dashboardlist = 1, $limit_dashboardlist = 25) { $ip_id = $this->realEscapeSingle($ip_id); $user_request_page = ($page_dashboardlist - 1) * $limit_dashboardlist; diff --git a/includes/debug.php b/includes/debug.php index 854d7ea7..0e51970f 100644 --- a/includes/debug.php +++ b/includes/debug.php @@ -3,17 +3,21 @@ * GSP – Global Debug System * ------------------------- * Loaded early in every request (after config.inc.php defines DEBUG_MODE). - * Controlled by the DEBUG_MODE constant. Set to false (or leave undefined) - * in production to disable ALL output and keep standard error suppression. * - * Activation: - * In includes/config.inc.php add: define('DEBUG_MODE', true); - * In production set it to false or remove the line entirely. + * Constants (set in includes/config.inc.php): + * DEBUG_MODE – true/false master switch. + * DEBUG_LEVEL – 0=off, 1=fatal only, 2=errors+warnings, 3=all (default 1) + * + * The panel Settings page exposes a "debug_level" dropdown that overrides + * DEBUG_LEVEL at runtime (applied in home.php after the DB is ready). */ if (!defined('DEBUG_MODE')) { define('DEBUG_MODE', false); } +if (!defined('DEBUG_LEVEL')) { + define('DEBUG_LEVEL', 1); // fatal errors only by default +} if (!DEBUG_MODE) { // Production: suppress all output, only log to server error log @@ -26,14 +30,52 @@ if (!DEBUG_MODE) { // ── Development mode ────────────────────────────────────────────────────────── -error_reporting(E_ALL); ini_set('display_errors', '1'); ini_set('display_startup_errors', '1'); ini_set('log_errors', '1'); +// Apply the initial level from the constant; may be overridden from DB later. +gsp_apply_debug_level(DEBUG_LEVEL); + // Accumulated non-fatal errors collected by the custom handler $GLOBALS['_gsp_debug_errors'] = []; +/** + * Apply an error-reporting level for GSP debug mode. + * + * Level map: + * 0 = off – suppress everything + * 1 = fatal only – E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR + * 2 = errors+warnings – adds E_WARNING, E_USER_ERROR, E_USER_WARNING + * 3 = all – E_ALL + * + * Safe to call multiple times (e.g. once from config, once after DB load). + */ +function gsp_apply_debug_level(int $level): void +{ + switch ($level) { + case 0: + error_reporting(0); + ini_set('display_errors', '0'); + break; + case 1: + error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR | E_RECOVERABLE_ERROR); + ini_set('display_errors', '1'); + break; + case 2: + error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR + | E_RECOVERABLE_ERROR | E_WARNING | E_USER_ERROR | E_USER_WARNING); + ini_set('display_errors', '1'); + break; + case 3: + default: + error_reporting(E_ALL); + ini_set('display_errors', '1'); + break; + } +} + + /** * Custom error handler – captures E_WARNING, E_NOTICE, E_DEPRECATED, etc. * Fatal errors (E_ERROR, E_PARSE …) are handled by the shutdown function. diff --git a/includes/view.php b/includes/view.php index bfb7b0dd..f360ea80 100644 --- a/includes/view.php +++ b/includes/view.php @@ -26,27 +26,29 @@ define("DEFAULT_REFRESH_TIME","2"); class OGPView { - private $meta; - private $title; + private string $meta = ''; + private string $title = 'Open Game Panel'; + private string $header_code = ''; private $refreshTime; private $refreshUrl; + public string $logo = 'home.php?m=dashboard&p=dashboard'; + public string $bg_wrapper = ''; + public string $charset = 'utf-8'; + public string $time_zone = 'America/Chicago'; + function __construct() { ob_start(); - $this->logo = "home.php?m=dashboard&p=dashboard"; - $this->bg_wrapper = ""; - $this->title = "Open Game Panel"; - $this->charset = "utf-8"; $this->refreshTime = DEFAULT_REFRESH_TIME; } function __destruct() { } - - function menu(){} + function menu(){} + function printView($cleared = false, $dataType = "html") { global $db, $OGPLangPre; @@ -134,9 +136,9 @@ class OGPView { { $global_js_file = 'js/' . MODULES . "{$m['folder']}_global.js"; if(is_readable($path . $global_js_file)) // Priority to the theme's js - $javascript .= "\n"; + $javascript .= "\n"; elseif(is_readable($global_js_file)) - $javascript .= "\n"; + $javascript .= "\n"; } } @@ -145,15 +147,15 @@ class OGPView { { $subpage = (isset($_GET['p']) and !empty($_GET['p']))?$_GET['p']:$_GET['m']; $fc = array( - $path . MODULES . "{$_GET['m']}/${subpage}.css", + $path . MODULES . "{$_GET['m']}/{$subpage}.css", $path . MODULES . "{$_GET['m']}/{$_GET['m']}.css", - MODULES . "{$_GET['m']}/${subpage}.css", + MODULES . "{$_GET['m']}/{$subpage}.css", MODULES . "{$_GET['m']}/{$_GET['m']}.css" ); foreach ((array)$fc as $file_check){ if(is_readable($file_check)){ - $stylesheet .= "\n"; + $stylesheet .= "\n"; break; } } @@ -165,7 +167,7 @@ class OGPView { foreach ((array)$fc as $file_check){ if(is_readable($file_check)){ - $javascript .= "\n"; + $javascript .= "\n"; break; } } diff --git a/index.php b/index.php index e4d5fb90..69e69721 100644 --- a/index.php +++ b/index.php @@ -76,6 +76,11 @@ $settings = $db->getSettings(); @$GLOBALS['panel_language'] = $settings['panel_language']; ogpLang(); +// Apply debug level from panel settings (overrides the DEBUG_LEVEL constant) +if (defined('DEBUG_MODE') && DEBUG_MODE && function_exists('gsp_apply_debug_level')) { + gsp_apply_debug_level((int)($settings['debug_level'] ?? DEBUG_LEVEL)); +} + require_once("includes/view.php"); $view = new OGPView(); $view->setCharset( get_lang('lang_charset') ); diff --git a/lang/English/modules/settings.php b/lang/English/modules/settings.php index 8a4b2480..0b7a61b3 100644 --- a/lang/English/modules/settings.php +++ b/lang/English/modules/settings.php @@ -145,4 +145,11 @@ define('OGP_LANG_reset_game_server_order', "Reset Game Server Ordering"); define('OGP_LANG_reset_game_server_order_info', "Resets game server ordering back to the default of using the server ID"); + +// Debug level +define('OGP_LANG_debug_level', "Panel Debug Level"); +define('OGP_LANG_debug_off', "Off (production)"); +define('OGP_LANG_debug_fatal_only', "Fatal errors only (page-breaking)"); +define('OGP_LANG_debug_errors_warnings', "Errors & Warnings"); +define('OGP_LANG_debug_all', "All (verbose - E_ALL)"); ?> diff --git a/modules/mysql/mysqli_database.php b/modules/mysql/mysqli_database.php index ed1dd3a8..34290755 100644 --- a/modules/mysql/mysqli_database.php +++ b/modules/mysql/mysqli_database.php @@ -35,7 +35,7 @@ class MySQLModuleDatabase extends OGPDatabaseMySQL parent::__destruct(); } - public function connect($db_host, $db_user, $db_pass, $db_name, $table_prefix = NULL) { + public function connect($db_host, $db_user, $db_pass, $db_name, $table_prefix = NULL, $db_port = NULL) { if ( !extension_loaded("mysqli") ) return -99; diff --git a/modules/settings/settings.php b/modules/settings/settings.php index 84f201ea..a495ca7d 100644 --- a/modules/settings/settings.php +++ b/modules/settings/settings.php @@ -76,7 +76,9 @@ function exec_ogp_module() // Discord Integration "discord_invite_url" => $_REQUEST['discord_invite_url'], "discord_webhook_main" => $_REQUEST['discord_webhook_main'], - "discord_webhook_admin" => $_REQUEST['discord_webhook_admin'] + "discord_webhook_admin" => $_REQUEST['discord_webhook_admin'], + // Debug + "debug_level" => $_REQUEST['debug_level'] ?? '1' ); $db->setSettings($settings); @@ -201,6 +203,16 @@ function exec_ogp_module() $ft->add_field('string','discord_webhook_main',@$row['discord_webhook_main']); $ft->add_field('string','discord_webhook_admin',@$row['discord_webhook_admin']); + // Debug level + $debug_level_options = array( + '0' => get_lang('debug_off'), + '1' => get_lang('debug_fatal_only'), + '2' => get_lang('debug_errors_warnings'), + '3' => get_lang('debug_all'), + ); + $ft->add_custom_field('debug_level', + create_drop_box_from_array($debug_level_options, 'debug_level', @$row['debug_level'] ?? '1', false)); + // Add option to reset game server order to default $ft->add_field('checkbox','reset_game_server_order','0');