log messages

This commit is contained in:
HB9HIL
2024-07-22 15:09:07 +02:00
parent ed59ce9b02
commit 3f40c62be3
10 changed files with 124 additions and 27 deletions

3
.gitignore vendored
View File

@@ -1,6 +1,6 @@
/application/config/database.php
/application/config/config.php
/application/logs/*.php
/application/logs/*
/application/cache/*
/uploads
/uploads/*.adi
@@ -8,7 +8,6 @@
/uploads/*.tq8
/uploads/*.TQ8
/install/.lock
/install/log/debug.log
/updates/*.xml
/updates/*.html
/images/eqsl_card_images/*.jpg

17
install/ajax.php Normal file
View File

@@ -0,0 +1,17 @@
<?php
// Target for Ajax Calls
require_once('includes/install_config/install_lib.php');
require_once('includes/install_config/install_config.php');
require_once('includes/gettext/gettext.php');
require_once('includes/gettext/gettext_conf.php');
require_once('includes/core/core_class.php');
require_once('includes/core/database_class.php');
$core = new Core();
$database = new Database();
require_once('includes/interface_assets/triggers.php');

View File

@@ -96,6 +96,7 @@ class Core
if ($counter == '13') {
return true;
} else {
log_message('error', 'Failed to validate POST data');
return false;
}
}

View File

@@ -14,7 +14,7 @@ $db_file_path = $db_config_path . "database.php";
// Logfile Path
global $logfile;
$logfile = '../install/log/debug.log';
$logfile = '../application/logs/installer_debug.log';
// Wanted Pre-Check Parameters
// PHP

View File

@@ -63,7 +63,7 @@ function verify_log() {
if (!file_exists($logfile)) {
if (touch($logfile)) {
if(is_writable($logfile)) {
$log_header = "Wavelog Installer Debug Log\n-------\n\n";
$log_header = "Wavelog Installer Debug Log\n-------\nLog Location: $logfile\n\n";
file_put_contents($logfile, $log_header, FILE_APPEND);
return true;
} else {

View File

@@ -59,6 +59,8 @@ $language = $_COOKIE[$gt_conf['lang_cookie']];
// and set the locale for gettext
T_setlocale(LC_MESSAGES, $language);
$websiteurl = $http_scheme . '://' . str_replace("index.php", "", $_SERVER['HTTP_HOST'] . str_replace("/install/", "", $_SERVER['REQUEST_URI'])) . '/';
?>
<!DOCTYPE html>
<html lang="<?= $language; ?>">
@@ -67,7 +69,7 @@ T_setlocale(LC_MESSAGES, $language);
function log_message(level, message) {
$.ajax({
type: 'POST',
url: 'index.php',
url: 'ajax.php',
data: {
write_to_logfile: 1,
log_level: level,

View File

@@ -42,8 +42,20 @@ if ($_POST['write_to_logfile'] ?? false == true) {
*
*/
// config_file()
if ($_POST['check_lockfile'] ?? false == true) {
$lockfile = '../install/.lock';
if (file_exists($lockfile)) {
$result = 'installer_locked';
} else {
$result = 'no_lockfile';
}
echo $result;
exit;
}
// config_file()
if ($_POST['run_config_file'] ?? false == true) {
sleep(1);
$data = $_POST['data'];

View File

@@ -323,7 +323,7 @@ if (!file_exists('.lock')) {
</div>
<div class="mb-3 position-relative">
<label for="websiteurl" class="form-label required"><?= __("Website URL"); ?></label><i id="websiteurl_tooltip" data-bs-toggle="tooltip" data-bs-placement="top" class="fas fa-question-circle text-muted ms-2" data-bs-custom-class="custom-tooltip" data-bs-html="true" data-bs-title="<?= sprintf(__("This is the complete URL where your Wavelog Instance will be available. If you run this installer locally but want to place Wavelog behind a Reverse Proxy with SSL you should type in the new URL here (e.g. %s instead of %s). Don't forget to include the directory from above."), "https://mywavelog.example.org/", "http://192.168.1.100/"); ?>"></i>
<input type="text" id="websiteurl" value="<?php echo $http_scheme; ?>://<?php echo str_replace("index.php", "", $_SERVER['HTTP_HOST'] . str_replace("/install/", "", $_SERVER['REQUEST_URI'])) . '/'; ?>" class="form-control" name="websiteurl" />
<input type="text" id="websiteurl" value="<?php echo $websiteurl; ?>" class="form-control" name="websiteurl" />
<div class="invalid-tooltip">
<?= __("This field can't be empty and have to end with a slash 'example/'!"); ?>
</div>
@@ -1605,7 +1605,8 @@ if (!file_exists('.lock')) {
<?php } else {
header("Location: " . strtok($_SERVER['REQUEST_URI'], 'install'));
header("Location: $websiteurl");
} ?>
</html>

View File

View File

@@ -38,6 +38,9 @@
<div class="mb-3" id="success_message" style="display: none;">
<p><?= sprintf(__("All install steps went through. Redirect to user login in %s seconds..."), "<span id='countdown'>4</span>"); ?></p>
</div>
<div class="mb-3" id="success_button" style="display: none;">
<a class="btn btn-primary" href="<?php echo $_POST['websiteurl'] ?? $websiteurl."index.php/user/login/1"; ?>"><?= __("Done. Go to the user login ->"); ?></a>
</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>
@@ -61,6 +64,8 @@
$(document).ready(async function() {
init_read_log();
try {
await check_lockfile();
await config_file();
await database_file();
await database_tables();
@@ -68,19 +73,24 @@
await update_dxcc();
await installer_lock();
// after all install steps went through we can show a success message and redirect to the user/login
$("#success_message").show();
if($('#logContainer').css('display') == 'none') {
// after all install steps went through we can show a success message and redirect to the user/login
$("#success_message").show();
// Initialize the countdown
var countdown = 4;
var countdownInterval = setInterval(function() {
countdown--;
$("#countdown").text(countdown);
if (countdown <= 0) {
clearInterval(countdownInterval);
window.location.href = _POST.websiteurl + "index.php/user/login/1";
}
}, 1000);
// Initialize the countdown
var countdown = 4;
var countdownInterval = setInterval(function() {
countdown--;
$("#countdown").text(countdown);
if (countdown <= 0) {
clearInterval(countdownInterval);
window.location.href = _POST.websiteurl + "index.php/user/login/1";
}
}, 1000);
} else {
// after all install steps went through we can show the redirect button
$("#success_button").show();
}
} catch (error) {
$("#error_message").text("Installation failed: " + error).show();
}
@@ -90,7 +100,7 @@
setInterval(function() {
$.ajax({
type: 'POST',
url: 'index.php',
url: 'ajax.php',
data: {
read_logfile: 1
},
@@ -112,16 +122,48 @@
}
});
// if a user goes back to the installer we need to redirect him
async function check_lockfile() {
log_message('error', "Attention! Installer was called again. Let's check for a lockfile.");
return new Promise((resolve, reject) => {
$.ajax({
type: 'POST',
url: 'ajax.php',
data: {
check_lockfile: 1
},
success: function(response) {
if (response != 'installer_locked') {
log_message('debug', "Seems like there is no .lock file. Let's try to run the installer again.");
resolve();
} else {
log_message('error', 'Installer is locked. Redirect to user/login.');
reject(response);
window.location.href = "<?php echo str_replace('run.php', '', $websiteurl); ?>" + "index.php/user/login";
}
},
error: function(error) {
log_message('error', "Install Lock Check wen't wrong...");
reject(error);
window.location.href = "<?php echo str_replace('run.php', '', $websiteurl); ?>" + "index.php/user/login";
}
});
});
}
async function config_file() {
var field = '#config_file';
running(field, true);
log_message('debug', 'Start writing config.php');
return new Promise((resolve, reject) => {
$.ajax({
type: 'POST',
url: 'index.php',
url: 'ajax.php',
data: {
data: _POST,
run_config_file: 1
@@ -129,13 +171,16 @@
success: function(response) {
if (response == 'success') {
running(field, false);
log_message('debug', 'File: config.php successfully written');
resolve();
} else {
running(field, false, true);
log_message('error', 'File: Could not write file. Check Permissions.');
reject("<?= __("Could not create application/config/config.php"); ?>");
}
},
error: function(error) {
log_message('error', 'File: Could not write file. Ajax failed.');
running(field, false, true);
reject(error);
}
@@ -148,11 +193,12 @@
var field = '#database_file';
running(field, true);
log_message('debug', 'Start writing database.php');
return new Promise((resolve, reject) => {
$.ajax({
type: 'POST',
url: 'index.php',
url: 'ajax.php',
data: {
data: _POST,
run_database_file: 1
@@ -160,13 +206,16 @@
success: function(response) {
if (response == 'success') {
running(field, false);
log_message('debug', 'File: database.php successfully written');
resolve();
} else {
running(field, false, true);
log_message('error', 'File: Could not write file. Check Permissions.');
reject("<?= __("Could not create application/config/database.php"); ?>");
}
},
error: function(error) {
log_message('error', 'File: Could not write file. Ajax failed.');
running(field, false, true);
reject(error);
}
@@ -178,26 +227,30 @@
var field = '#database_tables';
running(field, true);
log_message('debug', 'Start creating database structure with assets/install.sql');
return new Promise((resolve, reject) => {
$.ajax({
type: 'POST',
url: 'index.php',
url: 'ajax.php',
data: {
data: _POST,
run_database_tables: 1
},
success: function(response) {
if (response == 'success') {
log_message('debug', 'Tables successfully created');
running(field, false);
resolve();
} else {
running(field, false, true);
log_message('error', 'Creating database tables from assets/install.sql failed.');
reject("<?= __("Could not create database tables"); ?>");
}
},
error: function(error) {
running(field, false, true);
log_message('error', 'Creating database tables failed. Ajax crashed.');
reject(error);
}
});
@@ -208,21 +261,25 @@
var field = '#database_migrations';
running(field, true);
log_message('debug', 'Start migrating database to the newest version.');
return new Promise((resolve, reject) => {
$.ajax({
url: "<?php echo $_POST['websiteurl']; ?>" + "index.php/migrate",
url: "<?php echo $_POST['websiteurl'] ?? $websiteurl; ?>" + "index.php/migrate",
success: function(response) {
if (response == 'success') {
running(field, false);
log_message('debug', 'Database successfully created.');
resolve();
} else {
running(field, false, true);
log_message('error', 'Could not migrate database.');
reject("<?= __("Could not run database migrations"); ?>");
}
},
error: function(error) {
running(field, false, true);
log_message('error', 'Could not migrate database. Ajax crashed.');
reject(error);
}
});
@@ -236,20 +293,24 @@
if(_POST.skip_dxcc_update == 0) {
running(field, true);
log_message('debug', 'Start updating DXCC database. This can take a moment or two... Please wait');
$.ajax({
url: "<?php echo $_POST['websiteurl']; ?>" + "index.php/update/dxcc",
url: "<?php echo $_POST['websiteurl'] ?? $websiteurl; ?>" + "index.php/update/dxcc",
success: function(response) {
if (response == 'success') {
running(field, false);
log_message('debug', 'Successfully update DXCC database');
resolve();
} else {
running(field, false, true);
log_message('error', 'Could not update DXCC data.');
reject("<?= __("Could not update DXCC data"); ?>");
}
},
error: function(error) {
running(field, false, true);
log_message('error', 'Could not update DXCC data. Ajax crashed.');
reject(error);
}
});
@@ -262,26 +323,30 @@
async function installer_lock() {
var field = '#installer_lock';
log_message('debug', 'Try to create .lock file for the installer');
running(field, true);
return new Promise((resolve, reject) => {
$.ajax({
type: 'POST',
url: 'index.php',
url: 'ajax.php',
data: {
run_installer_lock: 1
},
success: function(response) {
if (response == 'success') {
running(field, false);
log_message('debug', 'Successfully created .lock file in folder /install');
resolve();
} else {
running(field, false, true);
log_message('error', 'Could not create .lock file.');
reject("<?= __("Could not create install/.lock file"); ?>");
}
},
error: function(error) {
running(field, false, true);
log_message('error', 'Could not create .lock file. Ajax crashed');
reject(error);
}
});