This commit is contained in:
Roman Hergenreder 2020-02-09 23:30:26 +01:00
parent 62f67967ba
commit f4ed99fc72
7 changed files with 82 additions and 72 deletions

@ -1,4 +1,3 @@
Mail\.class\.php Mail\.class\.php
JWT\.class\.php JWT\.class\.php
Database\.class\.php Database\.class\.php
Google\.class\.php

@ -7,7 +7,6 @@ class Configuration {
private $database; private $database;
private $mail; private $mail;
private $jwt; private $jwt;
private $google;
function __construct() { function __construct() {
} }
@ -18,8 +17,7 @@ class Configuration {
$classes = array( $classes = array(
\Configuration\Database::class => &$this->database, \Configuration\Database::class => &$this->database,
\Configuration\Mail::class => &$this->mail, \Configuration\Mail::class => &$this->mail,
\Configuration\JWT::class => &$this->jwt, \Configuration\JWT::class => &$this->jwt
\Configuration\Google::class => &$this->google,
); );
$success = true; $success = true;
@ -54,35 +52,57 @@ class Configuration {
$path = getClassPath("\\Configuration\\$className"); $path = getClassPath("\\Configuration\\$className");
if($data) { if($data) {
if(is_string($data)) {
$key = addslashes($data);
$code = intendCode(
"<?php
// TODO: Generalize this... namespace Configuration;
$superClass = get_class($data);
$host = addslashes($data->getHost());
$port = intval($data->getPort());
$login = addslashes($data->getLogin());
$password = addslashes($data->getPassword());
$properties = ""; class $className {
foreach($data->getProperties() as $key => $val) {
$key = addslashes($key);
$val = is_string($val) ? "'" . addslashes($val) . "'" : $val;
$properties .= "\n\$this->setProperty('$key', $val);";
}
$code = intendCode( private \$key;
"<?php
namespace Configuration; public function __construct() {
\$this->key = '$key';
}
class $className extends \\$superClass { public function getKey() {
return \$this->key;
public function __construct() { }
parent::__construct('$host', $port, '$login', '$password');$properties
} }
?>", false
);
} else {
$superClass = get_class($data);
$host = addslashes($data->getHost());
$port = intval($data->getPort());
$login = addslashes($data->getLogin());
$password = addslashes($data->getPassword());
$properties = "";
foreach($data->getProperties() as $key => $val) {
$key = addslashes($key);
$val = is_string($val) ? "'" . addslashes($val) . "'" : $val;
$properties .= "\n\$this->setProperty('$key', $val);";
} }
?>", false $code = intendCode(
); "<?php
namespace Configuration;
class $className extends \\$superClass {
public function __construct() {
parent::__construct('$host', $port, '$login', '$password');$properties
}
}
?>", false
);
}
} else { } else {
$code = intendCode( $code = intendCode(
"<?php "<?php

@ -59,11 +59,12 @@ namespace Documents\Install {
const DATABASE_CONFIGURATION = 2; const DATABASE_CONFIGURATION = 2;
const CREATE_USER = 3; const CREATE_USER = 3;
const ADD_MAIL_SERVICE = 4; const ADD_MAIL_SERVICE = 4;
const ADD_GOOGLE_SERVICE = 5; const FINISH_INSTALLATION = 5;
// //
private $configDirectory; private $configDirectory;
private $databaseScript; private $databaseScript;
private $errorString;
function __construct($document) { function __construct($document) {
parent::__construct($document); parent::__construct($document);
@ -71,6 +72,7 @@ namespace Documents\Install {
// TODO: make better // TODO: make better
$this->configDirectory = getWebRoot() . '/core/Configuration'; $this->configDirectory = getWebRoot() . '/core/Configuration';
$this->databaseScript = getWebRoot() . '/core/Configuration/database.sql'; $this->databaseScript = getWebRoot() . '/core/Configuration/database.sql';
$this->errorString = "";
} }
private function getParameter($name) { private function getParameter($name) {
@ -98,7 +100,6 @@ namespace Documents\Install {
$query = "SELECT * FROM User"; $query = "SELECT * FROM User";
$sql = $user->getSQL(); $sql = $user->getSQL();
if(!is_null($sql) && $sql->isConnected()) { if(!is_null($sql) && $sql->isConnected()) {
$this->getDocument()->getUser()->setSql($sql);
$res = $sql->query($query); $res = $sql->query($query);
if($res) { if($res) {
if($res->num_rows === 0) { if($res->num_rows === 0) {
@ -112,7 +113,10 @@ namespace Documents\Install {
} }
if($step == self::ADD_MAIL_SERVICE && $config->isFilePresent("Mail")) { if($step == self::ADD_MAIL_SERVICE && $config->isFilePresent("Mail")) {
$step = self::ADD_GOOGLE_SERVICE; $step = self::FINISH_INSTALLATION;
if(!$config->isFilePresent("JWT") && $config->create("JWT", generateRandomString(32))) {
$this->errorString = "Unable to create jwt file";
}
} }
return $step; return $step;
@ -120,7 +124,7 @@ namespace Documents\Install {
private function checkRequirements() { private function checkRequirements() {
$msg = ""; $msg = $this->errorString;
$success = true; $success = true;
$failedRequirements = array(); $failedRequirements = array();
@ -243,7 +247,7 @@ namespace Documents\Install {
$password = $this->getParameter("password"); $password = $this->getParameter("password");
$confirmPassword = $this->getParameter("confirmPassword"); $confirmPassword = $this->getParameter("confirmPassword");
$msg = ""; $msg = $this->errorString;
$success = true; $success = true;
$missingInputs = array(); $missingInputs = array();
@ -297,7 +301,7 @@ namespace Documents\Install {
} }
$success = true; $success = true;
$msg = ""; $msg = $this->errorString;
if($this->getParameter("skip") === "true") { if($this->getParameter("skip") === "true") {
if(!$user->getConfiguration()->create("Mail", null)) { if(!$user->getConfiguration()->create("Mail", null)) {
$success = false; $success = false;
@ -378,10 +382,6 @@ namespace Documents\Install {
return array("success" => $success, "msg" => $msg); return array("success" => $success, "msg" => $msg);
} }
private function addGoogleService() {
// return array("success" => $success, "msg" => $msg);
}
private function performStep() { private function performStep() {
switch($this->currentStep) { switch($this->currentStep) {
@ -398,9 +398,6 @@ namespace Documents\Install {
case self::ADD_MAIL_SERVICE: case self::ADD_MAIL_SERVICE:
return $this->addMailService(); return $this->addMailService();
case self::ADD_GOOGLE_SERVICE:
return $this->addGoogleService();
default: default:
return array( return array(
"success" => false, "success" => false,
@ -555,8 +552,9 @@ namespace Documents\Install {
), ),
"skip" => true "skip" => true
), ),
self::ADD_GOOGLE_SERVICE => array( self::FINISH_INSTALLATION => array(
"title" => "Optional: Add Google Services", "title" => "Finish Installation",
"text" => "Installation finished, you can now customize your own website, check the source code and stuff."
) )
); );
@ -571,6 +569,11 @@ namespace Documents\Install {
$html = "<h4 class=\"mb-3\">$title</h4><hr class=\"mb-4\">"; $html = "<h4 class=\"mb-3\">$title</h4><hr class=\"mb-4\">";
if(isset($currentView["text"])) {
$text = $currentView["text"];
$html .= "<div class=\"my-3\">$text</i></div>";
}
if(isset($currentView["progressText"])) { if(isset($currentView["progressText"])) {
$progressText = $currentView["progressText"]; $progressText = $currentView["progressText"];
$html .= "<div id=\"progressText\" class=\"my-3\">$progressText$spinnerIcon</i></div>"; $html .= "<div id=\"progressText\" class=\"my-3\">$progressText$spinnerIcon</i></div>";
@ -597,10 +600,15 @@ namespace Documents\Install {
} }
$buttons = array( $buttons = array(
array("title" => "Go Back", "type" => "info", "id" => "btnPrev", "float" => "left", "disabled" => $prevDisabled), array("title" => "Go Back", "type" => "info", "id" => "btnPrev", "float" => "left", "disabled" => $prevDisabled)
array("title" => "Submit", "type" => "success", "id" => "btnSubmit", "float" => "right")
); );
if($this->currentStep != self::FINISH_INSTALLATION) {
$buttons[] = array("title" => "Submit", "type" => "success", "id" => "btnSubmit", "float" => "right");
} else {
$buttons[] = array("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[] = array("title" => "Skip", "type" => "secondary", "id" => "btnSkip", "float" => "right");
} }
@ -653,8 +661,8 @@ namespace Documents\Install {
"title" => "Add Mail Service", "title" => "Add Mail Service",
"status" => self::NOT_STARTED "status" => self::NOT_STARTED
), ),
self::ADD_GOOGLE_SERVICE => array( self::FINISH_INSTALLATION => array(
"title" => "Add Google Services", "title" => "Finish Installation",
"status" => self::NOT_STARTED "status" => self::NOT_STARTED
), ),
); );
@ -666,6 +674,10 @@ namespace Documents\Install {
$this->steps[$step]["status"] = self::SUCCESFULL; $this->steps[$step]["status"] = self::SUCCESFULL;
} }
if($this->currentStep == self::FINISH_INSTALLATION) {
$this->steps[$this->currentStep]["status"] = self::SUCCESFULL;
}
// POST // POST
if($_SERVER['REQUEST_METHOD'] == 'POST') { if($_SERVER['REQUEST_METHOD'] == 'POST') {
$response = $this->performStep(); $response = $this->performStep();
@ -682,6 +694,7 @@ namespace Documents\Install {
$progressSidebar = $this->createProgressSidebar(); $progressSidebar = $this->createProgressSidebar();
$progressMainview = $this->createProgessMainview(); $progressMainview = $this->createProgessMainview();
$errorStyle = ($this->errorString ? '' : ' style="display:none"');
$html .= " $html .= "
<body class=\"bg-light\"> <body class=\"bg-light\">
@ -705,7 +718,7 @@ namespace Documents\Install {
</div> </div>
<div class=\"col-md-8 order-md-1\"> <div class=\"col-md-8 order-md-1\">
$progressMainview $progressMainview
<div class=\"alert margin-top-m\" id=\"status\" style=\"display:none\"></div> <div class=\"alert margin-top-m\" id=\"status\"$errorStyle>$this->errorString</div>
</div> </div>
</div> </div>
</div> </div>

@ -33,7 +33,6 @@ class User extends ApiObject {
} }
} }
public function setSql($sql) { $this->sql = $sql; }
public function getId() { return $this->uid; } public function getId() { return $this->uid; }
public function isLoggedIn() { return $this->loggedIn; } public function isLoggedIn() { return $this->loggedIn; }
public function getUsername() { return $this->username; } public function getUsername() { return $this->username; }

@ -1,12 +1,5 @@
<?php <?php
// Autoload function
// function __autoload($class) {
// $parts = explode('\\', $class);
// $path = implode(DIRECTORY_SEPERATOR, $parts);
// require "$path.php";
// }
function getClassPath($class, $suffix=true) { function getClassPath($class, $suffix=true) {
$path = str_replace('\\', '/', $class); $path = str_replace('\\', '/', $class);
$suffix = ($suffix ? ".class" : ""); $suffix = ($suffix ? ".class" : "");
@ -41,22 +34,4 @@ if ($installation) {
} }
die($document->getCode()); die($document->getCode());
// if(!file_exists($configPath)) {
// require_once 'core/objects/User.php';
// require_once 'core/documents/install.php';
//
// // $user = new CUser(null);
// // $installPage = new CDocumentInstall($user);
// // die($installPage->getCode());
// } else {
// $perms = fileperms($configPath);
// if($perms != 0x8600) {
// die("<b>Invalid conf file permissions</b>. expected permissions: 8600, got: $perms");
// }
//
// require_once $configPath;
// // require_once realpath($_SERVER['DOCUMENT_ROOT']) . '/php/pages/home.php';
// // CDocument::createDocument(CDocumentHome::class);
// }
?> ?>

@ -120,6 +120,10 @@ $(document).ready(function() {
}); });
}); });
$("#btnFinish").click(function() {
window.location.reload();
});
$("#btnRetry").click(function() { $("#btnRetry").click(function() {
retry(); retry();
}); });