2017-03-10 23:25:12 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Pterodactyl - Panel
|
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
|
|
|
*
|
2017-09-26 02:43:01 +00:00
|
|
|
* This software is licensed under the terms of the MIT license.
|
|
|
|
* https://opensource.org/licenses/MIT
|
2017-03-10 23:25:12 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Controllers\Admin;
|
|
|
|
|
2017-03-12 05:00:06 +00:00
|
|
|
use Javascript;
|
2017-10-07 04:57:53 +00:00
|
|
|
use Pterodactyl\Models\Egg;
|
2017-03-10 23:25:12 +00:00
|
|
|
use Illuminate\Http\Request;
|
2017-08-12 20:29:01 +00:00
|
|
|
use Prologue\Alerts\AlertsMessageBag;
|
2017-03-10 23:25:12 +00:00
|
|
|
use Pterodactyl\Http\Controllers\Controller;
|
2017-10-07 04:57:53 +00:00
|
|
|
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
|
|
|
|
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
|
2017-06-18 01:52:32 +00:00
|
|
|
use Pterodactyl\Http\Requests\Admin\Service\EditOptionScript;
|
2017-08-12 20:29:01 +00:00
|
|
|
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;
|
2017-08-19 03:19:06 +00:00
|
|
|
use Pterodactyl\Exceptions\Service\ServiceOption\InvalidCopyFromException;
|
|
|
|
use Pterodactyl\Exceptions\Service\ServiceOption\NoParentConfigurationFoundException;
|
2017-03-10 23:25:12 +00:00
|
|
|
|
|
|
|
class OptionController extends Controller
|
|
|
|
{
|
2017-06-11 03:28:44 +00:00
|
|
|
/**
|
2017-08-09 04:24:55 +00:00
|
|
|
* @var \Prologue\Alerts\AlertsMessageBag
|
2017-06-11 03:28:44 +00:00
|
|
|
*/
|
2017-08-09 04:24:55 +00:00
|
|
|
protected $alert;
|
|
|
|
|
|
|
|
/**
|
2017-08-12 20:29:01 +00:00
|
|
|
* @var \Pterodactyl\Services\Services\Options\InstallScriptUpdateService
|
|
|
|
*/
|
|
|
|
protected $installScriptUpdateService;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Services\Services\Options\OptionCreationService
|
|
|
|
*/
|
|
|
|
protected $optionCreationService;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Services\Services\Options\OptionDeletionService
|
2017-08-09 04:24:55 +00:00
|
|
|
*/
|
2017-08-12 20:29:01 +00:00
|
|
|
protected $optionDeletionService;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Services\Services\Options\OptionUpdateService
|
|
|
|
*/
|
|
|
|
protected $optionUpdateService;
|
2017-08-09 04:24:55 +00:00
|
|
|
|
|
|
|
/**
|
2017-10-07 04:57:53 +00:00
|
|
|
* @var \Pterodactyl\Contracts\Repository\NestRepositoryInterface
|
2017-08-09 04:24:55 +00:00
|
|
|
*/
|
|
|
|
protected $serviceRepository;
|
|
|
|
|
|
|
|
/**
|
2017-10-07 04:57:53 +00:00
|
|
|
* @var \Pterodactyl\Contracts\Repository\EggRepositoryInterface
|
2017-08-09 04:24:55 +00:00
|
|
|
*/
|
2017-08-12 20:29:01 +00:00
|
|
|
protected $serviceOptionRepository;
|
2017-06-11 03:28:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* OptionController constructor.
|
2017-08-09 04:24:55 +00:00
|
|
|
*
|
2017-10-07 04:57:53 +00:00
|
|
|
* @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
|
2017-06-11 03:28:44 +00:00
|
|
|
*/
|
2017-08-09 04:24:55 +00:00
|
|
|
public function __construct(
|
|
|
|
AlertsMessageBag $alert,
|
2017-08-12 20:29:01 +00:00
|
|
|
InstallScriptUpdateService $installScriptUpdateService,
|
|
|
|
OptionCreationService $optionCreationService,
|
|
|
|
OptionDeletionService $optionDeletionService,
|
|
|
|
OptionUpdateService $optionUpdateService,
|
2017-10-07 04:57:53 +00:00
|
|
|
NestRepositoryInterface $serviceRepository,
|
|
|
|
EggRepositoryInterface $serviceOptionRepository
|
2017-08-09 04:24:55 +00:00
|
|
|
) {
|
|
|
|
$this->alert = $alert;
|
2017-08-12 20:29:01 +00:00
|
|
|
$this->installScriptUpdateService = $installScriptUpdateService;
|
|
|
|
$this->optionCreationService = $optionCreationService;
|
|
|
|
$this->optionDeletionService = $optionDeletionService;
|
|
|
|
$this->optionUpdateService = $optionUpdateService;
|
2017-08-09 04:24:55 +00:00
|
|
|
$this->serviceRepository = $serviceRepository;
|
2017-08-12 20:29:01 +00:00
|
|
|
$this->serviceOptionRepository = $serviceOptionRepository;
|
2017-06-11 03:28:44 +00:00
|
|
|
}
|
|
|
|
|
2017-03-12 05:00:06 +00:00
|
|
|
/**
|
|
|
|
* Handles request to view page for adding new option.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
2017-08-09 04:24:55 +00:00
|
|
|
public function create()
|
2017-03-12 05:00:06 +00:00
|
|
|
{
|
2017-08-09 04:24:55 +00:00
|
|
|
$services = $this->serviceRepository->getWithOptions();
|
2017-03-12 05:00:06 +00:00
|
|
|
Javascript::put(['services' => $services->keyBy('id')]);
|
|
|
|
|
|
|
|
return view('admin.services.options.new', ['services' => $services]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-08-09 04:24:55 +00:00
|
|
|
* Handle adding a new service option.
|
|
|
|
*
|
2017-08-22 03:10:48 +00:00
|
|
|
* @param \Pterodactyl\Http\Requests\Admin\Service\ServiceOptionFormRequest $request
|
2017-08-09 04:24:55 +00:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
2017-03-12 20:28:38 +00:00
|
|
|
*
|
2017-08-09 04:24:55 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
2017-03-12 05:00:06 +00:00
|
|
|
*/
|
2017-08-09 04:24:55 +00:00
|
|
|
public function store(ServiceOptionFormRequest $request)
|
2017-03-12 05:00:06 +00:00
|
|
|
{
|
2017-08-12 20:29:01 +00:00
|
|
|
try {
|
|
|
|
$option = $this->optionCreationService->handle($request->normalize());
|
|
|
|
$this->alert->success(trans('admin/services.options.notices.option_created'))->flash();
|
|
|
|
} catch (NoParentConfigurationFoundException $exception) {
|
|
|
|
$this->alert->danger($exception->getMessage())->flash();
|
|
|
|
|
|
|
|
return redirect()->back()->withInput();
|
|
|
|
}
|
2017-03-12 05:00:06 +00:00
|
|
|
|
2017-08-09 04:24:55 +00:00
|
|
|
return redirect()->route('admin.services.option.view', $option->id);
|
2017-03-12 05:00:06 +00:00
|
|
|
}
|
|
|
|
|
2017-03-12 20:28:38 +00:00
|
|
|
/**
|
2017-08-12 20:29:01 +00:00
|
|
|
* Delete a given option from the database.
|
2017-03-12 20:28:38 +00:00
|
|
|
*
|
2017-10-07 04:57:53 +00:00
|
|
|
* @param \Pterodactyl\Models\Egg $option
|
2017-03-19 23:36:50 +00:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
2017-08-21 00:23:50 +00:00
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Service\HasActiveServersException
|
2017-03-12 20:28:38 +00:00
|
|
|
*/
|
2017-10-07 04:57:53 +00:00
|
|
|
public function destroy(Egg $option)
|
2017-03-12 20:28:38 +00:00
|
|
|
{
|
2017-08-21 00:23:50 +00:00
|
|
|
$this->optionDeletionService->handle($option->id);
|
|
|
|
$this->alert->success(trans('admin/services.options.notices.option_deleted'))->flash();
|
2017-03-12 20:28:38 +00:00
|
|
|
|
2017-08-12 20:29:01 +00:00
|
|
|
return redirect()->route('admin.services.view', $option->service_id);
|
2017-03-12 05:00:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-08-12 20:29:01 +00:00
|
|
|
* Display option overview page.
|
2017-03-12 05:00:06 +00:00
|
|
|
*
|
2017-10-07 04:57:53 +00:00
|
|
|
* @param \Pterodactyl\Models\Egg $option
|
2017-03-12 05:00:06 +00:00
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
2017-10-07 04:57:53 +00:00
|
|
|
public function viewConfiguration(Egg $option)
|
2017-03-12 05:00:06 +00:00
|
|
|
{
|
2017-08-12 20:29:01 +00:00
|
|
|
return view('admin.services.options.view', ['option' => $option]);
|
2017-03-10 23:25:12 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 17:09:30 +00:00
|
|
|
/**
|
|
|
|
* Display script management page for an option.
|
|
|
|
*
|
2017-08-22 03:10:48 +00:00
|
|
|
* @param int $option
|
2017-03-18 17:09:30 +00:00
|
|
|
* @return \Illuminate\View\View
|
2017-08-12 20:29:01 +00:00
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
2017-03-18 17:09:30 +00:00
|
|
|
*/
|
2017-08-12 20:29:01 +00:00
|
|
|
public function viewScripts($option)
|
2017-03-18 17:09:30 +00:00
|
|
|
{
|
2017-10-04 01:18:27 +00:00
|
|
|
$option = $this->serviceOptionRepository->getWithCopyAttributes($option);
|
2017-08-12 20:29:01 +00:00
|
|
|
$copyOptions = $this->serviceOptionRepository->findWhere([
|
|
|
|
['copy_script_from', '=', null],
|
|
|
|
['service_id', '=', $option->service_id],
|
|
|
|
['id', '!=', $option],
|
|
|
|
]);
|
|
|
|
$relyScript = $this->serviceOptionRepository->findWhere([['copy_script_from', '=', $option]]);
|
2017-04-27 20:16:57 +00:00
|
|
|
|
|
|
|
return view('admin.services.options.scripts', [
|
2017-08-12 20:29:01 +00:00
|
|
|
'copyFromOptions' => $copyOptions,
|
|
|
|
'relyOnScript' => $relyScript,
|
2017-04-27 20:16:57 +00:00
|
|
|
'option' => $option,
|
|
|
|
]);
|
2017-03-18 17:09:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-12 05:00:06 +00:00
|
|
|
/**
|
|
|
|
* Handles POST when editing a configration for a service option.
|
|
|
|
*
|
2017-10-07 04:57:53 +00:00
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param \Pterodactyl\Models\Egg $option
|
2017-03-19 23:36:50 +00:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
2017-03-12 05:00:06 +00:00
|
|
|
*
|
2017-08-12 20:29:01 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
2017-03-12 05:00:06 +00:00
|
|
|
*/
|
2017-10-07 04:57:53 +00:00
|
|
|
public function editConfiguration(Request $request, Egg $option)
|
2017-03-12 05:00:06 +00:00
|
|
|
{
|
|
|
|
try {
|
2017-08-12 20:29:01 +00:00
|
|
|
$this->optionUpdateService->handle($option, $request->all());
|
|
|
|
$this->alert->success(trans('admin/services.options.notices.option_updated'))->flash();
|
|
|
|
} catch (NoParentConfigurationFoundException $exception) {
|
|
|
|
$this->alert->danger($exception->getMessage())->flash();
|
2017-03-12 05:00:06 +00:00
|
|
|
}
|
|
|
|
|
2017-08-12 20:29:01 +00:00
|
|
|
return redirect()->route('admin.services.option.view', $option->id);
|
2017-03-12 05:00:06 +00:00
|
|
|
}
|
2017-03-18 17:09:30 +00:00
|
|
|
|
|
|
|
/**
|
2017-06-11 03:28:44 +00:00
|
|
|
* Handles POST when updating script for a service option.
|
2017-03-18 17:09:30 +00:00
|
|
|
*
|
2017-08-22 03:10:48 +00:00
|
|
|
* @param \Pterodactyl\Http\Requests\Admin\Service\EditOptionScript $request
|
2017-10-07 04:57:53 +00:00
|
|
|
* @param \Pterodactyl\Models\Egg $option
|
2017-06-11 03:28:44 +00:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
2017-08-12 20:29:01 +00:00
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
2017-08-16 03:21:47 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
2017-03-18 17:09:30 +00:00
|
|
|
*/
|
2017-10-07 04:57:53 +00:00
|
|
|
public function updateScripts(EditOptionScript $request, Egg $option)
|
2017-03-18 17:09:30 +00:00
|
|
|
{
|
|
|
|
try {
|
2017-08-12 20:29:01 +00:00
|
|
|
$this->installScriptUpdateService->handle($option, $request->normalize());
|
|
|
|
$this->alert->success(trans('admin/services.options.notices.script_updated'))->flash();
|
|
|
|
} catch (InvalidCopyFromException $exception) {
|
|
|
|
$this->alert->danger($exception->getMessage())->flash();
|
2017-03-18 17:09:30 +00:00
|
|
|
}
|
|
|
|
|
2017-08-12 20:29:01 +00:00
|
|
|
return redirect()->route('admin.services.option.scripts', $option->id);
|
2017-03-18 17:09:30 +00:00
|
|
|
}
|
2017-03-10 23:25:12 +00:00
|
|
|
}
|