2017-12-15 03:05:26 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Providers;
|
|
|
|
|
2018-05-13 16:25:34 +00:00
|
|
|
use Psr\Log\LoggerInterface as Log;
|
2017-12-31 02:53:34 +00:00
|
|
|
use Illuminate\Database\QueryException;
|
2017-12-15 03:05:26 +00:00
|
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
use Illuminate\Contracts\Encryption\Encrypter;
|
|
|
|
use Illuminate\Contracts\Encryption\DecryptException;
|
|
|
|
use Illuminate\Contracts\Config\Repository as ConfigRepository;
|
|
|
|
use Pterodactyl\Contracts\Repository\SettingsRepositoryInterface;
|
|
|
|
|
|
|
|
class SettingsServiceProvider extends ServiceProvider
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* An array of configuration keys to override with database values
|
|
|
|
* if they exist.
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
protected array $keys = [
|
2017-12-15 03:05:26 +00:00
|
|
|
'app:name',
|
|
|
|
'app:locale',
|
|
|
|
'recaptcha:enabled',
|
|
|
|
'recaptcha:secret_key',
|
|
|
|
'recaptcha:website_key',
|
|
|
|
'pterodactyl:guzzle:timeout',
|
|
|
|
'pterodactyl:guzzle:connect_timeout',
|
|
|
|
'pterodactyl:console:count',
|
|
|
|
'pterodactyl:console:frequency',
|
|
|
|
'pterodactyl:auth:2fa_required',
|
2020-10-31 21:58:15 +00:00
|
|
|
'pterodactyl:client_features:allocations:enabled',
|
|
|
|
'pterodactyl:client_features:allocations:range_start',
|
|
|
|
'pterodactyl:client_features:allocations:range_end',
|
2017-12-15 03:05:26 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Keys specific to the mail driver that are only grabbed from the database
|
|
|
|
* when using the SMTP driver.
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
protected array $emailKeys = [
|
2022-12-12 21:21:47 +00:00
|
|
|
'mail:mailers:smtp:host',
|
|
|
|
'mail:mailers:smtp:port',
|
|
|
|
'mail:mailers:smtp:encryption',
|
|
|
|
'mail:mailers:smtp:username',
|
|
|
|
'mail:mailers:smtp:password',
|
2017-12-15 03:05:26 +00:00
|
|
|
'mail:from:address',
|
|
|
|
'mail:from:name',
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Keys that are encrypted and should be decrypted when set in the
|
|
|
|
* configuration array.
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
protected static array $encrypted = [
|
2022-12-12 21:31:49 +00:00
|
|
|
'mail:mailers:smtp:password',
|
2017-12-15 03:05:26 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Boot the service provider.
|
|
|
|
*/
|
2023-02-23 19:30:16 +00:00
|
|
|
public function boot(ConfigRepository $config, Encrypter $encrypter, Log $log, SettingsRepositoryInterface $settings): void
|
2017-12-15 03:05:26 +00:00
|
|
|
{
|
|
|
|
// Only set the email driver settings from the database if we
|
|
|
|
// are configured using SMTP as the driver.
|
2022-10-24 00:51:20 +00:00
|
|
|
if ($config->get('mail.default') === 'smtp') {
|
2017-12-15 03:05:26 +00:00
|
|
|
$this->keys = array_merge($this->keys, $this->emailKeys);
|
|
|
|
}
|
|
|
|
|
2017-12-31 02:53:34 +00:00
|
|
|
try {
|
|
|
|
$values = $settings->all()->mapWithKeys(function ($setting) {
|
|
|
|
return [$setting->key => $setting->value];
|
|
|
|
})->toArray();
|
|
|
|
} catch (QueryException $exception) {
|
2018-09-16 17:20:57 +00:00
|
|
|
$log->notice('A query exception was encountered while trying to load settings from the database: ' . $exception->getMessage());
|
2017-12-31 02:53:34 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2017-12-15 03:05:26 +00:00
|
|
|
|
|
|
|
foreach ($this->keys as $key) {
|
|
|
|
$value = array_get($values, 'settings::' . $key, $config->get(str_replace(':', '.', $key)));
|
|
|
|
if (in_array($key, self::$encrypted)) {
|
|
|
|
try {
|
|
|
|
$value = $encrypter->decrypt($value);
|
|
|
|
} catch (DecryptException $exception) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-17 19:07:38 +00:00
|
|
|
switch (strtolower($value)) {
|
|
|
|
case 'true':
|
|
|
|
case '(true)':
|
|
|
|
$value = true;
|
|
|
|
break;
|
|
|
|
case 'false':
|
|
|
|
case '(false)':
|
|
|
|
$value = false;
|
|
|
|
break;
|
|
|
|
case 'empty':
|
|
|
|
case '(empty)':
|
|
|
|
$value = '';
|
|
|
|
break;
|
|
|
|
case 'null':
|
|
|
|
case '(null)':
|
|
|
|
$value = null;
|
|
|
|
}
|
|
|
|
|
2017-12-15 03:05:26 +00:00
|
|
|
$config->set(str_replace(':', '.', $key), $value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getEncryptedKeys(): array
|
|
|
|
{
|
|
|
|
return self::$encrypted;
|
|
|
|
}
|
|
|
|
}
|