diff --git a/install/assets/css/installer.css b/install/assets/css/installer.css index d6334cc37..466f65557 100644 --- a/install/assets/css/installer.css +++ b/install/assets/css/installer.css @@ -219,4 +219,17 @@ div.alert-danger { .required-prefix:before { content: "* "; color: red; +} + +#logContainer { + display: none; + padding: 10px; + font-family: "Courier New", Courier, monospace; + font-size: 14px; + color: #a4a4a4; + white-space: pre-wrap; + text-align: left; + font-style: italic; + background-color: #1a1a1a; + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); } \ No newline at end of file diff --git a/install/includes/install_config/install_config.php b/install/includes/install_config/install_config.php index 83d8d24e5..c8e8a8064 100644 --- a/install/includes/install_config/install_config.php +++ b/install/includes/install_config/install_config.php @@ -12,6 +12,10 @@ if (isset($_ENV['CI_ENV'])) { } $db_file_path = $db_config_path . "database.php"; +// Logfile Path +global $logfile; +$logfile = '../install/log/debug.log'; + // Wanted Pre-Check Parameters // PHP $min_php_version = '7.4.0'; diff --git a/install/includes/install_config/install_lib.php b/install/includes/install_config/install_lib.php index b514a5e64..14a1701be 100644 --- a/install/includes/install_config/install_lib.php +++ b/install/includes/install_config/install_lib.php @@ -30,6 +30,7 @@ function is_really_writable($path) { // Check if the folder exists if (!file_exists($path)) { + log_message('error', 'is_really_writable(): File "'.$path.'" does not exist.'); return false; } @@ -49,8 +50,31 @@ function is_really_writable($path) { return true; } } catch (Exception $e) { + log_message('error', 'is_really_writable(): Something went wrong while testing write permissions.'); return false; } return false; } + +// Function to read the debug logfile +function read_logfile() { + global $logfile; + $file_content = file_get_contents($logfile); + echo $file_content; +} + +// Function to log messages in the installer logfile +function log_message($level, $message) { + global $logfile; + $level = strtoupper($level); + $timestamp = date("Y-m-d H:i:s"); + $logMessage = $level . " - " . $timestamp . " --> " . $message . PHP_EOL; + file_put_contents($logfile, $logMessage, FILE_APPEND); +} + +// Custom error handler +function customError($errno, $errstr, $errfile, $errline) { + $message = "[$errno] $errstr in $errfile on line $errline"; + log_message('error', $message); +} \ No newline at end of file diff --git a/install/includes/interface_assets/header.php b/install/includes/interface_assets/header.php index fb324102f..0e2a7efa5 100644 --- a/install/includes/interface_assets/header.php +++ b/install/includes/interface_assets/header.php @@ -18,6 +18,10 @@ $database = new Database(); include('includes/interface_assets/triggers.php'); +// Configure PHP to log errors +set_error_handler("customError"); +ini_set('error_reporting', E_ALL); + /** * Gettext Implementation */ @@ -31,14 +35,21 @@ $languages = $gt_conf['languages']; // if we come with a get call we can switch the language cookie if (isset($_GET['lang'])) { switch_lang($_GET['lang']); + log_message('info', 'Manually switched language to "'.find_by('gettext',$_GET['lang'])['name_en'].'"'); header("Location: " . strtok($_SERVER['REQUEST_URI'], '?')); exit(); } // get the browsers language if no cookie exists and set one if (!isset($_COOKIE[$gt_conf['lang_cookie']])) { + + log_message('info', 'Called Installer index.php'); + log_message('info', 'With URL: '.$http_scheme.'://'. $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . '/'); + log_message('info', 'From IP: '. $_SERVER['REMOTE_ADDR']); + $browser_language = _get_client_language(); setcookie($gt_conf['lang_cookie'], $browser_language['gettext']); + log_message('info', 'Set language cookie to "'.$browser_language['name_en'].'"'); header("Location: " . $_SERVER['REQUEST_URI']); exit(); } @@ -52,6 +63,25 @@ T_setlocale(LC_MESSAGES, $language); + + diff --git a/install/includes/interface_assets/triggers.php b/install/includes/interface_assets/triggers.php index b88e32df8..4832228dd 100644 --- a/install/includes/interface_assets/triggers.php +++ b/install/includes/interface_assets/triggers.php @@ -13,6 +13,29 @@ if ($_POST['database_check'] ?? false == true) { } +if ($_POST['read_logfile'] ?? false == true) { + + $result = read_logfile(); + echo $result; + exit; + +} + +if ($_POST['write_to_logfile'] ?? false == true) { + + $level = $_POST['log_level']; + $message = $_POST['log_message']; + + if(log_message($level, $message)) { + $result = 'success'; + } else { + $result = 'error'; + } + echo $result; + exit; + +} + /** * * Install Triggers diff --git a/install/log/debug.log b/install/log/debug.log new file mode 100644 index 000000000..a41952345 --- /dev/null +++ b/install/log/debug.log @@ -0,0 +1,5 @@ + +Wavelog Installer - Debug Log + +--- + diff --git a/install/run.php b/install/run.php index bf13ce796..9ce9f164b 100644 --- a/install/run.php +++ b/install/run.php @@ -39,6 +39,16 @@

4"); ?>

+
+ +
+
+                            
+                                
+                            
+                        
+
+
@@ -49,6 +59,7 @@ let _POST = ; $(document).ready(async function() { + init_read_log(); try { await config_file(); await database_file(); @@ -75,6 +86,32 @@ } }); + function init_read_log() { + setInterval(function() { + $.ajax({ + type: 'POST', + url: 'index.php', + data: { + read_logfile: 1 + }, + success: function(response) { + $("#debuglog").text(response); + } + }); + }, 500); + } + + $('#toggleLogButton').on('click', function() { + var logContainer = $('#logContainer'); + logContainer.toggle(); + console.log(logContainer.css('display')); + if(logContainer.css('display') == 'none') { + $('#toggleLogButton').text(""); + } else { + $('#toggleLogButton').text(""); + } + }); + async function config_file() { var field = '#config_file'; @@ -194,7 +231,7 @@ async function update_dxcc() { var field = '#update_dxcc'; - + return new Promise((resolve, reject) => { if(_POST.skip_dxcc_update == 0) {