This breaks literally the entire panel.
This commit is contained in:
parent
344c1a9885
commit
df87ea0867
88 changed files with 1205 additions and 992 deletions
76
app/Services/Eggs/Sharing/EggExporterService.php
Normal file
76
app/Services/Eggs/Sharing/EggExporterService.php
Normal file
|
@ -0,0 +1,76 @@
|
|||
<?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\Eggs\Sharing;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
|
||||
|
||||
class EggExporterService
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\EggRepositoryInterface
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* EggExporterService constructor.
|
||||
*
|
||||
* @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $repository
|
||||
*/
|
||||
public function __construct(EggRepositoryInterface $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a JSON representation of an egg and its variables.
|
||||
*
|
||||
* @param int $egg
|
||||
* @return string
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function handle(int $egg): string
|
||||
{
|
||||
$egg = $this->repository->getWithExportAttributes($egg);
|
||||
|
||||
$struct = [
|
||||
'_comment' => 'DO NOT EDIT: FILE GENERATED AUTOMATICALLY BY PTERODACTYL PANEL - PTERODACTYL.IO',
|
||||
'meta' => [
|
||||
'version' => 'PTDL_v1',
|
||||
],
|
||||
'exported_at' => Carbon::now()->toIso8601String(),
|
||||
'name' => $egg->name,
|
||||
'author' => $egg->author,
|
||||
'description' => $egg->description,
|
||||
'image' => $egg->docker_image,
|
||||
'config' => [
|
||||
'files' => $egg->inherit_config_files,
|
||||
'startup' => $egg->inherit_config_startup,
|
||||
'logs' => $egg->inherit_config_logs,
|
||||
'stop' => $egg->inherit_config_stop,
|
||||
],
|
||||
'scripts' => [
|
||||
'installation' => [
|
||||
'script' => $egg->copy_script_install,
|
||||
'container' => $egg->copy_script_container,
|
||||
'entrypoint' => $egg->copy_script_entry,
|
||||
],
|
||||
],
|
||||
'variables' => $egg->variables->transform(function ($item) {
|
||||
return collect($item->toArray())->except([
|
||||
'id', 'egg_id', 'created_at', 'updated_at',
|
||||
])->toArray();
|
||||
}),
|
||||
];
|
||||
|
||||
return json_encode($struct, JSON_PRETTY_PRINT);
|
||||
}
|
||||
}
|
|
@ -10,16 +10,15 @@
|
|||
namespace Pterodactyl\Services\Services\Sharing;
|
||||
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Pterodactyl\Models\Egg;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Pterodactyl\Models\ServiceOption;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Pterodactyl\Contracts\Repository\ServiceRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
|
||||
use Pterodactyl\Exceptions\Service\Pack\InvalidFileUploadException;
|
||||
use Pterodactyl\Contracts\Repository\ServiceOptionRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\ServiceVariableRepositoryInterface;
|
||||
use Pterodactyl\Exceptions\Service\ServiceOption\DuplicateOptionTagException;
|
||||
use Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface;
|
||||
|
||||
class ServiceOptionImporterService
|
||||
class EggImporterService
|
||||
{
|
||||
/**
|
||||
* @var \Illuminate\Database\ConnectionInterface
|
||||
|
@ -27,77 +26,71 @@ class ServiceOptionImporterService
|
|||
protected $connection;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\ServiceOptionRepositoryInterface
|
||||
* @var \Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface
|
||||
*/
|
||||
protected $eggVariableRepository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\EggRepositoryInterface
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\ServiceRepositoryInterface
|
||||
* @var \Pterodactyl\Contracts\Repository\NestRepositoryInterface
|
||||
*/
|
||||
protected $serviceRepository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\ServiceVariableRepositoryInterface
|
||||
*/
|
||||
protected $serviceVariableRepository;
|
||||
|
||||
/**
|
||||
* XMLImporterService constructor.
|
||||
* EggImporterService constructor.
|
||||
*
|
||||
* @param \Illuminate\Database\ConnectionInterface $connection
|
||||
* @param \Pterodactyl\Contracts\Repository\ServiceRepositoryInterface $serviceRepository
|
||||
* @param \Pterodactyl\Contracts\Repository\ServiceOptionRepositoryInterface $repository
|
||||
* @param \Pterodactyl\Contracts\Repository\ServiceVariableRepositoryInterface $serviceVariableRepository
|
||||
* @param \Illuminate\Database\ConnectionInterface $connection
|
||||
* @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $repository
|
||||
* @param \Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface $eggVariableRepository
|
||||
* @param \Pterodactyl\Contracts\Repository\NestRepositoryInterface $serviceRepository
|
||||
*/
|
||||
public function __construct(
|
||||
ConnectionInterface $connection,
|
||||
ServiceRepositoryInterface $serviceRepository,
|
||||
ServiceOptionRepositoryInterface $repository,
|
||||
ServiceVariableRepositoryInterface $serviceVariableRepository
|
||||
EggRepositoryInterface $repository,
|
||||
EggVariableRepositoryInterface $eggVariableRepository,
|
||||
NestRepositoryInterface $serviceRepository
|
||||
) {
|
||||
$this->connection = $connection;
|
||||
$this->repository = $repository;
|
||||
$this->serviceRepository = $serviceRepository;
|
||||
$this->serviceVariableRepository = $serviceVariableRepository;
|
||||
$this->eggVariableRepository = $eggVariableRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Take an uploaded XML file and parse it into a new service option.
|
||||
* Take an uploaded JSON file and parse it into a new egg.
|
||||
*
|
||||
* @param \Illuminate\Http\UploadedFile $file
|
||||
* @param int $service
|
||||
* @return \Pterodactyl\Models\ServiceOption
|
||||
* @param int $nest
|
||||
* @return \Pterodactyl\Models\Egg
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
* @throws \Pterodactyl\Exceptions\Service\Pack\InvalidFileUploadException
|
||||
*/
|
||||
public function handle(UploadedFile $file, int $service): ServiceOption
|
||||
public function handle(UploadedFile $file, int $nest): Egg
|
||||
{
|
||||
if (! $file->isValid() || ! $file->isFile()) {
|
||||
throw new InvalidFileUploadException(trans('exceptions.service.exporter.import_file_error'));
|
||||
throw new InvalidFileUploadException(trans('exceptions.egg.importer.file_error'));
|
||||
}
|
||||
|
||||
$parsed = json_decode($file->openFile()->fread($file->getSize()));
|
||||
|
||||
if (object_get($parsed, 'meta.version') !== 'PTDL_v1') {
|
||||
throw new InvalidFileUploadException(trans('exceptions.service.exporter.invalid_json_provided'));
|
||||
throw new InvalidFileUploadException(trans('exceptions.egg.importer.invalid_json_provided'));
|
||||
}
|
||||
|
||||
$service = $this->serviceRepository->getWithOptions($service);
|
||||
$service->options->each(function ($option) use ($parsed) {
|
||||
if ($option->tag === object_get($parsed, 'tag')) {
|
||||
throw new DuplicateOptionTagException(trans('exceptions.service.options.duplicate_tag'));
|
||||
}
|
||||
});
|
||||
|
||||
$nest = $this->serviceRepository->getWithEggs($nest);
|
||||
$this->connection->beginTransaction();
|
||||
$option = $this->repository->create([
|
||||
|
||||
$egg = $this->repository->create([
|
||||
'uuid' => Uuid::uuid4()->toString(),
|
||||
'service_id' => $service->id,
|
||||
'nest_id' => $nest->id,
|
||||
'name' => object_get($parsed, 'name'),
|
||||
'description' => object_get($parsed, 'description'),
|
||||
'tag' => object_get($parsed, 'tag'),
|
||||
'docker_image' => object_get($parsed, 'image'),
|
||||
'config_files' => object_get($parsed, 'config.files'),
|
||||
'config_startup' => object_get($parsed, 'config.startup'),
|
||||
|
@ -110,14 +103,14 @@ class ServiceOptionImporterService
|
|||
'copy_script_from' => null,
|
||||
], true, true);
|
||||
|
||||
collect($parsed->variables)->each(function ($variable) use ($option) {
|
||||
$this->serviceVariableRepository->create(array_merge((array) $variable, [
|
||||
'option_id' => $option->id,
|
||||
collect($parsed->variables)->each(function ($variable) use ($egg) {
|
||||
$this->eggVariableRepository->create(array_merge((array) $variable, [
|
||||
'egg_id' => $egg->id,
|
||||
]));
|
||||
});
|
||||
|
||||
$this->connection->commit();
|
||||
|
||||
return $option;
|
||||
return $egg;
|
||||
}
|
||||
}
|
|
@ -7,59 +7,54 @@
|
|||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Services\Services;
|
||||
namespace Pterodactyl\Services\Nests;
|
||||
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Pterodactyl\Models\Service;
|
||||
use Pterodactyl\Traits\Services\CreatesServiceIndex;
|
||||
use Pterodactyl\Models\Nest;
|
||||
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
|
||||
use Illuminate\Contracts\Config\Repository as ConfigRepository;
|
||||
use Pterodactyl\Contracts\Repository\ServiceRepositoryInterface;
|
||||
|
||||
class ServiceCreationService
|
||||
class NestCreationService
|
||||
{
|
||||
use CreatesServiceIndex;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Config\Repository
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\ServiceRepositoryInterface
|
||||
* @var \Pterodactyl\Contracts\Repository\NestRepositoryInterface
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* ServiceCreationService constructor.
|
||||
* NestCreationService constructor.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Config\Repository $config
|
||||
* @param \Pterodactyl\Contracts\Repository\ServiceRepositoryInterface $repository
|
||||
* @param \Illuminate\Contracts\Config\Repository $config
|
||||
* @param \Pterodactyl\Contracts\Repository\NestRepositoryInterface $repository
|
||||
*/
|
||||
public function __construct(
|
||||
ConfigRepository $config,
|
||||
ServiceRepositoryInterface $repository
|
||||
NestRepositoryInterface $repository
|
||||
) {
|
||||
$this->config = $config;
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new service on the system.
|
||||
* Create a new nest on the system.
|
||||
*
|
||||
* @param array $data
|
||||
* @return \Pterodactyl\Models\Service
|
||||
* @return \Pterodactyl\Models\Nest
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
*/
|
||||
public function handle(array $data): Service
|
||||
public function handle(array $data): Nest
|
||||
{
|
||||
return $this->repository->create([
|
||||
'uuid' => Uuid::uuid4()->toString(),
|
||||
'author' => $this->config->get('pterodactyl.service.author'),
|
||||
'name' => array_get($data, 'name'),
|
||||
'description' => array_get($data, 'description'),
|
||||
'startup' => array_get($data, 'startup'),
|
||||
'index_file' => $this->getIndexScript(),
|
||||
], true, true);
|
||||
}
|
||||
}
|
|
@ -7,13 +7,13 @@
|
|||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Services\Services;
|
||||
namespace Pterodactyl\Services\Nests;
|
||||
|
||||
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
|
||||
use Pterodactyl\Exceptions\Service\HasActiveServersException;
|
||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\ServiceRepositoryInterface;
|
||||
|
||||
class ServiceDeletionService
|
||||
class NestDeletionService
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
|
||||
|
@ -21,39 +21,39 @@ class ServiceDeletionService
|
|||
protected $serverRepository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\ServiceRepositoryInterface
|
||||
* @var \Pterodactyl\Contracts\Repository\NestRepositoryInterface
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* ServiceDeletionService constructor.
|
||||
* NestDeletionService constructor.
|
||||
*
|
||||
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $serverRepository
|
||||
* @param \Pterodactyl\Contracts\Repository\ServiceRepositoryInterface $repository
|
||||
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $serverRepository
|
||||
* @param \Pterodactyl\Contracts\Repository\NestRepositoryInterface $repository
|
||||
*/
|
||||
public function __construct(
|
||||
ServerRepositoryInterface $serverRepository,
|
||||
ServiceRepositoryInterface $repository
|
||||
NestRepositoryInterface $repository
|
||||
) {
|
||||
$this->serverRepository = $serverRepository;
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a service from the system only if there are no servers attached to it.
|
||||
* Delete a nest from the system only if there are no servers attached to it.
|
||||
*
|
||||
* @param int $service
|
||||
* @param int $nest
|
||||
* @return int
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Service\HasActiveServersException
|
||||
*/
|
||||
public function handle(int $service): int
|
||||
public function handle(int $nest): int
|
||||
{
|
||||
$count = $this->serverRepository->findCountWhere([['service_id', '=', $service]]);
|
||||
$count = $this->serverRepository->findCountWhere([['nest_id', '=', $nest]]);
|
||||
if ($count > 0) {
|
||||
throw new HasActiveServersException(trans('exceptions.service.delete_has_servers'));
|
||||
}
|
||||
|
||||
return $this->repository->delete($service);
|
||||
return $this->repository->delete($nest);
|
||||
}
|
||||
}
|
|
@ -7,41 +7,41 @@
|
|||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Services\Services;
|
||||
namespace Pterodactyl\Services\Nests;
|
||||
|
||||
use Pterodactyl\Contracts\Repository\ServiceRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
|
||||
|
||||
class ServiceUpdateService
|
||||
class NestUpdateService
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\ServiceRepositoryInterface
|
||||
* @var \Pterodactyl\Contracts\Repository\NestRepositoryInterface
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* ServiceUpdateService constructor.
|
||||
* NestUpdateService constructor.
|
||||
*
|
||||
* @param \Pterodactyl\Contracts\Repository\ServiceRepositoryInterface $repository
|
||||
* @param \Pterodactyl\Contracts\Repository\NestRepositoryInterface $repository
|
||||
*/
|
||||
public function __construct(ServiceRepositoryInterface $repository)
|
||||
public function __construct(NestRepositoryInterface $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a service and prevent changing the author once it is set.
|
||||
* Update a nest and prevent changing the author once it is set.
|
||||
*
|
||||
* @param int $service
|
||||
* @param int $nest
|
||||
* @param array $data
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function handle(int $service, array $data)
|
||||
public function handle(int $nest, array $data)
|
||||
{
|
||||
if (! is_null(array_get($data, 'author'))) {
|
||||
unset($data['author']);
|
||||
}
|
||||
|
||||
$this->repository->withoutFresh()->update($service, $data);
|
||||
$this->repository->withoutFresh()->update($nest, $data);
|
||||
}
|
||||
}
|
|
@ -12,7 +12,7 @@ namespace Pterodactyl\Services\Servers;
|
|||
use Pterodactyl\Exceptions\DisplayValidationException;
|
||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
||||
use Illuminate\Contracts\Validation\Factory as ValidationFactory;
|
||||
use Pterodactyl\Contracts\Repository\OptionVariableRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\ServerVariableRepositoryInterface;
|
||||
|
||||
class VariableValidatorService
|
||||
|
@ -33,7 +33,7 @@ class VariableValidatorService
|
|||
protected $results = [];
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\OptionVariableRepositoryInterface
|
||||
* @var \Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface
|
||||
*/
|
||||
protected $optionVariableRepository;
|
||||
|
||||
|
@ -55,13 +55,13 @@ class VariableValidatorService
|
|||
/**
|
||||
* VariableValidatorService constructor.
|
||||
*
|
||||
* @param \Pterodactyl\Contracts\Repository\OptionVariableRepositoryInterface $optionVariableRepository
|
||||
* @param \Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface $optionVariableRepository
|
||||
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $serverRepository
|
||||
* @param \Pterodactyl\Contracts\Repository\ServerVariableRepositoryInterface $serverVariableRepository
|
||||
* @param \Illuminate\Contracts\Validation\Factory $validator
|
||||
*/
|
||||
public function __construct(
|
||||
OptionVariableRepositoryInterface $optionVariableRepository,
|
||||
EggVariableRepositoryInterface $optionVariableRepository,
|
||||
ServerRepositoryInterface $serverRepository,
|
||||
ServerVariableRepositoryInterface $serverVariableRepository,
|
||||
ValidationFactory $validator
|
||||
|
|
|
@ -9,23 +9,23 @@
|
|||
|
||||
namespace Pterodactyl\Services\Services\Options;
|
||||
|
||||
use Pterodactyl\Models\ServiceOption;
|
||||
use Pterodactyl\Contracts\Repository\ServiceOptionRepositoryInterface;
|
||||
use Pterodactyl\Models\Egg;
|
||||
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
|
||||
use Pterodactyl\Exceptions\Service\ServiceOption\InvalidCopyFromException;
|
||||
|
||||
class InstallScriptUpdateService
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\ServiceOptionRepositoryInterface
|
||||
* @var \Pterodactyl\Contracts\Repository\EggRepositoryInterface
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* InstallScriptUpdateService constructor.
|
||||
*
|
||||
* @param \Pterodactyl\Contracts\Repository\ServiceOptionRepositoryInterface $repository
|
||||
* @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $repository
|
||||
*/
|
||||
public function __construct(ServiceOptionRepositoryInterface $repository)
|
||||
public function __construct(EggRepositoryInterface $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
@ -33,8 +33,8 @@ class InstallScriptUpdateService
|
|||
/**
|
||||
* Modify the option install script for a given service option.
|
||||
*
|
||||
* @param int|\Pterodactyl\Models\ServiceOption $option
|
||||
* @param array $data
|
||||
* @param int|\Pterodactyl\Models\Egg $option
|
||||
* @param array $data
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
|
@ -42,7 +42,7 @@ class InstallScriptUpdateService
|
|||
*/
|
||||
public function handle($option, array $data)
|
||||
{
|
||||
if (! $option instanceof ServiceOption) {
|
||||
if (! $option instanceof Egg) {
|
||||
$option = $this->repository->find($option);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,8 +9,8 @@
|
|||
|
||||
namespace Pterodactyl\Services\Services\Options;
|
||||
|
||||
use Pterodactyl\Models\ServiceOption;
|
||||
use Pterodactyl\Contracts\Repository\ServiceOptionRepositoryInterface;
|
||||
use Pterodactyl\Models\Egg;
|
||||
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
|
||||
|
||||
class OptionConfigurationFileService
|
||||
{
|
||||
|
@ -19,9 +19,9 @@ class OptionConfigurationFileService
|
|||
/**
|
||||
* OptionConfigurationFileService constructor.
|
||||
*
|
||||
* @param \Pterodactyl\Contracts\Repository\ServiceOptionRepositoryInterface $repository
|
||||
* @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $repository
|
||||
*/
|
||||
public function __construct(ServiceOptionRepositoryInterface $repository)
|
||||
public function __construct(EggRepositoryInterface $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
@ -29,14 +29,14 @@ class OptionConfigurationFileService
|
|||
/**
|
||||
* Return a service configuration file to be used by the daemon.
|
||||
*
|
||||
* @param int|\Pterodactyl\Models\ServiceOption $option
|
||||
* @param int|\Pterodactyl\Models\Egg $option
|
||||
* @return array
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function handle($option): array
|
||||
{
|
||||
if (! $option instanceof ServiceOption) {
|
||||
if (! $option instanceof Egg) {
|
||||
$option = $this->repository->getWithCopyAttributes($option);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,9 +10,9 @@
|
|||
namespace Pterodactyl\Services\Services\Options;
|
||||
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Pterodactyl\Models\ServiceOption;
|
||||
use Pterodactyl\Models\Egg;
|
||||
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
|
||||
use Illuminate\Contracts\Config\Repository as ConfigRepository;
|
||||
use Pterodactyl\Contracts\Repository\ServiceOptionRepositoryInterface;
|
||||
use Pterodactyl\Exceptions\Service\ServiceOption\NoParentConfigurationFoundException;
|
||||
|
||||
class OptionCreationService
|
||||
|
@ -23,17 +23,17 @@ class OptionCreationService
|
|||
protected $config;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\ServiceOptionRepositoryInterface
|
||||
* @var \Pterodactyl\Contracts\Repository\EggRepositoryInterface
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* CreationService constructor.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Config\Repository $config
|
||||
* @param \Pterodactyl\Contracts\Repository\ServiceOptionRepositoryInterface $repository
|
||||
* @param \Illuminate\Contracts\Config\Repository $config
|
||||
* @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $repository
|
||||
*/
|
||||
public function __construct(ConfigRepository $config, ServiceOptionRepositoryInterface $repository)
|
||||
public function __construct(ConfigRepository $config, EggRepositoryInterface $repository)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->repository = $repository;
|
||||
|
@ -43,12 +43,12 @@ class OptionCreationService
|
|||
* Create a new service option and assign it to the given service.
|
||||
*
|
||||
* @param array $data
|
||||
* @return \Pterodactyl\Models\ServiceOption
|
||||
* @return \Pterodactyl\Models\Egg
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Service\ServiceOption\NoParentConfigurationFoundException
|
||||
*/
|
||||
public function handle(array $data): ServiceOption
|
||||
public function handle(array $data): Egg
|
||||
{
|
||||
if (! is_null(array_get($data, 'config_from'))) {
|
||||
$results = $this->repository->findCountWhere([
|
||||
|
|
|
@ -9,15 +9,15 @@
|
|||
|
||||
namespace Pterodactyl\Services\Services\Options;
|
||||
|
||||
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
|
||||
use Pterodactyl\Exceptions\Service\HasActiveServersException;
|
||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\ServiceOptionRepositoryInterface;
|
||||
use Pterodactyl\Exceptions\Service\ServiceOption\HasChildrenException;
|
||||
|
||||
class OptionDeletionService
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\ServiceOptionRepositoryInterface
|
||||
* @var \Pterodactyl\Contracts\Repository\EggRepositoryInterface
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
|
@ -29,12 +29,12 @@ class OptionDeletionService
|
|||
/**
|
||||
* OptionDeletionService constructor.
|
||||
*
|
||||
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $serverRepository
|
||||
* @param \Pterodactyl\Contracts\Repository\ServiceOptionRepositoryInterface $repository
|
||||
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $serverRepository
|
||||
* @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $repository
|
||||
*/
|
||||
public function __construct(
|
||||
ServerRepositoryInterface $serverRepository,
|
||||
ServiceOptionRepositoryInterface $repository
|
||||
EggRepositoryInterface $repository
|
||||
) {
|
||||
$this->repository = $repository;
|
||||
$this->serverRepository = $serverRepository;
|
||||
|
|
|
@ -9,23 +9,23 @@
|
|||
|
||||
namespace Pterodactyl\Services\Services\Options;
|
||||
|
||||
use Pterodactyl\Models\ServiceOption;
|
||||
use Pterodactyl\Contracts\Repository\ServiceOptionRepositoryInterface;
|
||||
use Pterodactyl\Models\Egg;
|
||||
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
|
||||
use Pterodactyl\Exceptions\Service\ServiceOption\NoParentConfigurationFoundException;
|
||||
|
||||
class OptionUpdateService
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\ServiceOptionRepositoryInterface
|
||||
* @var \Pterodactyl\Contracts\Repository\EggRepositoryInterface
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* OptionUpdateService constructor.
|
||||
*
|
||||
* @param \Pterodactyl\Contracts\Repository\ServiceOptionRepositoryInterface $repository
|
||||
* @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $repository
|
||||
*/
|
||||
public function __construct(ServiceOptionRepositoryInterface $repository)
|
||||
public function __construct(EggRepositoryInterface $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
@ -33,8 +33,8 @@ class OptionUpdateService
|
|||
/**
|
||||
* Update a service option.
|
||||
*
|
||||
* @param int|\Pterodactyl\Models\ServiceOption $option
|
||||
* @param array $data
|
||||
* @param int|\Pterodactyl\Models\Egg $option
|
||||
* @param array $data
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
|
@ -42,7 +42,7 @@ class OptionUpdateService
|
|||
*/
|
||||
public function handle($option, array $data)
|
||||
{
|
||||
if (! $option instanceof ServiceOption) {
|
||||
if (! $option instanceof Egg) {
|
||||
$option = $this->repository->find($option);
|
||||
}
|
||||
|
||||
|
|
|
@ -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\Services\Sharing;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Pterodactyl\Contracts\Repository\ServiceOptionRepositoryInterface;
|
||||
|
||||
class ServiceOptionExporterService
|
||||
{
|
||||
/**
|
||||
* @var \Carbon\Carbon
|
||||
*/
|
||||
protected $carbon;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\ServiceOptionRepositoryInterface
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* XMLExporterService constructor.
|
||||
*
|
||||
* @param \Carbon\Carbon $carbon
|
||||
* @param \Pterodactyl\Contracts\Repository\ServiceOptionRepositoryInterface $repository
|
||||
*/
|
||||
public function __construct(
|
||||
Carbon $carbon,
|
||||
ServiceOptionRepositoryInterface $repository
|
||||
) {
|
||||
$this->carbon = $carbon;
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an XML structure to represent this service option.
|
||||
*
|
||||
* @param int $option
|
||||
* @return string
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function handle(int $option): string
|
||||
{
|
||||
$option = $this->repository->getWithExportAttributes($option);
|
||||
|
||||
$struct = [
|
||||
'_comment' => 'DO NOT EDIT: FILE GENERATED AUTOMATICALLY BY PTERODACTYL PANEL - PTERODACTYL.IO',
|
||||
'meta' => [
|
||||
'version' => 'PTDL_v1',
|
||||
],
|
||||
'exported_at' => $this->carbon->now()->toIso8601String(),
|
||||
'name' => $option->name,
|
||||
'author' => array_get(explode(':', $option->tag), 0),
|
||||
'description' => $option->description,
|
||||
'image' => $option->docker_image,
|
||||
'config' => [
|
||||
'files' => $option->inherit_config_files,
|
||||
'startup' => $option->inherit_config_startup,
|
||||
'logs' => $option->inherit_config_logs,
|
||||
'stop' => $option->inherit_config_stop,
|
||||
],
|
||||
'scripts' => [
|
||||
'installation' => [
|
||||
'script' => $option->copy_script_install,
|
||||
'container' => $option->copy_script_container,
|
||||
'entrypoint' => $option->copy_script_entry,
|
||||
],
|
||||
],
|
||||
'variables' => $option->variables->transform(function ($item) {
|
||||
return collect($item->toArray())->except([
|
||||
'id', 'option_id', 'created_at', 'updated_at',
|
||||
])->toArray();
|
||||
}),
|
||||
];
|
||||
|
||||
return json_encode($struct, JSON_PRETTY_PRINT);
|
||||
}
|
||||
}
|
|
@ -9,16 +9,16 @@
|
|||
|
||||
namespace Pterodactyl\Services\Services\Variables;
|
||||
|
||||
use Pterodactyl\Models\ServiceOption;
|
||||
use Pterodactyl\Models\ServiceVariable;
|
||||
use Pterodactyl\Contracts\Repository\ServiceOptionRepositoryInterface;
|
||||
use Pterodactyl\Models\Egg;
|
||||
use Pterodactyl\Models\EggVariable;
|
||||
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\ServiceVariableRepositoryInterface;
|
||||
use Pterodactyl\Exceptions\Service\ServiceVariable\ReservedVariableNameException;
|
||||
|
||||
class VariableCreationService
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\ServiceOptionRepositoryInterface
|
||||
* @var \Pterodactyl\Contracts\Repository\EggRepositoryInterface
|
||||
*/
|
||||
protected $serviceOptionRepository;
|
||||
|
||||
|
@ -28,7 +28,7 @@ class VariableCreationService
|
|||
protected $serviceVariableRepository;
|
||||
|
||||
public function __construct(
|
||||
ServiceOptionRepositoryInterface $serviceOptionRepository,
|
||||
EggRepositoryInterface $serviceOptionRepository,
|
||||
ServiceVariableRepositoryInterface $serviceVariableRepository
|
||||
) {
|
||||
$this->serviceOptionRepository = $serviceOptionRepository;
|
||||
|
@ -38,20 +38,20 @@ class VariableCreationService
|
|||
/**
|
||||
* Create a new variable for a given service option.
|
||||
*
|
||||
* @param int|\Pterodactyl\Models\ServiceOption $option
|
||||
* @param array $data
|
||||
* @return \Pterodactyl\Models\ServiceVariable
|
||||
* @param int|\Pterodactyl\Models\Egg $option
|
||||
* @param array $data
|
||||
* @return \Pterodactyl\Models\EggVariable
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Service\ServiceVariable\ReservedVariableNameException
|
||||
*/
|
||||
public function handle($option, array $data)
|
||||
{
|
||||
if ($option instanceof ServiceOption) {
|
||||
if ($option instanceof Egg) {
|
||||
$option = $option->id;
|
||||
}
|
||||
|
||||
if (in_array(strtoupper(array_get($data, 'env_variable')), explode(',', ServiceVariable::RESERVED_ENV_NAMES))) {
|
||||
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.',
|
||||
array_get($data, 'env_variable')
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
namespace Pterodactyl\Services\Services\Variables;
|
||||
|
||||
use Pterodactyl\Models\ServiceVariable;
|
||||
use Pterodactyl\Models\EggVariable;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Pterodactyl\Contracts\Repository\ServiceVariableRepositoryInterface;
|
||||
use Pterodactyl\Exceptions\Service\ServiceVariable\ReservedVariableNameException;
|
||||
|
@ -34,8 +34,8 @@ class VariableUpdateService
|
|||
/**
|
||||
* Update a specific service variable.
|
||||
*
|
||||
* @param int|\Pterodactyl\Models\ServiceVariable $variable
|
||||
* @param array $data
|
||||
* @param int|\Pterodactyl\Models\EggVariable $variable
|
||||
* @param array $data
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
|
@ -45,12 +45,12 @@ class VariableUpdateService
|
|||
*/
|
||||
public function handle($variable, array $data)
|
||||
{
|
||||
if (! $variable instanceof ServiceVariable) {
|
||||
if (! $variable instanceof EggVariable) {
|
||||
$variable = $this->repository->find($variable);
|
||||
}
|
||||
|
||||
if (! is_null(array_get($data, 'env_variable'))) {
|
||||
if (in_array(strtoupper(array_get($data, 'env_variable')), explode(',', ServiceVariable::RESERVED_ENV_NAMES))) {
|
||||
if (in_array(strtoupper(array_get($data, 'env_variable')), explode(',', EggVariable::RESERVED_ENV_NAMES))) {
|
||||
throw new ReservedVariableNameException(trans('exceptions.service.variables.reserved_name', [
|
||||
'name' => array_get($data, 'env_variable'),
|
||||
]));
|
||||
|
|
Reference in a new issue