(refactor) revert the revert, things work now.
This commit is contained in:
parent
761d044957
commit
ffba7ebf1b
|
@ -35,7 +35,7 @@ if (isset($_POST['checkDB'])) {
|
||||||
// if ($key == "DB_PASSWORD") {
|
// if ($key == "DB_PASSWORD") {
|
||||||
// $param = '"' . $_POST[$value] . '"';
|
// $param = '"' . $_POST[$value] . '"';
|
||||||
// }
|
// }
|
||||||
setEnvironmentValue($key, $param);
|
setenv($key, $param);
|
||||||
}
|
}
|
||||||
|
|
||||||
wh_log('Database connection successful', 'debug');
|
wh_log('Database connection successful', 'debug');
|
||||||
|
@ -51,8 +51,8 @@ if (isset($_POST['checkGeneral'])) {
|
||||||
$appurl = substr_replace($appurl, '', -1);
|
$appurl = substr_replace($appurl, '', -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
setEnvironmentValue('APP_NAME', $appname);
|
setenv('APP_NAME', $appname);
|
||||||
setEnvironmentValue('APP_URL', $appurl);
|
setenv('APP_URL', $appurl);
|
||||||
|
|
||||||
wh_log('App settings set', 'debug');
|
wh_log('App settings set', 'debug');
|
||||||
header('LOCATION: index.php?step=4');
|
header('LOCATION: index.php?step=4');
|
||||||
|
@ -62,9 +62,9 @@ if (isset($_POST['feedDB'])) {
|
||||||
wh_log('Feeding the Database', 'debug');
|
wh_log('Feeding the Database', 'debug');
|
||||||
$logs = '';
|
$logs = '';
|
||||||
|
|
||||||
//$logs .= run_console(setEnvironmentValue('COMPOSER_HOME', dirname(__FILE__, 3) . '/vendor/bin/composer'));
|
//$logs .= run_console(setenv('COMPOSER_HOME', dirname(__FILE__, 3) . '/vendor/bin/composer'));
|
||||||
//$logs .= run_console('composer install --no-dev --optimize-autoloader');
|
//$logs .= run_console('composer install --no-dev --optimize-autoloader');
|
||||||
if (!str_contains(getEnvironmentValue('APP_KEY'), 'base64')) {
|
if (!str_contains(getenv('APP_KEY'), 'base64')) {
|
||||||
$logs .= run_console('php artisan key:generate --force');
|
$logs .= run_console('php artisan key:generate --force');
|
||||||
} else {
|
} else {
|
||||||
$logs .= "Key already exists. Skipping\n";
|
$logs .= "Key already exists. Skipping\n";
|
||||||
|
@ -75,7 +75,7 @@ if (isset($_POST['feedDB'])) {
|
||||||
|
|
||||||
wh_log($logs, 'debug');
|
wh_log($logs, 'debug');
|
||||||
|
|
||||||
if (str_contains(getEnvironmentValue('APP_KEY'), 'base64')) {
|
if (str_contains(getenv('APP_KEY'), 'base64')) {
|
||||||
wh_log('Feeding the Database successful', 'debug');
|
wh_log('Feeding the Database successful', 'debug');
|
||||||
header('LOCATION: index.php?step=3');
|
header('LOCATION: index.php?step=3');
|
||||||
} else {
|
} else {
|
||||||
|
@ -116,7 +116,7 @@ if (isset($_POST['checkSMTP'])) {
|
||||||
|
|
||||||
wh_log('SMTP Settings are correct', 'debug');
|
wh_log('SMTP Settings are correct', 'debug');
|
||||||
wh_log('Updating Database', 'debug');
|
wh_log('Updating Database', 'debug');
|
||||||
$db = new mysqli(getEnvironmentValue('DB_HOST'), getEnvironmentValue('DB_USERNAME'), getEnvironmentValue('DB_PASSWORD'), getEnvironmentValue('DB_DATABASE'), getEnvironmentValue('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');
|
||||||
header('LOCATION: index.php?step=4&message=Could not connect to the Database: ');
|
header('LOCATION: index.php?step=4&message=Could not connect to the Database: ');
|
||||||
|
@ -133,7 +133,7 @@ if (isset($_POST['checkSMTP'])) {
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ($values as $key => $value) {
|
foreach ($values as $key => $value) {
|
||||||
$query = 'UPDATE `' . getEnvironmentValue('DB_DATABASE') . "`.`settings` SET `payload` = '$value' WHERE `name` = '$key' AND `group` = mail";
|
$query = 'UPDATE `' . getenv('DB_DATABASE') . "`.`settings` SET `payload` = '$value' WHERE `name` = '$key' AND `group` = mail";
|
||||||
$db->query($query);
|
$db->query($query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,11 +195,11 @@ if (isset($_POST['checkPtero'])) {
|
||||||
$key = encryptSettingsValue($key);
|
$key = encryptSettingsValue($key);
|
||||||
$clientkey = encryptSettingsValue($clientkey);
|
$clientkey = encryptSettingsValue($clientkey);
|
||||||
|
|
||||||
$query1 = 'UPDATE `' . getEnvironmentValue('DB_DATABASE') . "`.`settings` SET `payload` = '" . json_encode($url) . "' WHERE (`name` = 'panel_url' AND `group` = 'pterodactyl')";
|
$query1 = 'UPDATE `' . getenv('DB_DATABASE') . "`.`settings` SET `payload` = '" . json_encode($url) . "' WHERE (`name` = 'panel_url' AND `group` = 'pterodactyl')";
|
||||||
$query2 = 'UPDATE `' . getEnvironmentValue('DB_DATABASE') . "`.`settings` SET `payload` = '" . json_encode($key) . "' WHERE (`name` = 'admin_token' AND `group` = 'pterodactyl')";
|
$query2 = 'UPDATE `' . getenv('DB_DATABASE') . "`.`settings` SET `payload` = '" . json_encode($key) . "' WHERE (`name` = 'admin_token' AND `group` = 'pterodactyl')";
|
||||||
$query3 = 'UPDATE `' . getEnvironmentValue('DB_DATABASE') . "`.`settings` SET `payload` = '" . json_encode($clientkey) . "' WHERE (`name` = 'user_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(getEnvironmentValue('DB_HOST'), getEnvironmentValue('DB_USERNAME'), getEnvironmentValue('DB_PASSWORD'), getEnvironmentValue('DB_DATABASE'), getEnvironmentValue('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');
|
||||||
header('LOCATION: index.php?step=5&message=Could not connect to the Database');
|
header('LOCATION: index.php?step=5&message=Could not connect to the Database');
|
||||||
|
@ -218,7 +218,7 @@ if (isset($_POST['checkPtero'])) {
|
||||||
|
|
||||||
if (isset($_POST['createUser'])) {
|
if (isset($_POST['createUser'])) {
|
||||||
wh_log('Creating User', 'debug');
|
wh_log('Creating User', 'debug');
|
||||||
$db = new mysqli(getEnvironmentValue('DB_HOST'), getEnvironmentValue('DB_USERNAME'), getEnvironmentValue('DB_PASSWORD'), getEnvironmentValue('DB_DATABASE'), getEnvironmentValue('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');
|
||||||
header('LOCATION: index.php?step=6&message=Could not connect to the Database');
|
header('LOCATION: index.php?step=6&message=Could not connect to the Database');
|
||||||
|
@ -229,9 +229,9 @@ if (isset($_POST['createUser'])) {
|
||||||
$pass = $_POST['pass'];
|
$pass = $_POST['pass'];
|
||||||
$repass = $_POST['repass'];
|
$repass = $_POST['repass'];
|
||||||
|
|
||||||
$key = $db->query('SELECT `payload` FROM `' . getEnvironmentValue('DB_DATABASE') . "`.`settings` WHERE `name` = 'admin_token' AND `group` = 'pterodactyl'")->fetch_assoc();
|
$key = $db->query('SELECT `payload` FROM `' . getenv('DB_DATABASE') . "`.`settings` WHERE `name` = 'admin_token' AND `group` = 'pterodactyl'")->fetch_assoc();
|
||||||
$key = encryptSettingsValue($key['value']);
|
$key = encryptSettingsValue($key['value']);
|
||||||
$pterobaseurl = $db->query('SELECT `payload` FROM `' . getEnvironmentValue('DB_DATABASE') . "`.`settings` WHERE `name` = 'panel_url' AND `group` = 'pterodactyl'")->fetch_assoc();
|
$pterobaseurl = $db->query('SELECT `payload` FROM `' . getenv('DB_DATABASE') . "`.`settings` WHERE `name` = 'panel_url' AND `group` = 'pterodactyl'")->fetch_assoc();
|
||||||
|
|
||||||
$pteroURL = $pterobaseurl['value'] . '/api/application/users/' . $pteroID;
|
$pteroURL = $pterobaseurl['value'] . '/api/application/users/' . $pteroID;
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
|
@ -287,7 +287,7 @@ if (isset($_POST['createUser'])) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$random = generateRandomString();
|
$random = generateRandomString();
|
||||||
$query1 = 'INSERT INTO `' . getEnvironmentValue('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')";
|
$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')";
|
||||||
|
|
||||||
if ($db->query($query1)) {
|
if ($db->query($query1)) {
|
||||||
wh_log('Created user with Email ' . $mail . ' and pterodactyl ID ' . $pteroID, 'info');
|
wh_log('Created user with Email ' . $mail . ' and pterodactyl ID ' . $pteroID, 'info');
|
||||||
|
|
|
@ -1,12 +1,16 @@
|
||||||
<?php
|
<?php
|
||||||
require '../../vendor/autoload.php';
|
require '../../vendor/autoload.php';
|
||||||
|
require 'dotenv.php';
|
||||||
|
|
||||||
|
use DevCoder\DotEnv;
|
||||||
use Illuminate\Encryption\Encrypter;
|
use Illuminate\Encryption\Encrypter;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Monolog\Formatter\LineFormatter;
|
use Monolog\Formatter\LineFormatter;
|
||||||
use Monolog\Handler\StreamHandler;
|
use Monolog\Handler\StreamHandler;
|
||||||
use Monolog\Logger;
|
use Monolog\Logger;
|
||||||
|
|
||||||
|
(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'];
|
||||||
|
|
||||||
$requirements = [
|
$requirements = [
|
||||||
|
@ -148,7 +152,7 @@ function checkExtensions(): array
|
||||||
* @param string $envValue The environment variable to set
|
* @param string $envValue The environment variable to set
|
||||||
* @return bool true on success or false on failure.
|
* @return bool true on success or false on failure.
|
||||||
*/
|
*/
|
||||||
function setEnvironmentValue($envKey, $envValue)
|
function setenv($envKey, $envValue)
|
||||||
{
|
{
|
||||||
$envFile = dirname(__FILE__, 3).'/.env';
|
$envFile = dirname(__FILE__, 3).'/.env';
|
||||||
$str = file_get_contents($envFile);
|
$str = file_get_contents($envFile);
|
||||||
|
@ -165,26 +169,6 @@ function setEnvironmentValue($envKey, $envValue)
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the variable from the env file
|
|
||||||
* @param string $envKey The environment variable to look for
|
|
||||||
* @return array|false|string Returns the value if found, otherwise returns false.
|
|
||||||
*/
|
|
||||||
function getEnvironmentValue($envKey)
|
|
||||||
{
|
|
||||||
$envFile = dirname(__FILE__, 3).'/.env';
|
|
||||||
$str = file_get_contents($envFile);
|
|
||||||
|
|
||||||
$str .= "\n"; // In case the searched variable is in the last line without \n
|
|
||||||
$keyPosition = strpos($str, "{$envKey}=");
|
|
||||||
$endOfLinePosition = strpos($str, PHP_EOL, $keyPosition);
|
|
||||||
$oldLine = substr($str, $keyPosition, $endOfLinePosition - $keyPosition);
|
|
||||||
$value = substr($oldLine, strpos($oldLine, '=') + 1);
|
|
||||||
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encrypt the given value
|
* Encrypt the given value
|
||||||
* @param mixed $value The variable to be encrypted
|
* @param mixed $value The variable to be encrypted
|
||||||
|
@ -193,7 +177,7 @@ function getEnvironmentValue($envKey)
|
||||||
*/
|
*/
|
||||||
function encryptSettingsValue(mixed $value, $serialize = true): string
|
function encryptSettingsValue(mixed $value, $serialize = true): string
|
||||||
{
|
{
|
||||||
$appKey = getEnvironmentValue('APP_KEY');
|
$appKey = getenv('APP_KEY');
|
||||||
$appKey = base64_decode(Str::after($appKey, 'base64:'));
|
$appKey = base64_decode(Str::after($appKey, 'base64:'));
|
||||||
$encrypter = new Encrypter($appKey);
|
$encrypter = new Encrypter($appKey);
|
||||||
$encryptedKey = $encrypter->encrypt($value, $serialize);
|
$encryptedKey = $encrypter->encrypt($value, $serialize);
|
||||||
|
@ -210,7 +194,7 @@ function encryptSettingsValue(mixed $value, $serialize = true): string
|
||||||
|
|
||||||
function decryptSettingsValue(mixed $payload, $unserialize = true)
|
function decryptSettingsValue(mixed $payload, $unserialize = true)
|
||||||
{
|
{
|
||||||
$appKey = getEnvironmentValue('APP_KEY');
|
$appKey = getenv('APP_KEY');
|
||||||
$appKey = base64_decode(Str::after($appKey, 'base64:'));
|
$appKey = base64_decode(Str::after($appKey, 'base64:'));
|
||||||
$encrypter = new Encrypter($appKey);
|
$encrypter = new Encrypter($appKey);
|
||||||
$decryptedKey = $encrypter->decrypt($payload, $unserialize);
|
$decryptedKey = $encrypter->decrypt($payload, $unserialize);
|
||||||
|
@ -267,7 +251,7 @@ function wh_log(string $message, string $level = 'info', array $context = []): v
|
||||||
|
|
||||||
switch (strtolower($level)) {
|
switch (strtolower($level)) {
|
||||||
case 'debug': // Only log debug messages if APP_DEBUG is true
|
case 'debug': // Only log debug messages if APP_DEBUG is true
|
||||||
if(getEnvironmentValue('APP_DEBUG') === false) return;
|
if(getenv('APP_DEBUG') === false) return;
|
||||||
$log->debug($message, $context);
|
$log->debug($message, $context);
|
||||||
break;
|
break;
|
||||||
case 'info':
|
case 'info':
|
||||||
|
|
|
@ -440,7 +440,7 @@ if (isset($_GET['step']) && $_GET['step'] == 7) {
|
||||||
echo $cardheader; ?>
|
echo $cardheader; ?>
|
||||||
<p class="login-box-msg">All done!</p>
|
<p class="login-box-msg">All done!</p>
|
||||||
<p class="login-box-msg">You may navigate to your Dashboard now and log in!</p>
|
<p class="login-box-msg">You may navigate to your Dashboard now and log in!</p>
|
||||||
<a href="<?php echo getEnvironmentValue('APP_URL'); ?>">
|
<a href="<?php echo getenv('APP_URL'); ?>">
|
||||||
<button class="btn btn-success">Lets go!</button>
|
<button class="btn btn-success">Lets go!</button>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue