Merge pull request #1 from zvikasdongre/fix/panel-installer

Fix installer setting pterodactyl settings without encryption, causing 500 Error in settings page.
This commit is contained in:
S0ly 2024-05-20 15:08:51 +02:00 committed by GitHub
commit b747b7df11
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 175 additions and 66 deletions

View file

@ -0,0 +1,49 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class GetSettingCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'settings:get {class : Settings Class (Example: GeneralSettings)} {key} {--sameline : Outputs the result without newline, useful for implementing in scripts.}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Gets value of a setting key and decrypts it if needed.';
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$class = $this->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;
}
}

View file

@ -0,0 +1,52 @@
<?php
namespace App\Console\Commands;
use Exception;
use Illuminate\Console\Command;
class SetSettingCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'settings:set {class : Settings Class (Example: GeneralSettings)} {key : Unique setting key} {value : Value to set}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Set value of a setting key.';
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$class = $this->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;
}
}

View file

@ -97,27 +97,30 @@ if (isset($_POST['checkSMTP'])) {
$mail = new PHPMailer(true); $mail = new PHPMailer(true);
//Server settings //Server settings
$mail->isSMTP(); // Send using SMTP // Send using SMTP
$mail->Host = $_POST['host']; // Set the SMTP server to send through $mail->isSMTP();
$mail->SMTPAuth = true; // Enable SMTP authentication $mail->Host = $_POST['host'];
$mail->Username = $_POST['user']; // SMTP username // Enable SMTP authentication
$mail->Password = $_POST['pass']; // SMTP password $mail->SMTPAuth = true;
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged $mail->Username = $_POST['user'];
$mail->Port = $_POST['port']; // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` $mail->Password = $_POST['pass'];
$mail->SMTPSecure = $_POST['encryption'];
$mail->Port = (int) $_POST['port'];
//Recipients // Test E-mail metadata
$mail->setFrom($_POST['user'], $_POST['user']); $mail->setFrom($_POST['user'], $_POST['user']);
$mail->addAddress($_POST['user'], $_POST['user']); // Add a recipient $mail->addAddress($_POST['user'], $_POST['user']);
// Content // Content
$mail->isHTML(true); // Set email format to HTML // Set email format to HTML
$mail->Subject = 'It Worked!'; $mail->isHTML(true);
$mail->Subject = 'It Worked! - Test E-Mail from Ctrlpanel.gg';
$mail->Body = 'Your E-Mail Settings are correct!'; $mail->Body = 'Your E-Mail Settings are correct!';
$mail->send(); $mail->send();
} catch (Exception $e) { } catch (Exception $e) {
wh_log($mail->ErrorInfo, 'error'); 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!<br>' . $mail->ErrorInfo);
exit(); exit();
} }
@ -140,8 +143,7 @@ if (isset($_POST['checkSMTP'])) {
]; ];
foreach ($values as $key => $value) { foreach ($values as $key => $value) {
$query = 'UPDATE `' . getenv('DB_DATABASE') . "`.`settings` SET `payload` = '$value' WHERE `name` = '$key' AND `group` = 'mail'"; run_console("php artisan settings:set 'MailSettings' '$key' '$value'");
$db->query($query);
} }
wh_log('Database updated', 'debug'); wh_log('Database updated', 'debug');
@ -197,34 +199,22 @@ if (isset($_POST['checkPtero'])) {
exit(); exit();
} else { } else {
wh_log('Pterodactyl Settings are correct', 'debug'); wh_log('Pterodactyl Settings are correct', 'debug');
wh_log('Updating Database', 'debug');
$key = $key; try {
$clientkey = $clientkey; run_console("php artisan settings:set 'PterodactylSettings' 'panel_url' '$url'");
run_console("php artisan settings:set 'PterodactylSettings' 'admin_token' '$key'");
$query1 = 'UPDATE `' . getenv('DB_DATABASE') . "`.`settings` SET `payload` = '" . json_encode($url) . "' WHERE (`name` = 'panel_url' AND `group` = 'pterodactyl')"; run_console("php artisan settings:set 'PterodactylSettings' 'user_token' '$clientkey'");
$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)) {
wh_log('Database updated', 'debug'); wh_log('Database updated', 'debug');
header('LOCATION: index.php?step=6'); header('LOCATION: index.php?step=6');
} else { } catch (\Throwable $th) {
wh_log($db->error, 'error'); wh_log("Setting Pterodactyl information failed.", 'error');
header('LOCATION: index.php?step=5&message=Something went wrong when communicating with the Database!'); header("LOCATION: index.php?step=5&message=" . $th->getMessage() . " <br>Please check the installer.log file in /var/www/controlpanel/storage/logs!");
} }
} }
} }
if (isset($_POST['createUser'])) { 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')); $db = new mysqli(getenv('DB_HOST'), getenv('DB_USERNAME'), getenv('DB_PASSWORD'), getenv('DB_DATABASE'), getenv('DB_PORT'));
if ($db->connect_error) { if ($db->connect_error) {
wh_log($db->connect_error, 'error'); wh_log($db->connect_error, 'error');
@ -236,19 +226,26 @@ if (isset($_POST['createUser'])) {
$pass = $_POST['pass']; $pass = $_POST['pass'];
$repass = $_POST['repass']; $repass = $_POST['repass'];
$key = $db->query('SELECT `payload` FROM `' . getenv('DB_DATABASE') . "`.`settings` WHERE `name` = 'admin_token' AND `group` = 'pterodactyl'")->fetch_assoc(); try {
$key = removeQuotes($key['payload']); $panel_url = run_console("php artisan settings:get 'PterodactylSettings' 'panel_url' --sameline");
$pterobaseurl = $db->query('SELECT `payload` FROM `' . getenv('DB_DATABASE') . "`.`settings` WHERE `name` = 'panel_url' AND `group` = 'pterodactyl'")->fetch_assoc(); $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() . " <br>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(); $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_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [ curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Accept: application/json', 'Accept: application/json',
'Content-Type: application/json', 'Content-Type: application/json',
'Authorization: Bearer ' . $key, 'Authorization: Bearer ' . $admin_token,
]); ]);
$response = curl_exec($ch); $response = curl_exec($ch);
$result = json_decode($response, true); $result = json_decode($response, true);
@ -267,15 +264,14 @@ if (isset($_POST['createUser'])) {
$name = $result['attributes']['username']; $name = $result['attributes']['username'];
$pass = password_hash($pass, PASSWORD_DEFAULT); $pass = password_hash($pass, PASSWORD_DEFAULT);
$pteroURL = removeQuotes($pterobaseurl['payload']) . '/api/application/users/' . $pteroID;
$ch = curl_init(); $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_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [ curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Accept: application/json', 'Accept: application/json',
'Content-Type: application/json', 'Content-Type: application/json',
'Authorization: Bearer ' . $key, 'Authorization: Bearer ' . $admin_token,
]); ]);
curl_setopt($ch, CURLOPT_POSTFIELDS, [ curl_setopt($ch, CURLOPT_POSTFIELDS, [
'email' => $mail, 'email' => $mail,

View file

@ -76,29 +76,36 @@ function cardStart($title, $subtitle = null)
<li class="<?php echo checkWriteable() == true ? 'ok' : 'not-ok'; ?> check">Write-permissions on .env-file</li> <li class="<?php echo checkWriteable() == true ? 'ok' : 'not-ok'; ?> check">Write-permissions on .env-file</li>
<li class="<?php echo checkPhpVersion() === 'OK' ? 'ok' : 'not-ok'; ?> check"> php <li class="<?php echo checkPhpVersion() === 'OK' ? 'ok' : 'not-ok'; ?> check">
version: <?php echo phpversion(); ?> (minimum required <?php echo $requirements['minPhp']; ?>)</li> php version: <?php echo phpversion(); ?> (minimum required <?php echo $requirements['minPhp']; ?>)
</li>
<li class="<?php echo getMySQLVersion() === 'OK' ? 'ok' : 'not-ok'; ?> check"> mysql <li class="<?php echo getMySQLVersion() === 'OK' ? 'ok' : 'not-ok'; ?> check">
version: <?php echo getMySQLVersion(); ?> (minimum required <?php echo $requirements['mysql']; ?>)</li> mysql version: <?php echo getMySQLVersion(); ?> (minimum required <?php echo $requirements['mysql']; ?>)
</li>
<li class="<?php echo count(checkExtensions()) == 0 ? 'ok' : 'not-ok'; ?> check"> Missing <li class="<?php echo count(checkExtensions()) == 0 ? 'ok' : 'not-ok'; ?> check">
php-extentions: <?php echo count(checkExtensions()) == 0 ? 'none' : ''; Missing php-extentions:
foreach (checkExtensions() as $ext) { <?php echo count(checkExtensions()) == 0 ? 'none' : '';
echo $ext . ', '; foreach (checkExtensions() as $ext) {
} echo $ext . ', ';
}
echo count(checkExtensions()) == 0 ? '' : '(Proceed anyway)'; ?></li> echo count(checkExtensions()) == 0 ? '' : '(Proceed anyway)'; ?>
</li>
<!-- <li class="<?php echo getZipVersion() === 'OK' ? 'ok' : 'not-ok'; ?> check"> Zip <!-- <li class="<?php echo getZipVersion() === 'OK' ? 'ok' : 'not-ok'; ?> check"> Zip
version: <?php echo getZipVersion(); ?> </li> --> version: <?php echo getZipVersion(); ?> </li> -->
<li class="<?php echo getGitVersion() === 'OK' ? 'ok' : 'not-ok'; ?> check"> Git <li class="<?php echo getGitVersion() === 'OK' ? 'ok' : 'not-ok'; ?> check">
version: <?php echo getGitVersion(); ?> </li> Git version:
<?php echo getGitVersion(); ?>
</li>
<li class="<?php echo getTarVersion() === 'OK' ? 'ok' : 'not-ok'; ?> check"> Tar <li class="<?php echo getTarVersion() === 'OK' ? 'ok' : 'not-ok'; ?> check">
version: <?php echo getTarVersion(); ?> </li> Tar version:
<?php echo getTarVersion(); ?>
</li>
</ul> </ul>
</div> </div>
@ -143,7 +150,7 @@ function cardStart($title, $subtitle = null)
<div class="form-group"> <div class="form-group">
<div class="flex flex-col mb-3"> <div class="flex flex-col mb-3">
<label for="databaseuser">Database User</label> <label for="databaseuser">Database User</label>
<input x-model="databaseuser" id="databaseuser" name="databaseuser" type="text" required value="controlpaneluser" class="px-2 py-1 bg-[#1D2125] border-2 focus:border-sky-500 box-border rounded-md border-transparent outline-none"> <input x-model="databaseuser" id="databaseuser" name="databaseuser" type="text" required value="ctrlpaneluser" class="px-2 py-1 bg-[#1D2125] border-2 focus:border-sky-500 box-border rounded-md border-transparent outline-none">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
@ -156,7 +163,7 @@ function cardStart($title, $subtitle = null)
<div class="form-group"> <div class="form-group">
<div class="flex flex-col"> <div class="flex flex-col">
<label for="database">Database</label> <label for="database">Database</label>
<input x-model="database" id="database" name="database" type="text" required value="controlpanel" class="px-2 py-1 bg-[#1D2125] border-2 focus:border-sky-500 box-border rounded-md border-transparent outline-none"> <input x-model="database" id="database" name="database" type="text" required value="ctrlpanel" class="px-2 py-1 bg-[#1D2125] border-2 focus:border-sky-500 box-border rounded-md border-transparent outline-none">
</div> </div>
</div> </div>
@ -213,8 +220,8 @@ function cardStart($title, $subtitle = null)
</div> </div>
<div class="form-group"> <div class="form-group">
<div class="flex flex-col"> <div class="flex flex-col">
<label for="name">Host Name</label> <label for="name">Dashboard Name</label>
<input id="name" name="name" type="text" required value="" class="px-2 py-1 bg-[#1D2125] border-2 focus:border-sky-500 box-border rounded-md border-transparent outline-none"> <input id="name" name="name" type="text" required value="CtrlPanel" class="px-2 py-1 bg-[#1D2125] border-2 focus:border-sky-500 box-border rounded-md border-transparent outline-none">
</div> </div>
</div> </div>
@ -248,8 +255,9 @@ function cardStart($title, $subtitle = null)
<div class="form-group"> <div class="form-group">
<div class="flex flex-col mb-3"> <div class="flex flex-col mb-3">
<label for="method">Your E-Mail Method</label> <label for="method">Your E-Mail Method</label>
<input id="method" name="method" type="text" required value="smtp" class="px-2 py-1 bg-[#1D2125] border-2 focus:border-sky-500 box-border rounded-md border-transparent outline-none"> <select id="method" name="method" required class="px-2 py-2 bg-[#1D2125] border-2 focus:border-sky-500 box-border rounded-md border-transparent outline-none">
<option value="smtp" selected>SMTP</option>
</select>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
@ -284,7 +292,11 @@ function cardStart($title, $subtitle = null)
<div class="form-group"> <div class="form-group">
<div class="flex flex-col"> <div class="flex flex-col">
<label for="encryption">Your Mail encryption method</label> <label for="encryption">Your Mail encryption method</label>
<input id="encryption" name="encryption" type="text" required value="tls" class="px-2 py-1 bg-[#1D2125] border-2 focus:border-sky-500 box-border rounded-md border-transparent outline-none"> <select id="encryption" name="encryption" required class="px-2 py-2 bg-[#1D2125] border-2 focus:border-sky-500 box-border rounded-md border-transparent outline-none">
<option value="tls" selected>TLS</option>
<option value="ssl">SSL</option>
<option value="null">None</option>
</select>
</div> </div>
</div> </div>
@ -431,4 +443,4 @@ function cardStart($title, $subtitle = null)
?> ?>
</body> </body>
</html> </html>