2016-02-15 20:21:28 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Pterodactyl - Panel
|
2017-01-24 22:57:08 +00:00
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
2016-02-15 20:21:28 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
2016-12-07 22:46:38 +00:00
|
|
|
|
2016-02-15 20:21:28 +00:00
|
|
|
namespace Pterodactyl\Http\Controllers\Admin;
|
|
|
|
|
2017-08-16 03:21:47 +00:00
|
|
|
use Pterodactyl\Models\Service;
|
|
|
|
use Prologue\Alerts\AlertsMessageBag;
|
2016-02-15 20:21:28 +00:00
|
|
|
use Pterodactyl\Http\Controllers\Controller;
|
2017-08-16 03:21:47 +00:00
|
|
|
use Pterodactyl\Services\Services\ServiceUpdateService;
|
|
|
|
use Pterodactyl\Services\Services\ServiceCreationService;
|
|
|
|
use Pterodactyl\Services\Services\ServiceDeletionService;
|
|
|
|
use Pterodactyl\Exceptions\Services\HasActiveServersException;
|
|
|
|
use Pterodactyl\Http\Requests\Admin\Service\ServiceFormRequest;
|
|
|
|
use Pterodactyl\Contracts\Repository\ServiceRepositoryInterface;
|
|
|
|
use Pterodactyl\Http\Requests\Admin\Service\ServiceFunctionsFormRequest;
|
2016-02-15 20:21:28 +00:00
|
|
|
|
|
|
|
class ServiceController extends Controller
|
|
|
|
{
|
2017-08-16 03:21:47 +00:00
|
|
|
/**
|
|
|
|
* @var \Prologue\Alerts\AlertsMessageBag
|
|
|
|
*/
|
|
|
|
protected $alert;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Services\Services\ServiceCreationService
|
|
|
|
*/
|
|
|
|
protected $creationService;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Services\Services\ServiceDeletionService
|
|
|
|
*/
|
|
|
|
protected $deletionService;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Contracts\Repository\ServiceRepositoryInterface
|
|
|
|
*/
|
|
|
|
protected $repository;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Services\Services\ServiceUpdateService
|
|
|
|
*/
|
|
|
|
protected $updateService;
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
AlertsMessageBag $alert,
|
|
|
|
ServiceCreationService $creationService,
|
|
|
|
ServiceDeletionService $deletionService,
|
|
|
|
ServiceRepositoryInterface $repository,
|
|
|
|
ServiceUpdateService $updateService
|
|
|
|
) {
|
|
|
|
$this->alert = $alert;
|
|
|
|
$this->creationService = $creationService;
|
|
|
|
$this->deletionService = $deletionService;
|
|
|
|
$this->repository = $repository;
|
|
|
|
$this->updateService = $updateService;
|
|
|
|
}
|
|
|
|
|
2017-03-10 23:25:12 +00:00
|
|
|
/**
|
|
|
|
* Display service overview page.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
2017-08-16 03:21:47 +00:00
|
|
|
public function index()
|
2016-02-15 20:21:28 +00:00
|
|
|
{
|
|
|
|
return view('admin.services.index', [
|
2017-08-16 03:21:47 +00:00
|
|
|
'services' => $this->repository->getWithOptions(),
|
2016-02-15 20:21:28 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2017-03-10 23:25:12 +00:00
|
|
|
/**
|
|
|
|
* Display create service page.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
2017-08-16 03:21:47 +00:00
|
|
|
public function create()
|
2016-02-15 20:21:28 +00:00
|
|
|
{
|
2016-02-20 21:02:49 +00:00
|
|
|
return view('admin.services.new');
|
2016-02-15 20:21:28 +00:00
|
|
|
}
|
|
|
|
|
2017-03-10 23:25:12 +00:00
|
|
|
/**
|
|
|
|
* Return base view for a service.
|
|
|
|
*
|
2017-08-16 03:21:47 +00:00
|
|
|
* @param int $service
|
2017-03-10 23:25:12 +00:00
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
2017-08-16 03:21:47 +00:00
|
|
|
public function view($service)
|
2016-02-15 20:21:28 +00:00
|
|
|
{
|
|
|
|
return view('admin.services.view', [
|
2017-08-16 03:21:47 +00:00
|
|
|
'service' => $this->repository->getWithOptionServers($service),
|
2016-02-15 20:21:28 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2017-03-12 19:59:17 +00:00
|
|
|
/**
|
|
|
|
* Return function editing view for a service.
|
|
|
|
*
|
2017-08-16 03:21:47 +00:00
|
|
|
* @param \Pterodactyl\Models\Service $service
|
2017-03-12 19:59:17 +00:00
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
2017-08-16 03:21:47 +00:00
|
|
|
public function viewFunctions(Service $service)
|
2017-03-12 19:59:17 +00:00
|
|
|
{
|
2017-08-16 03:21:47 +00:00
|
|
|
return view('admin.services.functions', ['service' => $service]);
|
2017-03-12 19:59:17 +00:00
|
|
|
}
|
|
|
|
|
2017-03-10 23:25:12 +00:00
|
|
|
/**
|
|
|
|
* Handle post action for new service.
|
|
|
|
*
|
2017-08-16 03:21:47 +00:00
|
|
|
* @param \Pterodactyl\Http\Requests\Admin\Service\ServiceFormRequest $request
|
2017-03-19 23:36:50 +00:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
2017-08-16 03:21:47 +00:00
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
2017-03-10 23:25:12 +00:00
|
|
|
*/
|
2017-08-16 03:21:47 +00:00
|
|
|
public function store(ServiceFormRequest $request)
|
2016-02-15 20:21:28 +00:00
|
|
|
{
|
2017-08-16 03:21:47 +00:00
|
|
|
$service = $this->creationService->handle($request->normalize());
|
|
|
|
$this->alert->success(trans('admin/services.notices.service_created', ['name' => $service->name]))->flash();
|
2016-12-07 22:46:38 +00:00
|
|
|
|
2017-08-16 03:21:47 +00:00
|
|
|
return redirect()->route('admin.services.view', $service->id);
|
2016-02-15 20:21:28 +00:00
|
|
|
}
|
|
|
|
|
2017-03-10 23:25:12 +00:00
|
|
|
/**
|
|
|
|
* Edits configuration for a specific service.
|
|
|
|
*
|
2017-08-16 03:21:47 +00:00
|
|
|
* @param \Pterodactyl\Http\Requests\Admin\Service\ServiceFormRequest $request
|
|
|
|
* @param \Pterodactyl\Models\Service $service
|
2017-03-19 23:36:50 +00:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
2017-08-16 03:21:47 +00:00
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
2017-03-10 23:25:12 +00:00
|
|
|
*/
|
2017-08-16 03:21:47 +00:00
|
|
|
public function update(ServiceFormRequest $request, Service $service)
|
2016-02-20 21:45:13 +00:00
|
|
|
{
|
2017-08-16 03:21:47 +00:00
|
|
|
$this->updateService->handle($service->id, $request->normalize());
|
|
|
|
$this->alert->success(trans('admin/services.notices.service_updated'))->flash();
|
2016-02-20 21:45:13 +00:00
|
|
|
|
2017-08-16 03:21:47 +00:00
|
|
|
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\Service $service
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
|
|
|
*/
|
|
|
|
public function updateFunctions(ServiceFunctionsFormRequest $request, Service $service)
|
|
|
|
{
|
|
|
|
$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\Service $service
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function destroy(Service $service)
|
|
|
|
{
|
2016-02-20 21:45:13 +00:00
|
|
|
try {
|
2017-08-16 03:21:47 +00:00
|
|
|
$this->deletionService->handle($service->id);
|
|
|
|
$this->alert->success(trans('admin/services.notices.service_deleted'))->flash();
|
|
|
|
} catch (HasActiveServersException $exception) {
|
|
|
|
$this->alert->danger($exception->getMessage())->flash();
|
|
|
|
|
|
|
|
return redirect()->back();
|
2016-02-21 05:38:03 +00:00
|
|
|
}
|
2016-12-07 22:46:38 +00:00
|
|
|
|
2017-08-16 03:21:47 +00:00
|
|
|
return redirect()->route('admin.services');
|
2016-02-21 05:38:03 +00:00
|
|
|
}
|
2016-02-15 20:21:28 +00:00
|
|
|
}
|