mirror of
https://github.com/wavelog/wavelog.git
synced 2026-03-22 10:24:14 +00:00
error handling
This commit is contained in:
@@ -39,33 +39,33 @@ class Core
|
||||
}
|
||||
|
||||
// Validate First Name
|
||||
if (isset($_POST['firstname']) && !empty($_POST['firstname'])) {
|
||||
if (isset($data['firstname']) && !empty($data['firstname'])) {
|
||||
$counter++;
|
||||
}
|
||||
|
||||
// Validate Last Name
|
||||
if (isset($_POST['lastname']) && !empty($_POST['lastname'])) {
|
||||
if (isset($data['lastname']) && !empty($data['lastname'])) {
|
||||
$counter++;
|
||||
}
|
||||
|
||||
// Validate Username
|
||||
if (isset($_POST['username']) && !empty($_POST['username'])) {
|
||||
if (isset($data['username']) && !empty($data['username'])) {
|
||||
$counter++;
|
||||
}
|
||||
|
||||
// Validate Callsign
|
||||
if (isset($_POST['callsign']) && !empty($_POST['callsign'])) {
|
||||
if (isset($data['callsign']) && !empty($data['callsign'])) {
|
||||
$counter++;
|
||||
}
|
||||
|
||||
// Validate Password
|
||||
if (isset($_POST['password']) && !empty($_POST['password'])) {
|
||||
if (isset($data['password']) && !empty($data['password'])) {
|
||||
$counter++;
|
||||
}
|
||||
|
||||
// Validate Locator
|
||||
if (isset($_POST['userlocator']) && !empty($_POST['userlocator'])) {
|
||||
$locator = $_POST['userlocator'];
|
||||
if (isset($data['userlocator']) && !empty($data['userlocator'])) {
|
||||
$locator = $data['userlocator'];
|
||||
if (preg_match('/^[A-R]{2}[0-9]{2}[A-X]{2}$/i', $locator)) {
|
||||
$counter++;
|
||||
} else {
|
||||
@@ -76,19 +76,19 @@ class Core
|
||||
}
|
||||
|
||||
// Validate Confirm Password
|
||||
if (isset($_POST['cnfm_password']) && !empty($_POST['cnfm_password'])) {
|
||||
if (isset($data['cnfm_password']) && !empty($data['cnfm_password'])) {
|
||||
$counter++;
|
||||
}
|
||||
|
||||
// Validate Email Address
|
||||
if (isset($_POST['user_email']) && filter_var($_POST['user_email'], FILTER_VALIDATE_EMAIL)) {
|
||||
if (isset($data['user_email']) && filter_var($data['user_email'], FILTER_VALIDATE_EMAIL)) {
|
||||
$counter++;
|
||||
} else {
|
||||
$errors[] = "Invalid Email Address.";
|
||||
}
|
||||
|
||||
// Validate Timezone
|
||||
if (isset($_POST['timezone']) && is_numeric($_POST['timezone'])) {
|
||||
if (isset($data['timezone']) && is_numeric($data['timezone'])) {
|
||||
$counter++;
|
||||
}
|
||||
|
||||
@@ -100,12 +100,6 @@ class Core
|
||||
}
|
||||
}
|
||||
|
||||
// Function to show an error
|
||||
function show_message($type, $message)
|
||||
{
|
||||
return $message;
|
||||
}
|
||||
|
||||
// Function to write the config file
|
||||
function write_config($data) {
|
||||
|
||||
@@ -138,7 +132,11 @@ class Core
|
||||
|
||||
// Write the file
|
||||
if (fwrite($handle, $new)) {
|
||||
return true;
|
||||
if(file_exists($output_path)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@@ -188,7 +186,11 @@ class Core
|
||||
|
||||
// Write the file
|
||||
if (fwrite($handle, $new)) {
|
||||
return true;
|
||||
if(file_exists($output_path)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -19,32 +19,51 @@ if ($_POST['database_check'] ?? false == true) {
|
||||
*/
|
||||
|
||||
// config_file()
|
||||
// if ($core->validate_post($_POST) == true) {
|
||||
|
||||
if ($_POST['run_config_file'] ?? false == true) {
|
||||
sleep(1);
|
||||
$data = json_decode($_POST['data'], true);
|
||||
$result = $core->write_configfile($data);
|
||||
echo $result ? 'success' : 'error';
|
||||
if ($core->validate_post($data)) {
|
||||
if($core->write_configfile($data)) {
|
||||
$result = 'success';
|
||||
} else {
|
||||
$result = 'error';
|
||||
}
|
||||
} else {
|
||||
$result = 'error';
|
||||
}
|
||||
echo $result;
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($_POST['run_database_file'] ?? false == true) {
|
||||
sleep(1);
|
||||
$data = json_decode($_POST['data'], true);
|
||||
$result = $core->write_config($data);
|
||||
echo $result ? 'success' : 'error';
|
||||
if ($core->validate_post($data)) {
|
||||
if($core->write_config($data)) {
|
||||
$result = 'success';
|
||||
} else {
|
||||
$result = 'error';
|
||||
}
|
||||
} else {
|
||||
$result = 'error';
|
||||
}
|
||||
echo $result;
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($_POST['run_database_tables'] ?? false == true) {
|
||||
$data = json_decode($_POST['data'], true);
|
||||
$result = $database->create_tables($data);
|
||||
if ($core->validate_post($data)) {
|
||||
$result = $database->create_tables($data);
|
||||
} else {
|
||||
$result = 'error';
|
||||
}
|
||||
echo $result ? 'success' : 'error';
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($_POST['run_installer_lock'] ?? false) {
|
||||
if ($_POST['run_installer_lock'] ?? false == true) {
|
||||
exec('touch .lock', $output, $return_var);
|
||||
if ($return_var === 0 && file_exists('.lock')) {
|
||||
echo 'success';
|
||||
@@ -53,6 +72,3 @@ if ($_POST['run_installer_lock'] ?? false) {
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
// }
|
||||
243
install/run.php
243
install/run.php
@@ -38,6 +38,7 @@
|
||||
<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 id="error_message"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -45,27 +46,30 @@
|
||||
|
||||
<script>
|
||||
$(document).ready(async function() {
|
||||
try {
|
||||
await config_file();
|
||||
await database_file();
|
||||
await database_tables();
|
||||
await database_migrations();
|
||||
await update_dxcc();
|
||||
await installer_lock();
|
||||
|
||||
await config_file();
|
||||
await database_file();
|
||||
await database_tables();
|
||||
await database_migrations();
|
||||
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();
|
||||
|
||||
// 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 = "/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 = "/index.php/user/login/1";
|
||||
}
|
||||
}, 1000);
|
||||
} catch (error) {
|
||||
$("#error_message").text("Installation failed: " + error).show();
|
||||
}
|
||||
});
|
||||
|
||||
let _POST = '<?php echo json_encode($_POST); ?>';
|
||||
@@ -76,23 +80,28 @@
|
||||
|
||||
running(field, true);
|
||||
|
||||
await $.ajax({
|
||||
type: 'POST',
|
||||
url: 'index.php',
|
||||
data: {
|
||||
data: _POST,
|
||||
run_config_file: 1
|
||||
},
|
||||
success: function(response) {
|
||||
if (response == 'success') {
|
||||
running(field, false);
|
||||
} else {
|
||||
running(field, true, true);
|
||||
return new Promise((resolve, reject) => {
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: 'index.php',
|
||||
data: {
|
||||
data: _POST,
|
||||
run_config_file: 1
|
||||
},
|
||||
success: function(response) {
|
||||
if (response == 'success') {
|
||||
running(field, false);
|
||||
resolve();
|
||||
} else {
|
||||
running(field, false, true);
|
||||
reject("<?= __("Could not create application/config/config.php"); ?>");
|
||||
}
|
||||
},
|
||||
error: function(error) {
|
||||
running(field, false, true);
|
||||
reject(error);
|
||||
}
|
||||
},
|
||||
error: function(error) {
|
||||
running(field, true, true);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -102,23 +111,28 @@
|
||||
|
||||
running(field, true);
|
||||
|
||||
await $.ajax({
|
||||
type: 'POST',
|
||||
url: 'index.php',
|
||||
data: {
|
||||
data: _POST,
|
||||
run_database_file: 1
|
||||
},
|
||||
success: function(response) {
|
||||
if (response == 'success') {
|
||||
running(field, false);
|
||||
} else {
|
||||
running(field, true, true);
|
||||
return new Promise((resolve, reject) => {
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: 'index.php',
|
||||
data: {
|
||||
data: _POST,
|
||||
run_database_file: 1
|
||||
},
|
||||
success: function(response) {
|
||||
if (response == 'success') {
|
||||
running(field, false);
|
||||
resolve();
|
||||
} else {
|
||||
running(field, false, true);
|
||||
reject("<?= __("Could not create application/config/database.php"); ?>");
|
||||
}
|
||||
},
|
||||
error: function(error) {
|
||||
running(field, false, true);
|
||||
reject(error);
|
||||
}
|
||||
},
|
||||
error: function(error) {
|
||||
running(field, true, true);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -127,23 +141,28 @@
|
||||
|
||||
running(field, true);
|
||||
|
||||
await $.ajax({
|
||||
type: 'POST',
|
||||
url: 'index.php',
|
||||
data: {
|
||||
data: _POST,
|
||||
run_database_tables: 1
|
||||
},
|
||||
success: function(response) {
|
||||
if (response == 'success') {
|
||||
running(field, false);
|
||||
} else {
|
||||
running(field, true, true);
|
||||
return new Promise((resolve, reject) => {
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: 'index.php',
|
||||
data: {
|
||||
data: _POST,
|
||||
run_database_tables: 1
|
||||
},
|
||||
success: function(response) {
|
||||
if (response == 'success') {
|
||||
running(field, false);
|
||||
resolve();
|
||||
} else {
|
||||
running(field, false, true);
|
||||
reject("<?= __("Could not create database tables"); ?>");
|
||||
}
|
||||
},
|
||||
error: function(error) {
|
||||
running(field, false, true);
|
||||
reject(error);
|
||||
}
|
||||
},
|
||||
error: function(error) {
|
||||
running(field, true, true);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -152,18 +171,23 @@
|
||||
|
||||
running(field, true);
|
||||
|
||||
await $.ajax({
|
||||
url: "<?php echo $_POST['websiteurl']; ?>" + "index.php/migrate",
|
||||
success: function(response) {
|
||||
if (response == 'success') {
|
||||
running(field, false);
|
||||
} else {
|
||||
running(field, true, true);
|
||||
return new Promise((resolve, reject) => {
|
||||
$.ajax({
|
||||
url: "<?php echo $_POST['websiteurl']; ?>" + "index.php/migrate",
|
||||
success: function(response) {
|
||||
if (response == 'success') {
|
||||
running(field, false);
|
||||
resolve();
|
||||
} else {
|
||||
running(field, false, true);
|
||||
reject("<?= __("Could not run database migrations"); ?>");
|
||||
}
|
||||
},
|
||||
error: function(error) {
|
||||
running(field, false, true);
|
||||
reject(error);
|
||||
}
|
||||
},
|
||||
error: function(error) {
|
||||
running(field, true, true);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -172,18 +196,23 @@
|
||||
|
||||
running(field, true);
|
||||
|
||||
await $.ajax({
|
||||
url: "<?php echo $_POST['websiteurl']; ?>" + "index.php/update/dxcc",
|
||||
success: function(response) {
|
||||
if (response == 'success') {
|
||||
running(field, false);
|
||||
} else {
|
||||
running(field, true, true);
|
||||
return new Promise((resolve, reject) => {
|
||||
$.ajax({
|
||||
url: "<?php echo $_POST['websiteurl']; ?>" + "index.php/update/dxcc",
|
||||
success: function(response) {
|
||||
if (response == 'success') {
|
||||
running(field, false);
|
||||
resolve();
|
||||
} else {
|
||||
running(field, false, true);
|
||||
reject("<?= __("Could not update DXCC data"); ?>");
|
||||
}
|
||||
},
|
||||
error: function(error) {
|
||||
running(field, false, true);
|
||||
reject(error);
|
||||
}
|
||||
},
|
||||
error: function(error) {
|
||||
running(field, true, true);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -191,23 +220,27 @@
|
||||
var field = '#installer_lock';
|
||||
|
||||
running(field, true);
|
||||
|
||||
await $.ajax({
|
||||
type: 'POST',
|
||||
url: 'index.php',
|
||||
data: {
|
||||
run_installer_lock: 1
|
||||
},
|
||||
success: function(response) {
|
||||
if (response == 'success') {
|
||||
running(field, false);
|
||||
} else {
|
||||
running(field, true, true);
|
||||
return new Promise((resolve, reject) => {
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: 'index.php',
|
||||
data: {
|
||||
run_installer_lock: 1
|
||||
},
|
||||
success: function(response) {
|
||||
if (response == 'success') {
|
||||
running(field, false);
|
||||
resolve();
|
||||
} else {
|
||||
running(field, false, true);
|
||||
reject("<?= __("Could not create install/.lock file"); ?>");
|
||||
}
|
||||
},
|
||||
error: function(error) {
|
||||
running(field, false, true);
|
||||
reject(error);
|
||||
}
|
||||
},
|
||||
error: function(error) {
|
||||
running(field, true, true);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user