2016-11-16 01:20:32 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Pterodactyl - Panel
|
2017-01-24 22:57:08 +00:00
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
2016-11-16 01:20:32 +00:00
|
|
|
*
|
2017-09-26 02:43:01 +00:00
|
|
|
* This software is licensed under the terms of the MIT license.
|
|
|
|
* https://opensource.org/licenses/MIT
|
2016-11-16 01:20:32 +00:00
|
|
|
*/
|
2016-12-14 21:56:25 +00:00
|
|
|
|
2016-11-16 01:20:32 +00:00
|
|
|
namespace Pterodactyl\Http\Controllers\Admin;
|
|
|
|
|
2017-08-27 19:55:25 +00:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Pterodactyl\Models\Pack;
|
2017-08-20 01:40:00 +00:00
|
|
|
use Prologue\Alerts\AlertsMessageBag;
|
2020-09-13 16:59:54 +00:00
|
|
|
use Spatie\QueryBuilder\QueryBuilder;
|
2017-08-27 19:55:25 +00:00
|
|
|
use Pterodactyl\Http\Controllers\Controller;
|
2017-08-21 00:23:50 +00:00
|
|
|
use Pterodactyl\Services\Packs\ExportPackService;
|
2017-08-27 19:55:25 +00:00
|
|
|
use Pterodactyl\Services\Packs\PackUpdateService;
|
2017-08-20 01:40:00 +00:00
|
|
|
use Pterodactyl\Services\Packs\PackCreationService;
|
|
|
|
use Pterodactyl\Services\Packs\PackDeletionService;
|
2017-08-27 19:55:25 +00:00
|
|
|
use Pterodactyl\Http\Requests\Admin\PackFormRequest;
|
2017-08-20 01:40:00 +00:00
|
|
|
use Pterodactyl\Services\Packs\TemplateUploadService;
|
2017-10-07 04:57:53 +00:00
|
|
|
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
|
2017-08-27 19:55:25 +00:00
|
|
|
use Pterodactyl\Contracts\Repository\PackRepositoryInterface;
|
|
|
|
use Illuminate\Contracts\Config\Repository as ConfigRepository;
|
2016-11-16 01:20:32 +00:00
|
|
|
|
|
|
|
class PackController extends Controller
|
|
|
|
{
|
2017-08-20 01:40:00 +00:00
|
|
|
/**
|
|
|
|
* @var \Prologue\Alerts\AlertsMessageBag
|
|
|
|
*/
|
|
|
|
protected $alert;
|
|
|
|
|
2017-08-21 00:23:50 +00:00
|
|
|
/**
|
|
|
|
* @var \Illuminate\Contracts\Config\Repository
|
|
|
|
*/
|
|
|
|
protected $config;
|
|
|
|
|
2017-08-20 01:40:00 +00:00
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Services\Packs\PackCreationService
|
|
|
|
*/
|
|
|
|
protected $creationService;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Services\Packs\PackDeletionService
|
|
|
|
*/
|
|
|
|
protected $deletionService;
|
|
|
|
|
2017-08-21 00:23:50 +00:00
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Services\Packs\ExportPackService
|
|
|
|
*/
|
|
|
|
protected $exportService;
|
|
|
|
|
2017-08-20 01:40:00 +00:00
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Contracts\Repository\PackRepositoryInterface
|
|
|
|
*/
|
|
|
|
protected $repository;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Services\Packs\PackUpdateService
|
|
|
|
*/
|
2017-08-21 00:23:50 +00:00
|
|
|
protected $updateService;
|
|
|
|
|
|
|
|
/**
|
2017-10-07 04:57:53 +00:00
|
|
|
* @var \Pterodactyl\Contracts\Repository\NestRepositoryInterface
|
2017-08-21 00:23:50 +00:00
|
|
|
*/
|
|
|
|
protected $serviceRepository;
|
2017-08-20 01:40:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Services\Packs\TemplateUploadService
|
|
|
|
*/
|
|
|
|
protected $templateUploadService;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PackController constructor.
|
|
|
|
*
|
2019-09-06 04:32:57 +00:00
|
|
|
* @param \Prologue\Alerts\AlertsMessageBag $alert
|
|
|
|
* @param \Illuminate\Contracts\Config\Repository $config
|
|
|
|
* @param \Pterodactyl\Services\Packs\ExportPackService $exportService
|
|
|
|
* @param \Pterodactyl\Services\Packs\PackCreationService $creationService
|
|
|
|
* @param \Pterodactyl\Services\Packs\PackDeletionService $deletionService
|
2017-10-07 04:57:53 +00:00
|
|
|
* @param \Pterodactyl\Contracts\Repository\PackRepositoryInterface $repository
|
2019-09-06 04:32:57 +00:00
|
|
|
* @param \Pterodactyl\Services\Packs\PackUpdateService $updateService
|
2017-10-07 04:57:53 +00:00
|
|
|
* @param \Pterodactyl\Contracts\Repository\NestRepositoryInterface $serviceRepository
|
2019-09-06 04:32:57 +00:00
|
|
|
* @param \Pterodactyl\Services\Packs\TemplateUploadService $templateUploadService
|
2017-08-20 01:40:00 +00:00
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
AlertsMessageBag $alert,
|
2017-08-21 00:23:50 +00:00
|
|
|
ConfigRepository $config,
|
|
|
|
ExportPackService $exportService,
|
2017-08-20 01:40:00 +00:00
|
|
|
PackCreationService $creationService,
|
|
|
|
PackDeletionService $deletionService,
|
|
|
|
PackRepositoryInterface $repository,
|
2017-08-21 00:23:50 +00:00
|
|
|
PackUpdateService $updateService,
|
2017-10-07 04:57:53 +00:00
|
|
|
NestRepositoryInterface $serviceRepository,
|
2017-08-20 01:40:00 +00:00
|
|
|
TemplateUploadService $templateUploadService
|
|
|
|
) {
|
|
|
|
$this->alert = $alert;
|
2017-08-21 00:23:50 +00:00
|
|
|
$this->config = $config;
|
2017-08-20 01:40:00 +00:00
|
|
|
$this->creationService = $creationService;
|
|
|
|
$this->deletionService = $deletionService;
|
2017-08-21 00:23:50 +00:00
|
|
|
$this->exportService = $exportService;
|
2017-08-20 01:40:00 +00:00
|
|
|
$this->repository = $repository;
|
2017-08-21 00:23:50 +00:00
|
|
|
$this->updateService = $updateService;
|
|
|
|
$this->serviceRepository = $serviceRepository;
|
2017-08-20 01:40:00 +00:00
|
|
|
$this->templateUploadService = $templateUploadService;
|
|
|
|
}
|
|
|
|
|
2017-03-15 01:18:36 +00:00
|
|
|
/**
|
|
|
|
* Display listing of all packs on the system.
|
|
|
|
*
|
2017-08-22 03:10:48 +00:00
|
|
|
* @param \Illuminate\Http\Request $request
|
2017-03-15 01:18:36 +00:00
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function index(Request $request)
|
2016-11-16 01:20:32 +00:00
|
|
|
{
|
2017-08-21 00:23:50 +00:00
|
|
|
return view('admin.packs.index', [
|
2020-09-13 16:59:54 +00:00
|
|
|
'packs' => $this->repository->paginateWithEggAndServerCount(),
|
2017-08-21 00:23:50 +00:00
|
|
|
]);
|
2016-11-16 04:12:47 +00:00
|
|
|
}
|
|
|
|
|
2017-03-15 01:18:36 +00:00
|
|
|
/**
|
|
|
|
* Display new pack creation form.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\View\View
|
2017-10-07 23:08:19 +00:00
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
2017-03-15 01:18:36 +00:00
|
|
|
*/
|
2017-08-21 00:23:50 +00:00
|
|
|
public function create()
|
2016-11-16 04:12:47 +00:00
|
|
|
{
|
2017-03-15 01:18:36 +00:00
|
|
|
return view('admin.packs.new', [
|
2017-10-07 23:08:19 +00:00
|
|
|
'nests' => $this->serviceRepository->getWithEggs(),
|
2016-11-16 04:12:47 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2017-03-15 01:18:36 +00:00
|
|
|
/**
|
|
|
|
* Display new pack creation modal for use with template upload.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\View\View
|
2017-10-07 23:08:19 +00:00
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
2017-03-15 01:18:36 +00:00
|
|
|
*/
|
2017-08-21 00:23:50 +00:00
|
|
|
public function newTemplate()
|
2016-11-16 04:12:47 +00:00
|
|
|
{
|
2017-03-15 01:18:36 +00:00
|
|
|
return view('admin.packs.modal', [
|
2017-10-07 23:08:19 +00:00
|
|
|
'nests' => $this->serviceRepository->getWithEggs(),
|
2016-11-16 01:20:32 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2017-03-16 00:52:37 +00:00
|
|
|
/**
|
|
|
|
* Handle create pack request and route user to location.
|
|
|
|
*
|
2017-08-21 00:23:50 +00:00
|
|
|
* @param \Pterodactyl\Http\Requests\Admin\PackFormRequest $request
|
2017-03-16 00:52:37 +00:00
|
|
|
* @return \Illuminate\View\View
|
2017-08-20 01:40:00 +00:00
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Service\Pack\InvalidFileMimeTypeException
|
2017-10-09 04:50:52 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\Service\InvalidFileUploadException
|
2017-08-20 01:40:00 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\Service\Pack\InvalidPackArchiveFormatException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Service\Pack\UnreadableZipArchiveException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Service\Pack\ZipExtractionException
|
2017-03-16 00:52:37 +00:00
|
|
|
*/
|
2017-08-21 00:23:50 +00:00
|
|
|
public function store(PackFormRequest $request)
|
2016-11-16 01:20:32 +00:00
|
|
|
{
|
2017-12-17 19:07:38 +00:00
|
|
|
if ($request->filled('from_template')) {
|
2017-10-07 23:08:19 +00:00
|
|
|
$pack = $this->templateUploadService->handle($request->input('egg_id'), $request->file('file_upload'));
|
2017-08-20 01:40:00 +00:00
|
|
|
} else {
|
2017-08-21 00:23:50 +00:00
|
|
|
$pack = $this->creationService->handle($request->normalize(), $request->file('file_upload'));
|
2016-11-16 22:22:22 +00:00
|
|
|
}
|
2016-12-14 21:56:25 +00:00
|
|
|
|
2017-08-20 01:40:00 +00:00
|
|
|
$this->alert->success(trans('admin/pack.notices.pack_created'))->flash();
|
|
|
|
|
|
|
|
return redirect()->route('admin.packs.view', $pack->id);
|
2016-11-16 22:22:22 +00:00
|
|
|
}
|
2017-03-15 01:18:36 +00:00
|
|
|
|
2017-03-16 00:52:37 +00:00
|
|
|
/**
|
|
|
|
* Display pack view template to user.
|
|
|
|
*
|
2018-01-05 04:49:50 +00:00
|
|
|
* @param \Pterodactyl\Models\Pack $pack
|
2017-03-16 00:52:37 +00:00
|
|
|
* @return \Illuminate\View\View
|
2017-10-07 23:08:19 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
2017-03-16 00:52:37 +00:00
|
|
|
*/
|
2018-01-05 04:49:50 +00:00
|
|
|
public function view(Pack $pack)
|
2017-03-16 00:52:37 +00:00
|
|
|
{
|
|
|
|
return view('admin.packs.view', [
|
2018-01-05 04:49:50 +00:00
|
|
|
'pack' => $this->repository->loadServerData($pack),
|
2017-10-07 23:08:19 +00:00
|
|
|
'nests' => $this->serviceRepository->getWithEggs(),
|
2017-03-16 00:52:37 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle updating or deleting pack information.
|
|
|
|
*
|
2017-08-22 03:10:48 +00:00
|
|
|
* @param \Pterodactyl\Http\Requests\Admin\PackFormRequest $request
|
2019-09-06 04:32:57 +00:00
|
|
|
* @param \Pterodactyl\Models\Pack $pack
|
2017-03-19 23:36:50 +00:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
2017-08-21 00:23:50 +00:00
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Service\HasActiveServersException
|
2017-03-16 00:52:37 +00:00
|
|
|
*/
|
2017-08-21 00:23:50 +00:00
|
|
|
public function update(PackFormRequest $request, Pack $pack)
|
2017-03-16 00:52:37 +00:00
|
|
|
{
|
2017-08-21 00:23:50 +00:00
|
|
|
$this->updateService->handle($pack, $request->normalize());
|
|
|
|
$this->alert->success(trans('admin/pack.notices.pack_updated'))->flash();
|
2017-03-16 00:52:37 +00:00
|
|
|
|
2017-08-21 00:23:50 +00:00
|
|
|
return redirect()->route('admin.packs.view', $pack->id);
|
2017-03-16 00:52:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-08-21 00:23:50 +00:00
|
|
|
* Delete a pack if no servers are attached to it currently.
|
2017-03-16 00:52:37 +00:00
|
|
|
*
|
2017-08-22 03:10:48 +00:00
|
|
|
* @param \Pterodactyl\Models\Pack $pack
|
2017-08-21 00:23:50 +00:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Service\HasActiveServersException
|
2017-03-16 00:52:37 +00:00
|
|
|
*/
|
2017-08-21 00:23:50 +00:00
|
|
|
public function destroy(Pack $pack)
|
2017-03-16 00:52:37 +00:00
|
|
|
{
|
2017-08-21 00:23:50 +00:00
|
|
|
$this->deletionService->handle($pack->id);
|
|
|
|
$this->alert->success(trans('admin/pack.notices.pack_deleted', [
|
2017-03-16 00:52:37 +00:00
|
|
|
'name' => $pack->name,
|
2017-08-21 00:23:50 +00:00
|
|
|
]))->flash();
|
2017-03-16 00:52:37 +00:00
|
|
|
|
2017-08-21 00:23:50 +00:00
|
|
|
return redirect()->route('admin.packs');
|
|
|
|
}
|
2017-03-16 00:52:37 +00:00
|
|
|
|
2017-08-21 00:23:50 +00:00
|
|
|
/**
|
|
|
|
* Creates an archive of the pack and downloads it to the browser.
|
|
|
|
*
|
2017-08-22 03:10:48 +00:00
|
|
|
* @param \Pterodactyl\Models\Pack $pack
|
2019-09-06 04:32:57 +00:00
|
|
|
* @param bool|string $files
|
2017-08-21 00:23:50 +00:00
|
|
|
* @return \Symfony\Component\HttpFoundation\Response
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Service\Pack\ZipArchiveCreationException
|
|
|
|
*/
|
|
|
|
public function export(Pack $pack, $files = false)
|
|
|
|
{
|
|
|
|
$filename = $this->exportService->handle($pack, is_string($files));
|
2017-03-16 00:52:37 +00:00
|
|
|
|
2017-08-21 00:23:50 +00:00
|
|
|
if (is_string($files)) {
|
2017-03-16 00:52:37 +00:00
|
|
|
return response()->download($filename, 'pack-' . $pack->name . '.zip')->deleteFileAfterSend(true);
|
|
|
|
}
|
2017-08-21 00:23:50 +00:00
|
|
|
|
|
|
|
return response()->download($filename, 'pack-' . $pack->name . '.json', [
|
|
|
|
'Content-Type' => 'application/json',
|
|
|
|
])->deleteFileAfterSend(true);
|
2017-03-16 00:52:37 +00:00
|
|
|
}
|
2016-11-16 01:20:32 +00:00
|
|
|
}
|