diff --git a/install/includes/database_class.php b/install/includes/database_class.php index 94e2b28dc..84b81a913 100644 --- a/install/includes/database_class.php +++ b/install/includes/database_class.php @@ -1,19 +1,20 @@ query("CREATE DATABASE IF NOT EXISTS ".$data['db_name']); + $mysqli->query("CREATE DATABASE IF NOT EXISTS " . $data['db_name']); // Close the connection $mysqli->close(); @@ -25,24 +26,24 @@ class Database { function create_tables($data) { // Connect to the database - $mysqli = new mysqli($data['db_hostname'],$data['db_username'],$data['db_password'],$data['db_name']); + $mysqli = new mysqli($data['db_hostname'], $data['db_username'], $data['db_password'], $data['db_name']); // Check for errors - if(mysqli_connect_errno()) + if (mysqli_connect_errno()) return false; // Open the default SQL file $query = file_get_contents('assets/install.sql'); - $newpw=password_hash($data['password'], PASSWORD_DEFAULT); - $newquery = str_replace("%%FIRSTUSER_NAME%%",$data['username'],$query); - $newquery = str_replace("%%FIRSTUSER_PASS%%",$newpw,$newquery); - $newquery = str_replace("%%FIRSTUSER_MAIL%%",$data['user_email'],$newquery); - $newquery = str_replace("%%FIRSTUSER_CALL%%",$data['callsign'],$newquery); - $newquery = str_replace("%%FIRSTUSER_LOCATOR%%",$data['userlocator'],$newquery); - $newquery = str_replace("%%FIRSTUSER_FIRSTNAME%%",$data['firstname'],$newquery); - $newquery = str_replace("%%FIRSTUSER_LASTNAME%%",$data['lastname'],$newquery); - $newquery = str_replace("%%FIRSTUSER_TIMEZONE%%",$data['timezone'],$newquery); + $newpw = password_hash($data['password'], PASSWORD_DEFAULT); + $newquery = str_replace("%%FIRSTUSER_NAME%%", $data['username'], $query); + $newquery = str_replace("%%FIRSTUSER_PASS%%", $newpw, $newquery); + $newquery = str_replace("%%FIRSTUSER_MAIL%%", $data['user_email'], $newquery); + $newquery = str_replace("%%FIRSTUSER_CALL%%", $data['callsign'], $newquery); + $newquery = str_replace("%%FIRSTUSER_LOCATOR%%", $data['userlocator'], $newquery); + $newquery = str_replace("%%FIRSTUSER_FIRSTNAME%%", $data['firstname'], $newquery); + $newquery = str_replace("%%FIRSTUSER_LASTNAME%%", $data['lastname'], $newquery); + $newquery = str_replace("%%FIRSTUSER_TIMEZONE%%", $data['timezone'], $newquery); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); @@ -51,7 +52,9 @@ class Database { $mysqli->multi_query($newquery); // MultiQuery is NON-Blocking,so wait until everything is done - do { null; } while($mysqli->next_result()); + do { + null; + } while ($mysqli->next_result()); $result = $mysqli->store_result(); @@ -60,5 +63,28 @@ class Database { return true; } + + function database_check($data) + { + try { + $timeout = 5; /* five seconds for timeout */ + $link = mysqli_init(); + + $link->options(MYSQLI_OPT_CONNECT_TIMEOUT, $timeout); + + $link->real_connect($data['db_hostname'], $data['db_username'], $data['db_password'], $data['db_name']); + + if ($link->connect_error) { + throw new Exception('Connection Error: ' . $link->connect_error); + } + + $mysql_version = $link->server_info; + + $link->close(); + + return $mysql_version; + } catch (Exception $e) { + return 'Error: ' . $e->getMessage(); + } + } } -?> diff --git a/install/index.php b/install/index.php index acd760ce8..fca947088 100644 --- a/install/index.php +++ b/install/index.php @@ -83,43 +83,50 @@ if ($_POST) { $core = new Core(); $database = new Database(); - // Validate the post data - if ($core->validate_post($_POST) == true) { + if ($_POST['database_check'] == 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 /application/config/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 /application/config/config.php file to 777"); - } - - // If no errors, redirect to registration page - if (!isset($message)) { - sleep(1); - $ch = curl_init(); - $protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https" : "http"; - list($realHost,) = explode(':', $_SERVER['HTTP_HOST']); - $wavelog_url = $protocol . "://" . $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: ' . $protocol . "://" . $_SERVER['HTTP_HOST'] . $_POST['directory']); - echo "
Please delete the install folder"; - exit; - } + $result = $database->database_check($_POST); + echo $result; + exit; } else { - $message = $core->show_message('error', 'Not all fields have been filled in correctly. The host, username, password, and database name are required.'); + // 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 /application/config/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 /application/config/config.php file to 777"); + } + + // If no errors, redirect to registration page + if (!isset($message)) { + sleep(1); + $ch = curl_init(); + $protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https" : "http"; + list($realHost,) = explode(':', $_SERVER['HTTP_HOST']); + $wavelog_url = $protocol . "://" . $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: ' . $protocol . "://" . $_SERVER['HTTP_HOST'] . $_POST['directory']); + echo "
Please delete the install folder"; + 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; @@ -144,7 +151,7 @@ global $wavelog_url; ' . $message . '
'; + echo '' . $message . '
'; // TODO Integrate Message into the design, Dialog??? } ?> @@ -359,30 +366,22 @@ global $wavelog_url;Configure some basic parameters for your wavelog instance. You can change them later in 'application/config/config.php'
To properly install Wavelog you already should have setup a mariadb/mysql database. Provide the parameters here.
-