From 1c30f1310d16a0e3cc3cbce6dc86633b9027a636 Mon Sep 17 00:00:00 2001 From: S0ly Date: Tue, 14 May 2024 15:03:06 +0200 Subject: [PATCH 01/19] ADD: redis to php extention check of the panel installer --- public/install/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/install/functions.php b/public/install/functions.php index a5f2b045..01dbcd04 100644 --- a/public/install/functions.php +++ b/public/install/functions.php @@ -15,7 +15,7 @@ (new DotEnv(dirname(__FILE__, 3) . '/.env'))->load(); -$required_extensions = ['openssl', 'gd', 'mysql', 'PDO', 'mbstring', 'tokenizer', 'bcmath', 'xml', 'curl', 'zip', 'intl']; +$required_extensions = ['openssl', 'gd', 'mysql', 'PDO', 'mbstring', 'tokenizer', 'bcmath', 'xml', 'curl', 'zip', 'intl', 'redis']; $requirements = [ 'minPhp' => '8.1', From 98ce2e331501d6b3459e20c8df86b5e4b87a3855 Mon Sep 17 00:00:00 2001 From: S0ly Date: Tue, 14 May 2024 15:10:03 +0200 Subject: [PATCH 02/19] FIX: trusted proxy depreciated issue --- config/trustedproxy.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/trustedproxy.php b/config/trustedproxy.php index dc46c31b..f3b88cd5 100644 --- a/config/trustedproxy.php +++ b/config/trustedproxy.php @@ -26,7 +26,7 @@ * subsequently passed through. */ 'proxies' => in_array(env('TRUSTED_PROXIES', []), ['*', '**']) ? - env('TRUSTED_PROXIES') : explode(',', env('TRUSTED_PROXIES', null)), + env('TRUSTED_PROXIES') : explode(',', env('TRUSTED_PROXIES', '')), /* * Or, to trust all proxies that connect From cea4e9efd7b936f743ed0a43531cd816793dbac0 Mon Sep 17 00:00:00 2001 From: 1day2die Date: Thu, 16 May 2024 13:14:55 +0200 Subject: [PATCH 03/19] implementing a mechanism to detect the absence of install.lock and redirecting users to /install to initiate the installation process. --- .gitignore | 1 + app/Http/Kernel.php | 2 ++ app/Http/Middleware/InstallerLock.php | 24 ++++++++++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 app/Http/Middleware/InstallerLock.php diff --git a/.gitignore b/.gitignore index f72249a8..feb1500a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ # Ignore dependencies and cache +/.idea /node_modules /vendor /storage/*.key diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index d0b1c7f7..96815f45 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -4,6 +4,7 @@ use App\Http\Middleware\ApiAuthToken; use App\Http\Middleware\CheckSuspended; +use App\Http\Middleware\InstallerLock; use App\Http\Middleware\isAdmin; use App\Http\Middleware\isMod; use App\Http\Middleware\LastSeen; @@ -36,6 +37,7 @@ class Kernel extends HttpKernel */ protected $middlewareGroups = [ 'web' => [ + InstallerLock::class, \App\Http\Middleware\EncryptCookies::class, \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, \Illuminate\Session\Middleware\StartSession::class, diff --git a/app/Http/Middleware/InstallerLock.php b/app/Http/Middleware/InstallerLock.php new file mode 100644 index 00000000..9390a598 --- /dev/null +++ b/app/Http/Middleware/InstallerLock.php @@ -0,0 +1,24 @@ + Date: Thu, 16 May 2024 13:22:44 +0200 Subject: [PATCH 04/19] Remove unused Middlewares --- app/Http/Kernel.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 96815f45..cd7cef5f 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -5,8 +5,6 @@ use App\Http\Middleware\ApiAuthToken; use App\Http\Middleware\CheckSuspended; use App\Http\Middleware\InstallerLock; -use App\Http\Middleware\isAdmin; -use App\Http\Middleware\isMod; use App\Http\Middleware\LastSeen; use Illuminate\Foundation\Http\Kernel as HttpKernel; @@ -72,8 +70,6 @@ class Kernel extends HttpKernel 'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class, 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, 'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class, - 'admin' => isAdmin::class, - 'moderator' => isMod::class, 'api.token' => ApiAuthToken::class, 'checkSuspended' => CheckSuspended::class, 'role' => \Spatie\Permission\Middlewares\RoleMiddleware::class, From be6c5d7addc299edde2e45d46d9d85ba44e69427 Mon Sep 17 00:00:00 2001 From: Vikas Dongre Date: Mon, 20 May 2024 18:10:22 +0530 Subject: [PATCH 05/19] fix: pterodactyl settings not getting encrypted during installation Also fixes minor issues like spelling / sentence mistakes. Refactored some variable names, and made it actually show error message on the page instead of only in logs. Now email settings have select input for mail method and encryption. --- app/Console/Commands/GetSettingCommand.php | 49 +++++++++++++ app/Console/Commands/SetSettingCommand.php | 52 ++++++++++++++ public/install/forms.php | 84 +++++++++++----------- public/install/index.php | 58 +++++++++------ 4 files changed, 176 insertions(+), 67 deletions(-) create mode 100644 app/Console/Commands/GetSettingCommand.php create mode 100644 app/Console/Commands/SetSettingCommand.php diff --git a/app/Console/Commands/GetSettingCommand.php b/app/Console/Commands/GetSettingCommand.php new file mode 100644 index 00000000..9be2191a --- /dev/null +++ b/app/Console/Commands/GetSettingCommand.php @@ -0,0 +1,49 @@ +argument('class'); + $key = $this->argument('key'); + $sameline = $this->option('sameline'); + + try { + $settings_class = "App\\Settings\\$class"; + $settings = new $settings_class(); + + $this->output->write($settings->$key, !$sameline); + + return Command::SUCCESS; + } catch (\Throwable $th) { + $this->error('Error: ' . $th->getMessage()); + return Command::FAILURE; + } + + return Command::SUCCESS; + } +} diff --git a/app/Console/Commands/SetSettingCommand.php b/app/Console/Commands/SetSettingCommand.php new file mode 100644 index 00000000..03481f93 --- /dev/null +++ b/app/Console/Commands/SetSettingCommand.php @@ -0,0 +1,52 @@ +argument('class'); + $key = $this->argument('key'); + $value = $this->argument('value'); + + try { + $settings_class = "App\\Settings\\$class"; + $settings = new $settings_class(); + + $settings->$key = $value; + + $settings->save(); + + $this->info("Successfully updated '$key'."); + } catch (\Throwable $th) { + $this->error('Error: ' . $th->getMessage()); + return Command::FAILURE; + } + + return Command::SUCCESS; + } +} diff --git a/public/install/forms.php b/public/install/forms.php index 96f1dfa1..9bed6eda 100644 --- a/public/install/forms.php +++ b/public/install/forms.php @@ -97,27 +97,30 @@ $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->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` - - //Recipients + // Send using SMTP + $mail->isSMTP(); + $mail->Host = $_POST['host']; + // Enable SMTP authentication + $mail->SMTPAuth = true; + $mail->Username = $_POST['user']; + $mail->Password = $_POST['pass']; + $mail->SMTPSecure = $_POST['encryption']; + $mail->Port = (int) $_POST['port']; + + // Test E-mail metadata $mail->setFrom($_POST['user'], $_POST['user']); - $mail->addAddress($_POST['user'], $_POST['user']); // Add a recipient + $mail->addAddress($_POST['user'], $_POST['user']); // Content - $mail->isHTML(true); // Set email format to HTML - $mail->Subject = 'It Worked!'; + // Set email format to HTML + $mail->isHTML(true); + $mail->Subject = 'It Worked! - Test E-Mail from Ctrlpanel.gg'; $mail->Body = 'Your E-Mail Settings are correct!'; $mail->send(); } catch (Exception $e) { wh_log($mail->ErrorInfo, 'error'); - header('LOCATION: index.php?step=4&message=Something wasnt right when sending the E-Mail!'); + header('LOCATION: index.php?step=4&message=Something went wrong while sending test E-Mail!
' . $mail->ErrorInfo); exit(); } @@ -140,8 +143,7 @@ ]; foreach ($values as $key => $value) { - $query = 'UPDATE `' . getenv('DB_DATABASE') . "`.`settings` SET `payload` = '$value' WHERE `name` = '$key' AND `group` = 'mail'"; - $db->query($query); + run_console("php artisan settings:set 'MailSettings' '$key' '$value'"); } wh_log('Database updated', 'debug'); @@ -197,34 +199,22 @@ exit(); } else { wh_log('Pterodactyl Settings are correct', 'debug'); - wh_log('Updating Database', 'debug'); - $key = $key; - $clientkey = $clientkey; - - $query1 = 'UPDATE `' . getenv('DB_DATABASE') . "`.`settings` SET `payload` = '" . json_encode($url) . "' WHERE (`name` = 'panel_url' AND `group` = 'pterodactyl')"; - $query2 = 'UPDATE `' . getenv('DB_DATABASE') . "`.`settings` SET `payload` = '" . json_encode($key) . "' WHERE (`name` = 'admin_token' AND `group` = 'pterodactyl')"; - $query3 = 'UPDATE `' . getenv('DB_DATABASE') . "`.`settings` SET `payload` = '" . json_encode($clientkey) . "' WHERE (`name` = 'user_token' AND `group` = 'pterodactyl')"; - - $db = new mysqli(getenv('DB_HOST'), getenv('DB_USERNAME'), getenv('DB_PASSWORD'), getenv('DB_DATABASE'), getenv('DB_PORT')); - if ($db->connect_error) { - wh_log($db->connect_error, 'error'); - header('LOCATION: index.php?step=5&message=Could not connect to the Database'); - exit(); - } - - if ($db->query($query1) && $db->query($query2) && $db->query($query3)) { + try { + run_console("php artisan settings:set 'PterodactylSettings' 'panel_url' '$url'"); + run_console("php artisan settings:set 'PterodactylSettings' 'admin_token' '$key'"); + run_console("php artisan settings:set 'PterodactylSettings' 'user_token' '$clientkey'"); wh_log('Database updated', 'debug'); header('LOCATION: index.php?step=6'); - } else { - wh_log($db->error, 'error'); - header('LOCATION: index.php?step=5&message=Something went wrong when communicating with the Database!'); + } catch (\Throwable $th) { + wh_log("Setting Pterodactyl information failed.", 'error'); + header("LOCATION: index.php?step=5&message=" . $th->getMessage() . "
Please check the installer.log file in /var/www/controlpanel/storage/logs!"); } } } if (isset($_POST['createUser'])) { - wh_log('Creating User', 'debug'); + wh_log('Getting Pterodactyl User', 'debug'); $db = new mysqli(getenv('DB_HOST'), getenv('DB_USERNAME'), getenv('DB_PASSWORD'), getenv('DB_DATABASE'), getenv('DB_PORT')); if ($db->connect_error) { wh_log($db->connect_error, 'error'); @@ -236,19 +226,26 @@ $pass = $_POST['pass']; $repass = $_POST['repass']; - $key = $db->query('SELECT `payload` FROM `' . getenv('DB_DATABASE') . "`.`settings` WHERE `name` = 'admin_token' AND `group` = 'pterodactyl'")->fetch_assoc(); - $key = removeQuotes($key['payload']); - $pterobaseurl = $db->query('SELECT `payload` FROM `' . getenv('DB_DATABASE') . "`.`settings` WHERE `name` = 'panel_url' AND `group` = 'pterodactyl'")->fetch_assoc(); + try { + $panel_url = run_console("php artisan settings:get 'PterodactylSettings' 'panel_url' --sameline"); + $admin_token = run_console("php artisan settings:get 'PterodactylSettings' 'admin_token' --sameline"); + wh_log('Database updated', 'debug'); + header('LOCATION: index.php?step=6'); + } catch (\Throwable $th) { + wh_log("Getting Pterodactyl information failed.", 'error'); + header("LOCATION: index.php?step=5&message=" . $th->getMessage() . "
Please check the installer.log file in /var/www/controlpanel/storage/logs!"); + } + + $panel_api_url = $panel_url . '/api/application/users/' . $pteroID; - $pteroURL = removeQuotes($pterobaseurl['payload']) . '/api/application/users/' . $pteroID; $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $pteroURL); + curl_setopt($ch, CURLOPT_URL, $panel_api_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Accept: application/json', 'Content-Type: application/json', - 'Authorization: Bearer ' . $key, + 'Authorization: Bearer ' . $admin_token, ]); $response = curl_exec($ch); $result = json_decode($response, true); @@ -267,15 +264,14 @@ $name = $result['attributes']['username']; $pass = password_hash($pass, PASSWORD_DEFAULT); - $pteroURL = removeQuotes($pterobaseurl['payload']) . '/api/application/users/' . $pteroID; $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $pteroURL); + curl_setopt($ch, CURLOPT_URL, $panel_api_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Accept: application/json', 'Content-Type: application/json', - 'Authorization: Bearer ' . $key, + 'Authorization: Bearer ' . $admin_token, ]); curl_setopt($ch, CURLOPT_POSTFIELDS, [ 'email' => $mail, diff --git a/public/install/index.php b/public/install/index.php index 6afd2e70..8d63f71d 100644 --- a/public/install/index.php +++ b/public/install/index.php @@ -76,29 +76,36 @@ function cardStart($title, $subtitle = null)
  • Write-permissions on .env-file
  • -
  • php - version: (minimum required )
  • +
  • + php version: (minimum required ) +
  • -
  • mysql - version: (minimum required )
  • +
  • + mysql version: (minimum required ) +
  • -
  • Missing - php-extentions:
  • +
  • + Missing php-extentions: + +
  • -
  • Git - version:
  • +
  • + Git version: + +
  • -
  • Tar - version:
  • +
  • + Tar version: + +
  • @@ -143,7 +150,7 @@ function cardStart($title, $subtitle = null)
    - +
    @@ -156,7 +163,7 @@ function cardStart($title, $subtitle = null)
    - +
    @@ -213,8 +220,8 @@ function cardStart($title, $subtitle = null)
    - - + +
    @@ -248,8 +255,9 @@ function cardStart($title, $subtitle = null)
    - - +
    @@ -284,7 +292,11 @@ function cardStart($title, $subtitle = null)
    - +
    @@ -431,4 +443,4 @@ function cardStart($title, $subtitle = null) ?> - + \ No newline at end of file From 392b6011ba021b76e659a57b536fc49621d3fb64 Mon Sep 17 00:00:00 2001 From: S0ly Date: Sun, 9 Jun 2024 18:38:50 +0200 Subject: [PATCH 06/19] refactor: added warning and deleted useless check in installer first step --- public/install/functions.php | 30 ------------------------------ public/install/index.php | 20 ++++++++++---------- 2 files changed, 10 insertions(+), 40 deletions(-) diff --git a/public/install/functions.php b/public/install/functions.php index 01dbcd04..c23856e8 100644 --- a/public/install/functions.php +++ b/public/install/functions.php @@ -48,36 +48,6 @@ function checkWriteable(): bool return is_writable('../../.env'); } -/** - * Check if the server runs using HTTPS - * @return bool Returns true on HTTPS or false on HTTP. - */ -function checkHTTPS(): bool -{ - $isHttps = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] == 443; - wh_log('https:', 'debug', (array)$isHttps); - return $isHttps; -} - -/** - * Check if MySQL is installed and runs the correct version using a shell command - * @return mixed|string 'OK' if required version is met, returns MySQL version if not met. - */ -function getMySQLVersion(): mixed -{ - global $requirements; - - wh_log('attempting to get mysql version', 'debug'); - - $output = shell_exec('mysql -V') ?? ''; - preg_match('@[0-9]+\.[0-9]+\.[0-9]+@', $output, $version); - - $versionoutput = $version[0] ?? '0'; - wh_log('mysql version: ' . $versionoutput, 'debug'); - - return intval($versionoutput) > intval($requirements['mysql']) ? 'OK' : $versionoutput; -} - /** * Check if zip is installed using a shell command * @return string 'OK' on success and 'not OK' on failure. diff --git a/public/install/index.php b/public/install/index.php index 8d63f71d..37347ce6 100644 --- a/public/install/index.php +++ b/public/install/index.php @@ -72,18 +72,12 @@ function cardStart($title, $subtitle = null)
      -
    • HTTPS is required
    • -
    • Write-permissions on .env-file
    • php version: (minimum required )
    • -
    • - mysql version: (minimum required ) -
    • -
    • Missing php-extentions:
    • - - -
    • Git version: @@ -106,6 +96,16 @@ function cardStart($title, $subtitle = null) Tar version:
    • + +
    • +

      +
      + Important: + CtrlPanel.gg requires a MySQL-Database, Redis-Server, and Pterodactyl-Panel to work.
      + Please make sure you have these installed and running before you continue. +

      +
    • +
    From 07355304b8ff5fbf83d3558b0d835fc47ef2ab29 Mon Sep 17 00:00:00 2001 From: jameskitt616 <52933658+jameskitt616@users.noreply.github.com> Date: Tue, 11 Jun 2024 23:05:44 +0200 Subject: [PATCH 07/19] Add redis configuration to installer --- public/install/forms.php | 49 ++-- public/install/functions.php | 6 +- public/install/index.php | 497 +++++++++++++++++++---------------- 3 files changed, 307 insertions(+), 245 deletions(-) diff --git a/public/install/forms.php b/public/install/forms.php index 9bed6eda..5439ac89 100644 --- a/public/install/forms.php +++ b/public/install/forms.php @@ -48,22 +48,6 @@ header('LOCATION: index.php?step=2.5'); } -if (isset($_POST['checkGeneral'])) { - wh_log('setting app settings', 'debug'); - $appname = '"' . $_POST['name'] . '"'; - $appurl = $_POST['url']; - - if (substr($appurl, -1) === '/') { - $appurl = substr_replace($appurl, '', -1); - } - - setenv('APP_NAME', $appname); - setenv('APP_URL', $appurl); - - wh_log('App settings set', 'debug'); - header('LOCATION: index.php?step=4'); -} - if (isset($_POST['feedDB'])) { wh_log('Feeding the Database', 'debug'); $logs = ''; @@ -84,13 +68,44 @@ wh_log($logs, 'debug'); wh_log('Feeding the Database successful', 'debug'); - header('LOCATION: index.php?step=3'); + header('LOCATION: index.php?step=2.6'); } catch (\Throwable $th) { wh_log('Feeding the Database failed', 'error'); header("LOCATION: index.php?step=2.5&message=" . $th->getMessage() . "
    Please check the installer.log file in /var/www/controlpanel/storage/logs !"); } } +if (isset($_POST['redisSetup'])) { + wh_log('Setting up Redis', 'debug'); + $redisHost = $_POST['redishost']; + $redisPort = $_POST['redisport']; + $redisPassword = $_POST['redispassword']; + + setenv('MEMCACHED_HOST', $redisHost); + setenv('REDIS_HOST', $redisHost); + setenv('REDIS_PORT', $redisPort); + setenv('REDIS_PASSWORD', ($redisPassword === '' ? 'null' : $redisPassword)); + + wh_log('Redis settings set', 'debug'); + header('LOCATION: index.php?step=3'); +} + +if (isset($_POST['checkGeneral'])) { + wh_log('setting app settings', 'debug'); + $appname = '"' . $_POST['name'] . '"'; + $appurl = $_POST['url']; + + if (substr($appurl, -1) === '/') { + $appurl = substr_replace($appurl, '', -1); + } + + setenv('APP_NAME', $appname); + setenv('APP_URL', $appurl); + + wh_log('App settings set', 'debug'); + header('LOCATION: index.php?step=4'); +} + if (isset($_POST['checkSMTP'])) { wh_log('Checking SMTP Settings', 'debug'); try { diff --git a/public/install/functions.php b/public/install/functions.php index 01dbcd04..ea1a1af6 100644 --- a/public/install/functions.php +++ b/public/install/functions.php @@ -243,7 +243,6 @@ function run_console(string $command, array $descriptors = null, string $cwd = n if ($exit_code > 0) { wh_log('command result: ' . $output, 'error'); throw new Exception("There was an error after running command `$command`", $exit_code); - return $output; } else { return $output; } @@ -303,3 +302,8 @@ function generateRandomString(int $length = 8): string return $randomString; } + +function determineIfRunningInDocker(): bool +{ + return file_exists('/.dockerenv'); +} diff --git a/public/install/index.php b/public/install/index.php index 8d63f71d..3c1483d4 100644 --- a/public/install/index.php +++ b/public/install/index.php @@ -63,66 +63,148 @@ function cardStart($title, $subtitle = null) - - + -
      +
        -
      • HTTPS is required
      • +
      • HTTPS is required
      • -
      • Write-permissions on .env-file
      • +
      • Write-permissions on .env-file
      • -
      • - php version: (minimum required ) -
      • +
      • + php version: (minimum required ) +
      • -
      • - mysql version: (minimum required ) -
      • +
      • + mysql version: (minimum required ) +
      • -
      • - Missing php-extentions: - -
      • +
      • + Missing php-extentions: + +
      • - -
      • - Git version: - -
      • +
      • + Git version: + +
      • + +
      • + Tar version: + +
      • +
      + + + + + + + + +
      + " . $_GET['message'] . '

      '; + } ?> + +
      +
      +
      +
      + + +
      +
      +
      +
      + + +
      +
      +
      +
      + + +
      +
      +
      +
      + + +
      +
      +
      +
      + + +
      +
      + +
      +
      + + +
      +
      + +
      -
    • - Tar version: - -
    • -
    + - - - +
    + +
    + + + + +
    + + This process might take a while. Please do not refresh or close this page!"); ?> + + " . $_GET['message'] . '

    '; + } ?> + + +
    + +
    +
    + echo cardStart($title = "Redis Configuration"); ?> -
    + " . $_GET['message'] . '

    '; } ?> @@ -131,71 +213,32 @@ function cardStart($title, $subtitle = null)
    - - -
    -
    -
    -
    - - -
    -
    -
    -
    - - + +
    - - + +
    - - + +
    - -
    -
    - - -
    -
    -
    - -
    - +
    +
    - -
    - - This process might take a while. Please do not refresh or close this page!"); ?> - - " . $_GET['message'] . '

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

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

    '; + } ?> -
    -
    -
    -
    - - -
    +
    +
    +
    +
    + +
    -
    -
    - - -
    +
    +
    +
    + +
    -
    -
    +
    -
    - -
    -
    +
    + +
    + +
    + Please do not refresh or close this page!"); ?> -
    - " . $_GET['message'] . '

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

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

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

    '; + } ?> -
    -
    -
    -
    +
    +
    +
    +
    - - -
    + +
    -
    -
    - - - [Found at: ptero.example.com/admin/api]
    The key needs all +
    +
    +
    + + + [Found at: ptero.example.com/admin/api]
    The key needs all Read & Write permissions!
    -
    -
    -
    - - - [Found at: ptero.example.com/account/api]
    Your Account +
    +
    +
    + + + [Found at: ptero.example.com/account/api]
    Your Account needs to be an Admin!
    -
    - -
    +
    -
    -
    - -
    - + +
    +
    + +
    + +
    -
    + - " . $_GET['message'] . '

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

    '; + } ?> -
    -
    - - - Found in the users-list on your pterodactyl dashboard -
    +
    +
    + + + Found in the users-list on your pterodactyl dashboard
    +
    -
    -
    - - - This will be your new pterodactyl password aswell! -
    -
    -
    -
    - - -
    +
    +
    + + + This will be your new pterodactyl password aswell!
    - +
    +
    +
    + +
    +
    +
    -
    - -
    - +
    +
    + +
    + - - - + + + -
    -
    +
    +
    + ?> - \ No newline at end of file + From 8d0690d2b318576c731b251d4bf99beb3ce6f88c Mon Sep 17 00:00:00 2001 From: jameskitt616 <52933658+jameskitt616@users.noreply.github.com> Date: Tue, 11 Jun 2024 23:08:20 +0200 Subject: [PATCH 08/19] Revert unnecessary changes in index.php --- public/install/index.php | 472 +++++++++++++++++++-------------------- 1 file changed, 236 insertions(+), 236 deletions(-) diff --git a/public/install/index.php b/public/install/index.php index 3c1483d4..9add8d5a 100644 --- a/public/install/index.php +++ b/public/install/index.php @@ -63,140 +63,140 @@ function cardStart($title, $subtitle = null) - - + -
      +
        -
      • HTTPS is required
      • +
      • HTTPS is required
      • -
      • Write-permissions on .env-file
      • +
      • Write-permissions on .env-file
      • -
      • - php version: (minimum required ) -
      • +
      • + php version: (minimum required ) +
      • -
      • - mysql version: (minimum required ) -
      • +
      • + mysql version: (minimum required ) +
      • -
      • - Missing php-extentions: - -
      • +
      • + Missing php-extentions: + +
      • - -
      • - Git version: - -
      • +
      • + Git version: + +
      • -
      • - Tar version: - -
      • -
      +
    • + Tar version: + +
    • +
    -
    - - - +
    + + + + echo cardStart($title = "Database Configuration"); ?> -
    - " . $_GET['message'] . '

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

    '; + } ?> -
    -
    -
    -
    - - +
    +
    +
    +
    + + +
    -
    -
    -
    - - +
    +
    + + +
    -
    -
    -
    - - +
    +
    + + +
    -
    -
    -
    - - +
    +
    + + +
    -
    -
    -
    - - +
    +
    + + +
    -
    -
    -
    - - +
    +
    + + +
    +
    +
    +
    + +
    +
    -
    -
    - -
    - -
    - -
    + // DB Migration & APP_KEY Generation + if (isset($_GET['step']) && $_GET['step'] == 2.5) { ?> + - This process might take a while. Please do not refresh or close this page!"); ?> + This process might take a while. Please do not refresh or close this page!"); ?> - " . $_GET['message'] . '

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

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

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

    '; + } ?> -
    -
    -
    -
    - - +
    +
    +
    +
    + + +
    -
    -
    -
    - - +
    +
    + + +
    -
    +
    -
    -
    +
    -
    - +
    + +
    +
    - -
    Please do not refresh or close this page!"); ?> -
    - " . $_GET['message'] . '

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

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

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

    '; + } ?> -
    -
    -
    -
    +
    +
    +
    +
    - - + + +
    -
    -
    -
    - - - [Found at: ptero.example.com/admin/api]
    The key needs all +
    +
    + + + [Found at: ptero.example.com/admin/api]
    The key needs all Read & Write permissions!
    +
    -
    -
    -
    - - - [Found at: ptero.example.com/account/api]
    Your Account +
    +
    + + + [Found at: ptero.example.com/account/api]
    Your Account needs to be an Admin!
    +
    -
    -
    +
    +
    +
    +
    + +
    +
    -
    -
    - -
    - -
    -
    + - " . $_GET['message'] . '

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

    '; + } ?> -
    -
    - - - Found in the users-list on your pterodactyl dashboard +
    +
    + + + Found in the users-list on your pterodactyl dashboard +
    -
    -
    -
    - - - This will be your new pterodactyl password aswell! +
    +
    + + + This will be your new pterodactyl password aswell! +
    -
    -
    -
    - - +
    +
    + + +
    -
    -
    +
    -
    - -
    +
    + +
    - -
    + +
    - - - + + + -
    -
    +
    +
    + ?> From fd6f0fdc6b0841398d148771b7d1598777a2c28f Mon Sep 17 00:00:00 2001 From: jameskitt616 <52933658+jameskitt616@users.noreply.github.com> Date: Tue, 11 Jun 2024 23:09:22 +0200 Subject: [PATCH 09/19] Revert unnecessary changes in functions.php --- public/install/functions.php | 1 + 1 file changed, 1 insertion(+) diff --git a/public/install/functions.php b/public/install/functions.php index ea1a1af6..ab1fb260 100644 --- a/public/install/functions.php +++ b/public/install/functions.php @@ -243,6 +243,7 @@ function run_console(string $command, array $descriptors = null, string $cwd = n if ($exit_code > 0) { wh_log('command result: ' . $output, 'error'); throw new Exception("There was an error after running command `$command`", $exit_code); + return $output; } else { return $output; } From d89a805e37731e10c261f7ed61034be2e5999fed Mon Sep 17 00:00:00 2001 From: jameskitt616 <52933658+jameskitt616@users.noreply.github.com> Date: Tue, 11 Jun 2024 23:10:49 +0200 Subject: [PATCH 10/19] Add docker check for mysql host --- public/install/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/install/index.php b/public/install/index.php index 9add8d5a..e01f47e3 100644 --- a/public/install/index.php +++ b/public/install/index.php @@ -138,7 +138,7 @@ function cardStart($title, $subtitle = null)
    - +
    From 03af8b3ed1ef1b644d710bc29b89f5324b7dd744 Mon Sep 17 00:00:00 2001 From: jameskitt616 <52933658+jameskitt616@users.noreply.github.com> Date: Tue, 11 Jun 2024 23:50:42 +0200 Subject: [PATCH 11/19] Verify that redis config is valid and working --- public/install/forms.php | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/public/install/forms.php b/public/install/forms.php index 5439ac89..9d0b83e4 100644 --- a/public/install/forms.php +++ b/public/install/forms.php @@ -5,6 +5,7 @@ use PHPMailer\PHPMailer\Exception; use PHPMailer\PHPMailer\PHPMailer; +use Predis\Client; require 'phpmailer/Exception.php'; require 'phpmailer/PHPMailer.php'; @@ -69,7 +70,7 @@ wh_log('Feeding the Database successful', 'debug'); header('LOCATION: index.php?step=2.6'); - } catch (\Throwable $th) { + } catch (Throwable $th) { wh_log('Feeding the Database failed', 'error'); header("LOCATION: index.php?step=2.5&message=" . $th->getMessage() . "
    Please check the installer.log file in /var/www/controlpanel/storage/logs !"); } @@ -81,13 +82,27 @@ $redisPort = $_POST['redisport']; $redisPassword = $_POST['redispassword']; - setenv('MEMCACHED_HOST', $redisHost); - setenv('REDIS_HOST', $redisHost); - setenv('REDIS_PORT', $redisPort); - setenv('REDIS_PASSWORD', ($redisPassword === '' ? 'null' : $redisPassword)); + $redisClient = new Client([ + 'host' => $redisHost, + 'port' => $redisPort, + 'password' => $redisPassword, + 'timeout' => 1.0, + ]); - wh_log('Redis settings set', 'debug'); - header('LOCATION: index.php?step=3'); + try { + $redisClient->ping(); + + setenv('MEMCACHED_HOST', $redisHost); + setenv('REDIS_HOST', $redisHost); + setenv('REDIS_PORT', $redisPort); + setenv('REDIS_PASSWORD', ($redisPassword === '' ? 'null' : $redisPassword)); + + wh_log('Redis connection successful. Settings updated.', 'debug'); + header('LOCATION: index.php?step=3'); + } catch (Throwable $th) { + wh_log('Redis connection failed. Settings updated.', 'debug'); + header("LOCATION: index.php?step=2.6&message=Please check your credentials!
    " . $th->getMessage()); + } } if (isset($_POST['checkGeneral'])) { @@ -221,7 +236,7 @@ run_console("php artisan settings:set 'PterodactylSettings' 'user_token' '$clientkey'"); wh_log('Database updated', 'debug'); header('LOCATION: index.php?step=6'); - } catch (\Throwable $th) { + } catch (Throwable $th) { wh_log("Setting Pterodactyl information failed.", 'error'); header("LOCATION: index.php?step=5&message=" . $th->getMessage() . "
    Please check the installer.log file in /var/www/controlpanel/storage/logs!"); } @@ -246,7 +261,7 @@ $admin_token = run_console("php artisan settings:get 'PterodactylSettings' 'admin_token' --sameline"); wh_log('Database updated', 'debug'); header('LOCATION: index.php?step=6'); - } catch (\Throwable $th) { + } catch (Throwable $th) { wh_log("Getting Pterodactyl information failed.", 'error'); header("LOCATION: index.php?step=5&message=" . $th->getMessage() . "
    Please check the installer.log file in /var/www/controlpanel/storage/logs!"); } From c508b783ea772eb5178234f8da1f2fa05ecc5132 Mon Sep 17 00:00:00 2001 From: jameskitt616 <52933658+jameskitt616@users.noreply.github.com> Date: Wed, 12 Jun 2024 10:50:05 +0200 Subject: [PATCH 12/19] Fix some error handling on installer --- composer.json | 2 + public/install/forms.php | 139 ++++++++++++++++++++++----------------- public/install/index.php | 16 ++--- 3 files changed, 90 insertions(+), 67 deletions(-) diff --git a/composer.json b/composer.json index b316eec1..f36209e1 100644 --- a/composer.json +++ b/composer.json @@ -10,6 +10,8 @@ "require": { "php": "^8.1", "ext-intl": "*", + "ext-mysqli": "*", + "ext-curl": "*", "biscolab/laravel-recaptcha": "^5.4", "doctrine/dbal": "^3.5.3", "guzzlehttp/guzzle": "^7.5", diff --git a/public/install/forms.php b/public/install/forms.php index 9d0b83e4..8cbd84e2 100644 --- a/public/install/forms.php +++ b/public/install/forms.php @@ -69,7 +69,7 @@ wh_log($logs, 'debug'); wh_log('Feeding the Database successful', 'debug'); - header('LOCATION: index.php?step=2.6'); + header('LOCATION: index.php?step=3'); } catch (Throwable $th) { wh_log('Feeding the Database failed', 'error'); header("LOCATION: index.php?step=2.5&message=" . $th->getMessage() . "
    Please check the installer.log file in /var/www/controlpanel/storage/logs !"); @@ -98,10 +98,10 @@ setenv('REDIS_PASSWORD', ($redisPassword === '' ? 'null' : $redisPassword)); wh_log('Redis connection successful. Settings updated.', 'debug'); - header('LOCATION: index.php?step=3'); + header('LOCATION: index.php?step=4'); } catch (Throwable $th) { wh_log('Redis connection failed. Settings updated.', 'debug'); - header("LOCATION: index.php?step=2.6&message=Please check your credentials!
    " . $th->getMessage()); + header("LOCATION: index.php?step=3&message=Please check your credentials!
    " . $th->getMessage()); } } @@ -118,7 +118,7 @@ setenv('APP_URL', $appurl); wh_log('App settings set', 'debug'); - header('LOCATION: index.php?step=4'); + header('LOCATION: index.php?step=5'); } if (isset($_POST['checkSMTP'])) { @@ -150,7 +150,7 @@ $mail->send(); } catch (Exception $e) { wh_log($mail->ErrorInfo, 'error'); - header('LOCATION: index.php?step=4&message=Something went wrong while sending test E-Mail!
    ' . $mail->ErrorInfo); + header('LOCATION: index.php?step=5&message=Something went wrong while sending test E-Mail!
    ' . $mail->ErrorInfo); exit(); } @@ -159,7 +159,7 @@ $db = new mysqli(getenv('DB_HOST'), getenv('DB_USERNAME'), getenv('DB_PASSWORD'), getenv('DB_DATABASE'), getenv('DB_PORT')); if ($db->connect_error) { wh_log($db->connect_error, 'error'); - header('LOCATION: index.php?step=4&message=Could not connect to the Database: '); + header('LOCATION: index.php?step=5&message=Could not connect to the Database: '); exit(); } $values = [ @@ -177,7 +177,7 @@ } wh_log('Database updated', 'debug'); - header('LOCATION: index.php?step=5'); + header('LOCATION: index.php?step=6'); } if (isset($_POST['checkPtero'])) { @@ -187,10 +187,20 @@ $key = $_POST['key']; $clientkey = $_POST['clientkey']; - if (substr($url, -1) === '/') { - $url = substr_replace($url, '', -1); + $parsedUrl = parse_url($url); + + if (!isset($parsedUrl['scheme'])) { + header('LOCATION: index.php?step=6&message=Please set an URL Scheme like "https://"!'); + exit(); } + if (!isset($parsedUrl['host'])) { + header('LOCATION: index.php?step=6&message=Please set an valid URL host like "https://panel.example.com"!'); + exit(); + } + + $url = $parsedUrl['scheme'] . '://' . $parsedUrl['host']; + $callpteroURL = $url . '/api/client/account'; $call = curl_init(); @@ -203,7 +213,7 @@ ]); $callresponse = curl_exec($call); $callresult = json_decode($callresponse, true); - curl_close($call); // Close the connection + curl_close($call); $pteroURL = $url . '/api/application/users'; $ch = curl_init(); @@ -217,38 +227,46 @@ ]); $response = curl_exec($ch); $result = json_decode($response, true); - curl_close($ch); // Close the connection + curl_close($ch); + + if (!is_array($result)) { + wh_log('No array in response found', 'error'); + header('LOCATION: index.php?step=6&message=An unknown Error occured, please try again!'); + } - if (!is_array($result) and $result['errors'][0] !== null) { - header('LOCATION: index.php?step=5&message=Couldn\'t connect to Pterodactyl. Make sure your API key has all read and write permissions!'); + if (array_key_exists('errors', $result) && $result['errors'][0]['detail'] === 'This action is unauthorized.') { wh_log('API CALL ERROR: ' . $result['errors'][0]['code'], 'error'); + header('LOCATION: index.php?step=6&message=Couldn\'t connect to Pterodactyl. Make sure your Application API key has all read and write permissions!'); exit(); - } elseif (!is_array($callresult) and $callresult['errors'][0] !== null or $callresult['attributes']['admin'] == false) { - header('LOCATION: index.php?step=5&message=Your ClientAPI Key is wrong or the account is not an admin!'); + } + + if (array_key_exists('errors', $callresult) && $callresult['errors'][0]['detail'] === 'Unauthenticated.') { wh_log('API CALL ERROR: ' . $callresult['errors'][0]['code'], 'error'); + header('LOCATION: index.php?step=6&message=Your ClientAPI Key is wrong or the account is not an admin!'); + exit(); + } + + try { + run_console("php artisan settings:set 'PterodactylSettings' 'panel_url' '$url'"); + run_console("php artisan settings:set 'PterodactylSettings' 'admin_token' '$key'"); + run_console("php artisan settings:set 'PterodactylSettings' 'user_token' '$clientkey'"); + wh_log('Database updated', 'debug'); + header('LOCATION: index.php?step=7'); + } catch (Throwable $th) { + wh_log("Setting Pterodactyl information failed.", 'error'); + header("LOCATION: index.php?step=6&message=" . $th->getMessage() . "
    Please check the installer.log file in /var/www/controlpanel/storage/logs!"); exit(); - } else { - wh_log('Pterodactyl Settings are correct', 'debug'); - - try { - run_console("php artisan settings:set 'PterodactylSettings' 'panel_url' '$url'"); - run_console("php artisan settings:set 'PterodactylSettings' 'admin_token' '$key'"); - run_console("php artisan settings:set 'PterodactylSettings' 'user_token' '$clientkey'"); - wh_log('Database updated', 'debug'); - header('LOCATION: index.php?step=6'); - } catch (Throwable $th) { - wh_log("Setting Pterodactyl information failed.", 'error'); - header("LOCATION: index.php?step=5&message=" . $th->getMessage() . "
    Please check the installer.log file in /var/www/controlpanel/storage/logs!"); - } } } if (isset($_POST['createUser'])) { wh_log('Getting Pterodactyl User', 'debug'); - $db = new mysqli(getenv('DB_HOST'), getenv('DB_USERNAME'), getenv('DB_PASSWORD'), getenv('DB_DATABASE'), getenv('DB_PORT')); - if ($db->connect_error) { - wh_log($db->connect_error, 'error'); - header('LOCATION: index.php?step=6&message=Could not connect to the Database'); + + try { + $db = new mysqli(getenv('DB_HOST'), getenv('DB_USERNAME'), getenv('DB_PASSWORD'), getenv('DB_DATABASE'), getenv('DB_PORT')); + } catch (Throwable $th) { + wh_log($th->getMessage(), 'error'); + header('LOCATION: index.php?step=7&message=Could not connect to the Database'); exit(); } @@ -257,36 +275,36 @@ $repass = $_POST['repass']; try { - $panel_url = run_console("php artisan settings:get 'PterodactylSettings' 'panel_url' --sameline"); - $admin_token = run_console("php artisan settings:get 'PterodactylSettings' 'admin_token' --sameline"); - wh_log('Database updated', 'debug'); - header('LOCATION: index.php?step=6'); + $panelUrl = run_console("php artisan settings:get 'PterodactylSettings' 'panel_url' --sameline"); + $adminToken = run_console("php artisan settings:get 'PterodactylSettings' 'admin_token' --sameline"); } catch (Throwable $th) { wh_log("Getting Pterodactyl information failed.", 'error'); - header("LOCATION: index.php?step=5&message=" . $th->getMessage() . "
    Please check the installer.log file in /var/www/controlpanel/storage/logs!"); + header("LOCATION: index.php?step=6&message=" . $th->getMessage() . "
    Please check the installer.log file in /var/www/controlpanel/storage/logs!"); + exit(); } - $panel_api_url = $panel_url . '/api/application/users/' . $pteroID; + $panelApiUrl = $panelUrl . '/api/application/users/' . $pteroID; $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $panel_api_url); + curl_setopt($ch, CURLOPT_URL, $panelApiUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Accept: application/json', 'Content-Type: application/json', - 'Authorization: Bearer ' . $admin_token, + 'Authorization: Bearer ' . $adminToken, ]); $response = curl_exec($ch); $result = json_decode($response, true); - curl_close($ch); // Close the connection + curl_close($ch); - if (!$result['attributes']['email']) { - header('LOCATION: index.php?step=6&message=Could not find the user with pterodactyl ID ' . $pteroID); + if ($pass !== $repass) { + header('LOCATION: index.php?step=7&message=The Passwords did not match!'); exit(); } - if ($pass !== $repass) { - header('LOCATION: index.php?step=6&message=The Passwords did not match!'); + + if (array_key_exists('errors', $result)) { + header('LOCATION: index.php?step=7&message=Could not find the user with pterodactyl ID ' . $pteroID); exit(); } @@ -296,12 +314,12 @@ $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $panel_api_url); + curl_setopt($ch, CURLOPT_URL, $panelApiUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Accept: application/json', 'Content-Type: application/json', - 'Authorization: Bearer ' . $admin_token, + 'Authorization: Bearer ' . $adminToken, ]); curl_setopt($ch, CURLOPT_POSTFIELDS, [ 'email' => $mail, @@ -312,22 +330,25 @@ ]); $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=Couldn\'t connect to Pterodactyl. Make sure your API key has all read and write permissions!'); - exit(); - } + curl_close($ch); $random = generateRandomString(); $query1 = 'INSERT INTO `' . getenv('DB_DATABASE') . "`.`users` (`name`, `role`, `credits`, `server_limit`, `pterodactyl_id`, `email`, `password`, `created_at`, `referral_code`) VALUES ('$name', 'admin', '250', '1', '$pteroID', '$mail', '$pass', CURRENT_TIMESTAMP, '$random')"; $query2 = "INSERT INTO `" . getenv('DB_DATABASE') . "`.`model_has_roles` (`role_id`, `model_type`, `model_id`) VALUES ('1', 'App\\\Models\\\User', '1')"; - if ($db->query($query1) && $db->query($query2)) { - wh_log('Created user with Email ' . $mail . ' and pterodactyl ID ' . $pteroID, 'info'); - header('LOCATION: index.php?step=7'); - } else { - wh_log($db->error, 'error'); - header('LOCATION: index.php?step=6&message=Something went wrong when communicating with the Database'); + try { + $db->query($query1); + $db->query($query2); + + wh_log('Created user with Email ' . $mail . ' and pterodactyl ID ' . $pteroID); + header('LOCATION: index.php?step=8'); + } catch (Throwable $th) { + wh_log($th->getMessage(), 'error'); + if (str_contains($th->getMessage(), 'Duplicate entry')) { + header('LOCATION: index.php?step=7&message=User already exists in CtrlPanel\'s Database.'); + } else { + header('LOCATION: index.php?step=7&message=Something went wrong when communicating with the Database.'); + } + exit(); } } diff --git a/public/install/index.php b/public/install/index.php index e01f47e3..dc3e0448 100644 --- a/public/install/index.php +++ b/public/install/index.php @@ -200,7 +200,7 @@ function cardStart($title, $subtitle = null) } // Redis Config - if (isset($_GET['step']) && $_GET['step'] == 2.6) { + if (isset($_GET['step']) && $_GET['step'] == 3) { echo cardStart($title = "Redis Configuration"); ?> @@ -243,7 +243,7 @@ function cardStart($title, $subtitle = null) } // Dashboard Config - if (isset($_GET['step']) && $_GET['step'] == 3) { + if (isset($_GET['step']) && $_GET['step'] == 4) { echo cardStart($title = "Dashboard Configuration"); ?> @@ -284,7 +284,7 @@ function cardStart($title, $subtitle = null) } // Email Config - if (isset($_GET['step']) && $_GET['step'] == 4) { + if (isset($_GET['step']) && $_GET['step'] == 5) { echo cardStart($title = "E-Mail Configuration", $subtitle = "This process might take a few seconds when submitted.
    Please do not refresh or close this page!"); ?> @@ -297,7 +297,7 @@ function cardStart($title, $subtitle = null)
    - + @@ -354,7 +354,7 @@ function cardStart($title, $subtitle = null)
    - + @@ -367,7 +367,7 @@ function cardStart($title, $subtitle = null) } // Pterodactyl Config - if (isset($_GET['step']) && $_GET['step'] == 5) { + if (isset($_GET['step']) && $_GET['step'] == 6) { echo cardStart($title = "Pterodactyl Configuration", $subtitle = "Lets get some info about your Pterodactyl Installation!"); ?> @@ -418,7 +418,7 @@ function cardStart($title, $subtitle = null) } // Admin Creation Form - if (isset($_GET['step']) && $_GET['step'] == 6) { + if (isset($_GET['step']) && $_GET['step'] == 7) { echo cardStart($title = "First Admin Creation", $subtitle = "Lets create the first admin user!"); ?> @@ -466,7 +466,7 @@ function cardStart($title, $subtitle = null) } // Install Finished - if (isset($_GET['step']) && $_GET['step'] == 7) { + if (isset($_GET['step']) && $_GET['step'] == 8) { $lockfile = fopen('../../install.lock', 'w') or exit('Unable to open file!'); fwrite($lockfile, 'locked'); fclose($lockfile); From 4ccea68f3d724d9200d823b60005a52440bb3f3d Mon Sep 17 00:00:00 2001 From: jameskitt616 <52933658+jameskitt616@users.noreply.github.com> Date: Wed, 12 Jun 2024 22:21:33 +0200 Subject: [PATCH 13/19] Add set timezone to install script --- public/install/forms.php | 72 +++-- public/install/index.php | 597 ++++++++++++++++++++++----------------- 2 files changed, 376 insertions(+), 293 deletions(-) diff --git a/public/install/forms.php b/public/install/forms.php index 8cbd84e2..23f910ef 100644 --- a/public/install/forms.php +++ b/public/install/forms.php @@ -13,6 +13,16 @@ include 'functions.php'; +if (isset($_POST['timezoneConfig'])) { + wh_log('Setting up Timezone', 'debug'); + $timezone = $_POST['timezone']; + + setenv('APP_TIMEZONE', $timezone); + + wh_log('Timezone set: ' . $timezone, 'debug'); + header('LOCATION: index.php?step=3'); +} + mysqli_report(MYSQLI_REPORT_STRICT | MYSQLI_REPORT_ALL); if (isset($_POST['checkDB'])) { @@ -32,7 +42,7 @@ $db = new mysqli($_POST['databasehost'], $_POST['databaseuser'], $_POST['databaseuserpass'], $_POST['database'], $_POST['databaseport']); } catch (mysqli_sql_exception $e) { wh_log($e->getMessage(), 'error'); - header('LOCATION: index.php?step=2&message=' . $e->getMessage()); + header('LOCATION: index.php?step=3&message=' . $e->getMessage()); exit(); } @@ -46,7 +56,7 @@ } wh_log('Database connection successful', 'debug'); - header('LOCATION: index.php?step=2.5'); + header('LOCATION: index.php?step=3.5'); } if (isset($_POST['feedDB'])) { @@ -69,10 +79,10 @@ wh_log($logs, 'debug'); wh_log('Feeding the Database successful', 'debug'); - header('LOCATION: index.php?step=3'); + header('LOCATION: index.php?step=4'); } catch (Throwable $th) { wh_log('Feeding the Database failed', 'error'); - header("LOCATION: index.php?step=2.5&message=" . $th->getMessage() . "
    Please check the installer.log file in /var/www/controlpanel/storage/logs !"); + header("LOCATION: index.php?step=3.5&message=" . $th->getMessage() . "
    Please check the installer.log file in /var/www/controlpanel/storage/logs !"); } } @@ -98,10 +108,10 @@ setenv('REDIS_PASSWORD', ($redisPassword === '' ? 'null' : $redisPassword)); wh_log('Redis connection successful. Settings updated.', 'debug'); - header('LOCATION: index.php?step=4'); + header('LOCATION: index.php?step=5'); } catch (Throwable $th) { wh_log('Redis connection failed. Settings updated.', 'debug'); - header("LOCATION: index.php?step=3&message=Please check your credentials!
    " . $th->getMessage()); + header("LOCATION: index.php?step=4&message=Please check your credentials!
    " . $th->getMessage()); } } @@ -110,15 +120,25 @@ $appname = '"' . $_POST['name'] . '"'; $appurl = $_POST['url']; - if (substr($appurl, -1) === '/') { - $appurl = substr_replace($appurl, '', -1); + $parsedUrl = parse_url($appurl); + + if (!isset($parsedUrl['scheme'])) { + header('LOCATION: index.php?step=5&message=Please set an URL Scheme like "https://"!'); + exit(); + } + + if (!isset($parsedUrl['host'])) { + header('LOCATION: index.php?step=5&message=Please set an valid URL host like "https://ctrlpanel.example.com"!'); + exit(); } + $appurl = $parsedUrl['scheme'] . '://' . $parsedUrl['host']; + setenv('APP_NAME', $appname); setenv('APP_URL', $appurl); wh_log('App settings set', 'debug'); - header('LOCATION: index.php?step=5'); + header('LOCATION: index.php?step=6'); } if (isset($_POST['checkSMTP'])) { @@ -150,7 +170,7 @@ $mail->send(); } catch (Exception $e) { wh_log($mail->ErrorInfo, 'error'); - header('LOCATION: index.php?step=5&message=Something went wrong while sending test E-Mail!
    ' . $mail->ErrorInfo); + header('LOCATION: index.php?step=6&message=Something went wrong while sending test E-Mail!
    ' . $mail->ErrorInfo); exit(); } @@ -159,7 +179,7 @@ $db = new mysqli(getenv('DB_HOST'), getenv('DB_USERNAME'), getenv('DB_PASSWORD'), getenv('DB_DATABASE'), getenv('DB_PORT')); if ($db->connect_error) { wh_log($db->connect_error, 'error'); - header('LOCATION: index.php?step=5&message=Could not connect to the Database: '); + header('LOCATION: index.php?step=6&message=Could not connect to the Database: '); exit(); } $values = [ @@ -177,7 +197,7 @@ } wh_log('Database updated', 'debug'); - header('LOCATION: index.php?step=6'); + header('LOCATION: index.php?step=7'); } if (isset($_POST['checkPtero'])) { @@ -190,12 +210,12 @@ $parsedUrl = parse_url($url); if (!isset($parsedUrl['scheme'])) { - header('LOCATION: index.php?step=6&message=Please set an URL Scheme like "https://"!'); + header('LOCATION: index.php?step=7&message=Please set an URL Scheme like "https://"!'); exit(); } if (!isset($parsedUrl['host'])) { - header('LOCATION: index.php?step=6&message=Please set an valid URL host like "https://panel.example.com"!'); + header('LOCATION: index.php?step=7&message=Please set an valid URL host like "https://panel.example.com"!'); exit(); } @@ -231,18 +251,18 @@ if (!is_array($result)) { wh_log('No array in response found', 'error'); - header('LOCATION: index.php?step=6&message=An unknown Error occured, please try again!'); + header('LOCATION: index.php?step=7&message=An unknown Error occured, please try again!'); } if (array_key_exists('errors', $result) && $result['errors'][0]['detail'] === 'This action is unauthorized.') { wh_log('API CALL ERROR: ' . $result['errors'][0]['code'], 'error'); - header('LOCATION: index.php?step=6&message=Couldn\'t connect to Pterodactyl. Make sure your Application API key has all read and write permissions!'); + header('LOCATION: index.php?step=7&message=Couldn\'t connect to Pterodactyl. Make sure your Application API key has all read and write permissions!'); exit(); } if (array_key_exists('errors', $callresult) && $callresult['errors'][0]['detail'] === 'Unauthenticated.') { wh_log('API CALL ERROR: ' . $callresult['errors'][0]['code'], 'error'); - header('LOCATION: index.php?step=6&message=Your ClientAPI Key is wrong or the account is not an admin!'); + header('LOCATION: index.php?step=7&message=Your ClientAPI Key is wrong or the account is not an admin!'); exit(); } @@ -251,10 +271,10 @@ run_console("php artisan settings:set 'PterodactylSettings' 'admin_token' '$key'"); run_console("php artisan settings:set 'PterodactylSettings' 'user_token' '$clientkey'"); wh_log('Database updated', 'debug'); - header('LOCATION: index.php?step=7'); + header('LOCATION: index.php?step=8'); } catch (Throwable $th) { wh_log("Setting Pterodactyl information failed.", 'error'); - header("LOCATION: index.php?step=6&message=" . $th->getMessage() . "
    Please check the installer.log file in /var/www/controlpanel/storage/logs!"); + header("LOCATION: index.php?step=7&message=" . $th->getMessage() . "
    Please check the installer.log file in /var/www/controlpanel/storage/logs!"); exit(); } } @@ -266,7 +286,7 @@ $db = new mysqli(getenv('DB_HOST'), getenv('DB_USERNAME'), getenv('DB_PASSWORD'), getenv('DB_DATABASE'), getenv('DB_PORT')); } catch (Throwable $th) { wh_log($th->getMessage(), 'error'); - header('LOCATION: index.php?step=7&message=Could not connect to the Database'); + header('LOCATION: index.php?step=8&message=Could not connect to the Database'); exit(); } @@ -279,7 +299,7 @@ $adminToken = run_console("php artisan settings:get 'PterodactylSettings' 'admin_token' --sameline"); } catch (Throwable $th) { wh_log("Getting Pterodactyl information failed.", 'error'); - header("LOCATION: index.php?step=6&message=" . $th->getMessage() . "
    Please check the installer.log file in /var/www/controlpanel/storage/logs!"); + header("LOCATION: index.php?step=7&message=" . $th->getMessage() . "
    Please check the installer.log file in /var/www/controlpanel/storage/logs!"); exit(); } @@ -299,12 +319,12 @@ curl_close($ch); if ($pass !== $repass) { - header('LOCATION: index.php?step=7&message=The Passwords did not match!'); + header('LOCATION: index.php?step=8&message=The Passwords did not match!'); exit(); } if (array_key_exists('errors', $result)) { - header('LOCATION: index.php?step=7&message=Could not find the user with pterodactyl ID ' . $pteroID); + header('LOCATION: index.php?step=8&message=Could not find the user with pterodactyl ID ' . $pteroID); exit(); } @@ -341,13 +361,13 @@ $db->query($query2); wh_log('Created user with Email ' . $mail . ' and pterodactyl ID ' . $pteroID); - header('LOCATION: index.php?step=8'); + header('LOCATION: index.php?step=9'); } catch (Throwable $th) { wh_log($th->getMessage(), 'error'); if (str_contains($th->getMessage(), 'Duplicate entry')) { - header('LOCATION: index.php?step=7&message=User already exists in CtrlPanel\'s Database.'); + header('LOCATION: index.php?step=8&message=User already exists in CtrlPanel\'s Database.'); } else { - header('LOCATION: index.php?step=7&message=Something went wrong when communicating with the Database.'); + header('LOCATION: index.php?step=8&message=Something went wrong when communicating with the Database.'); } exit(); } diff --git a/public/install/index.php b/public/install/index.php index dc3e0448..78656d38 100644 --- a/public/install/index.php +++ b/public/install/index.php @@ -5,7 +5,7 @@ exit("The installation has been completed already. Please delete the File 'install.lock' to re-run"); } -function cardStart($title, $subtitle = null) +function cardStart($title, $subtitle = null): string { return "
    @@ -14,13 +14,12 @@ function cardStart($title, $subtitle = null)

    $title

    " . (isset($subtitle) ? "

    $subtitle

    " : ""); } -?> - +?> + CtrlPanel.gg installer Script -