Remove all references of packs from the Panel
This commit is contained in:
parent
f1978683cc
commit
3c7ffaaadb
60 changed files with 129 additions and 2517 deletions
|
@ -34,7 +34,6 @@ class AdminAcl
|
|||
const RESOURCE_EGGS = 'eggs';
|
||||
const RESOURCE_DATABASE_HOSTS = 'database_hosts';
|
||||
const RESOURCE_SERVER_DATABASES = 'server_databases';
|
||||
const RESOURCE_PACKS = 'packs';
|
||||
|
||||
/**
|
||||
* Determine if an API key has permission to perform a specific read/write operation.
|
||||
|
|
|
@ -1,97 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* This software is licensed under the terms of the MIT license.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Services\Packs;
|
||||
|
||||
use ZipArchive;
|
||||
use Pterodactyl\Models\Pack;
|
||||
use Pterodactyl\Contracts\Repository\PackRepositoryInterface;
|
||||
use Illuminate\Contracts\Filesystem\Factory as FilesystemFactory;
|
||||
use Pterodactyl\Exceptions\Service\Pack\ZipArchiveCreationException;
|
||||
|
||||
class ExportPackService
|
||||
{
|
||||
/**
|
||||
* @var \ZipArchive
|
||||
*/
|
||||
protected $archive;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\PackRepositoryInterface
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Filesystem\Factory
|
||||
*/
|
||||
protected $storage;
|
||||
|
||||
/**
|
||||
* ExportPackService constructor.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Filesystem\Factory $storage
|
||||
* @param \Pterodactyl\Contracts\Repository\PackRepositoryInterface $repository
|
||||
* @param \ZipArchive $archive
|
||||
*/
|
||||
public function __construct(
|
||||
FilesystemFactory $storage,
|
||||
PackRepositoryInterface $repository,
|
||||
ZipArchive $archive
|
||||
) {
|
||||
$this->archive = $archive;
|
||||
$this->repository = $repository;
|
||||
$this->storage = $storage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare a pack for export.
|
||||
*
|
||||
* @param int|\Pterodactyl\Models\Pack $pack
|
||||
* @param bool $files
|
||||
* @return string
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
* @throws \Pterodactyl\Exceptions\Service\Pack\ZipArchiveCreationException
|
||||
*/
|
||||
public function handle($pack, $files = false)
|
||||
{
|
||||
if (! $pack instanceof Pack) {
|
||||
$pack = $this->repository->find($pack);
|
||||
}
|
||||
|
||||
$json = [
|
||||
'name' => $pack->name,
|
||||
'version' => $pack->version,
|
||||
'description' => $pack->description,
|
||||
'selectable' => $pack->selectable,
|
||||
'visible' => $pack->visible,
|
||||
'locked' => $pack->locked,
|
||||
];
|
||||
|
||||
$filename = tempnam(sys_get_temp_dir(), 'pterodactyl_');
|
||||
if ($files) {
|
||||
if (! $this->archive->open($filename, $this->archive::CREATE)) {
|
||||
throw new ZipArchiveCreationException;
|
||||
}
|
||||
|
||||
foreach ($this->storage->disk()->files('packs/' . $pack->uuid) as $file) {
|
||||
$this->archive->addFile(storage_path('app/' . $file), basename(storage_path('app/' . $file)));
|
||||
}
|
||||
|
||||
$this->archive->addFromString('import.json', json_encode($json, JSON_PRETTY_PRINT));
|
||||
$this->archive->close();
|
||||
} else {
|
||||
$fp = fopen($filename, 'a+');
|
||||
fwrite($fp, json_encode($json, JSON_PRETTY_PRINT));
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
return $filename;
|
||||
}
|
||||
}
|
|
@ -1,104 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* This software is licensed under the terms of the MIT license.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Services\Packs;
|
||||
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Pterodactyl\Contracts\Repository\PackRepositoryInterface;
|
||||
use Pterodactyl\Exceptions\Service\InvalidFileUploadException;
|
||||
use Illuminate\Contracts\Filesystem\Factory as FilesystemFactory;
|
||||
use Pterodactyl\Exceptions\Service\Pack\InvalidFileMimeTypeException;
|
||||
|
||||
class PackCreationService
|
||||
{
|
||||
const VALID_UPLOAD_TYPES = [
|
||||
'application/gzip',
|
||||
'application/x-gzip',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Database\ConnectionInterface
|
||||
*/
|
||||
protected $connection;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\PackRepositoryInterface
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Filesystem\Factory
|
||||
*/
|
||||
protected $storage;
|
||||
|
||||
/**
|
||||
* PackCreationService constructor.
|
||||
*
|
||||
* @param \Illuminate\Database\ConnectionInterface $connection
|
||||
* @param \Illuminate\Contracts\Filesystem\Factory $storage
|
||||
* @param \Pterodactyl\Contracts\Repository\PackRepositoryInterface $repository
|
||||
*/
|
||||
public function __construct(
|
||||
ConnectionInterface $connection,
|
||||
FilesystemFactory $storage,
|
||||
PackRepositoryInterface $repository
|
||||
) {
|
||||
$this->connection = $connection;
|
||||
$this->repository = $repository;
|
||||
$this->storage = $storage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new service pack to the system.
|
||||
*
|
||||
* @param array $data
|
||||
* @param \Illuminate\Http\UploadedFile|null $file
|
||||
* @return \Pterodactyl\Models\Pack
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Service\Pack\InvalidFileMimeTypeException
|
||||
* @throws \Pterodactyl\Exceptions\Service\InvalidFileUploadException
|
||||
*/
|
||||
public function handle(array $data, UploadedFile $file = null)
|
||||
{
|
||||
if (! is_null($file)) {
|
||||
if (! $file->isValid()) {
|
||||
throw new InvalidFileUploadException(trans('exceptions.packs.invalid_upload'));
|
||||
}
|
||||
|
||||
if (! in_array($file->getMimeType(), self::VALID_UPLOAD_TYPES)) {
|
||||
throw new InvalidFileMimeTypeException(trans('exceptions.packs.invalid_mime', [
|
||||
'type' => implode(', ', self::VALID_UPLOAD_TYPES),
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
||||
// Transform values to boolean
|
||||
$data['selectable'] = isset($data['selectable']);
|
||||
$data['visible'] = isset($data['visible']);
|
||||
$data['locked'] = isset($data['locked']);
|
||||
|
||||
$this->connection->beginTransaction();
|
||||
$pack = $this->repository->create(array_merge(
|
||||
['uuid' => Uuid::uuid4()],
|
||||
$data
|
||||
));
|
||||
|
||||
$this->storage->disk()->makeDirectory('packs/' . $pack->uuid);
|
||||
if (! is_null($file)) {
|
||||
$file->storeAs('packs/' . $pack->uuid, 'archive.tar.gz');
|
||||
}
|
||||
|
||||
$this->connection->commit();
|
||||
|
||||
return $pack;
|
||||
}
|
||||
}
|
|
@ -1,85 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* This software is licensed under the terms of the MIT license.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Services\Packs;
|
||||
|
||||
use Pterodactyl\Models\Pack;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Pterodactyl\Contracts\Repository\PackRepositoryInterface;
|
||||
use Pterodactyl\Exceptions\Service\HasActiveServersException;
|
||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
||||
use Illuminate\Contracts\Filesystem\Factory as FilesystemFactory;
|
||||
|
||||
class PackDeletionService
|
||||
{
|
||||
/**
|
||||
* @var \Illuminate\Database\ConnectionInterface
|
||||
*/
|
||||
protected $connection;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\PackRepositoryInterface
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
|
||||
*/
|
||||
protected $serverRepository;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Filesystem\Factory
|
||||
*/
|
||||
protected $storage;
|
||||
|
||||
/**
|
||||
* PackDeletionService constructor.
|
||||
*
|
||||
* @param \Illuminate\Database\ConnectionInterface $connection
|
||||
* @param \Illuminate\Contracts\Filesystem\Factory $storage
|
||||
* @param \Pterodactyl\Contracts\Repository\PackRepositoryInterface $repository
|
||||
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $serverRepository
|
||||
*/
|
||||
public function __construct(
|
||||
ConnectionInterface $connection,
|
||||
FilesystemFactory $storage,
|
||||
PackRepositoryInterface $repository,
|
||||
ServerRepositoryInterface $serverRepository
|
||||
) {
|
||||
$this->connection = $connection;
|
||||
$this->repository = $repository;
|
||||
$this->serverRepository = $serverRepository;
|
||||
$this->storage = $storage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a pack from the database as well as the archive stored on the server.
|
||||
*
|
||||
* @param int|\Pterodactyl\Models\Pack $pack
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Service\HasActiveServersException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function handle($pack)
|
||||
{
|
||||
if (! $pack instanceof Pack) {
|
||||
$pack = $this->repository->setColumns(['id', 'uuid'])->find($pack);
|
||||
}
|
||||
|
||||
$count = $this->serverRepository->findCountWhere([['pack_id', '=', $pack->id]]);
|
||||
if ($count !== 0) {
|
||||
throw new HasActiveServersException(trans('exceptions.packs.delete_has_servers'));
|
||||
}
|
||||
|
||||
$this->connection->beginTransaction();
|
||||
$this->repository->delete($pack->id);
|
||||
$this->storage->disk()->deleteDirectory('packs/' . $pack->uuid);
|
||||
$this->connection->commit();
|
||||
}
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* This software is licensed under the terms of the MIT license.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Services\Packs;
|
||||
|
||||
use Pterodactyl\Models\Pack;
|
||||
use Pterodactyl\Contracts\Repository\PackRepositoryInterface;
|
||||
use Pterodactyl\Exceptions\Service\HasActiveServersException;
|
||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
||||
|
||||
class PackUpdateService
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\PackRepositoryInterface
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
|
||||
*/
|
||||
protected $serverRepository;
|
||||
|
||||
/**
|
||||
* PackUpdateService constructor.
|
||||
*
|
||||
* @param \Pterodactyl\Contracts\Repository\PackRepositoryInterface $repository
|
||||
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $serverRepository
|
||||
*/
|
||||
public function __construct(
|
||||
PackRepositoryInterface $repository,
|
||||
ServerRepositoryInterface $serverRepository
|
||||
) {
|
||||
$this->repository = $repository;
|
||||
$this->serverRepository = $serverRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a pack.
|
||||
*
|
||||
* @param int|\Pterodactyl\Models\Pack $pack
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Service\HasActiveServersException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function handle($pack, array $data)
|
||||
{
|
||||
if (! $pack instanceof Pack) {
|
||||
$pack = $this->repository->setColumns(['id', 'egg_id'])->find($pack);
|
||||
}
|
||||
|
||||
if ((int) array_get($data, 'egg_id', $pack->egg_id) !== $pack->egg_id) {
|
||||
$count = $this->serverRepository->findCountWhere([['pack_id', '=', $pack->id]]);
|
||||
|
||||
if ($count !== 0) {
|
||||
throw new HasActiveServersException(trans('exceptions.packs.update_has_servers'));
|
||||
}
|
||||
}
|
||||
|
||||
// Transform values to boolean
|
||||
$data['selectable'] = isset($data['selectable']);
|
||||
$data['visible'] = isset($data['visible']);
|
||||
$data['locked'] = isset($data['locked']);
|
||||
|
||||
return $this->repository->withoutFreshModel()->update($pack->id, $data);
|
||||
}
|
||||
}
|
|
@ -1,125 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* This software is licensed under the terms of the MIT license.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Services\Packs;
|
||||
|
||||
use ZipArchive;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Pterodactyl\Exceptions\Service\InvalidFileUploadException;
|
||||
use Pterodactyl\Exceptions\Service\Pack\ZipExtractionException;
|
||||
use Pterodactyl\Exceptions\Service\Pack\InvalidFileMimeTypeException;
|
||||
use Pterodactyl\Exceptions\Service\Pack\UnreadableZipArchiveException;
|
||||
use Pterodactyl\Exceptions\Service\Pack\InvalidPackArchiveFormatException;
|
||||
|
||||
class TemplateUploadService
|
||||
{
|
||||
const VALID_UPLOAD_TYPES = [
|
||||
'application/zip',
|
||||
'text/plain',
|
||||
'application/json',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var \ZipArchive
|
||||
*/
|
||||
protected $archive;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Packs\PackCreationService
|
||||
*/
|
||||
protected $creationService;
|
||||
|
||||
/**
|
||||
* TemplateUploadService constructor.
|
||||
*
|
||||
* @param \Pterodactyl\Services\Packs\PackCreationService $creationService
|
||||
* @param \ZipArchive $archive
|
||||
*/
|
||||
public function __construct(
|
||||
PackCreationService $creationService,
|
||||
ZipArchive $archive
|
||||
) {
|
||||
$this->archive = $archive;
|
||||
$this->creationService = $creationService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process an uploaded file to create a new pack from a JSON or ZIP format.
|
||||
*
|
||||
* @param int $egg
|
||||
* @param \Illuminate\Http\UploadedFile $file
|
||||
* @return \Pterodactyl\Models\Pack
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Service\Pack\ZipExtractionException
|
||||
* @throws \Pterodactyl\Exceptions\Service\InvalidFileUploadException
|
||||
* @throws \Pterodactyl\Exceptions\Service\Pack\InvalidFileMimeTypeException
|
||||
* @throws \Pterodactyl\Exceptions\Service\Pack\UnreadableZipArchiveException
|
||||
* @throws \Pterodactyl\Exceptions\Service\Pack\InvalidPackArchiveFormatException
|
||||
*/
|
||||
public function handle($egg, UploadedFile $file)
|
||||
{
|
||||
if (! $file->isValid()) {
|
||||
throw new InvalidFileUploadException(trans('exceptions.packs.invalid_upload'));
|
||||
}
|
||||
|
||||
if (! in_array($file->getMimeType(), self::VALID_UPLOAD_TYPES)) {
|
||||
throw new InvalidFileMimeTypeException(trans('exceptions.packs.invalid_mime', [
|
||||
'type' => implode(', ', self::VALID_UPLOAD_TYPES),
|
||||
]));
|
||||
}
|
||||
|
||||
if ($file->getMimeType() === 'application/zip') {
|
||||
return $this->handleArchive($egg, $file);
|
||||
} else {
|
||||
$json = json_decode($file->openFile()->fread($file->getSize()), true);
|
||||
$json['egg_id'] = $egg;
|
||||
|
||||
return $this->creationService->handle($json);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a ZIP file to create a pack and stored archive.
|
||||
*
|
||||
* @param int $egg
|
||||
* @param \Illuminate\Http\UploadedFile $file
|
||||
* @return \Pterodactyl\Models\Pack
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Service\Pack\ZipExtractionException
|
||||
* @throws \Pterodactyl\Exceptions\Service\InvalidFileUploadException
|
||||
* @throws \Pterodactyl\Exceptions\Service\Pack\InvalidFileMimeTypeException
|
||||
* @throws \Pterodactyl\Exceptions\Service\Pack\UnreadableZipArchiveException
|
||||
* @throws \Pterodactyl\Exceptions\Service\Pack\InvalidPackArchiveFormatException
|
||||
*/
|
||||
protected function handleArchive($egg, $file)
|
||||
{
|
||||
if (! $this->archive->open($file->getRealPath())) {
|
||||
throw new UnreadableZipArchiveException(trans('exceptions.packs.unreadable'));
|
||||
}
|
||||
|
||||
if (! $this->archive->locateName('import.json') || ! $this->archive->locateName('archive.tar.gz')) {
|
||||
throw new InvalidPackArchiveFormatException(trans('exceptions.packs.invalid_archive_exception'));
|
||||
}
|
||||
|
||||
$json = json_decode($this->archive->getFromName('import.json'), true);
|
||||
$json['egg_id'] = $egg;
|
||||
|
||||
$pack = $this->creationService->handle($json);
|
||||
if (! $this->archive->extractTo(storage_path('app/packs/' . $pack->uuid), 'archive.tar.gz')) {
|
||||
// @todo delete the pack that was created.
|
||||
throw new ZipExtractionException(trans('exceptions.packs.zip_extraction'));
|
||||
}
|
||||
|
||||
$this->archive->close();
|
||||
|
||||
return $pack;
|
||||
}
|
||||
}
|
|
@ -15,7 +15,7 @@ use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
|||
|
||||
class ServerConfigurationStructureService
|
||||
{
|
||||
const REQUIRED_RELATIONS = ['allocation', 'allocations', 'pack', 'egg'];
|
||||
const REQUIRED_RELATIONS = ['allocation', 'allocations', 'egg'];
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Servers\EnvironmentService
|
||||
|
@ -139,7 +139,6 @@ class ServerConfigurationStructureService
|
|||
],
|
||||
'service' => [
|
||||
'egg' => $server->egg->uuid,
|
||||
'pack' => $server->pack ? $server->pack->uuid : null,
|
||||
'skip_scripts' => $server->skip_scripts,
|
||||
],
|
||||
'rebuild' => false,
|
||||
|
|
|
@ -246,7 +246,6 @@ class ServerCreationService
|
|||
'allocation_id' => Arr::get($data, 'allocation_id'),
|
||||
'nest_id' => Arr::get($data, 'nest_id'),
|
||||
'egg_id' => Arr::get($data, 'egg_id'),
|
||||
'pack_id' => empty($data['pack_id']) ? null : $data['pack_id'],
|
||||
'startup' => Arr::get($data, 'startup'),
|
||||
'image' => Arr::get($data, 'image'),
|
||||
'database_limit' => Arr::get($data, 'database_limit') ?? 0,
|
||||
|
|
|
@ -140,7 +140,6 @@ class StartupModificationService
|
|||
'startup' => array_get($data, 'startup', $server->startup),
|
||||
'nest_id' => array_get($data, 'nest_id', $server->nest_id),
|
||||
'egg_id' => array_get($data, 'egg_id', $server->egg_id),
|
||||
'pack_id' => array_get($data, 'pack_id', $server->pack_id) > 0 ? array_get($data, 'pack_id', $server->pack_id) : null,
|
||||
'skip_scripts' => array_get($data, 'skip_scripts') ?? isset($data['skip_scripts']),
|
||||
'image' => array_get($data, 'docker_image', $server->image),
|
||||
]);
|
||||
|
|
Reference in a new issue