From 3cc925d9ea3241442bac7ed381869bd269e00a73 Mon Sep 17 00:00:00 2001 From: HB9HIL Date: Sun, 21 Jul 2024 17:48:02 +0200 Subject: [PATCH] next install refactoring --- .../css/{overrides.css => installer.css} | 12 +- install/config/config.php | 4 +- install/includes/{ => core}/core_class.php | 14 +- .../includes/{ => core}/database_class.php | 28 +- install/includes/gettext/gettext.php | 5 +- install/includes/gettext/gettext_conf.php | 2 - .../install_config/install_config.php | 35 + .../includes/install_config/install_lib.php | 56 + install/includes/interface_assets/footer.php | 59 + install/includes/interface_assets/header.php | 69 + .../includes/interface_assets/triggers.php | 58 + install/index.php | 2880 ++++++++--------- install/run.php | 238 ++ 13 files changed, 1937 insertions(+), 1523 deletions(-) rename install/assets/css/{overrides.css => installer.css} (96%) rename install/includes/{ => core}/core_class.php (92%) rename install/includes/{ => core}/database_class.php (79%) create mode 100644 install/includes/install_config/install_config.php create mode 100644 install/includes/install_config/install_lib.php create mode 100644 install/includes/interface_assets/footer.php create mode 100644 install/includes/interface_assets/header.php create mode 100644 install/includes/interface_assets/triggers.php create mode 100644 install/run.php diff --git a/install/assets/css/overrides.css b/install/assets/css/installer.css similarity index 96% rename from install/assets/css/overrides.css rename to install/assets/css/installer.css index d75390c6d..d6334cc37 100644 --- a/install/assets/css/overrides.css +++ b/install/assets/css/installer.css @@ -205,8 +205,18 @@ div.alert-danger { --bs-tooltip-opacity: 1; } -#languageButton { +#languageButton, #advancedSettingsButton, #resetButton { position: absolute; bottom: 70px; right: 20px; +} + +.required:after { + content: " *"; + color: red; +} + +.required-prefix:before { + content: "* "; + color: red; } \ No newline at end of file diff --git a/install/config/config.php b/install/config/config.php index 2c4443207..d954cd39b 100644 --- a/install/config/config.php +++ b/install/config/config.php @@ -286,7 +286,7 @@ $config['allow_get_array'] = TRUE; | your log files will fill up very fast. | */ -$config['log_threshold'] = 0; +$config['log_threshold'] = '%log_threshold%'; /* |-------------------------------------------------------------------------- @@ -400,7 +400,7 @@ $config['cache_query_string'] = FALSE; | https://codeigniter.com/user_guide/libraries/encryption.html | */ -$config['encryption_key'] = 'flossie1234555541'; +$config['encryption_key'] = '%encryptionkey%'; /* |-------------------------------------------------------------------------- diff --git a/install/includes/core_class.php b/install/includes/core/core_class.php similarity index 92% rename from install/includes/core_class.php rename to install/includes/core/core_class.php index ccc39f012..58d2b1d83 100644 --- a/install/includes/core_class.php +++ b/install/includes/core/core_class.php @@ -26,7 +26,7 @@ class Core $counter++; } - if ($data['directory'] != "") { + if ($data['directory'] ?? '' != "") { if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/' . $data['directory'])) { //pass folders real $counter++; @@ -151,14 +151,17 @@ class Core function write_configfile($data) { $template_path = 'config/config.php'; - $output_path = $_SERVER['DOCUMENT_ROOT'] . '/' . $data['directory'] . '/application/config/config.php'; + $output_path = '../application/config/config.php'; if (isset($_ENV['CI_ENV'])) { - $output_path = $_SERVER['DOCUMENT_ROOT'] . '/' . $data['directory'] . '/application/config/'.$_ENV['CI_ENV'].'/config.php'; + $output_path = '../application/config/'.$_ENV['CI_ENV'].'/config.php'; } // Open the file $database_file = file_get_contents($template_path); + // creating a unique encryption key + $encryptionkey = uniqid(bin2hex(random_bytes(8)), false); + $new = str_replace("%baselocator%", $data['locator'], $database_file); $new = str_replace("%websiteurl%", $data['websiteurl'], $new); $new = str_replace("%directory%", $data['directory'], $new); @@ -174,13 +177,12 @@ class Core $new = str_replace("%hamqth_username%", $data['callbook_username'], $new); $new = str_replace("%hamqth_password%", $data['callbook_password'], $new); } + $new = str_replace("%encryptionkey%", $encryptionkey, $new); + $new = str_replace("'%log_threshold%'", $data['log_threshold'], $new); // Write the new config.php file $handle = fopen($output_path, 'w+'); - // Chmod the file, in case the user forgot - @chmod($output_path, 0777); - // Verify file permissions if (is_writable($output_path)) { diff --git a/install/includes/database_class.php b/install/includes/core/database_class.php similarity index 79% rename from install/includes/database_class.php rename to install/includes/core/database_class.php index 35aa27ad2..7334de9d1 100644 --- a/install/includes/database_class.php +++ b/install/includes/core/database_class.php @@ -1,30 +1,9 @@ query("CREATE DATABASE IF NOT EXISTS " . $data['db_name']); - - // Close the connection - $mysqli->close(); - - return true; - } +class Database { // Function to create the tables and fill them with the default data - function create_tables($data) - { + function create_tables($data) { // Connect to the database $mysqli = new mysqli($data['db_hostname'], $data['db_username'], $data['db_password'], $data['db_name']); @@ -67,8 +46,7 @@ class Database return true; } - function database_check($data) - { + function database_check($data) { try { $timeout = 5; /* five seconds for timeout */ $link = mysqli_init(); diff --git a/install/includes/gettext/gettext.php b/install/includes/gettext/gettext.php index 9e174a528..b3aee208d 100644 --- a/install/includes/gettext/gettext.php +++ b/install/includes/gettext/gettext.php @@ -76,10 +76,9 @@ function _get_client_language() { global $default_lang; if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { $code = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2); - $lang = find_by('code', $code) ?: $default_lang; + $lang = find_by('code', $code) ?? find_by('folder', $default_lang); } else { - $code = 'en'; - $lang = find_by('code', $code); + $lang = find_by('folder', $default_lang); } return $lang; } diff --git a/install/includes/gettext/gettext_conf.php b/install/includes/gettext/gettext_conf.php index 88e5302bd..84a90b01b 100644 --- a/install/includes/gettext/gettext_conf.php +++ b/install/includes/gettext/gettext_conf.php @@ -8,8 +8,6 @@ * */ - - $gt_conf['default_domain'] = 'installer'; $gt_conf['default_lang'] = 'english'; diff --git a/install/includes/install_config/install_config.php b/install/includes/install_config/install_config.php new file mode 100644 index 000000000..83d8d24e5 --- /dev/null +++ b/install/includes/install_config/install_config.php @@ -0,0 +1,35 @@ + ['condition' => isExtensionInstalled('curl')], + 'php-mysql' => ['condition' => isExtensionInstalled('mysqli')], + 'php-mbstring' => ['condition' => isExtensionInstalled('mbstring')], + 'php-xml' => ['condition' => isExtensionInstalled('xml')], + 'php-zip' => ['condition' => isExtensionInstalled('zip')], +]; + +// MariaDB / MySQL +$mariadb_version = 10.1; +$mysql_version = 5.7; diff --git a/install/includes/install_config/install_lib.php b/install/includes/install_config/install_lib.php new file mode 100644 index 000000000..b514a5e64 --- /dev/null +++ b/install/includes/install_config/install_lib.php @@ -0,0 +1,56 @@ +isDir() && basename($item->getPathName()) != '..') { + if (!is_writable($item->getRealPath())) { + return false; + } + } + } + + return true; + } + } catch (Exception $e) { + return false; + } + + return false; +} diff --git a/install/includes/interface_assets/footer.php b/install/includes/interface_assets/footer.php new file mode 100644 index 000000000..c4c8ba117 --- /dev/null +++ b/install/includes/interface_assets/footer.php @@ -0,0 +1,59 @@ + \ No newline at end of file diff --git a/install/includes/interface_assets/header.php b/install/includes/interface_assets/header.php new file mode 100644 index 000000000..fb324102f --- /dev/null +++ b/install/includes/interface_assets/header.php @@ -0,0 +1,69 @@ + + + + + + + + <?= __("Install | Wavelog"); ?> + + + + + + + + + + + \ No newline at end of file diff --git a/install/includes/interface_assets/triggers.php b/install/includes/interface_assets/triggers.php new file mode 100644 index 000000000..0d5b5d7c7 --- /dev/null +++ b/install/includes/interface_assets/triggers.php @@ -0,0 +1,58 @@ +database_check($_POST); + echo $result; + exit; +} + +/** + * + * Install Triggers + * + */ + +// 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'; + 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'; + exit; +} + +if ($_POST['run_database_tables'] ?? false == true) { + $data = json_decode($_POST['data'], true); + $result = $database->create_tables($data); + echo $result ? 'success' : 'error'; + exit; +} + +if ($_POST['run_installer_lock'] ?? false) { + exec('touch .lock', $output, $return_var); + if ($return_var === 0 && file_exists('.lock')) { + echo 'success'; + } else { + echo 'error'; + } + exit; +} + + +// } \ No newline at end of file diff --git a/install/index.php b/install/index.php index efd641b30..f618ba622 100644 --- a/install/index.php +++ b/install/index.php @@ -1,1395 +1,1204 @@ -function is_https() { - if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') { - return true; - } - if (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { - return true; - } - if (!empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] === 'on') { - return true; - } - return false; -} + +
-if (is_https()) { - $http_scheme = "https"; -} else { - $http_scheme = "http"; -} +
-global $installer_url; -$installer_url = $http_scheme . '://' . $_SERVER['HTTP_HOST'] . '/' . substr(str_replace(["index.php", "/install/"], "/", $_SERVER['REQUEST_URI']), 1) . 'install'; +
+ +
-// Config Paths -$db_config_path = '../application/config/'; -if (isset($_ENV['CI_ENV'])) { - $db_config_path = '../application/config/' . $_ENV['CI_ENV'] . '/'; -} -$db_file_path = $db_config_path . "database.php"; +
+
+
-// if you need to disabled all button locks you can create a root_mode file in the /install directory -$root_mode_file = '.root_mode'; + +
+
+
+ +
-// Wanted Pre-Check Parameters -// PHP -$min_php_version = '7.4.0'; -$max_execution_time = 600; // Seconds -$max_upload_file_size = 8; // Megabyte -$post_max_size = 8; // Megabyte -$req_allow_url_fopen = '1'; // 1 = on - -// Array of PHP modules to check -global $required_php_modules; -$required_php_modules = [ - 'php-curl' => ['condition' => isExtensionInstalled('curl')], - 'php-mysql' => ['condition' => isExtensionInstalled('mysqli')], - 'php-mbstring' => ['condition' => isExtensionInstalled('mbstring')], - 'php-xml' => ['condition' => isExtensionInstalled('xml')], - 'php-zip' => ['condition' => isExtensionInstalled('zip')], -]; - -// MariaDB / MySQL -$mariadb_version = 10.1; -$mysql_version = 5.7; - -// ######################################################### -// Gettext Implementation -// ######################################################### - -// include the lib and the conf file -require_once('includes/gettext/gettext.php'); -require_once('includes/gettext/gettext_conf.php'); - -/** - * save all available languages - * @var array $languages - */ -$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']); -} - -// get the browsers language if no cookie exists and set one -if (!isset($_COOKIE[$gt_conf['lang_cookie']])) { - $browser_language = _get_client_language(); - setcookie($gt_conf['lang_cookie'], $browser_language['gettext']); - header("Location: " . $installer_url); - exit(); -} -// get the language from the cookie -$language = $_COOKIE[$gt_conf['lang_cookie']]; - -// and set the locale for gettext -T_setlocale(LC_MESSAGES, $language); - -// function to switch the language based on the user selection -function switch_lang($new_language) { - global $gt_conf, $installer_url; - setcookie($gt_conf['lang_cookie'], $new_language); - header("Location: " . $installer_url); - exit(); -} - -// ######################################################### END OF PRECONFIGURATION - -// Function to check if a PHP extension is installed -function isExtensionInstalled($extensionName) { - return in_array($extensionName, get_loaded_extensions()); -} - -function delDir($dir) { - $files = glob($dir . '*', GLOB_MARK); - foreach ($files as $file) { - if (substr($file, -1) == '/') { - if (file_exists($file)) { - delDir($file); - } - } else { - if (file_exists($file)) { - unlink($file); - } - } - } -} - -if (file_exists($db_file_path)) { - delDir(getcwd()); - header("../"); - exit; -} - -if (file_exists($root_mode_file)) { - $root_mode = true; -} else { - $root_mode = false; -} - -// Only load the classes in case the user submitted the form -if ($_POST) { - - // Load the classes and create the new objects - require_once('includes/core_class.php'); - require_once('includes/database_class.php'); - - $core = new Core(); - $database = new Database(); - - if ($_POST['database_check'] ?? false == true) { - - $result = $database->database_check($_POST); - echo $result; - exit; - } else { - // Validate the post data - if ($core->validate_post($_POST) == true) { - - // First create the database, then create tables, then write config file - if ($database->create_database($_POST) == false) { - $message = $core->show_message('error', "The database could not be created, please verify your settings."); - } elseif ($database->create_tables($_POST) == false) { - $message = $core->show_message('error', "The database tables could not be created, please verify your settings."); - } elseif ($core->write_config($_POST) == false) { - $message = $core->show_message('error', "The database configuration file could not be written, please chmod " . $db_config_path . "/database.php file to 777"); - } - - if ($core->write_configfile($_POST) == false) { - $message = $core->show_message('error', "The config configuration file could not be written, please chmod " . $db_config_path . "/config.php file to 777"); - } - - // If no errors, redirect to registration page - if (!isset($message)) { - sleep(1); - $ch = curl_init(); - list($realHost,) = explode(':', $_SERVER['HTTP_HOST']); - $wavelog_url = $http_scheme . "://" . $realHost . ":" . $_SERVER['SERVER_PORT']; - curl_setopt($ch, CURLOPT_URL, $wavelog_url); - curl_setopt($ch, CURLOPT_VERBOSE, 0); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - $result = curl_exec($ch); - curl_setopt($ch, CURLOPT_URL, $wavelog_url . "/index.php/update/dxcc"); - $result = curl_exec($ch); - delDir(getcwd()); - header('Location: ' . $http_scheme . "://" . $_SERVER['HTTP_HOST'] . '/' . $_POST['directory']); - exit; - } - } else { - $message = $core->show_message('error', 'Not all fields have been filled in correctly. The host, username, password, and database name are required.'); - } - } -} -global $wavelog_url; - -?> - - - - - - - <?= __("Install | Wavelog"); ?> - - - - - - - - - - - - ' . $message . '

'; // TODO Integrate Message into the design, Dialog??? - } ?> - - -
- -
- -
- -
- -
- -
- - -
-
-
- -
- -
-

-

Wavelog is a powerful web-based amateur radio logging software. Follow the steps in each tab to configure and install Wavelog on your server."); ?>

-

" . __("Wiki") . "", "" . __("Discussions") . ""); ?>

-

- - -
+
+

+

Wavelog is a powerful web-based amateur radio logging software. Follow the steps in each tab to configure and install Wavelog on your server."); ?>

+

" . __("Wiki") . "", "" . __("Discussions") . ""); ?>

+

+ +
-