This breaks literally the entire panel.

This commit is contained in:
Dane Everitt 2017-10-06 23:57:53 -05:00
parent 344c1a9885
commit df87ea0867
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
88 changed files with 1205 additions and 992 deletions

View 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);
}
}

View file

@ -0,0 +1,116 @@
<?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 Ramsey\Uuid\Uuid;
use Pterodactyl\Models\Egg;
use Illuminate\Http\UploadedFile;
use Illuminate\Database\ConnectionInterface;
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
use Pterodactyl\Exceptions\Service\Pack\InvalidFileUploadException;
use Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface;
class EggImporterService
{
/**
* @var \Illuminate\Database\ConnectionInterface
*/
protected $connection;
/**
* @var \Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface
*/
protected $eggVariableRepository;
/**
* @var \Pterodactyl\Contracts\Repository\EggRepositoryInterface
*/
protected $repository;
/**
* @var \Pterodactyl\Contracts\Repository\NestRepositoryInterface
*/
protected $serviceRepository;
/**
* EggImporterService constructor.
*
* @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,
EggRepositoryInterface $repository,
EggVariableRepositoryInterface $eggVariableRepository,
NestRepositoryInterface $serviceRepository
) {
$this->connection = $connection;
$this->repository = $repository;
$this->serviceRepository = $serviceRepository;
$this->eggVariableRepository = $eggVariableRepository;
}
/**
* Take an uploaded JSON file and parse it into a new egg.
*
* @param \Illuminate\Http\UploadedFile $file
* @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 $nest): Egg
{
if (! $file->isValid() || ! $file->isFile()) {
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.egg.importer.invalid_json_provided'));
}
$nest = $this->serviceRepository->getWithEggs($nest);
$this->connection->beginTransaction();
$egg = $this->repository->create([
'uuid' => Uuid::uuid4()->toString(),
'nest_id' => $nest->id,
'name' => object_get($parsed, 'name'),
'description' => object_get($parsed, 'description'),
'docker_image' => object_get($parsed, 'image'),
'config_files' => object_get($parsed, 'config.files'),
'config_startup' => object_get($parsed, 'config.startup'),
'config_logs' => object_get($parsed, 'config.logs'),
'config_stop' => object_get($parsed, 'config.stop'),
'startup' => object_get($parsed, 'startup'),
'script_install' => object_get($parsed, 'scripts.installation.script'),
'script_entry' => object_get($parsed, 'scripts.installation.entrypoint'),
'script_container' => object_get($parsed, 'scripts.installation.container'),
'copy_script_from' => null,
], true, true);
collect($parsed->variables)->each(function ($variable) use ($egg) {
$this->eggVariableRepository->create(array_merge((array) $variable, [
'egg_id' => $egg->id,
]));
});
$this->connection->commit();
return $egg;
}
}