From 8c57fb88ab8b76459213f62a58f01e21613c5ee1 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Fri, 5 Sep 2014 09:57:06 +0200 Subject: [PATCH] Modularize web setup --- code/web/private_php/setup/config/config.php | 48 +- code/web/public_php/.htaccess | 2 + code/web/public_php/ams/index.php | 4 +- code/web/public_php/setup/auth.php | 52 ++ code/web/public_php/setup/footer.php | 12 + code/web/public_php/setup/header.php | 123 +++++ .../web/public_php/setup/img/agplv3-88x31.png | Bin 0 -> 1883 bytes code/web/public_php/setup/index.php | 371 ++------------ code/web/public_php/setup/install.php | 453 ++++++++++++++++++ 9 files changed, 705 insertions(+), 360 deletions(-) create mode 100644 code/web/public_php/.htaccess create mode 100644 code/web/public_php/setup/auth.php create mode 100644 code/web/public_php/setup/footer.php create mode 100644 code/web/public_php/setup/header.php create mode 100644 code/web/public_php/setup/img/agplv3-88x31.png create mode 100644 code/web/public_php/setup/install.php diff --git a/code/web/private_php/setup/config/config.php b/code/web/private_php/setup/config/config.php index 56a057cd1..8f24b245b 100644 --- a/code/web/private_php/setup/config/config.php +++ b/code/web/private_php/setup/config/config.php @@ -4,40 +4,40 @@ * @author Daan Janssens, mentored by Matthew Lagoe */ -// Variables for database access to the www/CMS database -$cfg['db']['web']['host'] = '%sqlHostname%'; +// Variables for database access to the www/CMS database (only if support role) +$cfg['db']['web']['host'] = '%amsSqlHostname%'; $cfg['db']['web']['port'] = '3306'; $cfg['db']['web']['name'] = '%amsDatabase%'; -$cfg['db']['web']['user'] = '%sqlUsername%'; -$cfg['db']['web']['pass'] = '%sqlPassword%'; +$cfg['db']['web']['user'] = '%amsSqlUsername%'; +$cfg['db']['web']['pass'] = '%amsSqlPassword%'; -// Variables for database access to the lib database -$cfg['db']['lib']['host'] = '%sqlHostname%'; +// Variables for database access to the lib database (only if support role) +$cfg['db']['lib']['host'] = '%amsSqlHostname%'; $cfg['db']['lib']['port'] = '3306'; $cfg['db']['lib']['name'] = '%amsLibDatabase%'; -$cfg['db']['lib']['user'] = '%sqlUsername%'; -$cfg['db']['lib']['pass'] = '%sqlPassword%'; +$cfg['db']['lib']['user'] = '%amsSqlUsername%'; +$cfg['db']['lib']['pass'] = '%amsSqlPassword%'; // Variables for database access to the shard database -$cfg['db']['shard']['host'] = '%sqlHostname%'; +$cfg['db']['shard']['host'] = '%nelSqlHostname%'; $cfg['db']['shard']['port'] = '3306'; $cfg['db']['shard']['name'] = '%nelDatabase%'; -$cfg['db']['shard']['user'] = '%sqlUsername%'; -$cfg['db']['shard']['pass'] = '%sqlPassword%'; +$cfg['db']['shard']['user'] = '%nelSqlUsername%'; +$cfg['db']['shard']['pass'] = '%nelSqlPassword%'; -// Variables for database access to the ring_open database -// $cfg['db']['ring']['host'] = '%sqlHostname%'; +// Variables for database access to the ring_open database (only if domain role) +// $cfg['db']['ring']['host'] = '%nelSqlHostname%'; // $cfg['db']['ring']['port'] = '3306'; // $cfg['db']['ring']['name'] = '%domainDatabase%'; -// $cfg['db']['ring']['user'] = '%sqlUsername%'; -// $cfg['db']['ring']['pass'] = '%sqlPassword%'; +// $cfg['db']['ring']['user'] = '%nelSqlUsername%'; +// $cfg['db']['ring']['pass'] = '%nelSqlPassword%'; -// Variables for database access to the nel_tool database -$cfg['db']['tool']['host'] = '%sqlHostname%'; +// Variables for database access to the nel_tool database (only if service role) +$cfg['db']['tool']['host'] = '%nelSqlHostname%'; $cfg['db']['tool']['port'] = '3306'; $cfg['db']['tool']['name'] = '%toolDatabase%'; -$cfg['db']['tool']['user'] = '%sqlUsername%'; -$cfg['db']['tool']['pass'] = '%sqlPassword%'; +$cfg['db']['tool']['user'] = '%nelSqlUsername%'; +$cfg['db']['tool']['pass'] = '%nelSqlPassword%'; // To connect to an IMAP server running on port 143 on the local machine, // do the following: $mbox = imap_open("{localhost:143}INBOX", "user_id", "password"); @@ -121,5 +121,11 @@ $INGAME_LAYOUT = "basic"; //forces to load the ingame templates if set to true $FORCE_INGAME = false; -//file storage path (must be a publicly accessible url for -$FILE_STORAGE_PATH = "/files/"; \ No newline at end of file +//file storage path (must be a publicly accessible url for +$FILE_STORAGE_PATH = "/files/"; + +// Setup password +$NEL_SETUP_PASSWORD = '%nelSetupPassword%'; + +// Name of current domain (only if domain role) +$NEL_DOMAIN_NAME = '%nelDomainName%'; diff --git a/code/web/public_php/.htaccess b/code/web/public_php/.htaccess new file mode 100644 index 000000000..c0b74b60d --- /dev/null +++ b/code/web/public_php/.htaccess @@ -0,0 +1,2 @@ +RewriteEngine On +RewriteRule ^$ /ams [R=301,L] diff --git a/code/web/public_php/ams/index.php b/code/web/public_php/ams/index.php index 7f8a40628..5f09babce 100644 --- a/code/web/public_php/ams/index.php +++ b/code/web/public_php/ams/index.php @@ -18,7 +18,7 @@ ini_set( 'display_errors', 'on' ); class SystemExit extends Exception {} try { -if (!file_exists( '../is_installed')) { +if (!file_exists( '../config.php')) { header("Cache-Control: max-age=1"); header('Location: ../setup', true, 303); throw new SystemExit(); @@ -52,7 +52,7 @@ if ( ! isset( $_GET["page"] ) ) { $page = 'login'; } } else { - // if the session exists load page with $_GET requests + // if the session exists load page with $_GET requests if ( isset( $_SESSION['user'] ) ) { $page = $_GET["page"]; } else { diff --git a/code/web/public_php/setup/auth.php b/code/web/public_php/setup/auth.php new file mode 100644 index 000000000..8289289f9 --- /dev/null +++ b/code/web/public_php/setup/auth.php @@ -0,0 +1,52 @@ + +
+ + + + +

+ Continue +

+ + + +
+
+ + + + + +
+
+ + + +
+ + diff --git a/code/web/public_php/setup/footer.php b/code/web/public_php/setup/footer.php new file mode 100644 index 000000000..6790d3be8 --- /dev/null +++ b/code/web/public_php/setup/footer.php @@ -0,0 +1,12 @@ + + + +
+ +
AGPLv3
+ + + + + + diff --git a/code/web/public_php/setup/header.php b/code/web/public_php/setup/header.php new file mode 100644 index 000000000..1c7b4cda0 --- /dev/null +++ b/code/web/public_php/setup/header.php @@ -0,0 +1,123 @@ + + + + + + + Ryzom Core | <?php print(htmlentities($pageTitle)); ?> + + + +'; + print $message; + print ''; +} +function is__writable($path) { + if ($path{strlen($path) - 1} == '/') { + return is__writable($path.uniqid(mt_rand()).'.tmp'); + } + + if (file_exists($path)) { + if (!($f = @fopen($path, 'r+'))) { + return false; + } + fclose($f); + return true; + } + + if (!($f = @fopen($path, 'w'))) { + return false; + } + fclose($f); + unlink($path); + return true; +} +function validate_writable($continue, $path) { + if (!is__writable($path)) { + printalert("danger", "Failed to get write permissions on " . htmlentities($path)); + return false; + } + return $continue; +} +function create_use_database($continue_r, $con, $database) { + $continue = $continue_r; + if ($continue) { + $sql = "CREATE DATABASE `" . mysqli_real_escape_string($con, $database) . "` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"; + if (mysqli_query($con, $sql)) { + printalert("success", "Database " . $database . " created"); + } else { + printalert("danger", "Error creating " . $database . " database: " . mysqli_error($con)); + $continue = false; + } + } + if ($continue) { + $sql = "USE `" . mysqli_real_escape_string($con, $database) . "`;"; + if (mysqli_query($con, $sql)) { + printalert("success", "Database " . $database . " selected"); + } else { + printalert("danger", "Error selecting " . $database . " database: " . mysqli_error($con)); + $continue = false; + } + } + return $continue; +} +function update_database_structure($continue_r, $con, $file) { + $continue = $continue_r; + if ($continue) { + $sql = file_get_contents($_POST["privatePhpDirectory"] . "/setup/sql/" . $file); + if (!$sql) { + printalert("danger", "Cannot read " . $file . ""); + $continue = false; + } else { + if (mysqli_multi_query($con, $sql)) { + printalert("success", "Database structure updated using " . $file . ""); + while (mysqli_more_results($con) && mysqli_next_result($con)) { + // no-op + } + } else { + printalert("danger", "Error updating database using " . $file . ": " . mysqli_error($con)); + $continue = false; + } + } + } + return $continue; +} +?> + + +
+ + + + + + diff --git a/code/web/public_php/setup/img/agplv3-88x31.png b/code/web/public_php/setup/img/agplv3-88x31.png new file mode 100644 index 0000000000000000000000000000000000000000..7a472a0d8f3dca824af43755da32020507ae3a69 GIT binary patch literal 1883 zcmV-h2c-CkP)Px#32;bRa{vGWCjbBfCjq_^R0se700(qQO+^RT0tgi!FnpsB!~g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q-#=98H%Q~frh zC)15ielIODbYp1=y_#>z{B9S z{8X+Sm4I2!wB%4Kz6J9e>S27zw+4@cvGij4@=e1iA7kBFOvP3O<7sQV7QLhY6E0r; zz+hzaZ7^`)$}8k4o+hHDV^m}YxBEoq0}j$gX43nZ#$?KNCcYCHW-kzlmPDTk8a0MT zi=bHbKCKVU!8lN*cw6A+X?dfJa^94?wJ5eeNMyQkh6*4`=JTJMtLa7=<|^%ajHXca z^-X)AzRKAJwu1x^Ub5d;-Hg`imRVW`p5?b=+2FYP7=+)D?FREeKi4q#&hPg9{R?~S VPG}_jwHp8c002ovPDHLkV1iNPinag% literal 0 HcmV?d00001 diff --git a/code/web/public_php/setup/index.php b/code/web/public_php/setup/index.php index a02d9e9e6..49d438e78 100644 --- a/code/web/public_php/setup/index.php +++ b/code/web/public_php/setup/index.php @@ -1,350 +1,47 @@ - - - - - - - Ryzom Core | Setup - - - '; - print $message; - print '
'; -} -function is__writable($path) { - if ($path{strlen($path) - 1} == '/') { - return is__writable($path.uniqid(mt_rand()).'.tmp'); - } - if (file_exists($path)) { - if (!($f = @fopen($path, 'r+'))) { - return false; - } - fclose($f); - return true; - } +error_reporting(E_ALL); +ini_set('display_errors', 'on'); + +class SystemExit extends Exception {} +try { + +$pageTitle = "Setup"; +include('header.php'); - if (!($f = @fopen($path, 'w'))) { - return false; - } - fclose($f); - unlink($path); - return true; -} -function validate_writable($continue, $path) { - if (!is__writable($path)) { - printalert("danger", "Failed to get write permissions on " . htmlentities($path)); - return false; - } - return $continue; -} -function create_use_database($continue_r, $con, $database) { - $continue = $continue_r; - if ($continue) { - $sql = "CREATE DATABASE `" . mysqli_real_escape_string($con, $database) . "` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"; - if (mysqli_query($con, $sql)) { - printalert("success", "Database " . $database . " created"); - } else { - printalert("danger", "Error creating " . $database . " database: " . mysqli_error($con)); - $continue = false; - } - } - if ($continue) { - $sql = "USE `" . mysqli_real_escape_string($con, $database) . "`;"; - if (mysqli_query($con, $sql)) { - printalert("success", "Database " . $database . " selected"); - } else { - printalert("danger", "Error selecting " . $database . " database: " . mysqli_error($con)); - $continue = false; - } - } - return $continue; -} -function update_database_structure($continue_r, $con, $file) { - $continue = $continue_r; - if ($continue) { - $sql = file_get_contents($_POST["privatePhpDirectory"] . "/setup/sql/" . $file); - if (!$sql) { - printalert("danger", "Cannot read " . $file . ""); - $continue = false; - } else { - if (mysqli_multi_query($con, $sql)) { - printalert("success", "Database structure updated using " . $file . ""); - while (mysqli_more_results($con) && mysqli_next_result($con)) { - // no-op - } - } else { - printalert("danger", "Error updating database using " . $file . ": " . mysqli_error($con)); - $continue = false; - } - } - } - return $continue; -} ?> - -
- +
+
- +

+ Upgrade +

- + - + - - -config.php"); - $continue = false; - } else { - $cwd = getcwd(); - $config = str_replace("%privatePhpDirectory%", addslashes(realpath($cwd . "/" . $_POST["privatePhpDirectory"])), $config); - $config = str_replace("%publicPhpDirectory%", addslashes(realpath($cwd)), $config); - $config = str_replace("%sqlHostname%", addslashes($_POST["sqlHostname"]), $config); - $config = str_replace("%sqlUsername%", addslashes($_POST["sqlUsername"]), $config); - $config = str_replace("%sqlPassword%", addslashes($_POST["sqlPassword"]), $config); - $config = str_replace("%nelDatabase%", addslashes($_POST["nelDatabase"]), $config); - $config = str_replace("%toolDatabase%", addslashes($_POST["toolDatabase"]), $config); - $config = str_replace("%amsDatabase%", addslashes($_POST["amsDatabase"]), $config); - $config = str_replace("%amsLibDatabase%", addslashes($_POST["amsLibDatabase"]), $config); - $config = str_replace("%amsAdminUsername%", addslashes($_POST["amsAdminUsername"]), $config); - $config = str_replace("%amsAdminPassword%", addslashes($_POST["amsAdminPassword"]), $config); - if (file_put_contents("config.php", $config)) { - printalert("success", "Generated config.php"); - } else { - printalert("danger", "Cannot write to config.php"); - $continue = false; - } - } - } - - // Load config - if ($continue) { - try { - require_once('config.php'); - } catch (Exception $e) { - printalert("danger", "Failed to include config.php"); - $continue = false; - } - } - - // Load AMS Library - if ($continue) { - try { - require_once($AMS_LIB . '/libinclude.php'); - } catch (Exception $e) { - printalert("danger", "Failed to include AMS libinclude.php"); - $continue = false; - } - } - - // Create AMS Admin user - if ($continue) { - $hashpass = crypt($_POST["amsAdminPassword"], Users::generateSALT()); - $params = array( - 'Login' => $_POST["amsAdminUsername"], - 'Password' => $hashpass, - 'Email' => "localhost@localhost", // TODO - ); - try { - $user_id = WebUsers::createWebuser($params['Login'], $params['Password'],$params['Email']); - $result = Webusers::createUser($params, $user_id); - Users::createPermissions(array($params['Login'])); - $dbl = new DBLayer("lib"); - $dbl->execute("UPDATE ticket_user SET Permission = 3 WHERE TUserId = :user_id",array('user_id' => $user_id)); - printalert("success", "AMS Admin account " . htmlentities($_POST["amsAdminUsername"]) . " created"); - } catch (PDOException $e) { - printalert("danger", "Failed to create AMS Admin account"); - $continue = false; - } - } - - if ($continue) { - if (file_put_contents("is_installed", "1")) { - printalert("success", "Success!"); - } else { - printalert("danger", "Failed to flag installation success"); - $continue = false; - } - } - - if ($con) { - mysqli_close($con); - printalert("info", "Disconnected from the SQL server"); - } -?> - - - -
-
-
-

Basics

-
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
-
-
-
-

Core

-
-
-
- -
- -
-
-
-
-
-
-

Admin

-
-
-
- -
- -
-
-
- -
-
-
-

AMS

-
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
+

+ Add Shard +

-
+ + Status + - - - +
+
+ + diff --git a/code/web/public_php/setup/install.php b/code/web/public_php/setup/install.php new file mode 100644 index 000000000..bcc57f4da --- /dev/null +++ b/code/web/public_php/setup/install.php @@ -0,0 +1,453 @@ + + + + + + + + + + +config.php"); + $continue = false; + } else { + $cwd = getcwd(); + $config = str_replace("%privatePhpDirectory%", addslashes(realpath($cwd . "/" . $_POST["privatePhpDirectory"])), $config); + $config = str_replace("%publicPhpDirectory%", addslashes(realpath($cwd)), $config); + $config = str_replace("%nelSqlHostname%", addslashes($_POST["nelSqlHostname"]), $config); + $config = str_replace("%nelSqlUsername%", addslashes($_POST["nelSqlUsername"]), $config); + $config = str_replace("%nelSqlPassword%", addslashes($_POST["nelSqlPassword"]), $config); + $config = str_replace("%nelDatabase%", addslashes($_POST["nelDatabase"]), $config); + $config = str_replace("%toolDatabase%", addslashes($_POST["toolDatabase"]), $config); + $config = str_replace("%amsSqlHostname%", addslashes($_POST["amsSqlHostname"]), $config); + $config = str_replace("%amsSqlUsername%", addslashes($_POST["amsSqlUsername"]), $config); + $config = str_replace("%amsSqlPassword%", addslashes($_POST["amsSqlPassword"]), $config); + $config = str_replace("%amsDatabase%", addslashes($_POST["amsDatabase"]), $config); + $config = str_replace("%amsLibDatabase%", addslashes($_POST["amsLibDatabase"]), $config); + $config = str_replace("%amsAdminUsername%", addslashes($_POST["amsAdminUsername"]), $config); + $config = str_replace("%amsAdminPassword%", addslashes($_POST["amsAdminPassword"]), $config); + $config = str_replace("%nelSetupPassword%", addslashes($_POST["nelSetupPassword"]), $config); + $config = str_replace("%domainDatabase%", addslashes($_POST["domainDatabase"]), $config); + $config = str_replace("%nelDomainName%", addslashes($_POST["nelDomainName"]), $config); + if (file_put_contents("config.php", $config)) { + printalert("success", "Generated config.php"); + } else { + printalert("danger", "Cannot write to config.php"); + $continue = false; + } + } + } + + // Load config + if ($continue) { + try { + require_once('config.php'); + } catch (Exception $e) { + printalert("danger", "Failed to include config.php"); + $continue = false; + } + } + + if ($roleSupport) { + // Load AMS Library + if ($continue) { + try { + require_once($AMS_LIB . '/libinclude.php'); + } catch (Exception $e) { + printalert("danger", "Failed to include AMS libinclude.php"); + $continue = false; + } + } + + // Create AMS Admin user + if ($continue) { + $hashpass = crypt($_POST["amsAdminPassword"], Users::generateSALT()); + $params = array( + 'Login' => $_POST["amsAdminUsername"], + 'Password' => $hashpass, + 'Email' => "localhost@localhost", // TODO + ); + try { + $user_id = WebUsers::createWebuser($params['Login'], $params['Password'],$params['Email']); + $result = Webusers::createUser($params, $user_id); + Users::createPermissions(array($params['Login'])); + $dbl = new DBLayer("lib"); + $dbl->execute("UPDATE ticket_user SET Permission = 3 WHERE TUserId = :user_id",array('user_id' => $user_id)); + printalert("success", "AMS Admin account " . htmlentities($_POST["amsAdminUsername"]) . " created"); + } catch (PDOException $e) { + printalert("danger", "Failed to create AMS Admin account"); + $continue = false; + } + } + } + + if ($continue && $roleSupport) { + if (file_put_contents("role_service", "1")) { + printalert("success", "Service role successfully installed"); + } else { + printalert("danger", "Failed to flag installation success"); + $continue = false; + } + } + + if ($continue && $roleSupport) { + if (file_put_contents("role_support", "1")) { + printalert("success", "Support role successfully installed"); + } else { + printalert("danger", "Failed to flag installation success"); + $continue = false; + } + } + + if ($continue && $roleDomain) { + if (file_put_contents("role_domain", "1")) { + printalert("success", "Domain role successfully installed"); + } else { + printalert("danger", "Failed to flag installation success"); + $continue = false; + } + } +?> + +

+ Continue +

+ + + + + +
+
+
+

Roles

+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+

Basics (Paths relative to the public root directory)

+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+
+
+

Service Database (Used for NeL login, admin tools and domain databases)

+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+
+
+

Shard Admin

+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+
+
+

AMS (Account Management System)

+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+
+
+

Domain

+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ +
+ + + + + +