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:
commit
b747b7df11
4 changed files with 175 additions and 66 deletions
49
app/Console/Commands/GetSettingCommand.php
Normal file
49
app/Console/Commands/GetSettingCommand.php
Normal 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;
|
||||
}
|
||||
}
|
52
app/Console/Commands/SetSettingCommand.php
Normal file
52
app/Console/Commands/SetSettingCommand.php
Normal 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;
|
||||
}
|
||||
}
|
|
@ -97,27 +97,30 @@ if (isset($_POST['checkSMTP'])) {
|
|||
$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`
|
||||
// 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'];
|
||||
|
||||
//Recipients
|
||||
// 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!<br>' . $mail->ErrorInfo);
|
||||
exit();
|
||||
}
|
||||
|
||||
|
@ -140,8 +143,7 @@ if (isset($_POST['checkSMTP'])) {
|
|||
];
|
||||
|
||||
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 @@ if (isset($_POST['checkPtero'])) {
|
|||
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() . " <br>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 @@ if (isset($_POST['createUser'])) {
|
|||
$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() . " <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();
|
||||
|
||||
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 @@ if (isset($_POST['createUser'])) {
|
|||
$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,
|
||||
|
|
|
@ -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 checkPhpVersion() === 'OK' ? 'ok' : 'not-ok'; ?> check"> php
|
||||
version: <?php echo phpversion(); ?> (minimum required <?php echo $requirements['minPhp']; ?>)</li>
|
||||
<li class="<?php echo checkPhpVersion() === 'OK' ? 'ok' : 'not-ok'; ?> check">
|
||||
php version: <?php echo phpversion(); ?> (minimum required <?php echo $requirements['minPhp']; ?>)
|
||||
</li>
|
||||
|
||||
<li class="<?php echo getMySQLVersion() === 'OK' ? 'ok' : 'not-ok'; ?> check"> mysql
|
||||
version: <?php echo getMySQLVersion(); ?> (minimum required <?php echo $requirements['mysql']; ?>)</li>
|
||||
<li class="<?php echo getMySQLVersion() === 'OK' ? 'ok' : 'not-ok'; ?> check">
|
||||
mysql version: <?php echo getMySQLVersion(); ?> (minimum required <?php echo $requirements['mysql']; ?>)
|
||||
</li>
|
||||
|
||||
<li class="<?php echo count(checkExtensions()) == 0 ? 'ok' : 'not-ok'; ?> check"> Missing
|
||||
php-extentions: <?php echo count(checkExtensions()) == 0 ? 'none' : '';
|
||||
foreach (checkExtensions() as $ext) {
|
||||
echo $ext . ', ';
|
||||
}
|
||||
|
||||
echo count(checkExtensions()) == 0 ? '' : '(Proceed anyway)'; ?></li>
|
||||
<li class="<?php echo count(checkExtensions()) == 0 ? 'ok' : 'not-ok'; ?> check">
|
||||
Missing php-extentions:
|
||||
<?php echo count(checkExtensions()) == 0 ? 'none' : '';
|
||||
foreach (checkExtensions() as $ext) {
|
||||
echo $ext . ', ';
|
||||
}
|
||||
echo count(checkExtensions()) == 0 ? '' : '(Proceed anyway)'; ?>
|
||||
</li>
|
||||
|
||||
|
||||
<!-- <li class="<?php echo getZipVersion() === 'OK' ? 'ok' : 'not-ok'; ?> check"> Zip
|
||||
version: <?php echo getZipVersion(); ?> </li> -->
|
||||
|
||||
<li class="<?php echo getGitVersion() === 'OK' ? 'ok' : 'not-ok'; ?> check"> Git
|
||||
version: <?php echo getGitVersion(); ?> </li>
|
||||
<li class="<?php echo getGitVersion() === 'OK' ? 'ok' : 'not-ok'; ?> check">
|
||||
Git version:
|
||||
<?php echo getGitVersion(); ?>
|
||||
</li>
|
||||
|
||||
<li class="<?php echo getTarVersion() === 'OK' ? 'ok' : 'not-ok'; ?> check"> Tar
|
||||
version: <?php echo getTarVersion(); ?> </li>
|
||||
<li class="<?php echo getTarVersion() === 'OK' ? 'ok' : 'not-ok'; ?> check">
|
||||
Tar version:
|
||||
<?php echo getTarVersion(); ?>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
@ -143,7 +150,7 @@ function cardStart($title, $subtitle = null)
|
|||
<div class="form-group">
|
||||
<div class="flex flex-col mb-3">
|
||||
<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 class="form-group">
|
||||
|
@ -156,7 +163,7 @@ function cardStart($title, $subtitle = null)
|
|||
<div class="form-group">
|
||||
<div class="flex flex-col">
|
||||
<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>
|
||||
|
||||
|
@ -213,8 +220,8 @@ function cardStart($title, $subtitle = null)
|
|||
</div>
|
||||
<div class="form-group">
|
||||
<div class="flex flex-col">
|
||||
<label for="name">Host 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">
|
||||
<label for="name">Dashboard Name</label>
|
||||
<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>
|
||||
|
||||
|
@ -248,8 +255,9 @@ function cardStart($title, $subtitle = null)
|
|||
<div class="form-group">
|
||||
<div class="flex flex-col mb-3">
|
||||
<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 class="form-group">
|
||||
|
@ -284,7 +292,11 @@ function cardStart($title, $subtitle = null)
|
|||
<div class="form-group">
|
||||
<div class="flex flex-col">
|
||||
<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>
|
||||
|
||||
|
@ -431,4 +443,4 @@ function cardStart($title, $subtitle = null)
|
|||
?>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</html>
|
Loading…
Reference in a new issue