diff --git a/code/web/private_php/setup/config/config.php b/code/web/private_php/setup/config/config.php index 5c8167ba1..a481cdf9d 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"); @@ -122,5 +122,11 @@ $INGAME_LAYOUT = "basic"; $FORCE_INGAME = false; //file storage path (must be a publicly accessible url for -$FILE_STORAGE_PATH = $PUBLIC_PHP_PATH."\\ams\\files\\"; -$FILE_WEB_PATH = $BASE_WEBPATH."files/"; \ No newline at end of file +$FILE_STORAGE_PATH = $PUBLIC_PHP_PATH . '/ams/files/'; +$FILE_WEB_PATH = $BASE_WEBPATH . '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 9e844006a..1ab707e79 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(); @@ -53,7 +53,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 000000000..7a472a0d8 Binary files /dev/null and b/code/web/public_php/setup/img/agplv3-88x31.png differ diff --git a/code/web/public_php/setup/index.php b/code/web/public_php/setup/index.php index 00dcda9ea..49d438e78 100644 --- a/code/web/public_php/setup/index.php +++ b/code/web/public_php/setup/index.php @@ -1,351 +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..8fdade460 --- /dev/null +++ b/code/web/public_php/setup/install.php @@ -0,0 +1,454 @@ + + + + + + + + + + +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

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