diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 189f64bf..cc92759c 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -51,5 +51,60 @@ class AppServiceProvider extends ServiceProvider return $ok; }); + + //only run if the installer has been executed + if (file_exists(public_path()."/install/install.lock")) { + $settings = Settings::all(); + // Set all configs from database + foreach ($settings as $setting) { + config([$setting->key => $setting->value]); + } + + // Set Mail Config + //only update config if mail settings have changed in DB + if ( + config('mail.default') != config('SETTINGS:MAIL:MAILER') || + config('mail.mailers.smtp.host') != config('SETTINGS:MAIL:HOST') || + config('mail.mailers.smtp.port') != config('SETTINGS:MAIL:PORT') || + config('mail.mailers.smtp.username') != config('SETTINGS:MAIL:USERNAME') || + config('mail.mailers.smtp.password') != config('SETTINGS:MAIL:PASSWORD') || + config('mail.mailers.smtp.encryption') != config('SETTINGS:MAIL:ENCRYPTION') || + config('mail.from.address') != config('SETTINGS:MAIL:FROM_ADDRESS') || + config('mail.from.name') != config('SETTINGS:MAIL:FROM_NAME') + ) { + config(['mail.default' => config('SETTINGS::MAIL:MAILER')]); + config(['mail.mailers.smtp' => [ + 'transport' => 'smtp', + 'host' => config('SETTINGS::MAIL:HOST'), + 'port' => config('SETTINGS::MAIL:PORT'), + 'encryption' => config('SETTINGS::MAIL:ENCRYPTION'), + 'username' => config('SETTINGS::MAIL:USERNAME'), + 'password' => config('SETTINGS::MAIL:PASSWORD'), + 'timeout' => null, + 'auth_mode' => null, + ]]); + config(['mail.from' => ['address' => config('SETTINGS::MAIL:FROM_ADDRESS'), 'name' => config('SETTINGS::MAIL:FROM_NAME')]]); + + Artisan::call('queue:restart'); + } + + + // Set Recaptcha API Config + //only update config if recaptcha settings have changed in DB + if ( + config('recaptcha.api_site_key') != config('SETTINGS::RECAPTCHA:SITE_KEY') || + config('recaptcha.api_secret_key') != config('SETTINGS::RECAPTCHA:SECRET_KEY') + ) { + config(['recaptcha.api_site_key' => config('SETTINGS::RECAPTCHA:SITE_KEY')]); + config(['recaptcha.api_secret_key' => config('SETTINGS::RECAPTCHA:SECRET_KEY')]); + + Artisan::call('config:clear'); + Artisan::call('cache:clear'); + } + + // Set Discord-API Config + config(['services.discord.client_id' => config('SETTINGS::DISCORD:CLIENT_ID')]); + config(['services.discord.client_secret' => config('SETTINGS::DISCORD:CLIENT_SECRET')]); + } } } diff --git a/public/install/dotenv.php b/public/install/dotenv.php index 695aa7f0..01a94658 100644 --- a/public/install/dotenv.php +++ b/public/install/dotenv.php @@ -14,13 +14,13 @@ class DotEnv public function __construct(string $path) { - if(!file_exists($path)) { + if (!file_exists($path)) { throw new \InvalidArgumentException(sprintf('%s does not exist', $path)); } $this->path = $path; } - public function load() :void + public function load(): void { if (!is_readable($this->path)) { throw new \RuntimeException(sprintf('%s file is not readable', $this->path)); diff --git a/public/install/forms.php b/public/install/forms.php index f20d1a09..6912d870 100644 --- a/public/install/forms.php +++ b/public/install/forms.php @@ -35,14 +35,12 @@ if (isset($_POST['checkDB'])) { foreach ($values as $key => $value) { $param = $_POST[$value]; - if ($key=="DB_PASSWORD"){ - $param ='"' . $_POST[$value] . '"'; - } + # if ($key == "DB_PASSWORD") { + # $param = '"' . $_POST[$value] . '"'; + # } setEnvironmentValue($key, $param); } - - header("LOCATION: index.php?step=2.5"); } @@ -68,24 +66,29 @@ if (isset($_POST['checkGeneral'])) { if (isset($_POST['installComposer'])) { $logs = ""; - $logs .= run_console(putenv('COMPOSER_HOME=' . dirname(__FILE__, 3) . '/vendor/bin/composer')); - $logs .= run_console('composer install --no-dev --optimize-autoloader'); - $logs .= run_console('php artisan key:generate --force'); - $logs .= run_console('php artisan storage:link'); - $logsfile = fopen("logs.txt", "w") or die("Unable to open file!"); - fwrite($logsfile, $logs); - fclose($logsfile); + #$logs .= run_console(putenv('COMPOSER_HOME=' . dirname(__FILE__, 3) . '/vendor/bin/composer')); + #$logs .= run_console('composer install --no-dev --optimize-autoloader'); + $logs .= run_console('php artisan migrate --seed --force'); + $logs .= run_console('php artisan db:seed --class=ExampleItemsSeeder --force'); + $logs .= run_console('php artisan key:generate --force'); + $logs .= run_console('php artisan storage:link'); + + $logsfile = fopen("logs.txt", "w") or die("Unable to open file!"); + fwrite($logsfile, $logs); + fclose($logsfile); + + if (str_contains(getEnvironmentValue("APP_KEY"), "base64")) { + header("LOCATION: index.php?step=3"); + } else { + header("LOCATION: index.php?step=2.5&message=There was an error. Please check install/logs.txt !"); + } - if(str_contains(getEnvironmentValue("APP_KEY"), "base64")){ - header("LOCATION: index.php?step=3"); - }else{ - header("LOCATION: index.php?step=2.5&message=There was an error. Please check install/logs.txt !"); - } } if (isset($_POST['checkSMTP'])) { + try { $mail = new PHPMailer(true); @@ -114,21 +117,26 @@ if (isset($_POST['checkSMTP'])) { die(); } + $db = new mysqli(getEnvironmentValue("DB_HOST"), getEnvironmentValue("DB_USERNAME"), getEnvironmentValue("DB_PASSWORD"), getEnvironmentValue("DB_DATABASE"), getEnvironmentValue("DB_PORT")); + if ($db->connect_error) { + header("LOCATION: index.php?step=4&message=Could not connect to the Database"); + 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" + "SETTINGS::MAIL:MAILER" => $_POST["method"], + "SETTINGS::MAIL:HOST" => $_POST["host"], + "SETTINGS::MAIL:PORT" => $_POST["port"], + "SETTINGS::MAIL:USERNAME" => $_POST["user"], + "SETTINGS::MAIL:PASSWORD" => $_POST["pass"], + "SETTINGS::MAIL:ENCRYPTION" => $_POST["encryption"], + "SETTINGS::MAIL:FROM_ADDRESS" => $_POST["user"] ]; foreach ($values as $key => $value) { - $param = $_POST[$value]; - setEnvironmentValue($key, $param); + $query = "UPDATE `" . getEnvironmentValue("DB_DATABASE") . "`.`settings` SET `value` = '$value' WHERE (`key` = '$key')"; + $db->query($query); } + header("LOCATION: index.php?step=5"); @@ -162,8 +170,10 @@ if (isset($_POST['checkPtero'])) { 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')"; + + $query1 = "UPDATE `" . getEnvironmentValue("DB_DATABASE") . "`.`settings` SET `value` = '$url' WHERE (`key` = 'SETTINGS::SYSTEM:PTERODACTYL:URL')"; + $query2 = "UPDATE `" . getEnvironmentValue("DB_DATABASE") . "`.`settings` SET `value` = '$key' WHERE (`key` = 'SETTINGS::SYSTEM:PTERODACTYL:TOKEN')"; + $db = new mysqli(getEnvironmentValue("DB_HOST"), getEnvironmentValue("DB_USERNAME"), getEnvironmentValue("DB_PASSWORD"), getEnvironmentValue("DB_DATABASE"), getEnvironmentValue("DB_PORT")); if ($db->connect_error) { @@ -194,8 +204,10 @@ if (isset($_POST['createUser'])) { $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(); + + $key = $db->query("SELECT `value` FROM `" . getEnvironmentValue("DB_DATABASE") . "`.`settings` WHERE `key` = 'SETTINGS::SYSTEM:PTERODACTYL:TOKEN'")->fetch_assoc(); + $pterobaseurl = $db->query("SELECT `value` FROM `" . getEnvironmentValue("DB_DATABASE") . "`.`settings` WHERE `key` = 'SETTINGS::SYSTEM:PTERODACTYL:URL'")->fetch_assoc(); + $pteroURL = $pterobaseurl["value"] . "/api/application/users/" . $pteroID; @@ -250,14 +262,16 @@ if (isset($_POST['createUser'])) { die(); } + $query1 = "INSERT INTO `" . getEnvironmentValue("DB_DATABASE") . "`.`users` (`name`, `role`, `credits`, `server_limit`, `pterodactyl_id`, `email`, `password`, `created_at`) VALUES ('$name', 'admin', '250', '1', '$pteroID', '$mail', '$pass', CURRENT_TIMESTAMP)"; - $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 d5188490..dc796a37 100644 --- a/public/install/functions.php +++ b/public/install/functions.php @@ -70,7 +70,7 @@ function checkExtensions() $extentions = get_loaded_extensions(); foreach ($required_extentions as $ext) { - if(!preg_grep("/^(?=.*".$ext.").*$/", $extentions)) + if (!preg_grep("/^(?=.*" . $ext . ").*$/", $extentions)) array_push($not_ok, $ext); } return $not_ok; @@ -95,7 +95,8 @@ function setEnvironmentValue($envKey, $envValue) fclose($fp); } -function getEnvironmentValue($envKey){ +function getEnvironmentValue($envKey) +{ $envFile = dirname(__FILE__, 3) . "/.env"; $str = file_get_contents($envFile); @@ -103,17 +104,20 @@ function getEnvironmentValue($envKey){ $keyPosition = strpos($str, "{$envKey}="); $endOfLinePosition = strpos($str, PHP_EOL, $keyPosition); $oldLine = substr($str, $keyPosition, $endOfLinePosition - $keyPosition); - $value = substr($oldLine, strpos($oldLine, "=") + 1); + $value = substr($oldLine, strpos($oldLine, "=") + 1); + return $value; } -function run_console($command){ - $path = dirname(__FILE__, 3); - $cmd = "cd '$path' && bash -c 'exec -a ServerCPP $command' 2>&1"; - return shell_exec($cmd); - } + +function run_console($command) +{ + $path = dirname(__FILE__, 3); + $cmd = "cd '$path' && bash -c 'exec -a ServerCPP $command' 2>&1"; + return shell_exec($cmd); +} ?> diff --git a/public/install/index.php b/public/install/index.php index f28db332..d2eb8322 100644 --- a/public/install/index.php +++ b/public/install/index.php @@ -53,9 +53,11 @@ $cardheader = ' if (!isset($_GET['step'])) { - - if(!file_exists("../../.env")){ - echo run_console('cp .env.example .env'); + + + if (!file_exists("../../.env")) { + echo run_console('cp .env.example .env'); + } echo $cardheader; ?> @@ -72,7 +74,9 @@ if (!isset($_GET['step'])) { foreach (checkExtensions() as $ext) { echo $ext . ", "; } - print(sizeof(checkExtensions()) == 0 ? "" : "(Proceed anyway)");?>

+ + print(sizeof(checkExtensions()) == 0 ? "" : "(Proceed anyway)"); ?>

+ @@ -169,7 +173,7 @@ echo $cardheader; if (isset($_GET['step']) && $_GET['step'] == 2.5) { echo $cardheader; ?> -

Lets install Composer!

+

Lets install Composer and generate some security keys!

This process might take a while. Please do not refresh or close this page!

" . $_GET['message'] . "

"; @@ -181,7 +185,7 @@ echo $cardheader; action="/install/forms.php" name="installComposer"> - + @@ -191,121 +195,43 @@ echo $cardheader; -

Tell us something about your Host

- " . $_GET['message'] . "

"; - } - ?> -
- -
-
-
-
- - -
-
-
-
- - -
-
- - -
- - -
- - - - - - -

Lets get your E-Mails going!

-

This might take a few seconds when submitted!

+

Tell us something about your Host

+ " . $_GET['message'] . "

"; } ?> + action="/install/forms.php" name="checkGeneral"> +
- - Your Dashboard URL + + value="https://dash.example.com" class="form-control">
- - Your Host-Name + -
-
- -
-
- - -
-
- -
-
- - -
-
- - -
-
- - -
-
- -
-
- - + value="Controlpanel.gg" class="form-control">
- +
@@ -314,41 +240,11 @@ echo $cardheader; - -

Almost done!

-

Lets get some info about your Pterodactyl Installation!

- - - - - - - - "; - if(str_contains($resp,"Database seeding completed successfully.")){ - echo "All done!"; - }else{ - - "There was an error. Check /install/logs.txt"; - } - echo ""; - } - ?> - +

Lets get your E-Mails going!

+

This might take a few seconds when submitted!

" . $_GET['message'] . "

"; @@ -356,32 +252,72 @@ echo $cardheader; ?> + + action="/install/forms.php" name="checkSMTP"> +
- - Your E-Mail method + + value="smtp" class="form-control"> +
- - Your Mailer-Host + + value="smtp.google.com" class="form-control"> +
+
+ +
+
+ + +
+
+ +
+
+ +
+
+
+ + +
+
+ +
+
+ + +
+
+
- + + +
@@ -391,68 +327,53 @@ echo $cardheader; -

Lets create yourself!

-

We're making the first Admin user

+ +

Almost done!

+

Lets get some info about your Pterodactyl Installation!

+ + " . $_GET['message'] . "

"; } ?> + + action="/install/forms.php" name="checkPtero"> +
- - Pterodactyl URL + + value="https://ptero.example.com" class="form-control">
- - + +
-
-
- - -
-
-
-
- - -
-
- -
-
- - -
-
-
- +
@@ -461,30 +382,101 @@ echo $cardheader; -

All done!

-

You may navigate to your Dashboard now and log in!

- "> - - - - - - - +

Lets create yourself!

+

We're making the first Admin user

+ " . $_GET['message'] . "

"; } ?> + - +
+
+
+
+ + +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ +
+
+ + +
+
+ +
+ + +
+ + + + + + +

All done!

+

You may navigate to your Dashboard now and log in!

+ "> + + + + + + + + + + diff --git a/public/install/install.lock b/public/install/install.lock new file mode 100644 index 00000000..e69de29b diff --git a/public/install/logs.txt b/public/install/logs.txt new file mode 100644 index 00000000..d9aba701 --- /dev/null +++ b/public/install/logs.txt @@ -0,0 +1,16 @@ +Nothing to migrate. +Seeding: Database\Seeders\Seeds\SettingsSeeder +Seeded: Database\Seeders\Seeds\SettingsSeeder (38.00ms) +Database seeding completed successfully. +Seeding: Database\Seeders\Seeds\ProductSeeder +Seeded: Database\Seeders\Seeds\ProductSeeder (100.42ms) +Seeding: Database\Seeders\Seeds\CreditProductSeeder +Seeded: Database\Seeders\Seeds\CreditProductSeeder (18.76ms) +Seeding: Database\Seeders\Seeds\ApplicationApiSeeder +Seeded: Database\Seeders\Seeds\ApplicationApiSeeder (3.40ms) +Seeding: Database\Seeders\Seeds\UsefulLinksSeeder +Seeded: Database\Seeders\Seeds\UsefulLinksSeeder (7.57ms) +Database seeding completed successfully. +Application key set successfully. +The [/windir/c/Users/leipe/Desktop/dashboard/public/storage] link already exists. +The links have been created. diff --git a/resources/views/admin/settings/index.blade.php b/resources/views/admin/settings/index.blade.php index 9ff11a06..226bd0b8 100644 --- a/resources/views/admin/settings/index.blade.php +++ b/resources/views/admin/settings/index.blade.php @@ -23,7 +23,6 @@
-