From 6b8464ea3a5eba43b5660acae53b6450771ba3e8 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 7 Oct 2017 16:16:51 -0500 Subject: [PATCH] Nest & Egg management working through the ACP now. --- .../HasChildrenException.php | 2 +- .../InvalidCopyFromException.php} | 6 +- .../NoParentConfigurationFoundException.php | 6 +- .../ReservedVariableNameException.php} | 6 +- .../API/Remote/OptionRetrievalController.php | 10 +- .../Controllers/Admin/Nests/EggController.php | 106 +++++++++- .../Admin/Nests/EggScriptController.php | 98 +++++++++ .../Admin/Nests/EggVariableController.php | 146 ++++++++++++++ .../Admin/Nests/NestController.php | 4 +- .../Controllers/Admin/OptionController.php | 48 ++--- .../Controllers/Admin/ServiceController.php | 187 ------------------ .../Controllers/Admin/VariableController.php | 133 ------------- .../Requests/Admin/Egg/EggFormRequest.php | 49 +++++ .../EggScriptFormRequest.php} | 4 +- .../EggVariableFormRequest.php} | 11 +- .../Service/ServiceOptionFormRequest.php | 24 --- app/Models/Egg.php | 6 +- .../EggConfigurationService.php} | 11 +- .../EggCreationService.php} | 25 +-- .../EggDeletionService.php} | 26 +-- .../EggUpdateService.php} | 24 +-- .../Scripts/InstallScriptService.php} | 28 +-- .../Variables/VariableCreationService.php | 45 ++--- .../Variables/VariableUpdateService.php | 22 +-- .../{services/options => eggs}/new.blade.php | 61 +++--- .../options => eggs}/scripts.blade.php | 36 ++-- .../options => eggs}/variables.blade.php | 32 +-- routes/admin.php | 2 +- .../InstallScriptUpdateServiceTest.php | 6 +- .../Options/OptionCreationServiceTest.php | 6 +- .../Options/OptionDeletionServiceTest.php | 6 +- .../Options/OptionUpdateServiceTest.php | 6 +- 32 files changed, 616 insertions(+), 566 deletions(-) rename app/Exceptions/Service/{ServiceOption => Egg}/HasChildrenException.php (84%) rename app/Exceptions/Service/{ServiceVariable/ReservedVariableNameException.php => Egg/InvalidCopyFromException.php} (59%) rename app/Exceptions/Service/{ServiceOption => Egg}/NoParentConfigurationFoundException.php (57%) rename app/Exceptions/Service/{ServiceOption/InvalidCopyFromException.php => Egg/Variable/ReservedVariableNameException.php} (57%) create mode 100644 app/Http/Controllers/Admin/Nests/EggScriptController.php create mode 100644 app/Http/Controllers/Admin/Nests/EggVariableController.php delete mode 100644 app/Http/Controllers/Admin/ServiceController.php delete mode 100644 app/Http/Controllers/Admin/VariableController.php create mode 100644 app/Http/Requests/Admin/Egg/EggFormRequest.php rename app/Http/Requests/Admin/{Service/EditOptionScript.php => Egg/EggScriptFormRequest.php} (88%) rename app/Http/Requests/Admin/{Service/OptionVariableFormRequest.php => Egg/EggVariableFormRequest.php} (80%) delete mode 100644 app/Http/Requests/Admin/Service/ServiceOptionFormRequest.php rename app/Services/{Services/Options/OptionConfigurationFileService.php => Eggs/EggConfigurationService.php} (83%) rename app/Services/{Services/Options/OptionCreationService.php => Eggs/EggCreationService.php} (67%) rename app/Services/{Services/Options/OptionDeletionService.php => Eggs/EggDeletionService.php} (66%) rename app/Services/{Services/Options/OptionUpdateService.php => Eggs/EggUpdateService.php} (64%) rename app/Services/{Services/Options/InstallScriptUpdateService.php => Eggs/Scripts/InstallScriptService.php} (66%) rename app/Services/{Services => Eggs}/Variables/VariableCreationService.php (51%) rename app/Services/{Services => Eggs}/Variables/VariableUpdateService.php (75%) rename resources/themes/pterodactyl/admin/{services/options => eggs}/new.blade.php (72%) rename resources/themes/pterodactyl/admin/{services/options => eggs}/scripts.blade.php (74%) rename resources/themes/pterodactyl/admin/{services/options => eggs}/variables.blade.php (84%) diff --git a/app/Exceptions/Service/ServiceOption/HasChildrenException.php b/app/Exceptions/Service/Egg/HasChildrenException.php similarity index 84% rename from app/Exceptions/Service/ServiceOption/HasChildrenException.php rename to app/Exceptions/Service/Egg/HasChildrenException.php index 0857bb887..7198f8306 100644 --- a/app/Exceptions/Service/ServiceOption/HasChildrenException.php +++ b/app/Exceptions/Service/Egg/HasChildrenException.php @@ -7,7 +7,7 @@ * https://opensource.org/licenses/MIT */ -namespace Pterodactyl\Exceptions\Service\ServiceOption; +namespace Pterodactyl\Exceptions\Service\Egg; use Pterodactyl\Exceptions\DisplayException; diff --git a/app/Exceptions/Service/ServiceVariable/ReservedVariableNameException.php b/app/Exceptions/Service/Egg/InvalidCopyFromException.php similarity index 59% rename from app/Exceptions/Service/ServiceVariable/ReservedVariableNameException.php rename to app/Exceptions/Service/Egg/InvalidCopyFromException.php index 2f0a335cc..149c42dd6 100644 --- a/app/Exceptions/Service/ServiceVariable/ReservedVariableNameException.php +++ b/app/Exceptions/Service/Egg/InvalidCopyFromException.php @@ -7,10 +7,10 @@ * https://opensource.org/licenses/MIT */ -namespace Pterodactyl\Exceptions\Service\ServiceVariable; +namespace Pterodactyl\Exceptions\Service\Egg; -use Exception; +use Pterodactyl\Exceptions\DisplayException; -class ReservedVariableNameException extends Exception +class InvalidCopyFromException extends DisplayException { } diff --git a/app/Exceptions/Service/ServiceOption/NoParentConfigurationFoundException.php b/app/Exceptions/Service/Egg/NoParentConfigurationFoundException.php similarity index 57% rename from app/Exceptions/Service/ServiceOption/NoParentConfigurationFoundException.php rename to app/Exceptions/Service/Egg/NoParentConfigurationFoundException.php index fe678bd3b..867b09c1a 100644 --- a/app/Exceptions/Service/ServiceOption/NoParentConfigurationFoundException.php +++ b/app/Exceptions/Service/Egg/NoParentConfigurationFoundException.php @@ -7,8 +7,10 @@ * https://opensource.org/licenses/MIT */ -namespace Pterodactyl\Exceptions\Service\ServiceOption; +namespace Pterodactyl\Exceptions\Service\Egg; -class NoParentConfigurationFoundException extends \Exception +use Pterodactyl\Exceptions\DisplayException; + +class NoParentConfigurationFoundException extends DisplayException { } diff --git a/app/Exceptions/Service/ServiceOption/InvalidCopyFromException.php b/app/Exceptions/Service/Egg/Variable/ReservedVariableNameException.php similarity index 57% rename from app/Exceptions/Service/ServiceOption/InvalidCopyFromException.php rename to app/Exceptions/Service/Egg/Variable/ReservedVariableNameException.php index 4bb527abf..03ad09e5e 100644 --- a/app/Exceptions/Service/ServiceOption/InvalidCopyFromException.php +++ b/app/Exceptions/Service/Egg/Variable/ReservedVariableNameException.php @@ -7,8 +7,10 @@ * https://opensource.org/licenses/MIT */ -namespace Pterodactyl\Exceptions\Service\ServiceOption; +namespace Pterodactyl\Exceptions\Service\Egg\Variable; -class InvalidCopyFromException extends \Exception +use Pterodactyl\Exceptions\DisplayException; + +class ReservedVariableNameException extends DisplayException { } diff --git a/app/Http/Controllers/API/Remote/OptionRetrievalController.php b/app/Http/Controllers/API/Remote/OptionRetrievalController.php index 46b4dfb3e..e1c3fe123 100644 --- a/app/Http/Controllers/API/Remote/OptionRetrievalController.php +++ b/app/Http/Controllers/API/Remote/OptionRetrievalController.php @@ -12,12 +12,12 @@ namespace Pterodactyl\Http\Controllers\API\Remote; use Illuminate\Http\JsonResponse; use Pterodactyl\Http\Controllers\Controller; use Pterodactyl\Contracts\Repository\EggRepositoryInterface; -use Pterodactyl\Services\Services\Options\OptionConfigurationFileService; +use Pterodactyl\Services\Services\Options\EggConfigurationService; class OptionRetrievalController extends Controller { /** - * @var \Pterodactyl\Services\Services\Options\OptionConfigurationFileService + * @var \Pterodactyl\Services\Services\Options\EggConfigurationService */ protected $configurationFileService; @@ -29,12 +29,12 @@ class OptionRetrievalController extends Controller /** * OptionUpdateController constructor. * - * @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $repository - * @param \Pterodactyl\Services\Services\Options\OptionConfigurationFileService $configurationFileService + * @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $repository + * @param \Pterodactyl\Services\Services\Options\EggConfigurationService $configurationFileService */ public function __construct( EggRepositoryInterface $repository, - OptionConfigurationFileService $configurationFileService + EggConfigurationService $configurationFileService ) { $this->configurationFileService = $configurationFileService; $this->repository = $repository; diff --git a/app/Http/Controllers/Admin/Nests/EggController.php b/app/Http/Controllers/Admin/Nests/EggController.php index 831305db4..56d69e3a7 100644 --- a/app/Http/Controllers/Admin/Nests/EggController.php +++ b/app/Http/Controllers/Admin/Nests/EggController.php @@ -9,24 +9,120 @@ namespace Pterodactyl\Http\Controllers\Admin\Nests; +use Javascript; use Illuminate\View\View; use Pterodactyl\Models\Egg; +use Illuminate\Http\RedirectResponse; +use Prologue\Alerts\AlertsMessageBag; use Pterodactyl\Http\Controllers\Controller; +use Pterodactyl\Services\Eggs\EggUpdateService; +use Pterodactyl\Services\Eggs\EggCreationService; +use Pterodactyl\Services\Eggs\EggDeletionService; +use Pterodactyl\Http\Requests\Admin\Egg\EggFormRequest; use Pterodactyl\Contracts\Repository\EggRepositoryInterface; +use Pterodactyl\Contracts\Repository\NestRepositoryInterface; class EggController extends Controller { + protected $alert; + protected $creationService; + protected $deletionService; + protected $nestRepository; protected $repository; + protected $updateService; - public function __construct(EggRepositoryInterface $repository) - { + public function __construct( + AlertsMessageBag $alert, + EggCreationService $creationService, + EggDeletionService $deletionService, + EggRepositoryInterface $repository, + EggUpdateService $updateService, + NestRepositoryInterface $nestRepository + ) { + $this->alert = $alert; + $this->creationService = $creationService; + $this->deletionService = $deletionService; + $this->nestRepository = $nestRepository; $this->repository = $repository; + $this->updateService = $updateService; } + /** + * Handle a request to display the Egg creation page. + * + * @return \Illuminate\View\View + * + * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException + */ + public function create(): View + { + $nests = $this->nestRepository->getWithEggs(); + Javascript::put(['nests' => $nests->keyBy('id')]); + + return view('admin.eggs.new', ['nests' => $nests]); + } + + /** + * Handle request to store a new Egg. + * + * @param \Pterodactyl\Http\Requests\Admin\Egg\EggFormRequest $request + * @return \Illuminate\Http\RedirectResponse + * + * @throws \Pterodactyl\Exceptions\Model\DataValidationException + * @throws \Pterodactyl\Exceptions\Service\Egg\NoParentConfigurationFoundException + */ + public function store(EggFormRequest $request): RedirectResponse + { + $egg = $this->creationService->handle($request->normalize()); + $this->alert->success(trans('admin/nests.eggs.notices.egg_created'))->flash(); + + return redirect()->route('admin.nests.egg.view', $egg->id); + } + + /** + * Handle request to view a single Egg. + * + * @param \Pterodactyl\Models\Egg $egg + * @return \Illuminate\View\View + */ public function view(Egg $egg): View { - return view('admin.eggs.view', [ - 'egg' => $egg, - ]); + return view('admin.eggs.view', ['egg' => $egg]); + } + + /** + * Handle request to update an Egg. + * + * @param \Pterodactyl\Http\Requests\Admin\Egg\EggFormRequest $request + * @param \Pterodactyl\Models\Egg $egg + * @return \Illuminate\Http\RedirectResponse + * + * @throws \Pterodactyl\Exceptions\Model\DataValidationException + * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException + * @throws \Pterodactyl\Exceptions\Service\Egg\NoParentConfigurationFoundException + */ + public function update(EggFormRequest $request, Egg $egg): RedirectResponse + { + $this->updateService->handle($egg, $request->normalize()); + $this->alert->success(trans('admin/nests.eggs.notices.updated'))->flash(); + + return redirect()->route('admin.nests.egg.view', $egg->id); + } + + /** + * Handle request to destroy an egg. + * + * @param \Pterodactyl\Models\Egg $egg + * @return \Illuminate\Http\RedirectResponse + * + * @throws \Pterodactyl\Exceptions\Service\Egg\HasChildrenException + * @throws \Pterodactyl\Exceptions\Service\HasActiveServersException + */ + public function destroy(Egg $egg): RedirectResponse + { + $this->deletionService->handle($egg->id); + $this->alert->success(trans('admin/nests.eggs.notices.deleted'))->flash(); + + return redirect()->route('admin.nests.view', $egg->nest_id); } } diff --git a/app/Http/Controllers/Admin/Nests/EggScriptController.php b/app/Http/Controllers/Admin/Nests/EggScriptController.php new file mode 100644 index 000000000..ac67a2a6d --- /dev/null +++ b/app/Http/Controllers/Admin/Nests/EggScriptController.php @@ -0,0 +1,98 @@ +. + * + * This software is licensed under the terms of the MIT license. + * https://opensource.org/licenses/MIT + */ + +namespace Pterodactyl\Http\Controllers\Admin\Nests; + +use Illuminate\View\View; +use Illuminate\Http\RedirectResponse; +use Prologue\Alerts\AlertsMessageBag; +use Pterodactyl\Http\Controllers\Controller; +use Pterodactyl\Services\Eggs\Scripts\InstallScriptService; +use Pterodactyl\Contracts\Repository\EggRepositoryInterface; +use Pterodactyl\Http\Requests\Admin\Egg\EggScriptFormRequest; + +class EggScriptController extends Controller +{ + /** + * @var \Prologue\Alerts\AlertsMessageBag + */ + protected $alert; + + /** + * @var \Pterodactyl\Services\Eggs\Scripts\InstallScriptService + */ + protected $installScriptService; + + /** + * @var \Pterodactyl\Contracts\Repository\EggRepositoryInterface + */ + protected $repository; + + /** + * EggScriptController constructor. + * + * @param \Prologue\Alerts\AlertsMessageBag $alert + * @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $repository + * @param \Pterodactyl\Services\Eggs\Scripts\InstallScriptService $installScriptService + */ + public function __construct( + AlertsMessageBag $alert, + EggRepositoryInterface $repository, + InstallScriptService $installScriptService + ) { + $this->alert = $alert; + $this->installScriptService = $installScriptService; + $this->repository = $repository; + } + + /** + * Handle requests to render installation script for an Egg. + * + * @param int $egg + * @return \Illuminate\View\View + */ + public function index(int $egg): View + { + $egg = $this->repository->getWithCopyAttributes($egg); + $copy = $this->repository->findWhere([ + ['copy_script_from', '=', null], + ['nest_id', '=', $egg->nest_id], + ['id', '!=', $egg], + ]); + + $rely = $this->repository->findWhere([ + ['copy_script_from', '=', $egg->id], + ]); + + return view('admin.eggs.scripts', [ + 'copyFromOptions' => $copy, + 'relyOnScript' => $rely, + 'egg' => $egg, + ]); + } + + /** + * Handle a request to update the installation script for an Egg. + * + * @param \Pterodactyl\Http\Requests\Admin\Egg\EggScriptFormRequest $request + * @param int $egg + * @return \Illuminate\Http\RedirectResponse + * + * @throws \Pterodactyl\Exceptions\Model\DataValidationException + * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException + * @throws \Pterodactyl\Exceptions\Service\Egg\InvalidCopyFromException + */ + public function update(EggScriptFormRequest $request, int $egg): RedirectResponse + { + $this->installScriptService->handle($egg, $request->normalize()); + $this->alert->success(trans('admin/nests.eggs.notices.script_updated'))->flash(); + + return redirect()->route('admin.nests.egg.scripts', $egg); + } +} diff --git a/app/Http/Controllers/Admin/Nests/EggVariableController.php b/app/Http/Controllers/Admin/Nests/EggVariableController.php new file mode 100644 index 000000000..8b68743fc --- /dev/null +++ b/app/Http/Controllers/Admin/Nests/EggVariableController.php @@ -0,0 +1,146 @@ +. + * + * This software is licensed under the terms of the MIT license. + * https://opensource.org/licenses/MIT + */ + +namespace Pterodactyl\Http\Controllers\Admin\Nests; + +use Illuminate\View\View; +use Pterodactyl\Models\Egg; +use Pterodactyl\Models\EggVariable; +use Illuminate\Http\RedirectResponse; +use Prologue\Alerts\AlertsMessageBag; +use Pterodactyl\Http\Controllers\Controller; +use Pterodactyl\Contracts\Repository\EggRepositoryInterface; +use Pterodactyl\Services\Eggs\Variables\VariableUpdateService; +use Pterodactyl\Http\Requests\Admin\Egg\EggVariableFormRequest; +use Pterodactyl\Services\Eggs\Variables\VariableCreationService; +use Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface; + +class EggVariableController extends Controller +{ + /** + * @var \Prologue\Alerts\AlertsMessageBag + */ + protected $alert; + + /** + * @var \Pterodactyl\Services\Eggs\Variables\VariableCreationService + */ + protected $creationService; + + /** + * @var \Pterodactyl\Contracts\Repository\EggRepositoryInterface + */ + protected $repository; + + /** + * @var \Pterodactyl\Services\Eggs\Variables\VariableUpdateService + */ + protected $updateService; + + /** + * @var \Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface + */ + protected $variableRepository; + + /** + * EggVariableController constructor. + * + * @param \Prologue\Alerts\AlertsMessageBag $alert + * @param \Pterodactyl\Services\Eggs\Variables\VariableCreationService $creationService + * @param \Pterodactyl\Services\Eggs\Variables\VariableUpdateService $updateService + * @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $repository + * @param \Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface $variableRepository + */ + public function __construct( + AlertsMessageBag $alert, + VariableCreationService $creationService, + VariableUpdateService $updateService, + EggRepositoryInterface $repository, + EggVariableRepositoryInterface $variableRepository + ) { + $this->alert = $alert; + $this->creationService = $creationService; + $this->repository = $repository; + $this->updateService = $updateService; + $this->variableRepository = $variableRepository; + } + + /** + * Handle request to view the variables attached to an Egg. + * + * @param int $egg + * @return \Illuminate\View\View + * + * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException + */ + public function view(int $egg): View + { + $egg = $this->repository->getWithVariables($egg); + + return view('admin.eggs.variables', ['egg' => $egg]); + } + + /** + * Handle a request to create a new Egg variable. + * + * @param \Pterodactyl\Http\Requests\Admin\Egg\EggVariableFormRequest $request + * @param \Pterodactyl\Models\Egg $egg + * + * @return \Illuminate\Http\RedirectResponse + * @throws \Pterodactyl\Exceptions\Model\DataValidationException + * @throws \Pterodactyl\Exceptions\Service\Egg\Variable\ReservedVariableNameException + */ + public function store(EggVariableFormRequest $request, Egg $egg): RedirectResponse + { + $this->creationService->handle($egg->id, $request->normalize()); + $this->alert->success(trans('admin/nests.variables.notices.variable_created'))->flash(); + + return redirect()->route('admin.nests.egg.variables', $egg->id); + } + + /** + * Handle a request to update an existing Egg variable. + * + * @param \Pterodactyl\Http\Requests\Admin\Egg\EggVariableFormRequest $request + * @param \Pterodactyl\Models\Egg $egg + * @param \Pterodactyl\Models\EggVariable $variable + * @return \Illuminate\Http\RedirectResponse + * + * @throws \Pterodactyl\Exceptions\DisplayException + * @throws \Pterodactyl\Exceptions\Model\DataValidationException + * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException + * @throws \Pterodactyl\Exceptions\Service\Egg\Variable\ReservedVariableNameException + */ + public function update(EggVariableFormRequest $request, Egg $egg, EggVariable $variable): RedirectResponse + { + $this->updateService->handle($variable, $request->normalize()); + $this->alert->success(trans('admin/nests.variables.notices.variable_updated', [ + 'variable' => $variable->name, + ]))->flash(); + + return redirect()->route('admin.nests.egg.variables', $egg->id); + } + + /** + * Handle a request to delete an existing Egg variable from the Panel. + * + * @param int $egg + * @param \Pterodactyl\Models\EggVariable $variable + * @return \Illuminate\Http\RedirectResponse + */ + public function destroy(int $egg, EggVariable $variable): RedirectResponse + { + $this->variableRepository->delete($variable->id); + $this->alert->success(trans('admin/nests.variables.notices.variable_deleted', [ + 'variable' => $variable->name, + ]))->flash(); + + return redirect()->route('admin.nests.egg.variables', $egg); + } +} diff --git a/app/Http/Controllers/Admin/Nests/NestController.php b/app/Http/Controllers/Admin/Nests/NestController.php index 204236025..b62753cad 100644 --- a/app/Http/Controllers/Admin/Nests/NestController.php +++ b/app/Http/Controllers/Admin/Nests/NestController.php @@ -145,12 +145,12 @@ class NestController extends Controller /** * Handle request to delete a nest. * - * @param \Pterodactyl\Models\Nest $nest + * @param int $nest * @return \Illuminate\Http\RedirectResponse * * @throws \Pterodactyl\Exceptions\Service\HasActiveServersException */ - public function destroy($nest): RedirectResponse + public function destroy(int $nest): RedirectResponse { $this->nestDeletionService->handle($nest); $this->alert->success(trans('admin/nests.notices.deleted'))->flash(); diff --git a/app/Http/Controllers/Admin/OptionController.php b/app/Http/Controllers/Admin/OptionController.php index 40e7b4f49..f99306e4c 100644 --- a/app/Http/Controllers/Admin/OptionController.php +++ b/app/Http/Controllers/Admin/OptionController.php @@ -14,16 +14,16 @@ use Pterodactyl\Models\Egg; use Illuminate\Http\Request; use Prologue\Alerts\AlertsMessageBag; use Pterodactyl\Http\Controllers\Controller; +use Pterodactyl\Http\Requests\Admin\Service\EggFormRequest; +use Pterodactyl\Services\Services\Options\EggUpdateService; use Pterodactyl\Contracts\Repository\EggRepositoryInterface; use Pterodactyl\Contracts\Repository\NestRepositoryInterface; use Pterodactyl\Http\Requests\Admin\Service\EditOptionScript; -use Pterodactyl\Services\Services\Options\OptionUpdateService; -use Pterodactyl\Services\Services\Options\OptionCreationService; -use Pterodactyl\Services\Services\Options\OptionDeletionService; -use Pterodactyl\Http\Requests\Admin\Service\ServiceOptionFormRequest; -use Pterodactyl\Services\Services\Options\InstallScriptUpdateService; -use Pterodactyl\Exceptions\Service\ServiceOption\InvalidCopyFromException; -use Pterodactyl\Exceptions\Service\ServiceOption\NoParentConfigurationFoundException; +use Pterodactyl\Services\Services\Options\EggCreationService; +use Pterodactyl\Services\Services\Options\EggDeletionService; +use Pterodactyl\Services\Services\Options\InstallScriptService; +use Pterodactyl\Exceptions\Service\Egg\InvalidCopyFromException; +use Pterodactyl\Exceptions\Service\Egg\NoParentConfigurationFoundException; class OptionController extends Controller { @@ -33,22 +33,22 @@ class OptionController extends Controller protected $alert; /** - * @var \Pterodactyl\Services\Services\Options\InstallScriptUpdateService + * @var \Pterodactyl\Services\Services\Options\InstallScriptService */ protected $installScriptUpdateService; /** - * @var \Pterodactyl\Services\Services\Options\OptionCreationService + * @var \Pterodactyl\Services\Services\Options\EggCreationService */ protected $optionCreationService; /** - * @var \Pterodactyl\Services\Services\Options\OptionDeletionService + * @var \Pterodactyl\Services\Services\Options\EggDeletionService */ protected $optionDeletionService; /** - * @var \Pterodactyl\Services\Services\Options\OptionUpdateService + * @var \Pterodactyl\Services\Services\Options\EggUpdateService */ protected $optionUpdateService; @@ -65,20 +65,20 @@ class OptionController extends Controller /** * OptionController constructor. * - * @param \Prologue\Alerts\AlertsMessageBag $alert - * @param \Pterodactyl\Services\Services\Options\InstallScriptUpdateService $installScriptUpdateService - * @param \Pterodactyl\Services\Services\Options\OptionCreationService $optionCreationService - * @param \Pterodactyl\Services\Services\Options\OptionDeletionService $optionDeletionService - * @param \Pterodactyl\Services\Services\Options\OptionUpdateService $optionUpdateService - * @param \Pterodactyl\Contracts\Repository\NestRepositoryInterface $serviceRepository - * @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $serviceOptionRepository + * @param \Prologue\Alerts\AlertsMessageBag $alert + * @param \Pterodactyl\Services\Services\Options\InstallScriptService $installScriptUpdateService + * @param \Pterodactyl\Services\Services\Options\EggCreationService $optionCreationService + * @param \Pterodactyl\Services\Services\Options\EggDeletionService $optionDeletionService + * @param \Pterodactyl\Services\Services\Options\EggUpdateService $optionUpdateService + * @param \Pterodactyl\Contracts\Repository\NestRepositoryInterface $serviceRepository + * @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $serviceOptionRepository */ public function __construct( AlertsMessageBag $alert, - InstallScriptUpdateService $installScriptUpdateService, - OptionCreationService $optionCreationService, - OptionDeletionService $optionDeletionService, - OptionUpdateService $optionUpdateService, + InstallScriptService $installScriptUpdateService, + EggCreationService $optionCreationService, + EggDeletionService $optionDeletionService, + EggUpdateService $optionUpdateService, NestRepositoryInterface $serviceRepository, EggRepositoryInterface $serviceOptionRepository ) { @@ -107,12 +107,12 @@ class OptionController extends Controller /** * Handle adding a new service option. * - * @param \Pterodactyl\Http\Requests\Admin\Service\ServiceOptionFormRequest $request + * @param \Pterodactyl\Http\Requests\Admin\Service\EggFormRequest $request * @return \Illuminate\Http\RedirectResponse * * @throws \Pterodactyl\Exceptions\Model\DataValidationException */ - public function store(ServiceOptionFormRequest $request) + public function store(EggFormRequest $request) { try { $option = $this->optionCreationService->handle($request->normalize()); diff --git a/app/Http/Controllers/Admin/ServiceController.php b/app/Http/Controllers/Admin/ServiceController.php deleted file mode 100644 index bdcfabaf2..000000000 --- a/app/Http/Controllers/Admin/ServiceController.php +++ /dev/null @@ -1,187 +0,0 @@ -. - * - * This software is licensed under the terms of the MIT license. - * https://opensource.org/licenses/MIT - */ - -namespace Pterodactyl\Http\Controllers\Admin; - -use Illuminate\View\View; -use Pterodactyl\Models\Nest; -use Illuminate\Http\RedirectResponse; -use Prologue\Alerts\AlertsMessageBag; -use Pterodactyl\Http\Controllers\Controller; -use Pterodactyl\Services\Services\NestUpdateService; -use Pterodactyl\Services\Services\NestCreationService; -use Pterodactyl\Services\Services\NestDeletionService; -use Pterodactyl\Contracts\Repository\NestRepositoryInterface; -use Pterodactyl\Http\Requests\Admin\Service\StoreNestFormRequest; -use Pterodactyl\Http\Requests\Admin\Service\ServiceFunctionsFormRequest; - -class ServiceController extends Controller -{ - /** - * @var \Prologue\Alerts\AlertsMessageBag - */ - protected $alert; - - /** - * @var \Pterodactyl\Services\Services\NestCreationService - */ - protected $creationService; - - /** - * @var \Pterodactyl\Services\Services\NestDeletionService - */ - protected $deletionService; - - /** - * @var \Pterodactyl\Contracts\Repository\NestRepositoryInterface - */ - protected $repository; - - /** - * @var \Pterodactyl\Services\Services\NestUpdateService - */ - protected $updateService; - - /** - * ServiceController constructor. - * - * @param \Prologue\Alerts\AlertsMessageBag $alert - * @param \Pterodactyl\Services\Services\NestCreationService $creationService - * @param \Pterodactyl\Services\Services\NestDeletionService $deletionService - * @param \Pterodactyl\Contracts\Repository\NestRepositoryInterface $repository - * @param \Pterodactyl\Services\Services\NestUpdateService $updateService - */ - public function __construct( - AlertsMessageBag $alert, - NestCreationService $creationService, - NestDeletionService $deletionService, - NestRepositoryInterface $repository, - NestUpdateService $updateService - ) { - $this->alert = $alert; - $this->creationService = $creationService; - $this->deletionService = $deletionService; - $this->repository = $repository; - $this->updateService = $updateService; - } - - /** - * Display service overview page. - * - * @return \Illuminate\View\View - */ - public function index(): View - { - return view('admin.services.index', [ - 'services' => $this->repository->getWithCounts(), - ]); - } - - /** - * Display create service page. - * - * @return \Illuminate\View\View - */ - public function create(): View - { - return view('admin.services.new'); - } - - /** - * Return base view for a service. - * - * @param int $service - * @return \Illuminate\View\View - */ - public function view(int $service): View - { - return view('admin.services.view', [ - 'service' => $this->repository->getWithOptionServers($service), - ]); - } - - /** - * Return function editing view for a service. - * - * @param \Pterodactyl\Models\Nest $service - * @return \Illuminate\View\View - */ - public function viewFunctions(Nest $service): View - { - return view('admin.services.functions', ['service' => $service]); - } - - /** - * Handle post action for new service. - * - * @param \Pterodactyl\Http\Requests\Admin\Service\StoreNestFormRequest $request - * @return \Illuminate\Http\RedirectResponse - * - * @throws \Pterodactyl\Exceptions\Model\DataValidationException - */ - public function store(StoreNestFormRequest $request): RedirectResponse - { - $service = $this->creationService->handle($request->normalize()); - $this->alert->success(trans('admin/services.notices.service_created', ['name' => $service->name]))->flash(); - - return redirect()->route('admin.services.view', $service->id); - } - - /** - * Edits configuration for a specific service. - * - * @param \Pterodactyl\Http\Requests\Admin\Service\StoreNestFormRequest $request - * @param \Pterodactyl\Models\Nest $service - * @return \Illuminate\Http\RedirectResponse - * - * @throws \Pterodactyl\Exceptions\Model\DataValidationException - * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException - */ - public function update(StoreNestFormRequest $request, Nest $service): RedirectResponse - { - $this->updateService->handle($service->id, $request->normalize()); - $this->alert->success(trans('admin/services.notices.service_updated'))->flash(); - - return redirect()->route('admin.services.view', $service); - } - - /** - * Update the functions file for a service. - * - * @param \Pterodactyl\Http\Requests\Admin\Service\ServiceFunctionsFormRequest $request - * @param \Pterodactyl\Models\Nest $service - * @return \Illuminate\Http\RedirectResponse - * - * @throws \Pterodactyl\Exceptions\Model\DataValidationException - * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException - */ - public function updateFunctions(ServiceFunctionsFormRequest $request, Nest $service): RedirectResponse - { - $this->updateService->handle($service->id, $request->normalize()); - $this->alert->success(trans('admin/services.notices.functions_updated'))->flash(); - - return redirect()->route('admin.services.view.functions', $service->id); - } - - /** - * Delete a service from the panel. - * - * @param \Pterodactyl\Models\Nest $service - * @return \Illuminate\Http\RedirectResponse - * - * @throws \Pterodactyl\Exceptions\Service\HasActiveServersException - */ - public function destroy(Nest $service): RedirectResponse - { - $this->deletionService->handle($service->id); - $this->alert->success(trans('admin/services.notices.service_deleted'))->flash(); - - return redirect()->route('admin.services'); - } -} diff --git a/app/Http/Controllers/Admin/VariableController.php b/app/Http/Controllers/Admin/VariableController.php deleted file mode 100644 index dc62ee71f..000000000 --- a/app/Http/Controllers/Admin/VariableController.php +++ /dev/null @@ -1,133 +0,0 @@ -. - * - * This software is licensed under the terms of the MIT license. - * https://opensource.org/licenses/MIT - */ - -namespace Pterodactyl\Http\Controllers\Admin; - -use Pterodactyl\Models\Egg; -use Pterodactyl\Models\EggVariable; -use Prologue\Alerts\AlertsMessageBag; -use Pterodactyl\Http\Controllers\Controller; -use Pterodactyl\Contracts\Repository\EggRepositoryInterface; -use Pterodactyl\Http\Requests\Admin\OptionVariableFormRequest; -use Pterodactyl\Repositories\Eloquent\ServiceVariableRepository; -use Pterodactyl\Services\Services\Variables\VariableUpdateService; -use Pterodactyl\Services\Services\Variables\VariableCreationService; - -class VariableController extends Controller -{ - /** - * @var \Prologue\Alerts\AlertsMessageBag - */ - protected $alert; - - /** - * @var \Pterodactyl\Services\Services\Variables\VariableCreationService - */ - protected $creationService; - - /** - * @var \Pterodactyl\Contracts\Repository\EggRepositoryInterface - */ - protected $serviceOptionRepository; - - /** - * @var \Pterodactyl\Repositories\Eloquent\ServiceVariableRepository - */ - protected $serviceVariableRepository; - - /** - * @var \Pterodactyl\Services\Services\Variables\VariableUpdateService - */ - protected $updateService; - - public function __construct( - AlertsMessageBag $alert, - EggRepositoryInterface $serviceOptionRepository, - ServiceVariableRepository $serviceVariableRepository, - VariableCreationService $creationService, - VariableUpdateService $updateService - ) { - $this->alert = $alert; - $this->creationService = $creationService; - $this->serviceOptionRepository = $serviceOptionRepository; - $this->serviceVariableRepository = $serviceVariableRepository; - $this->updateService = $updateService; - } - - /** - * Handles POST request to create a new option variable. - * - * @param \Pterodactyl\Http\Requests\Admin\OptionVariableFormRequest $request - * @param \Pterodactyl\Models\Egg $option - * @return \Illuminate\Http\RedirectResponse - * - * @throws \Pterodactyl\Exceptions\Model\DataValidationException - * @throws \Pterodactyl\Exceptions\Service\ServiceVariable\ReservedVariableNameException - */ - public function store(OptionVariableFormRequest $request, Egg $option) - { - $this->creationService->handle($option->id, $request->normalize()); - $this->alert->success(trans('admin/services.variables.notices.variable_created'))->flash(); - - return redirect()->route('admin.services.option.variables', $option->id); - } - - /** - * Display variable overview page for a service option. - * - * @param int $option - * @return \Illuminate\View\View - */ - public function view($option) - { - $option = $this->serviceOptionRepository->getWithVariables($option); - - return view('admin.services.options.variables', ['option' => $option]); - } - - /** - * Handles POST when editing a configration for a service variable. - * - * @param \Pterodactyl\Http\Requests\Admin\OptionVariableFormRequest $request - * @param \Pterodactyl\Models\Egg $option - * @param \Pterodactyl\Models\EggVariable $variable - * @return \Illuminate\Http\RedirectResponse - * - * @throws \Pterodactyl\Exceptions\DisplayException - * @throws \Pterodactyl\Exceptions\Model\DataValidationException - * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException - * @throws \Pterodactyl\Exceptions\Service\ServiceVariable\ReservedVariableNameException - */ - public function update(OptionVariableFormRequest $request, Egg $option, EggVariable $variable) - { - $this->updateService->handle($variable, $request->normalize()); - $this->alert->success(trans('admin/services.variables.notices.variable_updated', [ - 'variable' => $variable->name, - ]))->flash(); - - return redirect()->route('admin.services.option.variables', $option->id); - } - - /** - * Delete a service variable from the system. - * - * @param \Pterodactyl\Models\Egg $option - * @param \Pterodactyl\Models\EggVariable $variable - * @return \Illuminate\Http\RedirectResponse - */ - public function delete(Egg $option, EggVariable $variable) - { - $this->serviceVariableRepository->delete($variable->id); - $this->alert->success(trans('admin/services.variables.notices.variable_deleted', [ - 'variable' => $variable->name, - ]))->flash(); - - return redirect()->route('admin.services.option.variables', $option->id); - } -} diff --git a/app/Http/Requests/Admin/Egg/EggFormRequest.php b/app/Http/Requests/Admin/Egg/EggFormRequest.php new file mode 100644 index 000000000..539ee3adc --- /dev/null +++ b/app/Http/Requests/Admin/Egg/EggFormRequest.php @@ -0,0 +1,49 @@ +. + * + * This software is licensed under the terms of the MIT license. + * https://opensource.org/licenses/MIT + */ + +namespace Pterodactyl\Http\Requests\Admin\Egg; + +use Pterodactyl\Http\Requests\Admin\AdminFormRequest; + +class EggFormRequest extends AdminFormRequest +{ + /** + * {@inheritdoc} + */ + public function rules() + { + $rules = [ + 'name' => 'required|string|max:255', + 'description' => 'required|string', + 'docker_image' => 'required|string|max:255', + 'startup' => 'required|string', + 'config_from' => 'sometimes|bail|nullable|numeric', + 'config_stop' => 'required_without:config_from|nullable|string|max:255', + 'config_startup' => 'required_without:config_from|nullable|json', + 'config_logs' => 'required_without:config_from|nullable|json', + 'config_files' => 'required_without:config_from|nullable|json', + ]; + + if ($this->method() === 'POST') { + $rules['nest_id'] = 'required|numeric|exists:nests,id'; + } + + return $rules; + } + + /** + * @param \Illuminate\Contracts\Validation\Validator $validator + */ + public function withValidator($validator) + { + $validator->sometimes('config_from', 'exists:eggs,id', function () { + return (int) $this->input('config_from') !== 0; + }); + } +} diff --git a/app/Http/Requests/Admin/Service/EditOptionScript.php b/app/Http/Requests/Admin/Egg/EggScriptFormRequest.php similarity index 88% rename from app/Http/Requests/Admin/Service/EditOptionScript.php rename to app/Http/Requests/Admin/Egg/EggScriptFormRequest.php index 03d1612c9..3f522e96f 100644 --- a/app/Http/Requests/Admin/Service/EditOptionScript.php +++ b/app/Http/Requests/Admin/Egg/EggScriptFormRequest.php @@ -7,11 +7,11 @@ * https://opensource.org/licenses/MIT */ -namespace Pterodactyl\Http\Requests\Admin\Service; +namespace Pterodactyl\Http\Requests\Admin\Egg; use Pterodactyl\Http\Requests\Admin\AdminFormRequest; -class EditOptionScript extends AdminFormRequest +class EggScriptFormRequest extends AdminFormRequest { /** * Return the rules to be used when validating the sent data in the request. diff --git a/app/Http/Requests/Admin/Service/OptionVariableFormRequest.php b/app/Http/Requests/Admin/Egg/EggVariableFormRequest.php similarity index 80% rename from app/Http/Requests/Admin/Service/OptionVariableFormRequest.php rename to app/Http/Requests/Admin/Egg/EggVariableFormRequest.php index 2076e8da5..621fbd772 100644 --- a/app/Http/Requests/Admin/Service/OptionVariableFormRequest.php +++ b/app/Http/Requests/Admin/Egg/EggVariableFormRequest.php @@ -7,11 +7,12 @@ * https://opensource.org/licenses/MIT */ -namespace Pterodactyl\Http\Requests\Admin; +namespace Pterodactyl\Http\Requests\Admin\Egg; use Pterodactyl\Models\EggVariable; +use Pterodactyl\Http\Requests\Admin\AdminFormRequest; -class OptionVariableFormRequest extends AdminFormRequest +class EggVariableFormRequest extends AdminFormRequest { /** * @return array @@ -37,11 +38,9 @@ class OptionVariableFormRequest extends AdminFormRequest { $rules = $this->input('rules'); if ($this->method() === 'PATCH') { - $rules = $this->input('rules', $this->route()->parameter('variable')->rules); + $rules = $this->input('rules', $this->route()->parameter('egg')->rules); } - $validator->sometimes('default_value', $rules, function ($input) { - return $input->default_value; - }); + $validator->addRules(['default_value' => $rules]); } } diff --git a/app/Http/Requests/Admin/Service/ServiceOptionFormRequest.php b/app/Http/Requests/Admin/Service/ServiceOptionFormRequest.php deleted file mode 100644 index 065fef0f5..000000000 --- a/app/Http/Requests/Admin/Service/ServiceOptionFormRequest.php +++ /dev/null @@ -1,24 +0,0 @@ -. - * - * This software is licensed under the terms of the MIT license. - * https://opensource.org/licenses/MIT - */ - -namespace Pterodactyl\Http\Requests\Admin\Service; - -use Pterodactyl\Models\Egg; -use Pterodactyl\Http\Requests\Admin\AdminFormRequest; - -class ServiceOptionFormRequest extends AdminFormRequest -{ - /** - * {@inheritdoc} - */ - public function rules() - { - return Egg::getCreateRules(); - } -} diff --git a/app/Models/Egg.php b/app/Models/Egg.php index fd8740840..cf82f3a0d 100644 --- a/app/Models/Egg.php +++ b/app/Models/Egg.php @@ -64,7 +64,7 @@ class Egg extends Model implements CleansAttributes, ValidableContract * @var array */ protected static $applicationRules = [ - 'service_id' => 'required', + 'nest_id' => 'required', 'name' => 'required', 'description' => 'required', 'docker_image' => 'required', @@ -80,13 +80,13 @@ class Egg extends Model implements CleansAttributes, ValidableContract * @var array */ protected static $dataIntegrityRules = [ - 'service_id' => 'bail|numeric|exists:services,id', + 'nest_id' => 'bail|numeric|exists:nests,id', 'uuid' => 'string|size:36', 'name' => 'string|max:255', 'description' => 'string', 'docker_image' => 'string|max:255', 'startup' => 'nullable|string', - 'config_from' => 'bail|nullable|numeric|exists:service_options,id', + 'config_from' => 'bail|nullable|numeric|exists:eggs,id', 'config_stop' => 'nullable|string|max:255', 'config_startup' => 'nullable|json', 'config_logs' => 'nullable|json', diff --git a/app/Services/Services/Options/OptionConfigurationFileService.php b/app/Services/Eggs/EggConfigurationService.php similarity index 83% rename from app/Services/Services/Options/OptionConfigurationFileService.php rename to app/Services/Eggs/EggConfigurationService.php index e8656fdba..b308ca1e5 100644 --- a/app/Services/Services/Options/OptionConfigurationFileService.php +++ b/app/Services/Eggs/EggConfigurationService.php @@ -7,17 +7,20 @@ * https://opensource.org/licenses/MIT */ -namespace Pterodactyl\Services\Services\Options; +namespace Pterodactyl\Services\Eggs; use Pterodactyl\Models\Egg; use Pterodactyl\Contracts\Repository\EggRepositoryInterface; -class OptionConfigurationFileService +class EggConfigurationService { + /** + * @var \Pterodactyl\Contracts\Repository\EggRepositoryInterface + */ protected $repository; /** - * OptionConfigurationFileService constructor. + * EggConfigurationService constructor. * * @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $repository */ @@ -27,7 +30,7 @@ class OptionConfigurationFileService } /** - * Return a service configuration file to be used by the daemon. + * Return an Egg file to be used by the Daemon. * * @param int|\Pterodactyl\Models\Egg $option * @return array diff --git a/app/Services/Services/Options/OptionCreationService.php b/app/Services/Eggs/EggCreationService.php similarity index 67% rename from app/Services/Services/Options/OptionCreationService.php rename to app/Services/Eggs/EggCreationService.php index 05f4c639e..13f04c3b0 100644 --- a/app/Services/Services/Options/OptionCreationService.php +++ b/app/Services/Eggs/EggCreationService.php @@ -7,15 +7,16 @@ * https://opensource.org/licenses/MIT */ -namespace Pterodactyl\Services\Services\Options; +namespace Pterodactyl\Services\Eggs; use Ramsey\Uuid\Uuid; use Pterodactyl\Models\Egg; use Pterodactyl\Contracts\Repository\EggRepositoryInterface; use Illuminate\Contracts\Config\Repository as ConfigRepository; -use Pterodactyl\Exceptions\Service\ServiceOption\NoParentConfigurationFoundException; +use Pterodactyl\Exceptions\Service\Egg\NoParentConfigurationFoundException; -class OptionCreationService +// When a mommy and a daddy pterodactyl really like eachother... +class EggCreationService { /** * @var \Illuminate\Contracts\Config\Repository @@ -28,7 +29,7 @@ class OptionCreationService protected $repository; /** - * CreationService constructor. + * EggCreationService constructor. * * @param \Illuminate\Contracts\Config\Repository $config * @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $repository @@ -46,31 +47,25 @@ class OptionCreationService * @return \Pterodactyl\Models\Egg * * @throws \Pterodactyl\Exceptions\Model\DataValidationException - * @throws \Pterodactyl\Exceptions\Service\ServiceOption\NoParentConfigurationFoundException + * @throws \Pterodactyl\Exceptions\Service\Egg\NoParentConfigurationFoundException */ public function handle(array $data): Egg { - if (! is_null(array_get($data, 'config_from'))) { + $data['config_from'] = array_get($data, 'config_from'); + if (! is_null($data['config_from'])) { $results = $this->repository->findCountWhere([ - ['service_id', '=', array_get($data, 'service_id')], + ['nest_id', '=', array_get($data, 'nest_id')], ['id', '=', array_get($data, 'config_from')], ]); if ($results !== 1) { throw new NoParentConfigurationFoundException(trans('exceptions.service.options.must_be_child')); } - } else { - $data['config_from'] = null; - } - - if (count($parts = explode(':', array_get($data, 'tag'))) > 1) { - $data['tag'] = $this->config->get('pterodactyl.service.author') . ':' . trim(array_pop($parts)); - } else { - $data['tag'] = $this->config->get('pterodactyl.service.author') . ':' . trim(array_get($data, 'tag')); } return $this->repository->create(array_merge($data, [ 'uuid' => Uuid::uuid4()->toString(), + 'author' => $this->config->get('pterodactyl.service.author'), ]), true, true); } } diff --git a/app/Services/Services/Options/OptionDeletionService.php b/app/Services/Eggs/EggDeletionService.php similarity index 66% rename from app/Services/Services/Options/OptionDeletionService.php rename to app/Services/Eggs/EggDeletionService.php index 35c60cb93..5179f6a50 100644 --- a/app/Services/Services/Options/OptionDeletionService.php +++ b/app/Services/Eggs/EggDeletionService.php @@ -7,14 +7,14 @@ * https://opensource.org/licenses/MIT */ -namespace Pterodactyl\Services\Services\Options; +namespace Pterodactyl\Services\Eggs; use Pterodactyl\Contracts\Repository\EggRepositoryInterface; +use Pterodactyl\Exceptions\Service\Egg\HasChildrenException; use Pterodactyl\Exceptions\Service\HasActiveServersException; use Pterodactyl\Contracts\Repository\ServerRepositoryInterface; -use Pterodactyl\Exceptions\Service\ServiceOption\HasChildrenException; -class OptionDeletionService +class EggDeletionService { /** * @var \Pterodactyl\Contracts\Repository\EggRepositoryInterface @@ -27,7 +27,7 @@ class OptionDeletionService protected $serverRepository; /** - * OptionDeletionService constructor. + * EggDeletionService constructor. * * @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $serverRepository * @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $repository @@ -41,26 +41,26 @@ class OptionDeletionService } /** - * Delete an option from the database if it has no active servers attached to it. + * Delete an Egg from the database if it has no active servers attached to it. * - * @param int $option + * @param int $egg * @return int * * @throws \Pterodactyl\Exceptions\Service\HasActiveServersException - * @throws \Pterodactyl\Exceptions\Service\ServiceOption\HasChildrenException + * @throws \Pterodactyl\Exceptions\Service\Egg\HasChildrenException */ - public function handle(int $option): int + public function handle(int $egg): int { - $servers = $this->serverRepository->findCountWhere([['option_id', '=', $option]]); + $servers = $this->serverRepository->findCountWhere([['egg_id', '=', $egg]]); if ($servers > 0) { - throw new HasActiveServersException(trans('exceptions.service.options.delete_has_servers')); + throw new HasActiveServersException(trans('exceptions.nest.egg.delete_has_servers')); } - $children = $this->repository->findCountWhere([['config_from', '=', $option]]); + $children = $this->repository->findCountWhere([['config_from', '=', $egg]]); if ($children > 0) { - throw new HasChildrenException(trans('exceptions.service.options.has_children')); + throw new HasChildrenException(trans('exceptions.nest.egg.has_children')); } - return $this->repository->delete($option); + return $this->repository->delete($egg); } } diff --git a/app/Services/Services/Options/OptionUpdateService.php b/app/Services/Eggs/EggUpdateService.php similarity index 64% rename from app/Services/Services/Options/OptionUpdateService.php rename to app/Services/Eggs/EggUpdateService.php index 1daaf14ae..2932b7457 100644 --- a/app/Services/Services/Options/OptionUpdateService.php +++ b/app/Services/Eggs/EggUpdateService.php @@ -7,13 +7,13 @@ * https://opensource.org/licenses/MIT */ -namespace Pterodactyl\Services\Services\Options; +namespace Pterodactyl\Services\Eggs; use Pterodactyl\Models\Egg; use Pterodactyl\Contracts\Repository\EggRepositoryInterface; -use Pterodactyl\Exceptions\Service\ServiceOption\NoParentConfigurationFoundException; +use Pterodactyl\Exceptions\Service\Egg\NoParentConfigurationFoundException; -class OptionUpdateService +class EggUpdateService { /** * @var \Pterodactyl\Contracts\Repository\EggRepositoryInterface @@ -21,7 +21,7 @@ class OptionUpdateService protected $repository; /** - * OptionUpdateService constructor. + * EggUpdateService constructor. * * @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $repository */ @@ -33,30 +33,30 @@ class OptionUpdateService /** * Update a service option. * - * @param int|\Pterodactyl\Models\Egg $option + * @param int|\Pterodactyl\Models\Egg $egg * @param array $data * * @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException - * @throws \Pterodactyl\Exceptions\Service\ServiceOption\NoParentConfigurationFoundException + * @throws \Pterodactyl\Exceptions\Service\Egg\NoParentConfigurationFoundException */ - public function handle($option, array $data) + public function handle($egg, array $data) { - if (! $option instanceof Egg) { - $option = $this->repository->find($option); + if (! $egg instanceof Egg) { + $egg = $this->repository->find($egg); } if (! is_null(array_get($data, 'config_from'))) { $results = $this->repository->findCountWhere([ - ['service_id', '=', $option->service_id], + ['nest_id', '=', $egg->nest_id], ['id', '=', array_get($data, 'config_from')], ]); if ($results !== 1) { - throw new NoParentConfigurationFoundException(trans('exceptions.service.options.must_be_child')); + throw new NoParentConfigurationFoundException(trans('exceptions.nest.egg.must_be_child')); } } - $this->repository->withoutFresh()->update($option->id, $data); + $this->repository->withoutFresh()->update($egg->id, $data); } } diff --git a/app/Services/Services/Options/InstallScriptUpdateService.php b/app/Services/Eggs/Scripts/InstallScriptService.php similarity index 66% rename from app/Services/Services/Options/InstallScriptUpdateService.php rename to app/Services/Eggs/Scripts/InstallScriptService.php index 1d5a9a920..92493be35 100644 --- a/app/Services/Services/Options/InstallScriptUpdateService.php +++ b/app/Services/Eggs/Scripts/InstallScriptService.php @@ -7,13 +7,13 @@ * https://opensource.org/licenses/MIT */ -namespace Pterodactyl\Services\Services\Options; +namespace Pterodactyl\Services\Eggs\Scripts; use Pterodactyl\Models\Egg; use Pterodactyl\Contracts\Repository\EggRepositoryInterface; -use Pterodactyl\Exceptions\Service\ServiceOption\InvalidCopyFromException; +use Pterodactyl\Exceptions\Service\Egg\InvalidCopyFromException; -class InstallScriptUpdateService +class InstallScriptService { /** * @var \Pterodactyl\Contracts\Repository\EggRepositoryInterface @@ -21,7 +21,7 @@ class InstallScriptUpdateService protected $repository; /** - * InstallScriptUpdateService constructor. + * InstallScriptService constructor. * * @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $repository */ @@ -31,30 +31,30 @@ class InstallScriptUpdateService } /** - * Modify the option install script for a given service option. + * Modify the install script for a given Egg. * - * @param int|\Pterodactyl\Models\Egg $option + * @param int|\Pterodactyl\Models\Egg $egg * @param array $data * * @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException - * @throws \Pterodactyl\Exceptions\Service\ServiceOption\InvalidCopyFromException + * @throws \Pterodactyl\Exceptions\Service\Egg\InvalidCopyFromException */ - public function handle($option, array $data) + public function handle($egg, array $data) { - if (! $option instanceof Egg) { - $option = $this->repository->find($option); + if (! $egg instanceof Egg) { + $egg = $this->repository->find($egg); } if (! is_null(array_get($data, 'copy_script_from'))) { - if (! $this->repository->isCopiableScript(array_get($data, 'copy_script_from'), $option->service_id)) { - throw new InvalidCopyFromException(trans('exceptions.service.options.invalid_copy_id')); + if (! $this->repository->isCopiableScript(array_get($data, 'copy_script_from'), $egg->service_id)) { + throw new InvalidCopyFromException(trans('exceptions.nest.egg.invalid_copy_id')); } } - $this->repository->withoutFresh()->update($option->id, [ + $this->repository->withoutFresh()->update($egg->id, [ 'script_install' => array_get($data, 'script_install'), - 'script_is_privileged' => array_get($data, 'script_is_privileged'), + 'script_is_privileged' => array_get($data, 'script_is_privileged', 1), 'script_entry' => array_get($data, 'script_entry'), 'script_container' => array_get($data, 'script_container'), 'copy_script_from' => array_get($data, 'copy_script_from'), diff --git a/app/Services/Services/Variables/VariableCreationService.php b/app/Services/Eggs/Variables/VariableCreationService.php similarity index 51% rename from app/Services/Services/Variables/VariableCreationService.php rename to app/Services/Eggs/Variables/VariableCreationService.php index f6891df26..76aac4456 100644 --- a/app/Services/Services/Variables/VariableCreationService.php +++ b/app/Services/Eggs/Variables/VariableCreationService.php @@ -7,50 +7,51 @@ * https://opensource.org/licenses/MIT */ -namespace Pterodactyl\Services\Services\Variables; +namespace Pterodactyl\Services\Eggs\Variables; -use Pterodactyl\Models\Egg; use Pterodactyl\Models\EggVariable; use Pterodactyl\Contracts\Repository\EggRepositoryInterface; -use Pterodactyl\Contracts\Repository\ServiceVariableRepositoryInterface; -use Pterodactyl\Exceptions\Service\ServiceVariable\ReservedVariableNameException; +use Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface; +use Pterodactyl\Exceptions\Service\Egg\Variable\ReservedVariableNameException; class VariableCreationService { /** * @var \Pterodactyl\Contracts\Repository\EggRepositoryInterface */ - protected $serviceOptionRepository; + protected $eggRepository; /** - * @var \Pterodactyl\Contracts\Repository\ServiceVariableRepositoryInterface + * @var \Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface */ - protected $serviceVariableRepository; + protected $variableRepository; + /** + * VariableCreationService constructor. + * + * @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $eggRepository + * @param \Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface $variableRepository + */ public function __construct( - EggRepositoryInterface $serviceOptionRepository, - ServiceVariableRepositoryInterface $serviceVariableRepository + EggRepositoryInterface $eggRepository, + EggVariableRepositoryInterface $variableRepository ) { - $this->serviceOptionRepository = $serviceOptionRepository; - $this->serviceVariableRepository = $serviceVariableRepository; + $this->eggRepository = $eggRepository; + $this->variableRepository = $variableRepository; } /** - * Create a new variable for a given service option. + * Create a new variable for a given Egg. * - * @param int|\Pterodactyl\Models\Egg $option - * @param array $data + * @param int $egg + * @param array $data * @return \Pterodactyl\Models\EggVariable * * @throws \Pterodactyl\Exceptions\Model\DataValidationException - * @throws \Pterodactyl\Exceptions\Service\ServiceVariable\ReservedVariableNameException + * @throws \Pterodactyl\Exceptions\Service\Egg\Variable\ReservedVariableNameException */ - public function handle($option, array $data) + public function handle(int $egg, array $data): EggVariable { - if ($option instanceof Egg) { - $option = $option->id; - } - if (in_array(strtoupper(array_get($data, 'env_variable')), explode(',', EggVariable::RESERVED_ENV_NAMES))) { throw new ReservedVariableNameException(sprintf( 'Cannot use the protected name %s for this environment variable.', @@ -60,8 +61,8 @@ class VariableCreationService $options = array_get($data, 'options', []); - return $this->serviceVariableRepository->create(array_merge([ - 'option_id' => $option, + return $this->variableRepository->create(array_merge([ + 'egg_id' => $egg, 'user_viewable' => in_array('user_viewable', $options), 'user_editable' => in_array('user_editable', $options), ], $data)); diff --git a/app/Services/Services/Variables/VariableUpdateService.php b/app/Services/Eggs/Variables/VariableUpdateService.php similarity index 75% rename from app/Services/Services/Variables/VariableUpdateService.php rename to app/Services/Eggs/Variables/VariableUpdateService.php index 28573785d..9c4f67fa7 100644 --- a/app/Services/Services/Variables/VariableUpdateService.php +++ b/app/Services/Eggs/Variables/VariableUpdateService.php @@ -7,32 +7,32 @@ * https://opensource.org/licenses/MIT */ -namespace Pterodactyl\Services\Services\Variables; +namespace Pterodactyl\Services\Eggs\Variables; use Pterodactyl\Models\EggVariable; use Pterodactyl\Exceptions\DisplayException; -use Pterodactyl\Contracts\Repository\ServiceVariableRepositoryInterface; -use Pterodactyl\Exceptions\Service\ServiceVariable\ReservedVariableNameException; +use Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface; +use Pterodactyl\Exceptions\Service\Egg\Variable\ReservedVariableNameException; class VariableUpdateService { /** - * @var \Pterodactyl\Contracts\Repository\ServiceVariableRepositoryInterface + * @var \Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface */ protected $repository; /** * VariableUpdateService constructor. * - * @param \Pterodactyl\Contracts\Repository\ServiceVariableRepositoryInterface $repository + * @param \Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface $repository */ - public function __construct(ServiceVariableRepositoryInterface $repository) + public function __construct(EggVariableRepositoryInterface $repository) { $this->repository = $repository; } /** - * Update a specific service variable. + * Update a specific egg variable. * * @param int|\Pterodactyl\Models\EggVariable $variable * @param array $data @@ -41,7 +41,7 @@ class VariableUpdateService * @throws \Pterodactyl\Exceptions\DisplayException * @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException - * @throws \Pterodactyl\Exceptions\Service\ServiceVariable\ReservedVariableNameException + * @throws \Pterodactyl\Exceptions\Service\Egg\Variable\ReservedVariableNameException */ public function handle($variable, array $data) { @@ -58,7 +58,7 @@ class VariableUpdateService $search = $this->repository->withColumns('id')->findCountWhere([ ['env_variable', '=', array_get($data, 'env_variable')], - ['option_id', '=', $variable->option_id], + ['egg_id', '=', $variable->egg_id], ['id', '!=', $variable->id], ]); @@ -71,9 +71,9 @@ class VariableUpdateService $options = array_get($data, 'options', []); - return $this->repository->withoutFresh()->update($variable->id, array_merge([ + return $this->repository->withoutFresh()->update($variable->id, array_merge($data, [ 'user_viewable' => in_array('user_viewable', $options), 'user_editable' => in_array('user_editable', $options), - ], $data)); + ])); } } diff --git a/resources/themes/pterodactyl/admin/services/options/new.blade.php b/resources/themes/pterodactyl/admin/eggs/new.blade.php similarity index 72% rename from resources/themes/pterodactyl/admin/services/options/new.blade.php rename to resources/themes/pterodactyl/admin/eggs/new.blade.php index 79195f008..e432090f3 100644 --- a/resources/themes/pterodactyl/admin/services/options/new.blade.php +++ b/resources/themes/pterodactyl/admin/eggs/new.blade.php @@ -6,20 +6,20 @@ @extends('layouts.admin') @section('title') - Service → New Option + Nests → New Egg @endsection @section('content-header') -

New OptionCreate a new service option to assign to servers.

+

New EggCreate a new Egg to assign to servers.

@endsection @section('content') -
+
@@ -30,42 +30,37 @@
- - + +
+ +

Think of a Nest as a category. You can put multiple Eggs in a nest, but consider putting only Eggs that are related to eachother in each Nest.

+
- + -

A simple, human-readable name to use as an identifier for this service.

+

A simple, human-readable name to use as an identifier for this Egg. This is what users will see as thier gameserver type.

-

A description of this service that will be displayed throughout the panel as needed.

+

A description of this Egg.

- -
- {{ config('pterodactyl.service.author') }}: - -
-

This should be a unique identifer for this service option that is not used for any other service options. Must be alpha-numeric and no more than 60 characters in length.

-
-
- + -

The default docker image that should be used for new servers under this service option. This can be left blank to use the parent service's defined image, and can also be changed per-server.

+

The default docker image that should be used for new servers using this Egg. This can be changed per-server.

- - -

The default statup command that should be used for new servers under this service option. This can be left blank to use the parent service's startup, and can also be changed per-server.

+ + +

The default statup command that should be used for new servers created with this Egg. You can change this per-server as needed.

@@ -90,7 +85,7 @@ -

If you would like to default to settings from another option select the option from the menu above.

+

If you would like to default to settings from another Egg select it from the dropdown above.

@@ -118,7 +113,7 @@
@@ -131,15 +126,15 @@ {!! Theme::js('vendor/lodash/lodash.js') !!}