Misc fixes

This commit is contained in:
Dane Everitt 2017-10-08 21:36:22 -05:00
parent 864513c44b
commit aaf96669d4
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
15 changed files with 58 additions and 57 deletions

View File

@ -47,11 +47,11 @@ class EggRetrievalController extends Controller
*/ */
public function index(): JsonResponse public function index(): JsonResponse
{ {
$options = $this->repository->getAllWithCopyAttributes(); $eggs = $this->repository->getAllWithCopyAttributes();
$response = []; $response = [];
$options->each(function ($option) use (&$response) { $eggs->each(function ($egg) use (&$response) {
$response[$option->uuid] = sha1(json_encode($this->configurationFileService->handle($option))); $response[$egg->uuid] = sha1(json_encode($this->configurationFileService->handle($egg)));
}); });
return response()->json($response); return response()->json($response);

View File

@ -11,14 +11,20 @@ namespace Pterodactyl\Http\Controllers\Admin\Nests;
use Pterodactyl\Models\Egg; use Pterodactyl\Models\Egg;
use Illuminate\Http\RedirectResponse; use Illuminate\Http\RedirectResponse;
use Prologue\Alerts\AlertsMessageBag;
use Pterodactyl\Http\Controllers\Controller; use Pterodactyl\Http\Controllers\Controller;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Pterodactyl\Services\Eggs\Sharing\EggExporterService; use Pterodactyl\Services\Eggs\Sharing\EggExporterService;
use Pterodactyl\Services\Eggs\Sharing\EggImporterService; use Pterodactyl\Services\Eggs\Sharing\EggImporterService;
use Pterodactyl\Http\Requests\Admin\Service\OptionImportFormRequest; use Pterodactyl\Http\Requests\Admin\Egg\EggImportFormRequest;
class EggShareController extends Controller class EggShareController extends Controller
{ {
/**
* @var \Prologue\Alerts\AlertsMessageBag
*/
protected $alert;
/** /**
* @var \Pterodactyl\Services\Eggs\Sharing\EggExporterService * @var \Pterodactyl\Services\Eggs\Sharing\EggExporterService
*/ */
@ -32,13 +38,16 @@ class EggShareController extends Controller
/** /**
* OptionShareController constructor. * OptionShareController constructor.
* *
* @param \Prologue\Alerts\AlertsMessageBag $alert
* @param \Pterodactyl\Services\Eggs\Sharing\EggExporterService $exporterService * @param \Pterodactyl\Services\Eggs\Sharing\EggExporterService $exporterService
* @param \Pterodactyl\Services\Eggs\Sharing\EggImporterService $importerService * @param \Pterodactyl\Services\Eggs\Sharing\EggImporterService $importerService
*/ */
public function __construct( public function __construct(
AlertsMessageBag $alert,
EggExporterService $exporterService, EggExporterService $exporterService,
EggImporterService $importerService EggImporterService $importerService
) { ) {
$this->alert = $alert;
$this->exporterService = $exporterService; $this->exporterService = $exporterService;
$this->importerService = $importerService; $this->importerService = $importerService;
} }
@ -62,16 +71,17 @@ class EggShareController extends Controller
/** /**
* Import a new service option using an XML file. * Import a new service option using an XML file.
* *
* @param \Pterodactyl\Http\Requests\Admin\Service\OptionImportFormRequest $request * @param \Pterodactyl\Http\Requests\Admin\Egg\EggImportFormRequest $request
* @return \Illuminate\Http\RedirectResponse * @return \Illuminate\Http\RedirectResponse
* *
* @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Pterodactyl\Exceptions\Service\Pack\InvalidFileUploadException * @throws \Pterodactyl\Exceptions\Service\Pack\InvalidFileUploadException
*/ */
public function import(OptionImportFormRequest $request): RedirectResponse public function import(EggImportFormRequest $request): RedirectResponse
{ {
$egg = $this->importerService->handle($request->file('import_file'), $request->input('import_to_nest')); $egg = $this->importerService->handle($request->file('import_file'), $request->input('import_to_nest'));
$this->alert->success(trans('admin/nests.eggs.notices.imported'))->flash();
return redirect()->route('admin.nests.egg.view', ['egg' => $egg->id]); return redirect()->route('admin.nests.egg.view', ['egg' => $egg->id]);
} }

View File

@ -7,11 +7,11 @@
* https://opensource.org/licenses/MIT * https://opensource.org/licenses/MIT
*/ */
namespace Pterodactyl\Http\Requests\Admin\Service; namespace Pterodactyl\Http\Requests\Admin\Egg;
use Pterodactyl\Http\Requests\Admin\AdminFormRequest; use Pterodactyl\Http\Requests\Admin\AdminFormRequest;
class OptionImportFormRequest extends AdminFormRequest class EggImportFormRequest extends AdminFormRequest
{ {
/** /**
* @return array * @return array
@ -20,7 +20,7 @@ class OptionImportFormRequest extends AdminFormRequest
{ {
return [ return [
'import_file' => 'bail|required|file|max:1000|mimetypes:application/json,text/plain', 'import_file' => 'bail|required|file|max:1000|mimetypes:application/json,text/plain',
'import_to_service' => 'bail|required|integer|exists:services,id', 'import_to_nest' => 'bail|required|integer|exists:nests,id',
]; ];
} }
} }

View File

@ -1,25 +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\Http\Requests\Admin\Service;
use Pterodactyl\Http\Requests\Admin\AdminFormRequest;
class ServiceFunctionsFormRequest extends AdminFormRequest
{
/**
* @return array
*/
public function rules()
{
return [
'index_file' => 'required|nullable|string',
];
}
}

View File

@ -65,8 +65,10 @@ class Egg extends Model implements CleansAttributes, ValidableContract
*/ */
protected static $applicationRules = [ protected static $applicationRules = [
'nest_id' => 'required', 'nest_id' => 'required',
'uuid' => 'required',
'name' => 'required', 'name' => 'required',
'description' => 'required', 'description' => 'required',
'author' => 'required',
'docker_image' => 'required', 'docker_image' => 'required',
'startup' => 'required', 'startup' => 'required',
'config_from' => 'sometimes', 'config_from' => 'sometimes',
@ -84,6 +86,7 @@ class Egg extends Model implements CleansAttributes, ValidableContract
'uuid' => 'string|size:36', 'uuid' => 'string|size:36',
'name' => 'string|max:255', 'name' => 'string|max:255',
'description' => 'string', 'description' => 'string',
'author' => 'string|email',
'docker_image' => 'string|max:255', 'docker_image' => 'string|max:255',
'startup' => 'nullable|string', 'startup' => 'nullable|string',
'config_from' => 'bail|nullable|numeric|exists:eggs,id', 'config_from' => 'bail|nullable|numeric|exists:eggs,id',

View File

@ -49,7 +49,7 @@ class Nest extends Model implements CleansAttributes, ValidableContract
* @var array * @var array
*/ */
protected static $dataIntegrityRules = [ protected static $dataIntegrityRules = [
'author' => 'email', 'author' => 'string|email',
'name' => 'string|max:255', 'name' => 'string|max:255',
'description' => 'nullable|string', 'description' => 'nullable|string',
]; ];

View File

@ -32,22 +32,22 @@ class EggConfigurationService
/** /**
* Return an Egg file to be used by the Daemon. * Return an Egg file to be used by the Daemon.
* *
* @param int|\Pterodactyl\Models\Egg $option * @param int|\Pterodactyl\Models\Egg $egg
* @return array * @return array
* *
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/ */
public function handle($option): array public function handle($egg): array
{ {
if (! $option instanceof Egg) { if (! $egg instanceof Egg) {
$option = $this->repository->getWithCopyAttributes($option); $egg = $this->repository->getWithCopyAttributes($egg);
} }
return [ return [
'startup' => json_decode($option->inherit_config_startup), 'startup' => json_decode($egg->inherit_config_startup),
'stop' => $option->inherit_config_stop, 'stop' => $egg->inherit_config_stop,
'configs' => json_decode($option->inherit_config_files), 'configs' => json_decode($egg->inherit_config_files),
'log' => json_decode($option->inherit_config_logs), 'log' => json_decode($egg->inherit_config_logs),
'query' => 'none', 'query' => 'none',
]; ];
} }

View File

@ -51,6 +51,7 @@ class EggExporterService
'author' => $egg->author, 'author' => $egg->author,
'description' => $egg->description, 'description' => $egg->description,
'image' => $egg->docker_image, 'image' => $egg->docker_image,
'startup' => $egg->startup,
'config' => [ 'config' => [
'files' => $egg->inherit_config_files, 'files' => $egg->inherit_config_files,
'startup' => $egg->inherit_config_startup, 'startup' => $egg->inherit_config_startup,

View File

@ -89,6 +89,7 @@ class EggImporterService
$egg = $this->repository->create([ $egg = $this->repository->create([
'uuid' => Uuid::uuid4()->toString(), 'uuid' => Uuid::uuid4()->toString(),
'nest_id' => $nest->id, 'nest_id' => $nest->id,
'author' => object_get($parsed, 'author'),
'name' => object_get($parsed, 'name'), 'name' => object_get($parsed, 'name'),
'description' => object_get($parsed, 'description'), 'description' => object_get($parsed, 'description'),
'docker_image' => object_get($parsed, 'image'), 'docker_image' => object_get($parsed, 'image'),

View File

@ -72,7 +72,7 @@ class ServerConfigurationStructureService
], ],
'keys' => [], 'keys' => [],
'service' => [ 'service' => [
'option' => $server->option->uuid, 'egg' => $server->egg->uuid,
'pack' => object_get($server, 'pack.uuid'), 'pack' => object_get($server, 'pack.uuid'),
'skip_scripts' => $server->skip_scripts, 'skip_scripts' => $server->skip_scripts,
], ],

View File

@ -15,6 +15,7 @@ return [
], ],
'eggs' => [ 'eggs' => [
'notices' => [ 'notices' => [
'imported' => 'Successfully imported this Egg and its associated variables.',
'deleted' => 'Successfully deleted the requested egg from the Panel.', 'deleted' => 'Successfully deleted the requested egg from the Panel.',
'updated' => 'Egg configuration has been updated successfully.', 'updated' => 'Egg configuration has been updated successfully.',
'script_updated' => 'Egg install script has been updated and will run whenever servers are installed.', 'script_updated' => 'Egg install script has been updated and will run whenever servers are installed.',

View File

@ -52,20 +52,30 @@
<p class="text-muted small">A simple, human-readable name to use as an identifier for this Egg.</p> <p class="text-muted small">A simple, human-readable name to use as an identifier for this Egg.</p>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="pDescription" class="control-label">Description <span class="field-required"></span></label> <label for="pUuid" class="control-label">UUID</label>
<textarea id="pDescription" name="description" class="form-control" rows="10">{{ $egg->description }}</textarea> <input type="text" id="pUuid" readonly value="{{ $egg->uuid }}" class="form-control" />
<p class="text-muted small">A description of this Egg that will be displayed throughout the Panel as needed.</p> <p class="text-muted small">This is the globally unique identifier for this Egg which the Daemon uses as an identifier.</p>
</div> </div>
<div class="form-group">
<label for="pAuthor" class="control-label">Author</label>
<input type="text" id="pAuthor" readonly value="{{ $egg->author }}" class="form-control" />
<p class="text-muted small">The author of this version of the Egg. Uploading a new Egg configuration from a different author will change this.</p>
</div> </div>
<div class="col-sm-6">
<div class="form-group"> <div class="form-group">
<label for="pDockerImage" class="control-label">Docker Image <span class="field-required"></span></label> <label for="pDockerImage" class="control-label">Docker Image <span class="field-required"></span></label>
<input type="text" id="pDockerImage" name="docker_image" value="{{ $egg->docker_image }}" class="form-control" /> <input type="text" id="pDockerImage" name="docker_image" value="{{ $egg->docker_image }}" class="form-control" />
<p class="text-muted small">The default docker image that should be used for new servers using this Egg. This can be changed per-server as needed.</p> <p class="text-muted small">The default docker image that should be used for new servers using this Egg. This can be changed per-server as needed.</p>
</div> </div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label for="pDescription" class="control-label">Description <span class="field-required"></span></label>
<textarea id="pDescription" name="description" class="form-control" rows="6">{{ $egg->description }}</textarea>
<p class="text-muted small">A description of this Egg that will be displayed throughout the Panel as needed.</p>
</div>
<div class="form-group"> <div class="form-group">
<label for="pStartup" class="control-label">Startup Command <span class="field-required"></span></label> <label for="pStartup" class="control-label">Startup Command <span class="field-required"></span></label>
<textarea id="pStartup" name="startup" class="form-control" rows="9">{{ $egg->startup }}</textarea> <textarea id="pStartup" name="startup" class="form-control" rows="6">{{ $egg->startup }}</textarea>
<p class="text-muted small">The default statup command that should be used for new servers using this Egg.</p> <p class="text-muted small">The default statup command that should be used for new servers using this Egg.</p>
</div> </div>
</div> </div>
@ -141,7 +151,7 @@
<script> <script>
$('#pConfigFrom').select2(); $('#pConfigFrom').select2();
$('#deleteButton').on('mouseenter', function (event) { $('#deleteButton').on('mouseenter', function (event) {
$(this).find('i').html(' Delete Option'); $(this).find('i').html(' Delete Egg');
}).on('mouseleave', function (event) { }).on('mouseleave', function (event) {
$(this).find('i').html(''); $(this).find('i').html('');
}); });

View File

@ -75,9 +75,9 @@
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="control-label" for="pImportToService">Associated Nest <span class="field-required"></span></label> <label class="control-label" for="pImportToNest">Associated Nest <span class="field-required"></span></label>
<div> <div>
<select id="pImportToService" name="import_to_service"> <select id="pImportToNest" name="import_to_nest">
@foreach($nests as $nest) @foreach($nests as $nest)
<option value="{{ $nest->id }}">{{ $nest->name }} &lt;{{ $nest->author }}&gt;</option> <option value="{{ $nest->id }}">{{ $nest->name }} &lt;{{ $nest->author }}&gt;</option>
@endforeach @endforeach
@ -101,7 +101,7 @@
@parent @parent
<script> <script>
$(document).ready(function() { $(document).ready(function() {
$('#pImportToService').select2(); $('#pImportToNest').select2();
}); });
</script> </script>
@endsection @endsection

View File

@ -83,7 +83,7 @@
</tr> </tr>
@foreach($nest->eggs as $egg) @foreach($nest->eggs as $egg)
<tr> <tr>
<td class="align-middle"><a href="{{ route('admin.nests.egg.view', $egg->id) }}">{{ $egg->name }}</a></td> <td class="align-middle"><a href="{{ route('admin.nests.egg.view', $egg->id) }}" data-toggle="tooltip" data-placement="right" title="{{ $egg->author }}">{{ $egg->name }}</a></td>
<td class="col-xs-8 align-middle">{!! $egg->description !!}</td> <td class="col-xs-8 align-middle">{!! $egg->description !!}</td>
<td class="text-center align-middle"><code>{{ $egg->servers->count() }}</code></td> <td class="text-center align-middle"><code>{{ $egg->servers->count() }}</code></td>
<td class="align-middle"> <td class="align-middle">
@ -105,7 +105,7 @@
@parent @parent
<script> <script>
$('#deleteButton').on('mouseenter', function (event) { $('#deleteButton').on('mouseenter', function (event) {
$(this).find('i').html(' Delete Service'); $(this).find('i').html(' Delete Nest');
}).on('mouseleave', function (event) { }).on('mouseleave', function (event) {
$(this).find('i').html(''); $(this).find('i').html('');
}); });

View File

@ -9,6 +9,6 @@
Route::get('/authenticate/{token}', 'ValidateKeyController@index')->name('api.remote.authenticate'); Route::get('/authenticate/{token}', 'ValidateKeyController@index')->name('api.remote.authenticate');
Route::group(['prefix' => '/eggs'], function () { Route::group(['prefix' => '/eggs'], function () {
Route::get('/', 'EggRetrievalController@download@index')->name('api.remote.eggs'); Route::get('/', 'EggRetrievalController@index')->name('api.remote.eggs');
Route::get('/{uuid}', 'EggRetrievalController@download')->name('api.remote.eggs.download'); Route::get('/{uuid}', 'EggRetrievalController@download')->name('api.remote.eggs.download');
}); });