Installation fixed, version bump 2.4.0

This commit is contained in:
Roman 2024-05-04 12:23:14 +02:00
parent ae5210ec57
commit 76da46e157
7 changed files with 237 additions and 202 deletions

@ -140,10 +140,10 @@ class Parameter {
break; break;
case Parameter::TYPE_BOOLEAN: case Parameter::TYPE_BOOLEAN:
if (strcasecmp($value, 'true') === 0) { if (strcasecmp($value, 'true') === 0 || $value === 1) {
$this->value = true; $this->value = true;
$valid = true; $valid = true;
} else if (strcasecmp($value, 'false') === 0) { } else if (strcasecmp($value, 'false') === 0 || $value === 0) {
$this->value = false; $this->value = false;
$valid = true; $valid = true;
} else if (is_bool($value)) { } else if (is_bool($value)) {

@ -90,7 +90,7 @@ class Configuration {
} }
public function delete(string $className): bool { public function delete(string $className): bool {
$path = getClassPath("\\Configuration\\$className"); $path = getClassPath($className);
if (file_exists($path)) { if (file_exists($path)) {
return unlink($path); return unlink($path);
} }

@ -20,8 +20,10 @@ class CreateDatabase extends DatabaseScript {
->addBool("private", false) // these values are not returned from '/api/settings/get', but can be changed ->addBool("private", false) // these values are not returned from '/api/settings/get', but can be changed
->addBool("readonly", false) // these values are neither returned, nor can be changed from outside ->addBool("readonly", false) // these values are neither returned, nor can be changed from outside
->primaryKey("name"); ->primaryKey("name");
$settingsQuery = $sql->insert("Settings", array("name", "value", "private", "readonly"));
(Settings::loadDefaults())->addRows($settingsQuery); $defaultSettings = Settings::loadDefaults(loadEnv());
$settingsQuery = $sql->insert("Settings", ["name", "value", "private", "readonly"]);
$defaultSettings->addRows($settingsQuery);
$queries[] = $settingsQuery; $queries[] = $settingsQuery;
$queries[] = $sql->createTable("ApiPermission") $queries[] = $sql->createTable("ApiPermission")

@ -94,7 +94,7 @@ class Settings {
return $this->installationComplete; return $this->installationComplete;
} }
public static function loadDefaults(): Settings { public static function loadDefaults(?array $env = null): Settings {
$protocol = getProtocol(); $protocol = getProtocol();
$hostname = getCurrentHostName(); $hostname = getCurrentHostName();
$settings = new Settings(); $settings = new Settings();
@ -125,6 +125,9 @@ class Settings {
if (isDocker()) { if (isDocker()) {
$settings->rateLimitingEnabled = true; $settings->rateLimitingEnabled = true;
$settings->redisHost = "webbase-redis"; $settings->redisHost = "webbase-redis";
if ($env && array_key_exists("REDIS_PASSWORD", $env)) {
$settings->redisPassword = $env["REDIS_PASSWORD"];
}
} else { } else {
$settings->rateLimitingEnabled = false; $settings->rateLimitingEnabled = false;
$settings->redisHost = ""; $settings->redisHost = "";
@ -182,7 +185,7 @@ class Settings {
->addRow("mail_from", '""', false, false) ->addRow("mail_from", '""', false, false)
->addRow("mail_footer", '""', false, false) ->addRow("mail_footer", '""', false, false)
->addRow("mail_async", false, false, false) ->addRow("mail_async", false, false, false)
->addRow("rate_limiting_enabled", json_encode($this->allowedExtensions), false, false) ->addRow("rate_limiting_enabled", true, false, false)
->addRow("redis_host", json_encode($this->redisHost), false, false) ->addRow("redis_host", json_encode($this->redisHost), false, false)
->addRow("redis_port", json_encode($this->redisPort), false, false) ->addRow("redis_port", json_encode($this->redisPort), false, false)
->addRow("redis_password", json_encode($this->redisPassword), true, false) ->addRow("redis_password", json_encode($this->redisPassword), true, false)

@ -29,6 +29,7 @@ namespace Documents\Install {
use Core\External\PHPMailer\PHPMailer; use Core\External\PHPMailer\PHPMailer;
use Core\Objects\ConnectionData; use Core\Objects\ConnectionData;
use Core\Objects\DatabaseEntity\Group; use Core\Objects\DatabaseEntity\Group;
use Core\Objects\DatabaseEntity\User;
class InstallHead extends Head { class InstallHead extends Head {
@ -46,17 +47,17 @@ namespace Documents\Install {
} }
protected function initMetas(): array { protected function initMetas(): array {
return array( return [
array('name' => 'viewport', 'content' => 'width=device-width, initial-scale=1.0'), ['name' => 'viewport', 'content' => 'width=device-width, initial-scale=1.0'],
array('name' => 'format-detection', 'content' => 'telephone=yes'), ['name' => 'format-detection', 'content' => 'telephone=yes'],
array('charset' => 'utf-8'), ['charset' => 'utf-8'],
array("http-equiv" => 'expires', 'content' => '0'), ["http-equiv" => 'expires', 'content' => '0'],
array("name" => 'robots', 'content' => 'noarchive'), ["name" => 'robots', 'content' => 'noarchive'],
); ];
} }
protected function initRawFields(): array { protected function initRawFields(): array {
return array(); return [];
} }
protected function initTitle(): string { protected function initTitle(): string {
@ -90,7 +91,7 @@ namespace Documents\Install {
parent::__construct($document); parent::__construct($document);
$this->errorString = ""; $this->errorString = "";
$this->currentStep = InstallBody::CHECKING_REQUIREMENTS; $this->currentStep = InstallBody::CHECKING_REQUIREMENTS;
$this->steps = array(); $this->steps = [];
} }
private function getParameter($name): ?string { private function getParameter($name): ?string {
@ -189,11 +190,11 @@ namespace Documents\Install {
return self::DATABASE_CONFIGURATION; return self::DATABASE_CONFIGURATION;
} }
$res = $sql->select(new Count())->from("User")->execute(); $userCount = User::count($sql);
if ($res === FALSE) { if ($userCount === FALSE) {
return self::DATABASE_CONFIGURATION; return self::DATABASE_CONFIGURATION;
} else { } else {
if ($res[0]["count"] > 0) { if ($userCount > 0) {
$step = self::ADD_MAIL_SERVICE; $step = self::ADD_MAIL_SERVICE;
} else { } else {
return self::CREATE_USER; return self::CREATE_USER;
@ -202,7 +203,7 @@ namespace Documents\Install {
if ($step === self::ADD_MAIL_SERVICE) { if ($step === self::ADD_MAIL_SERVICE) {
$req = new \Core\API\Settings\Get($context); $req = new \Core\API\Settings\Get($context);
$success = $req->execute(array("key" => "^mail_enabled$")); $success = $req->execute(["key" => "^mail_enabled$"]);
if (!$success) { if (!$success) {
$this->errorString = $req->getLastError(); $this->errorString = $req->getLastError();
return self::DATABASE_CONFIGURATION; return self::DATABASE_CONFIGURATION;
@ -210,7 +211,7 @@ namespace Documents\Install {
$step = self::FINISH_INSTALLATION; $step = self::FINISH_INSTALLATION;
$req = new \Core\API\Settings\Set($context); $req = new \Core\API\Settings\Set($context);
$success = $req->execute(array("settings" => array("installation_completed" => "1"))); $success = $req->execute(["settings" => ["installation_completed" => "1"]]);
if (!$success) { if (!$success) {
$this->errorString = $req->getLastError(); $this->errorString = $req->getLastError();
} }
@ -229,7 +230,7 @@ namespace Documents\Install {
$msg = $this->errorString; $msg = $this->errorString;
$success = true; $success = true;
$failedRequirements = array(); $failedRequirements = [];
$requiredDirectories = [ $requiredDirectories = [
"/Site/Cache", "/Site/Cache",
@ -318,7 +319,7 @@ namespace Documents\Install {
$encoding = $this->getParameter("encoding") ?? "UTF8"; $encoding = $this->getParameter("encoding") ?? "UTF8";
$success = true; $success = true;
$missingInputs = array(); $missingInputs = [];
if (empty($host)) { if (empty($host)) {
$success = false; $success = false;
$missingInputs[] = "Host"; $missingInputs[] = "Host";
@ -428,16 +429,17 @@ namespace Documents\Install {
} }
} }
return array("success" => $success, "msg" => $msg); return ["success" => $success, "msg" => $msg];
} }
private function createUser(): array { private function createUser(): array {
$context = $this->getDocument()->getContext(); $context = $this->getDocument()->getContext();
if ($this->getParameter("prev") === "true") { if ($this->getParameter("prev") === "true") {
$success = $context->getConfig()->delete("Database"); // TODO: drop the previous database here?
$success = $context->getConfig()->delete("\\Site\\Configuration\\Database");
$msg = $success ? "" : error_get_last(); $msg = $success ? "" : error_get_last();
return array("success" => $success, "msg" => $msg); return ["success" => $success, "msg" => $msg];
} }
$username = $this->getParameter("username"); $username = $this->getParameter("username");
@ -446,7 +448,7 @@ namespace Documents\Install {
$email = $this->getParameter("email") ?? ""; $email = $this->getParameter("email") ?? "";
$success = true; $success = true;
$missingInputs = array(); $missingInputs = [];
if (empty($username)) { if (empty($username)) {
$success = false; $success = false;
@ -468,18 +470,18 @@ namespace Documents\Install {
$this->createUnorderedList($missingInputs); $this->createUnorderedList($missingInputs);
} else { } else {
$req = new \Core\API\User\Create($context); $req = new \Core\API\User\Create($context);
$success = $req->execute(array( $success = $req->execute([
'username' => $username, 'username' => $username,
'email' => $email, 'email' => $email,
'password' => $password, 'password' => $password,
'confirmPassword' => $confirmPassword, 'confirmPassword' => $confirmPassword,
'groups' => [Group::ADMIN] 'groups' => [Group::ADMIN]
)); ]);
$msg = $req->getLastError(); $msg = $req->getLastError();
} }
return array("msg" => $msg, "success" => $success); return ["msg" => $msg, "success" => $success];
} }
private function addMailService(): array { private function addMailService(): array {
@ -489,7 +491,7 @@ namespace Documents\Install {
$sql = $context->getSQL(); $sql = $context->getSQL();
$success = $sql->delete("User")->execute(); $success = $sql->delete("User")->execute();
$msg = $sql->getLastError(); $msg = $sql->getLastError();
return array("success" => $success, "msg" => $msg); return ["success" => $success, "msg" => $msg];
} }
if ($this->getParameter("skip") === "true") { if ($this->getParameter("skip") === "true") {
@ -504,7 +506,7 @@ namespace Documents\Install {
$password = $this->getParameter("password"); $password = $this->getParameter("password");
$success = true; $success = true;
$missingInputs = array(); $missingInputs = [];
if (empty($address)) { if (empty($address)) {
$success = false; $success = false;
$missingInputs[] = "SMTP Address"; $missingInputs[] = "SMTP Address";
@ -572,43 +574,29 @@ namespace Documents\Install {
} }
} }
return array("success" => $success, "msg" => $msg); return ["success" => $success, "msg" => $msg];
} }
private function performStep(): array { private function performStep(): array {
return match ($this->currentStep) {
switch ($this->currentStep) { self::CHECKING_REQUIREMENTS => $this->checkRequirements(),
self::INSTALL_DEPENDENCIES => $this->installDependencies(),
case self::CHECKING_REQUIREMENTS: self::DATABASE_CONFIGURATION => $this->databaseConfiguration(),
return $this->checkRequirements(); self::CREATE_USER => $this->createUser(),
self::ADD_MAIL_SERVICE => $this->addMailService(),
case self::INSTALL_DEPENDENCIES: default => [
return $this->installDependencies();
case self::DATABASE_CONFIGURATION:
return $this->databaseConfiguration();
case self::CREATE_USER:
return $this->createUser();
case self::ADD_MAIL_SERVICE:
return $this->addMailService();
default:
return array(
"success" => false, "success" => false,
"msg" => "Invalid step number" "msg" => "Invalid step number"
); ],
} };
} }
private function createProgressSidebar(): string { private function createProgressSidebar(): array {
$items = array(); $items = [];
foreach ($this->steps as $num => $step) { foreach ($this->steps as $num => $step) {
$title = $step["title"]; $title = $step["title"];
$status = $step["status"]; $status = $step["status"];
$currentStep = ($num == $this->currentStep) ? " id=\"currentStep\"" : "";
switch ($status) { switch ($status) {
case self::PENDING: case self::PENDING:
@ -637,17 +625,21 @@ namespace Documents\Install {
break; break;
} }
$items[] = " $attr = ["class" => "list-group-item d-flex justify-content-between lh-condensed"];
<li class=\"list-group-item d-flex justify-content-between lh-condensed\"$currentStep> if ($num == $this->currentStep) {
<div> $attr["id"] = "currentStep";
<h6 class=\"my-0\">$title</h6>
<small class=\"text-$statusColor\">$statusText</small>
</div>
<span class=\"text-$statusColor\">$statusIcon</span>
</li>";
} }
return implode("", $items); $items[] = html_tag("li", $attr, [
html_tag("div", [], [
html_tag("h6", ["class" => "my-0"], $title),
html_tag("small", ["class" => "text-$statusColor"], $statusText),
], false),
html_tag("span", ["class" => "text-$statusColor"], $statusIcon, false)
], false);
}
return $items;
} }
private function createFormItem($formItem, $inline = false): string { private function createFormItem($formItem, $inline = false): string {
@ -656,11 +648,11 @@ namespace Documents\Install {
$name = $formItem["name"]; $name = $formItem["name"];
$type = $formItem["type"]; $type = $formItem["type"];
$attributes = array( $attributes = [
"name" => $name, "name" => $name,
"id" => $name, "id" => $name,
"class" => "form-control" "class" => "form-control"
); ];
if (isset($formItem["required"]) && $formItem["required"]) { if (isset($formItem["required"]) && $formItem["required"]) {
$attributes["required"] = ""; $attributes["required"] = "";
@ -687,9 +679,8 @@ namespace Documents\Install {
} }
} }
// $attributes = html_attributes($attributes);
if ($type === "select") { if ($type === "select") {
$items = $formItem["items"] ?? array(); $items = $formItem["items"] ?? [];
$options = []; $options = [];
foreach ($items as $key => $val) { foreach ($items as $key => $val) {
$options[] = html_tag_ex("option", ["value" => $key], $val, true, false); $options[] = html_tag_ex("option", ["value" => $key], $val, true, false);
@ -705,87 +696,89 @@ namespace Documents\Install {
return html_tag_ex("div", ["class" => $className], $label . $element, false); return html_tag_ex("div", ["class" => $className], $label . $element, false);
} }
private function createProgressMainview(): string { private function createProgressMainView(): string {
if (isDocker()) { if (isDocker()) {
$env = loadEnv();
$defaultHost = "db"; $defaultHost = "db";
$defaultUsername = "root"; $defaultUsername = "root";
$defaultDatabase = "webbase"; $defaultDatabase = "webbase";
$defaultPassword = $env && array_key_exists("MYSQL_ROOT_PASSWORD", $env) ? $env["MYSQL_ROOT_PASSWORD"] : "";
} else { } else {
$defaultHost = "localhost"; $defaultHost = "localhost";
$defaultUsername = ""; $defaultUsername = "";
$defaultDatabase = ""; $defaultDatabase = "";
}
$defaultPassword = ""; $defaultPassword = "";
}
$views = array( $views = [
self::CHECKING_REQUIREMENTS => array( self::CHECKING_REQUIREMENTS => [
"title" => "Application Requirements", "title" => "Application Requirements",
"progressText" => "Checking requirements, please wait a moment…" "progressText" => "Checking requirements, please wait a moment…"
), ],
self::INSTALL_DEPENDENCIES => array( self::INSTALL_DEPENDENCIES => [
"title" => "Installing Dependencies", "title" => "Installing Dependencies",
"progressText" => "Please wait while required dependencies are being installed…", "progressText" => "Please wait while required dependencies are being installed…",
), ],
self::DATABASE_CONFIGURATION => array( self::DATABASE_CONFIGURATION => [
"title" => "Database configuration", "title" => "Database configuration",
"form" => array( "form" => [
array("title" => "Database Type", "name" => "type", "type" => "select", "required" => true, "items" => array( ["title" => "Database Type", "name" => "type", "type" => "select", "required" => true, "items" => [
"mysql" => "MySQL", "postgres" => "PostgreSQL" "mysql" => "MySQL", "postgres" => "PostgreSQL"
)), ]],
array("title" => "Username", "name" => "username", "type" => "text", "required" => true, "default" => $defaultUsername), ["title" => "Username", "name" => "username", "type" => "text", "required" => true, "default" => $defaultUsername],
array("title" => "Password", "name" => "password", "type" => "password", "default" => $defaultPassword), ["title" => "Password", "name" => "password", "type" => "password", "default" => $defaultPassword],
array("title" => "Database", "name" => "database", "type" => "text", "required" => true, "default" => $defaultDatabase), ["title" => "Database", "name" => "database", "type" => "text", "required" => true, "default" => $defaultDatabase],
array("type" => "row", "items" => array( ["type" => "row", "items" => [
array( [
"title" => "Address", "name" => "host", "type" => "text", "required" => true, "title" => "Address", "name" => "host", "type" => "text", "required" => true,
"value" => "localhost", "row" => true, "default" => $defaultHost "value" => "localhost", "row" => true, "default" => $defaultHost
), ],
array( [
"title" => "Port", "name" => "port", "type" => "number", "required" => true, "title" => "Port", "name" => "port", "type" => "number", "required" => true,
"value" => "3306", "min" => "1", "max" => "65535", "row" => true "value" => "3306", "min" => "1", "max" => "65535", "row" => true
) ]
)), ]],
array( [
"title" => "Encoding", "name" => "encoding", "type" => "text", "required" => false, "title" => "Encoding", "name" => "encoding", "type" => "text", "required" => false,
"value" => "UTF8" "value" => "UTF8"
), ],
) ]
), ],
self::CREATE_USER => array( self::CREATE_USER => [
"title" => "Create a User", "title" => "Create a User",
"form" => array( "form" => [
array("title" => "Username", "name" => "username", "type" => "text", "required" => true), ["title" => "Username", "name" => "username", "type" => "text", "required" => true],
array("title" => "Email", "name" => "email", "type" => "text"), ["title" => "Email", "name" => "email", "type" => "text"],
array("title" => "Password", "name" => "password", "type" => "password", "required" => true), ["title" => "Password", "name" => "password", "type" => "password", "required" => true],
array("title" => "Confirm Password", "name" => "confirmPassword", "type" => "password", "required" => true), ["title" => "Confirm Password", "name" => "confirmPassword", "type" => "password", "required" => true],
), ],
"previousButton" => true "previousButton" => true
), ],
self::ADD_MAIL_SERVICE => array( self::ADD_MAIL_SERVICE => [
"title" => "Optional: Add Mail Service", "title" => "Optional: Add Mail Service",
"form" => array( "form" => [
array("title" => "Username", "name" => "username", "type" => "text", "required" => true), ["title" => "Username", "name" => "username", "type" => "text", "required" => true],
array("title" => "Password", "name" => "password", "type" => "password"), ["title" => "Password", "name" => "password", "type" => "password"],
array("type" => "row", "items" => array( ["type" => "row", "items" => [
array( [
"title" => "SMTP Address", "name" => "address", "type" => "text", "required" => true, "title" => "SMTP Address", "name" => "address", "type" => "text", "required" => true,
"value" => "localhost", "row" => true "value" => "localhost", "row" => true
), ],
array( [
"title" => "Port", "name" => "port", "type" => "number", "required" => true, "title" => "Port", "name" => "port", "type" => "number", "required" => true,
"value" => "587", "min" => "1", "max" => "65535", "row" => true "value" => "587", "min" => "1", "max" => "65535", "row" => true
) ]
)), ]],
), ],
"skip" => true, "skip" => true,
"previousButton" => true "previousButton" => true
), ],
self::FINISH_INSTALLATION => array( self::FINISH_INSTALLATION => [
"title" => "Finish Installation", "title" => "Finish Installation",
"text" => "Installation finished, you can now customize your own website, check the source code and stuff." "text" => "Installation finished, you can now customize your own website, check the source code and stuff."
) ]
); ];
if (!isset($views[$this->currentStep])) { if (!isset($views[$this->currentStep])) {
return ""; return "";
@ -796,81 +789,87 @@ namespace Documents\Install {
$spinnerIcon = $this->createIcon("spinner"); $spinnerIcon = $this->createIcon("spinner");
$title = $currentView["title"]; $title = $currentView["title"];
$html = "<h4 class=\"mb-3\">$title</h4><hr class=\"mb-4\" />"; $html = html_tag("h4", ["class" => "mb-3"], $title);
$html .= html_tag_short("h4", ["class" => "mb-4"]);
if (isset($currentView["text"])) { if (isset($currentView["text"])) {
$text = $currentView["text"]; $text = $currentView["text"];
$html .= "<div class=\"my-3\">$text</i></div>"; $html .= html_tag("div", ["class" => "my-3"], $text);
} }
if (isset($currentView["progressText"])) { if (isset($currentView["progressText"])) {
$progressText = $currentView["progressText"]; $progressText = htmlspecialchars($currentView["progressText"]);
$hidden = (!in_array($this->currentStep, [self::CHECKING_REQUIREMENTS, self::INSTALL_DEPENDENCIES])) $class = ["my-3"];
? " hidden" : ""; if (!in_array($this->currentStep, [self::CHECKING_REQUIREMENTS, self::INSTALL_DEPENDENCIES])) {
$html .= "<div id=\"progressText\" class=\"my-3$hidden\">$progressText$spinnerIcon</i></div>"; $class[] = "hidden";
}
$html .= html_tag("div", ["class" => $class, "id" => "progressText"], [$progressText, $spinnerIcon], false);
} }
if (isset($currentView["form"])) { if (isset($currentView["form"])) {
$html .= "<form id=\"installForm\">"; $rows = [];
foreach ($currentView["form"] as $formItem) { foreach ($currentView["form"] as $formItem) {
if ($formItem["type"] === "row") { if ($formItem["type"] === "row") {
$html .= "<div class=\"row\">"; $rows[] = html_tag("div", ["class" => "row"], array_map(function ($item) {
foreach ($formItem["items"] as $item) { return $this->createFormItem($item, true);
$html .= $this->createFormItem($item, true); }, $formItem["items"]), false);
}
$html .= "</div>";
} else { } else {
$html .= $this->createFormItem($formItem); $rows[] = $this->createFormItem($formItem);
} }
} }
$html .= "</form>"; $html .= html_tag("form", ["id" => "installForm"], $rows, false);
} }
$buttons = array( $buttons = [
array("title" => "Go Back", "type" => "info", "id" => "btnPrev", "float" => "left", "disabled" => $prevDisabled) ["title" => "Go Back", "type" => "info", "id" => "btnPrev", "float" => "left", "disabled" => $prevDisabled]
); ];
if ($this->currentStep != self::FINISH_INSTALLATION) { if ($this->currentStep != self::FINISH_INSTALLATION) {
if (in_array($this->currentStep, [self::CHECKING_REQUIREMENTS, self::INSTALL_DEPENDENCIES])) { if (in_array($this->currentStep, [self::CHECKING_REQUIREMENTS, self::INSTALL_DEPENDENCIES])) {
$buttons[] = array("title" => "Retry", "type" => "success", "id" => "btnRetry", "float" => "right", "hidden" => true); $buttons[] = ["title" => "Retry", "type" => "success", "id" => "btnRetry", "float" => "right", "hidden" => true];
} else { } else {
$buttons[] = array("title" => "Submit", "type" => "success", "id" => "btnSubmit", "float" => "right"); $buttons[] = ["title" => "Submit", "type" => "success", "id" => "btnSubmit", "float" => "right"];
} }
} else { } else {
$buttons[] = array("title" => "Finish", "type" => "success", "id" => "btnFinish", "float" => "right"); $buttons[] = ["title" => "Finish", "type" => "success", "id" => "btnFinish", "float" => "right"];
} }
if (isset($currentView["skip"])) { if (isset($currentView["skip"])) {
$buttons[] = array("title" => "Skip", "type" => "secondary", "id" => "btnSkip", "float" => "right"); $buttons[] = ["title" => "Skip", "type" => "secondary", "id" => "btnSkip", "float" => "right"];
} }
$buttonsLeft = ""; $buttonsLeft = [];
$buttonsRight = ""; $buttonsRight = [];
foreach ($buttons as $button) { foreach ($buttons as $button) {
$title = $button["title"]; $title = $button["title"];
$type = $button["type"]; $type = $button["type"];
$id = $button["id"]; $id = $button["id"];
$float = $button["float"]; $float = $button["float"];
$disabled = (isset($button["disabled"]) && $button["disabled"]) ? " disabled" : "";
$hidden = (isset($button["hidden"]) && $button["hidden"]) ? " hidden" : "";
$button = "<button type=\"button\" id=\"$id\" class=\"btn btn-$type m-1$hidden\"$disabled>$title</button>";
$attrs = ["id" => $id, "class" => ["m-1", "btn", "btn-$type"]];
if (isset($button["hidden"]) && $button["hidden"]) {
$attrs["class"][] = "hidden";
}
if (isset($button["disabled"]) && $button["disabled"]) {
$attrs["class"][] = "disabled";
}
$button = html_tag("button", $attrs, $title, false);
if ($float === "left") { if ($float === "left") {
$buttonsLeft .= $button; $buttonsLeft[] = $button;
} else { } else {
$buttonsRight .= $button; $buttonsRight[] = $button;
} }
} }
$html .= $html .= html_tag("div", ["class" => "row"], [
"<div class=\"row\"> html_tag("div", ["class" => "col-6 float-left text-left"], $buttonsLeft, false),
<div class=\"col-6 float-left text-left\">$buttonsLeft</div> html_tag("div", ["class" => "col-6 float-right text-right"], $buttonsRight, false),
<div class=\"col-6 float-right text-right\">$buttonsRight</div> ], false);
</div>";
return $html; return $html;
} }
@ -878,32 +877,32 @@ namespace Documents\Install {
function getCode(): string { function getCode(): string {
$html = parent::getCode(); $html = parent::getCode();
$this->steps = array( $this->steps = [
self::CHECKING_REQUIREMENTS => array( self::CHECKING_REQUIREMENTS => [
"title" => "Checking requirements", "title" => "Checking requirements",
"status" => self::ERROR "status" => self::ERROR
), ],
self::INSTALL_DEPENDENCIES => array( self::INSTALL_DEPENDENCIES => [
"title" => "Install dependencies", "title" => "Install dependencies",
"status" => self::NOT_STARTED "status" => self::NOT_STARTED
), ],
self::DATABASE_CONFIGURATION => array( self::DATABASE_CONFIGURATION => [
"title" => "Database configuration", "title" => "Database configuration",
"status" => self::NOT_STARTED "status" => self::NOT_STARTED
), ],
self::CREATE_USER => array( self::CREATE_USER => [
"title" => "Create User", "title" => "Create User",
"status" => self::NOT_STARTED "status" => self::NOT_STARTED
), ],
self::ADD_MAIL_SERVICE => array( self::ADD_MAIL_SERVICE => [
"title" => "Add Mail Service", "title" => "Add Mail Service",
"status" => self::NOT_STARTED "status" => self::NOT_STARTED
), ],
self::FINISH_INSTALLATION => array( self::FINISH_INSTALLATION => [
"title" => "Finish Installation", "title" => "Finish Installation",
"status" => self::NOT_STARTED "status" => self::NOT_STARTED
), ],
); ];
$this->currentStep = $this->getCurrentStep(); $this->currentStep = $this->getCurrentStep();
@ -928,38 +927,49 @@ namespace Documents\Install {
} }
$progressSidebar = $this->createProgressSidebar(); $progressSidebar = $this->createProgressSidebar();
$progressMainView = $this->createProgressMainview(); $progressMainView = $this->createProgressMainView();
$errorStyle = ($this->errorString ? '' : ' style="display:none"'); $errorAttrs = ["class" => ["alert", "alert-danger", "mt-4"], "id" => "status"];
$errorClass = ($this->errorString ? ' alert-danger' : ''); if ($this->errorString) {
$errorAttrs["class"][] = "alert-danger";
} else {
$errorAttrs["class"][] = "d-none";
}
$html .= " $html .= html_tag("body", ["class" => "bg-light"],
<body class=\"bg-light\"> html_tag("div", ["class" => "container"], [
<div class=\"container\">
<div class=\"py-5 text-center\">
<h2>WebBase - Installation</h2>
<p class=\"lead\">
Process the following steps and fill out the required forms to install your WebBase-Installation.
</p>
</div>
<div class=\"row\"> // title
<div class=\"col-md-4 order-md-2 mb-4\"> html_tag("div", ["class" => "py-5 text-center"], [
<h4 class=\"d-flex justify-content-between align-items-center mb-3\"> html_tag("h2", [], "WebBase - Installation"),
<span class=\"text-muted\">Progress</span> html_tag("p", ["class" => "lead"],
</h4> "Process the following steps and fill out the required forms to install your WebBase-Installation."
)
], false),
<ul class=\"list-group mb-3\"> // content
$progressSidebar html_tag("div", ["class" => "row"], [
</ul>
</div> // right column
<div class=\"col-md-8 order-md-1\"> html_tag("div", ["class" => "col-md-4 order-md-2 mb-4"], [
$progressMainView html_tag("h4", ["class" => "d-flex justify-content-between align-items-center mb-3"],
<div class=\"alert$errorClass mt-4\" id=\"status\"$errorStyle>$this->errorString</div> html_tag("span", ["class" => "text-muted"], "Progress"),
</div> false
</div> ),
</div> html_tag("ul", ["class" => "list-group mb-3"], $progressSidebar, false)
</body>"; ], false),
// left column
html_tag("div", ["class" => "col-md-8 order-md-1"], [
$progressMainView,
html_tag("div", $errorAttrs, $this->errorString, false)
], false)
], false),
], false),
false
);
return $html; return $html;
} }

@ -10,7 +10,7 @@ if (is_file($autoLoad)) {
require_once $autoLoad; require_once $autoLoad;
} }
const WEBBASE_VERSION = "2.3.1"; const WEBBASE_VERSION = "2.4.0";
spl_autoload_extensions(".php"); spl_autoload_extensions(".php");
spl_autoload_register(function ($class) { spl_autoload_register(function ($class) {
@ -201,7 +201,8 @@ function intendCode($code, $escape = true): string {
function html_attributes(array $attributes): string { function html_attributes(array $attributes): string {
return implode(" ", array_map(function ($key) use ($attributes) { return implode(" ", array_map(function ($key) use ($attributes) {
$value = htmlspecialchars($attributes[$key]); $value = is_array($attributes[$key]) ? implode(" ", $attributes[$key]) : $attributes[$key];
$value = htmlspecialchars($value);
return "$key=\"$value\""; return "$key=\"$value\"";
}, array_keys($attributes))); }, array_keys($attributes)));
} }
@ -326,3 +327,22 @@ function rrmdir(string $dir): void {
rmdir($dir); rmdir($dir);
} }
} }
function loadEnv(?string $file = NULL, bool $putEnv = false): array|null {
if ($file === NULL) {
$file = WEBROOT . DIRECTORY_SEPARATOR . ".env";
}
if (!is_file($file)) {
return null;
}
$env = parse_ini_file('.env');
if ($putEnv) {
foreach ($env as $key => $value) {
putenv("$key=$value");
}
}
return $env;
}

@ -59,7 +59,7 @@ function sendRequest(params, done) {
let success = false; let success = false;
let statusBox = $("#status"); let statusBox = $("#status");
statusBox.hide(); statusBox.addClass("d-none");
$.post("/index.php", params, function(data) { $.post("/index.php", params, function(data) {
if(data.success || data.step !== getCurrentStep()) { if(data.success || data.step !== getCurrentStep()) {
success = true; success = true;
@ -68,7 +68,7 @@ function sendRequest(params, done) {
setState(ERROR); setState(ERROR);
statusBox.addClass("alert-danger"); statusBox.addClass("alert-danger");
statusBox.html("An error occurred during installation: " + data.msg); statusBox.html("An error occurred during installation: " + data.msg);
statusBox.show(); statusBox.removeClass("d-none");
} }
}, "json").fail(function() { }, "json").fail(function() {
setState(ERROR); setState(ERROR);