This commit is contained in:
botanic 2014-09-05 01:20:39 -07:00
commit 58be0a2b8e
10 changed files with 712 additions and 361 deletions

View file

@ -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/";
$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%';

View file

@ -0,0 +1,2 @@
RewriteEngine On
RewriteRule ^$ /ams [R=301,L]

View file

@ -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();

View file

@ -0,0 +1,6 @@
<?php
header("Cache-Control: max-age=1");
header('Location: ams/', true, 301);
?>

View file

@ -0,0 +1,52 @@
<?php
error_reporting(E_ALL);
ini_set('display_errors', 'on');
class SystemExit extends Exception {}
try {
$pageTitle = "Authenticate";
include('header.php');
?>
<div style="margin-left: auto; margin-right: auto; max-width: 512px;">
<?php /*var_dump($_POST);*/ if ($_POST) { ?>
<?php
// TODO
$_SESSION['nelSetupAuthenticated'] = 1;
printalert("success", "You are now authenticated");
?>
<p>
<a class="btn btn-primary" href="index.php">Continue</a>
</p>
<?php } else { ?>
<form class="form" role="form" method="POST" action="" enctype="application/x-www-form-urlencoded">
<div class="input-group">
<label for="nelSetupPassword" class="sr-only">NeL Setup Password</label>
<input type="password" class="form-control" id="nelSetupPassword" name="nelSetupPassword" placeholder="Password">
<span class="input-group-btn">
<input name="submit" type="submit" value="Authenticate" class="btn btn-primary">
</span>
</div>
</form>
<?php } ?>
</div>
<?php
include('footer.php');
}
catch (SystemExit $e) { /* do nothing */ }
?>

View file

@ -0,0 +1,12 @@
<!-- --------------------------------------------------------------- -->
<hr>
<div class="pull-right" style="margin-bottom: 32px;"><a href="http://www.gnu.org/licenses/agpl-3.0.txt"><img src="img/agplv3-88x31.png" alt="AGPLv3"></a></div>
</div>
<script src="js/bootstrap.min.js"></script>
</body>
</html>

View file

@ -0,0 +1,123 @@
<?php
if (file_exists( '../config.php')) {
session_start();
if ((!isset($_SESSION['nelSetupAuthenticated'])) || $_SESSION['nelSetupAuthenticated'] != 1) {
if (basename($_SERVER["SCRIPT_NAME"]) != "auth.php") {
header("Cache-Control: max-age=1");
header('Location: auth.php', true, 303);
throw new SystemExit();
}
}
} else if (basename($_SERVER["SCRIPT_NAME"]) != "install.php") {
header("Cache-Control: max-age=1");
header('Location: install.php', true, 303);
throw new SystemExit();
}
?><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Ryzom Core | <?php print(htmlentities($pageTitle)); ?></title>
<link href="css/bootstrap.min.css" rel="stylesheet">
</head>
<?php
function printalert($type, $message) {
print '<div class="alert alert-' . $type . '" role="alert">';
print $message;
print '</div>';
}
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 <em>" . $database . "</em> created");
} else {
printalert("danger", "Error creating <em>" . $database . "</em> database: " . mysqli_error($con));
$continue = false;
}
}
if ($continue) {
$sql = "USE `" . mysqli_real_escape_string($con, $database) . "`;";
if (mysqli_query($con, $sql)) {
printalert("success", "Database <em>" . $database . "</em> selected");
} else {
printalert("danger", "Error selecting <em>" . $database . "</em> 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 <em>" . $file . "</em>");
$continue = false;
} else {
if (mysqli_multi_query($con, $sql)) {
printalert("success", "Database structure updated using <em>" . $file . "</em>");
while (mysqli_more_results($con) && mysqli_next_result($con)) {
// no-op
}
} else {
printalert("danger", "Error updating database using <em>" . $file . "</em>: " . mysqli_error($con));
$continue = false;
}
}
}
return $continue;
}
?>
<body>
<div style="margin-left: auto; margin-right: auto; padding-left: 24px; padding-right: 24px; padding-bottom: 24px; max-width: 1024px;">
<div class="page-header">
<h1>Ryzom Core <small><?php print(htmlentities($pageTitle)); ?></small></h1>
</div>
<?php
// Change to root directory
if (!chdir("../")) {
printalert("danger", "Cannot change to public PHP root directory");
$continue = false;
}
?>
<!-- --------------------------------------------------------------- -->

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View file

@ -1,351 +1,47 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Ryzom Core | Setup</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
</head>
<?php
function printalert($type, $message) {
print '<div class="alert alert-' . $type . '" role="alert">';
print $message;
print '</div>';
}
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 <em>" . $database . "</em> created");
} else {
printalert("danger", "Error creating <em>" . $database . "</em> database: " . mysqli_error($con));
$continue = false;
}
}
if ($continue) {
$sql = "USE `" . mysqli_real_escape_string($con, $database) . "`;";
if (mysqli_query($con, $sql)) {
printalert("success", "Database <em>" . $database . "</em> selected");
} else {
printalert("danger", "Error selecting <em>" . $database . "</em> 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 <em>" . $file . "</em>");
$continue = false;
} else {
if (mysqli_multi_query($con, $sql)) {
printalert("success", "Database structure updated using <em>" . $file . "</em>");
while (mysqli_more_results($con) && mysqli_next_result($con)) {
// no-op
}
} else {
printalert("danger", "Error updating database using <em>" . $file . "</em>: " . mysqli_error($con));
$continue = false;
}
}
}
return $continue;
}
?>
<body>
<div style="margin-left: auto; margin-right: auto; padding-left: 24px; padding-right: 24px; padding-bottom: 24px; max-width: 1024px;">
<div class="page-header">
<h1>Ryzom Core <small>Setup</small></h1>
</div>
<?php if (file_exists( '../is_installed')) { ?>
<div class="alert alert-info" role="alert">
Already installed. Upgrading not available yet.
</div>
<?php } else if ($_POST) { ?>
<div class="alert alert-info" role="alert">
<?php var_dump($_POST); ?>
</div>
<?php
$continue = true;
// Change to root directory
if (!chdir("../")) {
printalert("Cannot change to public PHP root directory");
$continue = false;
}
// Validate basics
if ($continue) {
if (file_exists($_POST["privatePhpDirectory"])) {
printalert("success", "Private PHP Directory found");
} else {
printalert("danger", "Private PHP Directory not found (NOTE: This directory is relative to the root of the public PHP directory)");
$continue = false;
}
}
if ($continue) {
$continue = validate_writable($continue, "login/logs/");
$continue = validate_writable($continue, "admin/graphs_output/");
$continue = validate_writable($continue, "admin/templates/default_c/");
$continue = validate_writable($continue, "ams/cache/");
$continue = validate_writable($continue, "ams/templates_c/");
$continue = validate_writable($continue, "./");
if ($continue) {
printalert("success", "Paths are writable");
}
}
$con = null;
if ($continue) {
$con = mysqli_connect($_POST["sqlHostname"], $_POST["sqlUsername"], $_POST["sqlPassword"]);
if (mysqli_connect_errno()) {
printalert("danger", "Failed to connect to SQL: " . mysqli_connect_error());
$continue = false;
$con = null;
} else {
printalert("success", "Connected to the SQL server");
}
}
// Create NeL database
$continue = create_use_database($continue, $con, $_POST["nelDatabase"]);
$continue = update_database_structure($continue, $con, "nel_00001.sql");
// Create NeL Tools database
$continue = create_use_database($continue, $con, $_POST["toolDatabase"]);
$continue = update_database_structure($continue, $con, "nel_tool_00001.sql");
// Create AMS database
$continue = create_use_database($continue, $con, $_POST["amsDatabase"]);
$continue = update_database_structure($continue, $con, "nel_ams_00001.sql");
// Create AMS Library database
$continue = create_use_database($continue, $con, $_POST["amsLibDatabase"]);
$continue = update_database_structure($continue, $con, "nel_ams_lib_00001.sql");
$continue = update_database_structure($continue, $con, "nel_ams_lib_00002.sql");
// Write config.php
if ($continue) {
$config = file_get_contents($_POST["privatePhpDirectory"] . "/setup/config/config.php");
if (!$config) {
printalert("danger", "Cannot read <em>config.php</em>");
$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 <em>config.php</em>");
} else {
printalert("danger", "Cannot write to <em>config.php</em>");
$continue = false;
}
}
}
// Load config
if ($continue) {
try {
require_once('config.php');
} catch (Exception $e) {
printalert("danger", "Failed to include <em>config.php</em>");
$continue = false;
}
}
// Load AMS Library
if ($continue) {
try {
require_once($AMS_LIB . '/libinclude.php');
} catch (Exception $e) {
printalert("danger", "Failed to include AMS <em>libinclude.php</em>");
$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 <em>" . htmlentities($_POST["amsAdminUsername"]) . "</em> 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");
}
?>
<?php } /* ENDOF: if (isset($_POST)) { */ else { /* TODO: Refill form on failure */ ?>
<form class="form-horizontal" role="form" method="POST" action=".">
<div class="panel panel-default">
<div class="panel-heading">
<h2 class="panel-title">Basics</h2>
</div>
<div class="panel panel-default" style="margin-left: auto; margin-right: auto; max-width: 256px;">
<div class="panel-body">
<div class="form-group">
<label for="privatePhpDirectory" class="col-sm-3 control-label">Private PHP Directory</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="privatePhpDirectory" name="privatePhpDirectory" value="../private_php/">
</div>
</div>
<div class="form-group">
<label for="sqlHostname" class="col-sm-3 control-label">SQL Hostname</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="sqlHostname" name="sqlHostname" value="localhost">
</div>
</div>
<div class="form-group">
<label for="sqlUsername" class="col-sm-3 control-label">SQL Username</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="sqlUsername" name="sqlUsername" value="root">
</div>
</div>
<div class="form-group">
<label for="sqlPassword" class="col-sm-3 control-label">SQL Password</label>
<div class="col-sm-6">
<input type="password" class="form-control" id="sqlPassword" name="sqlPassword" value="">
</div>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h2 class="panel-title">Core</h2>
</div>
<div class="panel-body">
<div class="form-group">
<label for="nelDatabase" class="col-sm-3 control-label">NeL Database</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="nelDatabase" name="nelDatabase" value="nel">
</div>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h2 class="panel-title">Admin</h2>
</div>
<div class="panel-body">
<div class="form-group">
<label for="toolDatabase" class="col-sm-3 control-label">NeL Tools Database</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="toolDatabase" name="toolDatabase" value="nel_tool">
</div>
</div>
</div>
<!-- TODO: Initial admin user -->
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h2 class="panel-title">AMS</h2>
</div>
<div class="panel-body">
<div class="form-group">
<label for="amsDatabase" class="col-sm-3 control-label">AMS CMS Database</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="amsDatabase" name="amsDatabase" value="nel_ams">
</div>
</div>
<div class="form-group">
<label for="amsLibDatabase" class="col-sm-3 control-label">AMS Library Database</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="amsLibDatabase" name="amsLibDatabase" value="nel_ams_lib">
</div>
</div>
<div class="form-group">
<label for="amsAdminUsername" class="col-sm-3 control-label">AMS Admin Username</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="amsAdminUsername" name="amsAdminUsername" value="admin">
</div>
</div>
<div class="form-group">
<label for="amsAdminPassword" class="col-sm-3 control-label">AMS Admin Password</label>
<div class="col-sm-6">
<input type="password" class="form-control" id="amsAdminPassword" name="amsAdminPassword" value="admin">
</div>
</div>
</div>
<!-- TODO: Initial admin user -->
</div>
<button type="submit" class="btn btn-primary">Configure</button>
</form>
<p>
<a class="btn btn-default" style="width: 100%;" href="upgrade.php"><span class="glyphicon glyphicon-wrench"></span> Upgrade</a>
</p>
<?php if (file_exists('role_domain')) { ?>
<!--<p>
<a class="btn btn-default" style="width: 100%;" href="domain.php"><span class="glyphicon glyphicon-globe"></span> Add Domain</a>
</p>-->
<p>
<a class="btn btn-default" style="width: 100%;" href="upgrade.php"><span class="glyphicon glyphicon-tower"></span> Add Shard</a>
</p>
<?php } ?>
<!--<p>-->
<a class="btn btn-default" style="width: 100%;" href="status.php"><span class="glyphicon glyphicon-info-sign"></span> Status</a>
<!--</p>-->
</div>
</div>
<script src="js/bootstrap.min.js"></script>
</body>
</html>
<?php
include('footer.php');
}
catch (SystemExit $e) { /* do nothing */ }
?>

View file

@ -0,0 +1,454 @@
<?php
error_reporting(E_ALL);
ini_set('display_errors', 'on');
class SystemExit extends Exception {}
try {
$pageTitle = "Install";
include('header.php');
?>
<?php if (file_exists('config.php')) { ?>
<div class="alert alert-danger" role="alert">
Already installed.
</div>
<?php } else if ($_POST) { ?>
<div class="alert alert-info" role="alert">
<?php var_dump($_POST); ?>
</div>
<?php
$continue = true;
$roleService = isset($_POST["roleService"]) && $_POST["roleService"] == "on";
$roleSupport = isset($_POST["roleSupport"]) && $_POST["roleSupport"] == "on";
$roleDomain = isset($_POST["roleDomain"]) && $_POST["roleDomain"] == "on";
if (!$roleService && !$roleSupport && !$roleDomain) {
printalert("danger", "No server roles selected");
$continue = false;
}
// Validate basics
if ($continue) {
if (file_exists($_POST["privatePhpDirectory"])) {
printalert("success", "Private PHP Directory found");
} else {
printalert("danger", "Private PHP Directory not found (NOTE: This directory is relative to the root of the public PHP directory)");
$continue = false;
}
}
if ($continue) {
if ($roleService) {
$continue = validate_writable($continue, "login/logs/");
$continue = validate_writable($continue, "admin/graphs_output/");
$continue = validate_writable($continue, "admin/templates/default_c/");
}
if ($roleSupport) {
$continue = validate_writable($continue, "ams/cache/");
$continue = validate_writable($continue, "ams/templates_c/");
}
$continue = validate_writable($continue, "./");
if ($continue) {
printalert("success", "Paths are writable");
}
}
$con = null;
if ($continue) { // NOTE: Also test if this is reachable when not Service role
$con = mysqli_connect($_POST["nelSqlHostname"], $_POST["nelSqlUsername"], $_POST["nelSqlPassword"]);
if (mysqli_connect_errno()) {
printalert("danger", "Failed to connect to Service SQL: " . mysqli_connect_error());
$continue = false;
$con = null;
} else {
printalert("success", "Connected to the Service SQL server");
}
}
if ($roleService) {
// Create NeL database
$continue = create_use_database($continue, $con, $_POST["nelDatabase"]);
$continue = update_database_structure($continue, $con, "nel_00001.sql");
// Create NeL Tools database
$continue = create_use_database($continue, $con, $_POST["toolDatabase"]);
$continue = update_database_structure($continue, $con, "nel_tool_00001.sql");
}
if ($con) {
mysqli_close($con);
printalert("info", "Disconnected from the Service SQL server");
}
if ($roleSupport) {
if ($continue) {
$con = mysqli_connect($_POST["amsSqlHostname"], $_POST["amsSqlUsername"], $_POST["amsSqlPassword"]);
if (mysqli_connect_errno()) {
printalert("danger", "Failed to connect to Support SQL: " . mysqli_connect_error());
$continue = false;
$con = null;
} else {
printalert("success", "Connected to the Support SQL server");
}
}
// Create AMS database
$continue = create_use_database($continue, $con, $_POST["amsDatabase"]);
$continue = update_database_structure($continue, $con, "nel_ams_00001.sql");
// Create AMS Library database
$continue = create_use_database($continue, $con, $_POST["amsLibDatabase"]);
$continue = update_database_structure($continue, $con, "nel_ams_lib_00001.sql");
$continue = update_database_structure($continue, $con, "nel_ams_lib_00002.sql");
if ($con) {
mysqli_close($con);
printalert("info", "Disconnected from the Support SQL server");
}
}
// Write config.php
if ($continue) {
$config = file_get_contents($_POST["privatePhpDirectory"] . "/setup/config/config.php");
if (!$config) {
printalert("danger", "Cannot read <em>config.php</em>");
$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 <em>config.php</em>");
} else {
printalert("danger", "Cannot write to <em>config.php</em>");
$continue = false;
}
}
}
// Load config
if ($continue) {
try {
require_once('config.php');
} catch (Exception $e) {
printalert("danger", "Failed to include <em>config.php</em>");
$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 <em>libinclude.php</em>");
$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 <em>" . htmlentities($_POST["amsAdminUsername"]) . "</em> 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;
}
}
?>
<p>
<a class="btn btn-primary" href="index.php">Continue</a>
</p>
<?php } /* ENDOF: if (isset($_POST)) { */ else { /* TODO: Refill form on failure */ ?>
<script>
var visiblePanelClass = "panel panel-default";
var hiddenPanelClass = "panel panel-default hide";
function checkService() {
var panelClass = document.getElementById('roleService').checked
? visiblePanelClass
: hiddenPanelClass;
document.getElementById("panelAdmin").className = panelClass;
}
function checkSupport() {
var panelClass = document.getElementById('roleSupport').checked
? visiblePanelClass
: hiddenPanelClass;
document.getElementById("panelAMS").className = panelClass;
}
function checkDomain() {
var panelClass = document.getElementById('roleDomain').checked
? visiblePanelClass
: hiddenPanelClass;
document.getElementById("panelDomain").className = panelClass;
}
</script>
<form class="form-horizontal" role="form" method="POST" action="" enctype="application/x-www-form-urlencoded">
<div class="panel panel-default">
<div class="panel-heading">
<h2 class="panel-title">Roles</h2>
</div>
<div class="panel-body">
<div class="form-group">
<div class="col-sm-offset-3 col-sm-8">
<div class="checkbox">
<label>
<input id="roleService" name="roleService" type="checkbox" onclick="checkService();" checked> Service <small>(NeL Login, Shard Admin, Domain Database, ...)</small>
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-8">
<div class="checkbox">
<label>
<input id="roleSupport" name="roleSupport" type="checkbox" onclick="checkSupport();" checked> Support <small>(AMS, ...)</small>
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-8">
<div class="checkbox">
<label>
<input id="roleDomain" name="roleDomain" type="checkbox" onclick="checkDomain();" disabled> Domain <small>(Ring Database, ...) <em>TODO</em></small>
</label>
</div>
</div>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h2 class="panel-title">Basics <small>(Paths relative to the public root directory)</small></h2>
</div>
<div class="panel-body">
<div class="form-group">
<label for="privatePhpDirectory" class="col-sm-3 control-label">Private PHP Directory</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="privatePhpDirectory" name="privatePhpDirectory" value="../private_php/">
</div>
</div>
<div class="form-group">
<label for="nelSetupPassword" class="col-sm-3 control-label">Setup Password</label>
<div class="col-sm-6">
<input type="password" class="form-control" id="nelSetupPassword" name="nelSetupPassword" value="admin">
</div>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h2 class="panel-title">Service Database <small>(Used for NeL login, admin tools and domain databases)</small></h2>
</div>
<div class="panel-body">
<div class="form-group">
<label for="nelSqlHostname" class="col-sm-3 control-label">SQL Hostname</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="nelSqlHostname" name="nelSqlHostname" value="localhost">
</div>
</div>
<div class="form-group">
<label for="nelSqlUsername" class="col-sm-3 control-label">SQL Username</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="nelSqlUsername" name="nelSqlUsername" value="root">
</div>
</div>
<div class="form-group">
<label for="nelSqlPassword" class="col-sm-3 control-label">SQL Password</label>
<div class="col-sm-6">
<input type="password" class="form-control" id="nelSqlPassword" name="nelSqlPassword" value="">
</div>
</div>
<div class="form-group">
<label for="nelDatabase" class="col-sm-3 control-label">NeL Database</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="nelDatabase" name="nelDatabase" value="nel">
</div>
</div>
</div>
</div>
<div id="panelAdmin" class="panel panel-default">
<div class="panel-heading">
<h2 class="panel-title">Shard Admin</h2>
</div>
<div class="panel-body">
<div class="form-group">
<label for="toolDatabase" class="col-sm-3 control-label">NeL Tools Database</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="toolDatabase" name="toolDatabase" value="nel_tool">
</div>
</div>
<div class="form-group">
<label for="toolsAdminUsername" class="col-sm-3 control-label">Admin Username</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="toolsAdminUsername" name="toolsAdminUsername" value="admin">
</div>
</div>
<div class="form-group">
<label for="toolsAdminPassword" class="col-sm-3 control-label">Admin Password</label>
<div class="col-sm-6">
<input type="password" class="form-control" id="toolsAdminPassword" name="toolsAdminPassword" value="admin">
</div>
</div>
</div>
</div>
<div id="panelAMS" class="panel panel-default">
<div class="panel-heading">
<h2 class="panel-title">AMS <small>(Account Management System)</small></h2>
</div>
<div class="panel-body">
<div class="form-group">
<label for="amsSqlHostname" class="col-sm-3 control-label">SQL Hostname</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="amsSqlHostname" name="amsSqlHostname" value="localhost">
</div>
</div>
<div class="form-group">
<label for="amsSqlUsername" class="col-sm-3 control-label">SQL Username</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="amsSqlUsername" name="amsSqlUsername" value="root">
</div>
</div>
<div class="form-group">
<label for="amsSqlPassword" class="col-sm-3 control-label">SQL Password</label>
<div class="col-sm-6">
<input type="password" class="form-control" id="amsSqlPassword" name="amsSqlPassword" value="">
</div>
</div>
<div class="form-group">
<label for="amsDatabase" class="col-sm-3 control-label">CMS Database</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="amsDatabase" name="amsDatabase" value="nel_ams">
</div>
</div>
<div class="form-group">
<label for="amsLibDatabase" class="col-sm-3 control-label">Library Database</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="amsLibDatabase" name="amsLibDatabase" value="nel_ams_lib">
</div>
</div>
<div class="form-group">
<label for="amsAdminUsername" class="col-sm-3 control-label">Admin Username</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="amsAdminUsername" name="amsAdminUsername" value="admin">
</div>
</div>
<div class="form-group">
<label for="amsAdminPassword" class="col-sm-3 control-label">Admin Password</label>
<div class="col-sm-6">
<input type="password" class="form-control" id="amsAdminPassword" name="amsAdminPassword" value="admin">
</div>
</div>
</div>
</div>
<div id="panelDomain" class="panel panel-default hide">
<div class="panel-heading">
<h2 class="panel-title">Domain</h2>
</div>
<div class="panel-body">
<div class="form-group">
<label for="nelDomainName" class="col-sm-3 control-label">Name</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="nelDomainName" name="nelDomainName" value="mini01">
</div>
</div>
<div class="form-group">
<label for="domainDatabase" class="col-sm-3 control-label">Database</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="domainDatabase" name="domainDatabase" value="ring_mini01">
</div>
</div>
</div>
</div>
<input name="submit" type="submit" value="Configure" class="btn btn-primary">
</form>
<script>
checkService();
checkSupport();
checkDomain();
</script>
<?php } ?>
<?php
include('footer.php');
}
catch (SystemExit $e) { /* do nothing */ }
?>