This commit is contained in:
kaetemi 2014-09-05 11:22:18 +02:00
commit 17234d6398
4 changed files with 160 additions and 11 deletions

View file

@ -18,7 +18,7 @@ ini_set( 'display_errors', 'on' );
class SystemExit extends Exception {}
try {
if (!file_exists( '../config.php')) {
if (!file_exists('../role_support')) {
header("Cache-Control: max-age=1");
header('Location: ../setup', true, 303);
throw new SystemExit();

View file

@ -9,24 +9,34 @@ try {
$pageTitle = "Authenticate";
include('header.php');
require_once('config.php');
?>
<div style="margin-left: auto; margin-right: auto; max-width: 512px;">
<?php /*var_dump($_POST);*/ if ($_POST) { ?>
<?php /*var_dump($_POST);*/ $showForm = true; if ($_POST) { ?>
<?php if ($_POST['nelSetupPassword'] == $NEL_SETUP_PASSWORD) { ?>
<?php
// TODO
$_SESSION['nelSetupAuthenticated'] = 1;
printalert("success", "You are now authenticated");
$showForm = false;
?>
<p>
<a class="btn btn-primary" href="index.php">Continue</a>
</p>
<?php } else { ?>
<?php } else {
printalert("danger", "Invalid password");
} ?>
<?php } if ($showForm) { ?>
<form class="form" role="form" method="POST" action="" enctype="application/x-www-form-urlencoded">
<div class="input-group">

View file

@ -0,0 +1,117 @@
<?php
function set_db_version($continue_r, $name, $version) {
$continue = $continue_r;
if (file_put_contents("db_version_" . $name, (string)$version)) {
} else {
printalert("danger", "Failed to set database version");
$continue = false;
}
return $continue;
}
function get_db_version($name) {
if (!file_exists("db_version_" . $name)) {
return 0;
}
return (int)file_get_contents("db_version_" . $name);
}
function connect_database($continue, $name) {
$con = null;
global $cfg;
if ($continue) {
$con = mysqli_connect(
$cfg['db'][$name]['host'],
$cfg['db'][$name]['user'],
$cfg['db'][$name]['pass'],
$cfg['db'][$name]['name']);
if (mysqli_connect_errno()) {
printalert("danger", "Failed to connect to the <em>" . $name . "</em> SQL server: " . mysqli_connect_error());
$con = null;
} else {
printalert("success", "Connected to the <em>" . $name . "</em> SQL server");
}
}
return $con;
}
function disconnect_database($con, $name) {
if ($con) {
mysqli_close($con);
printalert("info", "Disconnected from the <em>" . $name . "</em> SQL server");
}
}
function upgrade_service_databases($continue_r) {
$continue = $continue_r;
$con = null;
$con = connect_database($continue, "shard");
$continue = ($con != null);
if ($continue && get_db_version("shard") < 1) {
$continue = update_database_structure($continue, $con, "nel_00001.sql");
$continue = set_db_version($continue, "shard", 1);
}
disconnect_database($con, "shard");
$con = null;
$con = connect_database($continue, "tool");
$continue = ($con != null);
if ($continue && get_db_version("tool") < 1) {
$continue = update_database_structure($continue, $con, "nel_tool_00001.sql");
$continue = set_db_version($continue, "tool", 1);
}
disconnect_database($con, "tool");
return $continue;
}
function upgrade_support_databases($continue_r) {
$continue = $continue_r;
$con = null;
$con = connect_database($continue, "web");
$continue = ($con != null);
if ($continue && get_db_version("web") < 1) {
$continue = update_database_structure($continue, $con, "nel_ams_00001.sql");
$continue = set_db_version($continue, "web", 1);
}
disconnect_database($con, "web");
$con = null;
$con = connect_database($continue, "lib");
$continue = ($con != null);
if ($continue && get_db_version("lib") < 1) {
$continue = update_database_structure($continue, $con, "nel_ams_lib_00001.sql");
$continue = set_db_version($continue, "lib", 1);
}
if ($continue && get_db_version("lib") < 2) {
$continue = update_database_structure($continue, $con, "nel_ams_lib_00002.sql");
$continue = set_db_version($continue, "lib", 2);
}
disconnect_database($con, "lib");
return $continue;
}
function upgrade_domain_databases($continue_r) {
$continue = $continue_r;
$con = null;
$con = connect_database($continue, "ring");
$continue = ($con != null);
if ($continue && get_db_version("ring") < 1) {
$continue = update_database_structure($continue, $con, "ring_domain_00001.sql");
$continue = set_db_version($continue, "ring", 1);
}
disconnect_database($con, "ring");
return $continue;
}
?>

View file

@ -75,11 +75,14 @@ include('header.php');
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 ($roleDomain) {
// Create Ring database
$continue = create_use_database($continue, $con, $_POST["domainDatabase"]);
}
if ($con) {
@ -101,12 +104,9 @@ include('header.php');
// 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);
@ -158,6 +158,24 @@ include('header.php');
}
}
require_once('database.php');
if ($roleSupport) {
$continue = upgrade_support_databases($continue);
}
if ($roleService) {
$continue = upgrade_service_databases($continue);
}
if ($roleDomain) {
$continue = upgrade_domain_databases($continue);
}
if ($roleService) {
// TODO: Create the default admin user
}
if ($roleSupport) {
// Load AMS Library
if ($continue) {
@ -191,7 +209,11 @@ include('header.php');
}
}
if ($continue && $roleSupport) {
if ($roleDomain) {
// TODO: Register the domain with the nel database etc
}
if ($continue && $roleService) {
if (file_put_contents("role_service", "1")) {
printalert("success", "Service role successfully installed");
} else {
@ -414,7 +436,7 @@ include('header.php');
</div>
<div id="panelDomain" class="panel panel-default hide">
<div class="panel-heading">
<h2 class="panel-title">Domain</h2>
<h2 class="panel-title">Domain <small>(Multiple domains require separate installations, as they may run different versions)</small></h2>
</div>
<div class="panel-body">
<div class="form-group">