mirror of
https://github.com/wavelog/wavelog.git
synced 2026-03-22 10:24:14 +00:00
ability to use log_message and read the logfile during installation
This commit is contained in:
@@ -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);
|
||||
}
|
||||
@@ -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';
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
<!DOCTYPE html>
|
||||
<html lang="<?= $language; ?>">
|
||||
|
||||
<script>
|
||||
function log_message(level, message) {
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: 'index.php',
|
||||
data: {
|
||||
write_to_logfile: 1,
|
||||
log_level: level,
|
||||
log_message: message
|
||||
},
|
||||
success: function(response) {
|
||||
},
|
||||
error: function(error) {
|
||||
console.error("log_message (js) failed: ".error);
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
5
install/log/debug.log
Normal file
5
install/log/debug.log
Normal file
@@ -0,0 +1,5 @@
|
||||
|
||||
Wavelog Installer - Debug Log
|
||||
|
||||
---
|
||||
|
||||
@@ -39,6 +39,16 @@
|
||||
<p><?= sprintf(__("All install steps went through. Redirect to user login in %s seconds..."), "<span id='countdown'>4</span>"); ?></p>
|
||||
</div>
|
||||
<div id="error_message"></div>
|
||||
<div class="container mt-5">
|
||||
<button id="toggleLogButton" class="btn btn-sm btn-secondary mb-3"><?= __("Show detailled debug log"); ?></button>
|
||||
<div id="logContainer">
|
||||
<pre>
|
||||
<code id="debuglog">
|
||||
<!-- Log Content -->
|
||||
</code>
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -49,6 +59,7 @@
|
||||
let _POST = <?php echo json_encode($_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("<?= __("Show detailled debug log"); ?>");
|
||||
} else {
|
||||
$('#toggleLogButton').text("<?= __("Hide detailled debug log"); ?>");
|
||||
}
|
||||
});
|
||||
|
||||
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) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user