Implement a better management interface for Settings (#809)
This commit is contained in:
parent
75eb506dab
commit
f9df463d32
40 changed files with 1274 additions and 383 deletions
|
@ -13,7 +13,6 @@ use Pterodactyl\Observers\UserObserver;
|
|||
use Pterodactyl\Observers\ServerObserver;
|
||||
use Pterodactyl\Observers\SubuserObserver;
|
||||
use Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider;
|
||||
use DaneEveritt\LoginNotifications\NotificationServiceProvider;
|
||||
use Barryvdh\Debugbar\ServiceProvider as DebugbarServiceProvider;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
|
@ -42,10 +41,6 @@ class AppServiceProvider extends ServiceProvider
|
|||
$this->app->register(DebugbarServiceProvider::class);
|
||||
$this->app->register(IdeHelperServiceProvider::class);
|
||||
}
|
||||
|
||||
if (config('pterodactyl.auth.notifications')) {
|
||||
$this->app->register(NotificationServiceProvider::class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -26,6 +26,7 @@ use Pterodactyl\Repositories\Eloquent\SubuserRepository;
|
|||
use Pterodactyl\Repositories\Eloquent\DatabaseRepository;
|
||||
use Pterodactyl\Repositories\Eloquent\LocationRepository;
|
||||
use Pterodactyl\Repositories\Eloquent\ScheduleRepository;
|
||||
use Pterodactyl\Repositories\Eloquent\SettingsRepository;
|
||||
use Pterodactyl\Repositories\Eloquent\DaemonKeyRepository;
|
||||
use Pterodactyl\Repositories\Eloquent\AllocationRepository;
|
||||
use Pterodactyl\Repositories\Eloquent\PermissionRepository;
|
||||
|
@ -47,6 +48,7 @@ use Pterodactyl\Contracts\Repository\SubuserRepositoryInterface;
|
|||
use Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\SettingsRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\DaemonKeyRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\AllocationRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\PermissionRepositoryInterface;
|
||||
|
@ -86,10 +88,13 @@ class RepositoryServiceProvider extends ServiceProvider
|
|||
$this->app->bind(ServerRepositoryInterface::class, ServerRepository::class);
|
||||
$this->app->bind(ServerVariableRepositoryInterface::class, ServerVariableRepository::class);
|
||||
$this->app->bind(SessionRepositoryInterface::class, SessionRepository::class);
|
||||
$this->app->bind(SettingsRepositoryInterface::class, SettingsRepository::class);
|
||||
$this->app->bind(SubuserRepositoryInterface::class, SubuserRepository::class);
|
||||
$this->app->bind(TaskRepositoryInterface::class, TaskRepository::class);
|
||||
$this->app->bind(UserRepositoryInterface::class, UserRepository::class);
|
||||
|
||||
$this->app->alias(SettingsRepositoryInterface::class, 'settings');
|
||||
|
||||
// Daemon Repositories
|
||||
if ($this->app->make('config')->get('pterodactyl.daemon.use_new_daemon')) {
|
||||
$this->app->bind(ConfigurationRepositoryInterface::class, \Pterodactyl\Repositories\Wings\ConfigurationRepository::class);
|
||||
|
|
101
app/Providers/SettingsServiceProvider.php
Normal file
101
app/Providers/SettingsServiceProvider.php
Normal file
|
@ -0,0 +1,101 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Providers;
|
||||
|
||||
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.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $keys = [
|
||||
'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',
|
||||
];
|
||||
|
||||
/**
|
||||
* Keys specific to the mail driver that are only grabbed from the database
|
||||
* when using the SMTP driver.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $emailKeys = [
|
||||
'mail:host',
|
||||
'mail:port',
|
||||
'mail:from:address',
|
||||
'mail:from:name',
|
||||
'mail:encryption',
|
||||
'mail:username',
|
||||
'mail:password',
|
||||
];
|
||||
|
||||
/**
|
||||
* Keys that are encrypted and should be decrypted when set in the
|
||||
* configuration array.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $encrypted = [
|
||||
'mail:password',
|
||||
];
|
||||
|
||||
/**
|
||||
* Boot the service provider.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Config\Repository $config
|
||||
* @param \Illuminate\Contracts\Encryption\Encrypter $encrypter
|
||||
* @param \Pterodactyl\Contracts\Repository\SettingsRepositoryInterface $settings
|
||||
*/
|
||||
public function boot(ConfigRepository $config, Encrypter $encrypter, SettingsRepositoryInterface $settings)
|
||||
{
|
||||
if ($config->get('pterodactyl.load_environment_only', false)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Only set the email driver settings from the database if we
|
||||
// are configured using SMTP as the driver.
|
||||
if ($config->get('mail.driver') === 'smtp') {
|
||||
$this->keys = array_merge($this->keys, $this->emailKeys);
|
||||
}
|
||||
|
||||
$values = $settings->all()->mapWithKeys(function ($setting) {
|
||||
return [$setting->key => $setting->value];
|
||||
})->toArray();
|
||||
|
||||
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) {
|
||||
}
|
||||
}
|
||||
|
||||
$config->set(str_replace(':', '.', $key), $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public static function getEncryptedKeys(): array
|
||||
{
|
||||
return self::$encrypted;
|
||||
}
|
||||
}
|
Reference in a new issue