1
1
mirror of https://github.com/pterodactyl/panel.git synced 2024-11-22 09:02:28 +01:00

Add service pack reference to server and send to daemon

This commit is contained in:
Dane Everitt 2016-11-27 14:50:10 -05:00
parent 238f08f222
commit c4a4b84bd3
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
4 changed files with 61 additions and 8 deletions

View File

@ -168,7 +168,9 @@ class ServersController extends Controller
try {
$server = new ServerRepository;
$response = $server->create($request->all());
$response = $server->create($request->except([
'_token'
]));
return redirect()->route('admin.servers.view', [ 'id' => $response ]);
} catch (DisplayValidationException $ex) {
return redirect()->route('admin.servers.new')->withErrors(json_decode($ex->getMessage()))->withInput();

View File

@ -86,6 +86,7 @@ class ServerRepository
'disk' => 'required|numeric|min:0',
'service' => 'bail|required|numeric|min:1|exists:services,id',
'option' => 'bail|required|numeric|min:1|exists:service_options,id',
'pack' => 'bail|required|numeric|min:0'
'startup' => 'string',
'custom_image_name' => 'required_if:use_custom_image,on',
'auto_deploy' => 'sometimes|boolean'
@ -161,6 +162,18 @@ class ServerRepository
throw new DisplayException('The requested service option does not exist for the specified service.');
}
// Validate the Pack
if ($data['pack'] === 0) {
$data['pack'] = null;
}
if (!is_null($data['pack'])) {
$pack = Models\ServicePack::where('id', $data['pack'])->where('option', $data['option'])->first();
if (!$pack) {
throw new DisplayException('The requested service pack does not seem to exist for this combination.');
}
}
// Load up the Service Information
$service = Models\Service::find($option->parent_service);
@ -248,6 +261,7 @@ class ServerRepository
'allocation' => $allocation->id,
'service' => $data['service'],
'option' => $data['option'],
'pack' => $data['pack'],
'startup' => $data['startup'],
'daemonSecret' => $uuid->generate('servers', 'daemonSecret'),
'image' => (isset($data['custom_image_name'])) ? $data['custom_image_name'] : $option->docker_image,
@ -297,10 +311,10 @@ class ServerRepository
'build' => [
'default' => [
'ip' => $allocation->ip,
'port' => (int) $allocation->port
'port' => (int) $allocation->port,
],
'ports' => [
(string) $allocation->ip => [ (int) $allocation->port ]
(string) $allocation->ip => [ (int) $allocation->port ],
],
'env' => $environmentVariables,
'memory' => (int) $server->memory,
@ -308,16 +322,17 @@ class ServerRepository
'io' => (int) $server->io,
'cpu' => (int) $server->cpu,
'disk' => (int) $server->disk,
'image' => (isset($data['custom_image_name'])) ? $data['custom_image_name'] : $option->docker_image
'image' => (isset($data['custom_image_name'])) ? $data['custom_image_name'] : $option->docker_image,
],
'service' => [
'type' => $service->file,
'option' => $option->tag
'option' => $option->tag,
'pack' => (isset($pack)) ? $pack->uuid : null,
],
'keys' => [
(string) $server->daemonSecret => $this->daemonPermissions
(string) $server->daemonSecret => $this->daemonPermissions,
],
'rebuild' => false
'rebuild' => false,
]
]);

View File

@ -0,0 +1,36 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddPackColumn extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('servers', function (Blueprint $table) {
$table->unsignedInteger('pack')->nullable()->after('option');
$table->foreign('pack')->references('id')->on('service_packs');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('servers', function (Blueprint $table) {
$table->dropForeign('servers_pack_foreign');
$table->dropIndex('servers_pack_foreign');
$table->dropColumn('pack');
});
}
}

View File

@ -451,7 +451,7 @@ $(document).ready(function () {
$.each(data.packs, function (i, item) {
$('#getPack').append('<option value="' + item.uuid + '">' + item.name + ' (' + item.version + ')</option>');
});
$('#getPack').append('<option value="none">No Service Pack</option>').parent().parent().removeClass('hidden');
$('#getPack').append('<option value="0">No Service Pack</option>').parent().parent().removeClass('hidden');
$.each(data.variables, function (i, item) {
var isRequired = (item.required === 1) ? '<span class="label label-primary">Required</span> ' : '';