From 54b55c0f5871e064e27e164b5f540e9cbefb4d4b Mon Sep 17 00:00:00 2001 From: 1Day Date: Tue, 8 Feb 2022 08:13:13 +0100 Subject: [PATCH] installer: Better logging --- public/install/forms.php | 17 ++++++++++------- public/install/functions.php | 13 +++++++++++++ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/public/install/forms.php b/public/install/forms.php index 8b6dbf01..4434c33a 100644 --- a/public/install/forms.php +++ b/public/install/forms.php @@ -29,6 +29,7 @@ if (isset($_POST['checkDB'])) { $db = new mysqli($_POST["databasehost"], $_POST["databaseuser"], $_POST["databaseuserpass"], $_POST["database"], $_POST["databaseport"]); if ($db->connect_error) { + wh_log($db->connect_error); header("LOCATION: index.php?step=2&message=Could not connect to the Database"); die(); } @@ -78,14 +79,12 @@ if (isset($_POST['feedDB'])) { } $logs .= run_console('php artisan storage:link'); - $logsfile = fopen("logs.txt", "w") or die("Unable to open file!"); - fwrite($logsfile, $logs); - fclose($logsfile); + wh_log($logs); if (strpos(getEnvironmentValue("APP_KEY"), 'base64') !== false) { header("LOCATION: index.php?step=3"); } else { - header("LOCATION: index.php?step=2.5&message=There was an error. Please check install/logs.txt !"); + header("LOCATION: index.php?step=2.5&message=There was an error. Please check the .txt file in install/log !"); } @@ -123,7 +122,8 @@ if (isset($_POST['checkSMTP'])) { $db = new mysqli(getEnvironmentValue("DB_HOST"), getEnvironmentValue("DB_USERNAME"), getEnvironmentValue("DB_PASSWORD"), getEnvironmentValue("DB_DATABASE"), getEnvironmentValue("DB_PORT")); if ($db->connect_error) { - header("LOCATION: index.php?step=4&message=Could not connect to the Database"); + wh_log($db->connect_error); + header("LOCATION: index.php?step=4&message=Could not connect to the Database: "); die(); } $values = [ @@ -181,6 +181,7 @@ if (isset($_POST['checkPtero'])) { $db = new mysqli(getEnvironmentValue("DB_HOST"), getEnvironmentValue("DB_USERNAME"), getEnvironmentValue("DB_PASSWORD"), getEnvironmentValue("DB_DATABASE"), getEnvironmentValue("DB_PORT")); if ($db->connect_error) { + wh_log($db->connect_error); header("LOCATION: index.php?step=5&message=Could not connect to the Database"); die(); } @@ -188,6 +189,7 @@ if (isset($_POST['checkPtero'])) { if ($db->query($query1) && $db->query($query2)) { header("LOCATION: index.php?step=6"); } else { + wh_log($db->error); header("LOCATION: index.php?step=5&message=Something went wrong when communicating with the Database!"); } } @@ -198,6 +200,7 @@ if (isset($_POST['checkPtero'])) { if (isset($_POST['createUser'])) { $db = new mysqli(getEnvironmentValue("DB_HOST"), getEnvironmentValue("DB_USERNAME"), getEnvironmentValue("DB_PASSWORD"), getEnvironmentValue("DB_DATABASE"), getEnvironmentValue("DB_PORT")); if ($db->connect_error) { + wh_log($db->connect_error); header("LOCATION: index.php?step=6&message=Could not connect to the Database"); die(); } @@ -273,8 +276,8 @@ if (isset($_POST['createUser'])) { if ($db->query($query1)) { header("LOCATION: index.php?step=7"); } else { - - header("LOCATION: index.php?step=6&message=Something went wrong when communicating with the Database!"); + wh_log($db->error); + header("LOCATION: index.php?step=6&message=Something went wrong when communicating with the Database"); } diff --git a/public/install/functions.php b/public/install/functions.php index b67b4ed0..ebc3c6bd 100644 --- a/public/install/functions.php +++ b/public/install/functions.php @@ -130,4 +130,17 @@ function run_console($command) return shell_exec($cmd); } +function wh_log($log_msg) +{ + $log_filename = "log"; + if (!file_exists($log_filename)) + { + // create directory/folder uploads. + mkdir($log_filename, 0777, true); + } + $log_file_data = $log_filename.'/log_' . date('d-M-Y') . '.log'; + // if you don't add `FILE_APPEND`, the file will be erased each time you add a log + file_put_contents($log_file_data, "[".date('h:i:s')."] " . $log_msg . "\n", FILE_APPEND); +} + ?>