|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Pterodactyl\Http\Controllers\Admin\Settings; |
| 4 | + |
| 5 | +use Illuminate\View\View; |
| 6 | +use Illuminate\Http\RedirectResponse; |
| 7 | +use Prologue\Alerts\AlertsMessageBag; |
| 8 | +use Illuminate\Contracts\Console\Kernel; |
| 9 | +use Pterodactyl\Http\Controllers\Controller; |
| 10 | +use Illuminate\Contracts\Config\Repository as ConfigRepository; |
| 11 | +use Pterodactyl\Contracts\Repository\SettingsRepositoryInterface; |
| 12 | +use Pterodactyl\Http\Requests\Admin\Settings\AdvancedSettingsFormRequest; |
| 13 | + |
| 14 | +class AdvancedController extends Controller |
| 15 | +{ |
| 16 | + /** |
| 17 | + * @var \Prologue\Alerts\AlertsMessageBag |
| 18 | + */ |
| 19 | + private $alert; |
| 20 | + |
| 21 | + /** |
| 22 | + * @var \Illuminate\Contracts\Config\Repository |
| 23 | + */ |
| 24 | + private $config; |
| 25 | + |
| 26 | + /** |
| 27 | + * @var \Illuminate\Contracts\Console\Kernel |
| 28 | + */ |
| 29 | + private $kernel; |
| 30 | + |
| 31 | + /** |
| 32 | + * @var \Pterodactyl\Contracts\Repository\SettingsRepositoryInterface |
| 33 | + */ |
| 34 | + private $settings; |
| 35 | + |
| 36 | + /** |
| 37 | + * AdvancedController constructor. |
| 38 | + * |
| 39 | + * @param \Prologue\Alerts\AlertsMessageBag $alert |
| 40 | + * @param \Illuminate\Contracts\Config\Repository $config |
| 41 | + * @param \Illuminate\Contracts\Console\Kernel $kernel |
| 42 | + * @param \Pterodactyl\Contracts\Repository\SettingsRepositoryInterface $settings |
| 43 | + */ |
| 44 | + public function __construct( |
| 45 | + AlertsMessageBag $alert, |
| 46 | + ConfigRepository $config, |
| 47 | + Kernel $kernel, |
| 48 | + SettingsRepositoryInterface $settings |
| 49 | + ) { |
| 50 | + $this->alert = $alert; |
| 51 | + $this->config = $config; |
| 52 | + $this->kernel = $kernel; |
| 53 | + $this->settings = $settings; |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * Render advanced Panel settings UI. |
| 58 | + * |
| 59 | + * @return \Illuminate\View\View |
| 60 | + */ |
| 61 | + public function index(): View |
| 62 | + { |
| 63 | + $showRecaptchaWarning = false; |
| 64 | + if ( |
| 65 | + $this->config->get('recaptcha._shipped_secret_key') === $this->config->get('recaptcha.secret_key') |
| 66 | + || $this->config->get('recaptcha._shipped_website_key') === $this->config->get('recaptcha.website_key') |
| 67 | + ) { |
| 68 | + $showRecaptchaWarning = true; |
| 69 | + } |
| 70 | + |
| 71 | + return view('admin.settings.advanced', [ |
| 72 | + 'showRecaptchaWarning' => $showRecaptchaWarning, |
| 73 | + ]); |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * @param \Pterodactyl\Http\Requests\Admin\Settings\AdvancedSettingsFormRequest $request |
| 78 | + * @return \Illuminate\Http\RedirectResponse |
| 79 | + */ |
| 80 | + public function update(AdvancedSettingsFormRequest $request): RedirectResponse |
| 81 | + { |
| 82 | + foreach ($request->normalize() as $key => $value) { |
| 83 | + $this->settings->set('settings::' . $key, $value); |
| 84 | + } |
| 85 | + |
| 86 | + $this->kernel->call('queue:restart'); |
| 87 | + $this->alert->success('Advanced settings have been updated successfully and the queue worker was restarted to apply these changes.')->flash(); |
| 88 | + |
| 89 | + return redirect()->route('admin.settings.advanced'); |
| 90 | + } |
| 91 | +} |
0 commit comments