formatting and user creating

This commit is contained in:
1day2die 2022-01-11 19:54:32 +01:00
parent f589f26e23
commit 2218ec21a5
4 changed files with 710 additions and 504 deletions

1
.gitignore vendored
View file

@ -21,3 +21,4 @@ yarn-error.log
storage/invoices.zip
storage/app/public/logo.png
*vscode
- Kopie.env

View file

@ -1,8 +1,8 @@
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
use DevCoder\DotEnv;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\PHPMailer;
require 'dotenv.php';
require 'phpmailer/Exception.php';
@ -27,7 +27,6 @@ if(isset($_POST['checkDB'])){
];
$db = new mysqli($_POST["databasehost"], $_POST["databaseuser"], $_POST["databaseuserpass"], $_POST["database"], $_POST["databaseport"]);
if ($db->connect_error) {
header("LOCATION: index.php?step=2&message=Could not connect to the Database");
@ -45,17 +44,18 @@ if(isset($_POST['checkDB'])){
if (isset($_POST['checkGeneral'])) {
$values = [
//SETTINGS::VALUE => REQUEST-VALUE (coming from the html-form)
"APP_NAME" => "name",
"APP_URL" => "url"
];
$appname = '"' . $_POST['name'] . '"';
$appurl = $_POST['url'];
foreach ($values as $key => $value) {
$param = $_POST[$value];
setEnvironmentValue($key, $param);
if (substr($appurl, -1) === "/") {
$appurl = substr_replace($appurl, "", -1);
}
setEnvironmentValue("APP_NAME", $appname);
setEnvironmentValue("APP_URL", $url);
header("LOCATION: index.php?step=4");
}
@ -107,7 +107,6 @@ if(isset($_POST['checkSMTP'])){
header("LOCATION: index.php?step=5");
}
if (isset($_POST['checkPtero'])) {
@ -155,6 +154,88 @@ if(isset($_POST['checkPtero'])){
}
}
if (isset($_POST['createUser'])) {
$db = new mysqli(getenv("DB_HOST"), getenv("DB_USERNAME"), getenv("DB_PASSWORD"), getenv("DB_DATABASE"), getenv("DB_PORT"));
if ($db->connect_error) {
header("LOCATION: index.php?step=6&message=Could not connect to the Database");
die();
}
$name = $_POST['user'];
$mail = $_POST['email'];
$pteroID = $_POST['pteroID'];
$pass = $_POST['pass'];
$repass = $_POST['repass'];
$key = $db->query("SELECT `value` FROM dashboard.settings WHERE `key` = 'SETTINGS::SYSTEM:PTERODACTYL:TOKEN'")->fetch_assoc();
$pterobaseurl = $db->query("SELECT `value` FROM dashboard.settings WHERE `key` = 'SETTINGS::SYSTEM:PTERODACTYL:URL'")->fetch_assoc();
$pteroURL = $pterobaseurl["value"] . "/api/application/users/" . $pteroID;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $pteroURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Accept: application/json",
"Content-Type: application/json",
"Authorization: Bearer " . $key["value"]
));
$response = curl_exec($ch);
$result = json_decode($response, true);
curl_close($ch); // Close the connection
if ($result["attributes"]["email"] !== $mail) {
header("LOCATION: index.php?step=6&message=The Email is not the same as the one used on Pterodactyl");
die();
}
if ($pass !== $repass) {
header("LOCATION: index.php?step=6&message=The Passwords did not match!");
die();
}
$pass = password_hash($pass, PASSWORD_DEFAULT);
$pteroURL = $pterobaseurl["value"] . "/api/application/users/" . $pteroID;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $pteroURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Accept: application/json",
"Content-Type: application/json",
"Authorization: Bearer " . $key["value"]
));
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
"email" => $mail,
"username" => $name,
"first_name" => $name,
"last_name" => $name,
"password" => $pass
));
$response = curl_exec($ch);
$result = json_decode($response, true);
curl_close($ch); // Close the connection
if (!is_array($result) or in_array($result["errors"][0]["code"], $result)) {
header("LOCATION: index.php?step=5&message=Couldnt connect to Pterodactyl. Make sure your API key has all read and write permissions!");
die();
}
$query1 = "INSERT INTO `dashboard`.`users` (`name`, `role`, `credits`, `server_limit`, `pterodactyl_id`, `email`, `password`) VALUES ('$name', 'admin', '250', '1', '$pteroID', '$mail', '$pass')";
if ($db->query($query1)) {
header("LOCATION: index.php?step=7");
} else {
header("LOCATION: index.php?step=6&message=Something went wrong when communicating with the Database!");
}
}

View file

@ -10,7 +10,8 @@ $requirements = [
];
function checkPhpVersion(){
function checkPhpVersion()
{
global $requirements;
if (version_compare(phpversion(), $requirements["php"], '>=')) {
return "OK";
@ -18,7 +19,8 @@ function checkPhpVersion(){
return "not OK";
}
function getMySQLVersion() {
function getMySQLVersion()
{
global $requirements;
$output = shell_exec('mysql -V');
@ -26,10 +28,11 @@ function getMySQLVersion() {
$versionoutput = $version[0] ?? "0";
return (intval($versionoutput) > intval($requirements["mysql"]) ? "OK":$versionoutput);;
return (intval($versionoutput) > intval($requirements["mysql"]) ? "OK" : $versionoutput);
}
function getZipVersion() {
function getZipVersion()
{
global $requirements;
$output = shell_exec('zip -v');
@ -37,10 +40,11 @@ function getZipVersion() {
$versionoutput = $version[0] ?? 0;
return ($versionoutput!=0 ? "OK":"not OK");;
return ($versionoutput != 0 ? "OK" : "not OK");
}
function getGitVersion() {
function getGitVersion()
{
global $requirements;
$output = shell_exec('git --version');
@ -48,10 +52,11 @@ function getGitVersion() {
$versionoutput = $version[0] ?? 0;
return ($versionoutput!=0 ? "OK":"not OK");;
return ($versionoutput != 0 ? "OK" : "not OK");
}
function getTarVersion() {
function getTarVersion()
{
global $requirements;
$output = shell_exec('tar --version');
@ -59,10 +64,11 @@ function getTarVersion() {
$versionoutput = $version[0] ?? 0;
return ($versionoutput!=0 ? "OK":"not OK");;
return ($versionoutput != 0 ? "OK" : "not OK");
}
function checkExtensions(){
function checkExtensions()
{
global $required_extentions;
$not_ok = [];
@ -96,5 +102,4 @@ function checkExtensions(){
}
?>

View file

@ -9,9 +9,12 @@ if (file_exists("install.lock")){
<html>
<head>
<title>Controlpanel.gg installer Script</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<style>
body {background-color: powderblue;}
body {
background-color: powderblue;
}
.card {
position: absolute;
@ -20,15 +23,19 @@ if (file_exists("install.lock")){
margin-right: -50%;
transform: translate(-50%, -50%);
}
.ok {
color: green;
}
.ok::before {
content: "✔️";
}
.notok {
color: red;
}
.notok::before {
content: "";
}
@ -43,21 +50,33 @@ if (file_exists("install.lock")){
</div>
<div class="card-body">
<p class="login-box-msg">This installer will lead you through the most crucial Steps of Controlpanel.gg`s setup</p>
<p class="login-box-msg">This installer will lead you through the most crucial Steps of Controlpanel.gg`s
setup</p>
<p class="<?php print(checkPhpVersion()==="OK"?"ok":"notok");?>"> php version: <?php echo phpversion();?> (required <?php echo $requirements["php"];?>)</p>
<p class="<?php print(getMySQLVersion()==="OK"?"ok":"notok");?>"> mysql version: <?php echo getMySQLVersion();?> (minimum required <?php echo $requirements["mysql"];?>)</p>
<p class="<?php print(checkPhpVersion() === "OK" ? "ok" : "notok"); ?>"> php
version: <?php echo phpversion(); ?> (required <?php echo $requirements["php"]; ?>)</p>
<p class="<?php print(getMySQLVersion() === "OK" ? "ok" : "notok"); ?>"> mysql
version: <?php echo getMySQLVersion(); ?> (minimum required <?php echo $requirements["mysql"]; ?>)</p>
<p class="<?php print(sizeof(checkExtensions()) == 0?"ok":"notok");?>"> Missing extentions: <?php print(sizeof(checkExtensions()) == 0?"None":"");foreach(checkExtensions() as $ext){ echo $ext.", ";};?> (try to install anyway)</p>
<p class="<?php print(sizeof(checkExtensions()) == 0 ? "ok" : "notok"); ?>"> Missing
extentions: <?php print(sizeof(checkExtensions()) == 0 ? "None" : "");
foreach (checkExtensions() as $ext) {
echo $ext . ", ";
} ?> (try to install anyway)</p>
<p class="<?php print(getZipVersion()==="OK"?"ok":"notok");?>"> Zip version: <?php echo getZipVersion();?> </p>
<p class="<?php print(getZipVersion() === "OK" ? "ok" : "notok"); ?>"> Zip
version: <?php echo getZipVersion(); ?> </p>
<p class="<?php print(getGitVersion()==="OK"?"ok":"notok");?>"> Git version: <?php echo getGitVersion();?> </p>
<p class="<?php print(getGitVersion() === "OK" ? "ok" : "notok"); ?>"> Git
version: <?php echo getGitVersion(); ?> </p>
<p class="<?php print(getTarVersion()==="OK"?"ok":"notok");?>"> Tar version: <?php echo getTarVersion();?> </p>
<p class="<?php print(getTarVersion() === "OK" ? "ok" : "notok"); ?>"> Tar
version: <?php echo getTarVersion(); ?> </p>
<a href="?step=2"><button class="btn btn-primary">Lets go</button></a>
<a href="?step=2">
<button class="btn btn-primary">Lets go</button>
</a>
</div>
</div>
@ -146,9 +165,6 @@ if (isset($_GET['step']) && $_GET['step']==2){
}
if (isset($_GET['step']) && $_GET['step'] == 3) {
?>
@ -301,8 +317,11 @@ if (isset($_GET['step']) && $_GET['step']==5){
<div class="card-body">
<p class="login-box-msg">Almost done! </p>
<p class="login-box-msg">Lets get some info about your Pterodactyl Installation!</p>
<p class="login-box-msg">Before this Step make sure you ran <b>php artisan migrate --seed --force</b> in your Linux Terminal!</p>
<a href="?step=5&exec"><button class="btn btn-success">You can also try to click here</button></a>
<p class="login-box-msg">Before this Step make sure you ran <b>php artisan migrate --seed --force</b> in
your Linux Terminal!</p>
<a href="?step=5&exec">
<button class="btn btn-success">You can also try to click here</button>
</a>
<?php if (isset($_GET['message'])) {
echo "<p class='notok'>" . $_GET['message'] . "</p>";
}
@ -318,7 +337,7 @@ if (isset($_GET['step']) && $_GET['step']==5){
<label for="url">Pterodactyl URL</label>
<input id="url" name="url"
type="text" required
value="" class="form-control">
value="https://ptero.example.com" class="form-control">
</div>
</div>
<div class="form-group">
@ -326,7 +345,8 @@ if (isset($_GET['step']) && $_GET['step']==5){
<label for="key">Pterodactyl API-Key</label>
<input id="key" name="key" type="text"
required
value="" class="form-control" placeholder="The Key needs ALL read&write Permissions!">
value="" class="form-control"
placeholder="The Key needs ALL read&write Permissions!">
</div>
</div>
@ -338,6 +358,104 @@ if (isset($_GET['step']) && $_GET['step']==5){
</div>
</div>
</div>
<?php
}
if (isset($_GET['step']) && $_GET['step'] == 6) {
?>
<div class="card card-outline card-primary">
<div class="card-header text-center">
<b class="mr-1">Controlpanel.GG</b>
</div>
<div class="card-body">
<p class="login-box-msg">Lets create yourself!</p>
<p class="login-box-msg">We're making the first Admin user</p>
<?php if (isset($_GET['message'])) {
echo "<p class='notok'>" . $_GET['message'] . "</p>";
}
?>
<form method="POST" enctype="multipart/form-data" class="mb-3"
action="/install/forms.php" name="createUser">
<div class="row">
<div class="col-md-12">
<div class="form-group">
<div class="custom-control mb-3">
<label for="user">Your Username</label>
<input id="user" name="user"
type="text" required
value="" class="form-control">
</div>
</div>
<div class="form-group">
<div class="custom-control mb-3">
<label for="email">Your Email Adress (used to Login)</label>
<input id="email" name="email"
type="text" required
value="" class="form-control">
</div>
</div>
<div class="form-group">
<div class="custom-control mb-3">
<label for="pass">Password</label>
<input id="pass" name="pass" type="password"
required
value="" class="form-control">
</div>
</div>
<div class="form-group">
<div class="custom-control mb-3">
<label for="repass">Retype Pass</label>
<input id="repass" name="repass" type="password"
required
value="" class="form-control">
</div>
</div>
<div class="form-group">
<div class="custom-control mb-3">
<label for="repass">Your Pterodactyl User-ID</label>
<input id="pteroID" name="pteroID" type="text"
required
value="" class="form-control">
</div>
</div>
</div>
<button class="btn btn-primary" name="createUser">Submit</button>
</div>
</div>
</div>
</div>
<?php
}
if (isset($_GET['step']) && $_GET['step'] == 7) {
?>
<div class="card card-outline card-primary">
<div class="card-header text-center">
<b class="mr-1">Controlpanel.GG</b>
</div>
<div class="card-body">
<p class="login-box-msg">All done!</p>
<p class="login-box-msg">You may navigate to your Dashboard now and log in!</p>
<a href="<?php echo "https://" . $_SERVER['SERVER_NAME']; ?>">
<button class="btn btn-success">Lets go!</button>
</a>
</div>
</div>
</div>
<?php
@ -345,7 +463,8 @@ if (isset($_GET['step']) && $_GET['step']==5){
?>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
crossorigin="anonymous"></script>
</body>
</html>