diff --git a/.gitignore b/.gitignore index 58e14883..57290b7a 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ yarn-error.log storage/invoices.zip storage/app/public/logo.png *vscode + - Kopie.env diff --git a/public/install/forms.php b/public/install/forms.php index c140ecb7..4b2a745f 100644 --- a/public/install/forms.php +++ b/public/install/forms.php @@ -1,161 +1,242 @@ -load(); +(new DotEnv(dirname(__FILE__, 3) . "/.env"))->load(); include("functions.php"); -if(isset($_POST['checkDB'])){ +if (isset($_POST['checkDB'])) { - $values = [ - //SETTINGS::VALUE => REQUEST-VALUE (coming from the html-form) - "DB_HOST" => "databasehost", - "DB_DATABASE" => "database", - "DB_USERNAME" => "databaseuser", - "DB_PASSWORD" => "databaseuserpass", - "DB_PORT" => "databaseport", - "DB_CONNECTION" => "databasedriver" - ]; + $values = [ + //SETTINGS::VALUE => REQUEST-VALUE (coming from the html-form) + "DB_HOST" => "databasehost", + "DB_DATABASE" => "database", + "DB_USERNAME" => "databaseuser", + "DB_PASSWORD" => "databaseuserpass", + "DB_PORT" => "databaseport", + "DB_CONNECTION" => "databasedriver" + ]; + $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"); + die(); + } - $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"); - die(); - } + foreach ($values as $key => $value) { + $param = $_POST[$value]; + setEnvironmentValue($key, $param); + } + header("LOCATION: index.php?step=3"); - foreach ($values as $key => $value) { - $param = $_POST[$value]; - setEnvironmentValue($key, $param); - } - header("LOCATION: index.php?step=3"); - - } +} -if(isset($_POST['checkGeneral'])){ - - $values = [ - //SETTINGS::VALUE => REQUEST-VALUE (coming from the html-form) - "APP_NAME" => "name", - "APP_URL" => "url" - ]; +if (isset($_POST['checkGeneral'])) { - foreach ($values as $key => $value) { - $param = $_POST[$value]; - setEnvironmentValue($key, $param); - } - header("LOCATION: index.php?step=4"); - - } + $appname = '"' . $_POST['name'] . '"'; + $appurl = $_POST['url']; -if(isset($_POST['checkSMTP'])){ - try{ + if (substr($appurl, -1) === "/") { + $appurl = substr_replace($appurl, "", -1); + } + + + setEnvironmentValue("APP_NAME", $appname); + setEnvironmentValue("APP_URL", $url); + + header("LOCATION: index.php?step=4"); + +} + +if (isset($_POST['checkSMTP'])) { + try { $mail = new PHPMailer(true); //Server settings $mail->isSMTP(); // Send using SMTP - $mail->Host = $_POST['host']; // Set the SMTP server to send through - $mail->SMTPAuth = true; // Enable SMTP authentication - $mail->Username = $_POST['user']; // SMTP username - $mail->Password = $_POST['pass']; // SMTP password + $mail->Host = $_POST['host']; // Set the SMTP server to send through + $mail->SMTPAuth = true; // Enable SMTP authentication + $mail->Username = $_POST['user']; // SMTP username + $mail->Password = $_POST['pass']; // SMTP password $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged - $mail->Port = $_POST['port']; // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` + $mail->Port = $_POST['port']; // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` //Recipients $mail->setFrom($_POST['user'], $_POST['user']); - $mail->addAddress($_POST['user'], $_POST['user']); // Add a recipient + $mail->addAddress($_POST['user'], $_POST['user']); // Add a recipient // Content $mail->isHTML(true); // Set email format to HTML $mail->Subject = 'It Worked!'; - $mail->Body = "Your E-Mail Settings are correct!"; + $mail->Body = "Your E-Mail Settings are correct!"; $mail->send(); - }catch (Exception $e){ - header("LOCATION: index.php?step=4&message=Something wasnt right when sending the E-Mail!"); - die(); + } catch (Exception $e) { + header("LOCATION: index.php?step=4&message=Something wasnt right when sending the E-Mail!"); + die(); } - $values = [ - //SETTINGS::VALUE => REQUEST-VALUE (coming from the html-form) - "MAIL_MAILER" => "method", - "MAIL_HOST" => "host", - "MAIL_PORT" => "port", - "MAIL_USERNAME" => "user", - "MAIL_PASSWORD" => "pass", - "MAIL_ENCRYPTION" => "encryption", - "MAIL_FROM_ADDRESS" => "user" - ]; + $values = [ + //SETTINGS::VALUE => REQUEST-VALUE (coming from the html-form) + "MAIL_MAILER" => "method", + "MAIL_HOST" => "host", + "MAIL_PORT" => "port", + "MAIL_USERNAME" => "user", + "MAIL_PASSWORD" => "pass", + "MAIL_ENCRYPTION" => "encryption", + "MAIL_FROM_ADDRESS" => "user" + ]; - foreach ($values as $key => $value) { - $param = $_POST[$value]; - setEnvironmentValue($key, $param); - } - header("LOCATION: index.php?step=5"); - - - - } - -if(isset($_POST['checkPtero'])){ - $url = $_POST['url']; - $key = $_POST['key']; - - if(substr($url, -1)==="/"){ - $url = substr_replace($url ,"", -1); - } + foreach ($values as $key => $value) { + $param = $_POST[$value]; + setEnvironmentValue($key, $param); + } + header("LOCATION: index.php?step=5"); - $pteroURL = $url."/api/application/users"; - $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 - )); - $response = curl_exec($ch); - $result = json_decode($response, true); - curl_close($ch); // Close the connection +if (isset($_POST['checkPtero'])) { + $url = $_POST['url']; + $key = $_POST['key']; + + if (substr($url, -1) === "/") { + $url = substr_replace($url, "", -1); + } - 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(); - }else{ - $query1= "UPDATE `dashboard`.`settings` SET `value` = '$url' WHERE (`key` = 'SETTINGS::SYSTEM:PTERODACTYL:URL')"; - $query2= "UPDATE `dashboard`.`settings` SET `value` = '$key' WHERE (`key` = 'SETTINGS::SYSTEM:PTERODACTYL:TOKEN')"; + $pteroURL = $url . "/api/application/users"; + $ch = curl_init(); - $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=5&message=Could not connect to the Database"); - die(); - } - - if($db->query($query1) && $db->query($query2)){ - header("LOCATION: index.php?step=6"); - }else{ - header("LOCATION: index.php?step=5&message=Something went wrong when communicating with the Database!"); - } - } - - - } + 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 + )); + $response = curl_exec($ch); + $result = json_decode($response, true); + curl_close($ch); // Close the connection -?> \ No newline at end of file + 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(); + } else { + $query1 = "UPDATE `dashboard`.`settings` SET `value` = '$url' WHERE (`key` = 'SETTINGS::SYSTEM:PTERODACTYL:URL')"; + $query2 = "UPDATE `dashboard`.`settings` SET `value` = '$key' WHERE (`key` = 'SETTINGS::SYSTEM:PTERODACTYL:TOKEN')"; + + $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=5&message=Could not connect to the Database"); + die(); + } + + if ($db->query($query1) && $db->query($query2)) { + header("LOCATION: index.php?step=6"); + } else { + header("LOCATION: index.php?step=5&message=Something went wrong when communicating with the Database!"); + } + } + + +} + +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!"); + } + + +} + + +?> diff --git a/public/install/functions.php b/public/install/functions.php index d3fe210e..09e2f8bd 100644 --- a/public/install/functions.php +++ b/public/install/functions.php @@ -1,100 +1,105 @@ - "7.4", - "mysql"=>"5.7.22", + "php" => "7.4", + "mysql" => "5.7.22", ]; -function checkPhpVersion(){ - global $requirements; - if (version_compare(phpversion(), $requirements["php"], '>=')){ - return "OK"; - } - return "not OK"; -} - -function getMySQLVersion() { - global $requirements; - - $output = shell_exec('mysql -V'); - preg_match('@[0-9]+\.[0-9]+\.[0-9]+@', $output, $version); - - $versionoutput = $version[0] ?? "0"; - - return (intval($versionoutput) > intval($requirements["mysql"]) ? "OK":$versionoutput);; -} - -function getZipVersion() { - global $requirements; - - $output = shell_exec('zip -v'); - preg_match('@[0-9]+\.[0-9]+\.[0-9]+@', $output, $version); - - $versionoutput = $version[0] ?? 0; - - return ($versionoutput!=0 ? "OK":"not OK");; -} - -function getGitVersion() { - global $requirements; - - $output = shell_exec('git --version'); - preg_match('@[0-9]+\.[0-9]+\.[0-9]+@', $output, $version); - - $versionoutput = $version[0] ?? 0; - - return ($versionoutput!=0 ? "OK":"not OK");; -} - -function getTarVersion() { - global $requirements; - - $output = shell_exec('tar --version'); - preg_match('@[0-9]+\.[0-9]+@', $output, $version); - - $versionoutput = $version[0] ?? 0; - - return ($versionoutput!=0 ? "OK":"not OK");; -} - -function checkExtensions(){ - global $required_extentions; - - $not_ok = []; - $extentions = get_loaded_extensions(); - - foreach($required_extentions as $ext){ - if(!in_array($ext,$extentions)){ - array_push($not_ok,$ext); - } - } - return $not_ok; - -} - - function setEnvironmentValue($envKey, $envValue) - { - - $envFile = dirname(__FILE__,3)."/.env"; - $str = file_get_contents($envFile); - - $str .= "\n"; // In case the searched variable is in the last line without \n - $keyPosition = strpos($str, "{$envKey}="); - $endOfLinePosition = strpos($str, PHP_EOL, $keyPosition); - $oldLine = substr($str, $keyPosition, $endOfLinePosition - $keyPosition); - $str = str_replace($oldLine, "{$envKey}={$envValue}", $str); - $str = substr($str, 0, -1); - - $fp = fopen($envFile, 'w'); - fwrite($fp, $str); - fclose($fp); +function checkPhpVersion() +{ + global $requirements; + if (version_compare(phpversion(), $requirements["php"], '>=')) { + return "OK"; } + return "not OK"; +} + +function getMySQLVersion() +{ + global $requirements; + + $output = shell_exec('mysql -V'); + preg_match('@[0-9]+\.[0-9]+\.[0-9]+@', $output, $version); + + $versionoutput = $version[0] ?? "0"; + + return (intval($versionoutput) > intval($requirements["mysql"]) ? "OK" : $versionoutput); +} + +function getZipVersion() +{ + global $requirements; + + $output = shell_exec('zip -v'); + preg_match('@[0-9]+\.[0-9]+\.[0-9]+@', $output, $version); + + $versionoutput = $version[0] ?? 0; + + return ($versionoutput != 0 ? "OK" : "not OK"); +} + +function getGitVersion() +{ + global $requirements; + + $output = shell_exec('git --version'); + preg_match('@[0-9]+\.[0-9]+\.[0-9]+@', $output, $version); + + $versionoutput = $version[0] ?? 0; + + return ($versionoutput != 0 ? "OK" : "not OK"); +} + +function getTarVersion() +{ + global $requirements; + + $output = shell_exec('tar --version'); + preg_match('@[0-9]+\.[0-9]+@', $output, $version); + + $versionoutput = $version[0] ?? 0; + + return ($versionoutput != 0 ? "OK" : "not OK"); +} + +function checkExtensions() +{ + global $required_extentions; + + $not_ok = []; + $extentions = get_loaded_extensions(); + + foreach ($required_extentions as $ext) { + if (!in_array($ext, $extentions)) { + array_push($not_ok, $ext); + } + } + return $not_ok; + +} + +function setEnvironmentValue($envKey, $envValue) +{ + + $envFile = dirname(__FILE__, 3) . "/.env"; + $str = file_get_contents($envFile); + + $str .= "\n"; // In case the searched variable is in the last line without \n + $keyPosition = strpos($str, "{$envKey}="); + $endOfLinePosition = strpos($str, PHP_EOL, $keyPosition); + $oldLine = substr($str, $keyPosition, $endOfLinePosition - $keyPosition); + $str = str_replace($oldLine, "{$envKey}={$envValue}", $str); + $str = substr($str, 0, -1); + + $fp = fopen($envFile, 'w'); + fwrite($fp, $str); + fclose($fp); +} - -?> \ No newline at end of file +?> diff --git a/public/install/index.php b/public/install/index.php index 3e09e689..2903e850 100644 --- a/public/install/index.php +++ b/public/install/index.php @@ -1,351 +1,470 @@ - + Controlpanel.gg installer Script - + - - + } - -
-
- Controlpanel.GG -
+ .ok { + color: green; + } -
- + .ok::before { + content: "✔️"; + } -

"> php version: (required )

-

"> mysql version: (minimum required )

+ .notok { + color: red; + } -

"> Missing extentions: (try to install anyway)

+ .notok::before { + content: "❌"; + } + + + -

"> Zip version:

+ +
+
+ Controlpanel.GG +
-

"> Git version:

+
+ -

"> Tar version:

+

"> php + version: (required )

+

"> mysql + version: (minimum required )

+ +

"> Missing + extentions: (try to install anyway)

+ +

"> Zip + version:

+ +

"> Git + version:

+ +

"> Tar + version:

- -
-
+ + + +
+
- - -
-
- Controlpanel.GG -
- -
- - ".$_GET['message']."

"; - } - ?> - -
- -
-
-
-
- - -
-
-
-
- - -
-
-
-
- - -
-
-
-
- - -
-
-
-
- - -
-
- -
-
- - -
-
- -
- - -
-
- - -
- - - -
-
- Controlpanel.GG -
- -
- - ".$_GET['message']."

"; - } - ?> - - - -
-
-
-
- - -
-
-
-
- - -
-
- - -
- - -
-
- - -
- -
-
- Controlpanel.GG -
+
+
+ Controlpanel.GG +
-
- - - ".$_GET['message']."

"; - } - ?> +
+ + " . $_GET['message'] . "

"; + } + ?> - + -
-
-
-
- - -
-
-
-
- - -
-
- -
-
- - -
-
- -
-
- - -
-
- - -
-
- - -
-
- -
-
- - -
-
- -
- - +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ +
+
+
+ + +
+
+
+ +
-
+
+ + +
+
-
-
- Controlpanel.GG -
+
+
+ Controlpanel.GG +
-
- - - - - ".$_GET['message']."

"; - } - ?> +
+ + " . $_GET['message'] . "

"; + } + ?> - + -
-
-
-
- - -
-
-
-
- - -
-
- - -
- - +
+
+
+
+ + +
+
+
+
+ +
+
+ +
-
+
+ + +
+
+ + +
+
+ Controlpanel.GG +
+ +
+ + + " . $_GET['message'] . "

"; + } + ?> + + + +
+
+
+
+ + +
+
+
+
+ + +
+
+ +
+
+ + +
+
+ +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+ + +
+
+ +
+ + +
+
+ + +
+
+ + +
+
+ Controlpanel.GG +
+ +
+ + + + + + + " . $_GET['message'] . "

"; + } + ?> + + + +
+
+
+
+ + +
+
+
+
+ + +
+
+ + +
+ + +
+
+ + +
+
+ + +
+
+ Controlpanel.GG +
+ +
+ + + " . $_GET['message'] . "

"; + } + ?> + + + +
+
+
+
+ + +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ +
+
+ + +
+
+ +
+ + +
+
+ + +
+ + + +
+
+ Controlpanel.GG +
+ +
+ + + "> + + +
+ + +
+ - - - - \ No newline at end of file + + +