';
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;
}
?>
Already installed. Upgrading not available yet.
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");
}
?>