Initial implementation of option scripts on panel side.
This commit is contained in:
parent
5d990dcb06
commit
03e0de28d9
10 changed files with 284 additions and 0 deletions
|
@ -137,6 +137,18 @@ class OptionController extends Controller
|
|||
return view('admin.services.options.variables', ['option' => ServiceOption::with('variables')->findOrFail($id)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display script management page for an option.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function viewScripts(Request $request, $id)
|
||||
{
|
||||
return view('admin.services.options.scripts', ['option' => ServiceOption::findOrFail($id)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles POST when editing a configration for a service option.
|
||||
*
|
||||
|
@ -207,4 +219,30 @@ class OptionController extends Controller
|
|||
|
||||
return redirect()->route('admin.services.option.variables', $option);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles POST when updating scripts for a service option.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Response\RedirectResponse
|
||||
*/
|
||||
public function updateScripts(Request $request, $id)
|
||||
{
|
||||
$repo = new OptionRepository;
|
||||
|
||||
try {
|
||||
$repo->scripts($id, $request->only([
|
||||
'script_install', 'script_upgrade',
|
||||
]));
|
||||
Alert::success('Successfully updated option scripts to be run when servers are installed or updated.')->flash();
|
||||
} catch (DisplayValidationException $ex) {
|
||||
return redirect()->route('admin.services.option.scripts', $id)->withErrors(json_decode($ex->getMessage()));
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
Alert::danger('An unhandled exception was encountered while attempting to process that request. This error has been logged.')->flash();
|
||||
}
|
||||
|
||||
return redirect()->route('admin.services.option.scripts', $id);
|
||||
}
|
||||
}
|
||||
|
|
56
app/Http/Controllers/Daemon/OptionController.php
Normal file
56
app/Http/Controllers/Daemon/OptionController.php
Normal file
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Http\Controllers\Daemon;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Pterodactyl\Models\ServiceOption;
|
||||
use Pterodactyl\Http\Controllers\Controller;
|
||||
|
||||
class OptionController extends Controller
|
||||
{
|
||||
public function details(Request $request, $server)
|
||||
{
|
||||
$server = Server::with('allocation', 'option', 'variables.variable')->where('uuid', $server)->firstOrFail();
|
||||
|
||||
$environment = $server->variables->map(function ($item) {
|
||||
return sprintf('%s=%s', $item->variable->env_variable, $item->variable_value);
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'scripts' => [
|
||||
'install' => str_replace(["\r\n", "\n", "\r"], "\n", $server->option->script_install),
|
||||
'upgrade' => str_replace(["\r\n", "\n", "\r"], "\n", $server->option->script_upgrade),
|
||||
'privileged' => $server->option->script_is_privileged,
|
||||
],
|
||||
'env' => $environment->merge([
|
||||
'STARTUP=' . $server->startup,
|
||||
'SERVER_MEMORY=' . $server->memory,
|
||||
'SERVER_IP=' . $server->allocation->ip,
|
||||
'SERVER_PORT=' . $server->allocation->port,
|
||||
])->toArray(),
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -434,6 +434,14 @@ class AdminRoutes
|
|||
'as' => 'admin.services.option.variables.edit',
|
||||
'uses' => 'Admin\OptionController@editVariable',
|
||||
]);
|
||||
|
||||
$router->get('/option/{id}/scripts', [
|
||||
'as' => 'admin.services.option.scripts',
|
||||
'uses' => 'Admin\OptionController@viewScripts',
|
||||
]);
|
||||
|
||||
$router->post('/option/{id}/scripts', 'Admin\OptionController@updateScripts');
|
||||
|
||||
});
|
||||
|
||||
// Service Packs
|
||||
|
|
|
@ -49,6 +49,11 @@ class DaemonRoutes
|
|||
'as' => 'daemon.pack.hash',
|
||||
'uses' => 'Daemon\PackController@hash',
|
||||
]);
|
||||
|
||||
$router->get('details/option/{server}', [
|
||||
'as' => 'daemon.pack.hash',
|
||||
'uses' => 'Daemon\OptionController@details',
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,6 +49,7 @@ class ServiceOption extends Model
|
|||
*/
|
||||
protected $casts = [
|
||||
'service_id' => 'integer',
|
||||
'script_is_privileged' => 'boolean',
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
@ -154,4 +154,35 @@ class OptionRepository
|
|||
|
||||
return $option;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a service option's scripts in the database.
|
||||
*
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
* @return \Pterodactyl\Models\ServiceOption
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\DisplayValidationException
|
||||
*/
|
||||
public function scripts($id, array $data)
|
||||
{
|
||||
$option = ServiceOption::findOrFail($id);
|
||||
|
||||
$data['script_install'] = empty($data['script_install']) ? null : $data['script_install'];
|
||||
$data['script_upgrade'] = empty($data['script_upgrade']) ? null : $data['script_upgrade'];
|
||||
|
||||
$validator = Validator::make($data, [
|
||||
'script_install' => 'sometimes|nullable|string',
|
||||
'script_upgrade' => 'sometimes|nullable|string',
|
||||
'script_is_privileged' => 'sometimes|required|boolean',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
throw new DisplayValidationException(json_encode($validator->errors()));
|
||||
}
|
||||
|
||||
$option->fill($data)->save();
|
||||
|
||||
return $option;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddInstallAndUpgradePaths extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('service_options', function (Blueprint $table) {
|
||||
$table->text('script_upgrade')->after('startup')->nullable();
|
||||
$table->text('script_install')->after('startup')->nullable();
|
||||
$table->boolean('script_is_privileged')->default(false)->after('startup');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('service_options', function (Blueprint $table) {
|
||||
$table->dropColumn('script_upgrade');
|
||||
$table->dropColumn('script_install');
|
||||
$table->dropColumn('script_is_privileged');
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,107 @@
|
|||
{{-- Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com> --}}
|
||||
|
||||
{{-- Permission is hereby granted, free of charge, to any person obtaining a copy --}}
|
||||
{{-- of this software and associated documentation files (the "Software"), to deal --}}
|
||||
{{-- in the Software without restriction, including without limitation the rights --}}
|
||||
{{-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell --}}
|
||||
{{-- copies of the Software, and to permit persons to whom the Software is --}}
|
||||
{{-- furnished to do so, subject to the following conditions: --}}
|
||||
|
||||
{{-- The above copyright notice and this permission notice shall be included in all --}}
|
||||
{{-- copies or substantial portions of the Software. --}}
|
||||
|
||||
{{-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR --}}
|
||||
{{-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, --}}
|
||||
{{-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE --}}
|
||||
{{-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER --}}
|
||||
{{-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, --}}
|
||||
{{-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE --}}
|
||||
{{-- SOFTWARE. --}}
|
||||
@extends('layouts.admin')
|
||||
|
||||
@section('title')
|
||||
Services → Option: {{ $option->name }} → Scripts
|
||||
@endsection
|
||||
|
||||
@section('content-header')
|
||||
<h1>{{ $option->name }}<small>Manage install and upgrade scripts for this service option.</small></h1>
|
||||
<ol class="breadcrumb">
|
||||
<li><a href="{{ route('admin.index') }}">Admin</a></li>
|
||||
<li><a href="{{ route('admin.services') }}">Services</a></li>
|
||||
<li><a href="{{ route('admin.services.view', $option->service->id) }}">{{ $option->service->name }}</a></li>
|
||||
<li class="active">{{ $option->name }}</li>
|
||||
</ol>
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
<div class="row">
|
||||
<div class="col-xs-12">
|
||||
<div class="nav-tabs-custom nav-tabs-floating">
|
||||
<ul class="nav nav-tabs">
|
||||
<li><a href="{{ route('admin.services.option.view', $option->id) }}">Configuration</a></li>
|
||||
<li><a href="{{ route('admin.services.option.variables', $option->id) }}">Variables</a></li>
|
||||
<li class="active"><a href="{{ route('admin.services.option.scripts', $option->id) }}">Scripts</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<form action="{{ route('admin.services.option.scripts', $option->id) }}" method="POST">
|
||||
<div class="row">
|
||||
<div class="col-xs-12">
|
||||
<div class="box">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">Install Script</h3>
|
||||
</div>
|
||||
<div class="box-body no-padding">
|
||||
<div id="editor_install"style="height:300px">{{ $option->script_install }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12">
|
||||
<div class="box">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">Upgrade Script</h3>
|
||||
</div>
|
||||
<div class="box-body no-padding">
|
||||
<div id="editor_upgrade"style="height:300px">{{ $option->script_upgrade }}</div>
|
||||
</div>
|
||||
<div class="box-footer">
|
||||
{!! csrf_field() !!}
|
||||
<textarea name="script_install" class="hidden"></textarea>
|
||||
<textarea name="script_upgrade" class="hidden"></textarea>
|
||||
<button type="submit" class="btn btn-primary btn-sm pull-right">Save Scripts</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
@endsection
|
||||
|
||||
@section('footer-scripts')
|
||||
@parent
|
||||
{!! Theme::js('js/vendor/ace/ace.js') !!}
|
||||
{!! Theme::js('js/vendor/ace/ext-modelist.js') !!}
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
const InstallEditor = ace.edit('editor_install');
|
||||
const UpgradeEditor = ace.edit('editor_upgrade');
|
||||
|
||||
const Modelist = ace.require('ace/ext/modelist')
|
||||
|
||||
InstallEditor.setTheme('ace/theme/chrome');
|
||||
InstallEditor.getSession().setMode('ace/mode/sh');
|
||||
InstallEditor.getSession().setUseWrapMode(true);
|
||||
InstallEditor.setShowPrintMargin(false);
|
||||
|
||||
UpgradeEditor.setTheme('ace/theme/chrome');
|
||||
UpgradeEditor.getSession().setMode('ace/mode/sh');
|
||||
UpgradeEditor.getSession().setUseWrapMode(true);
|
||||
UpgradeEditor.setShowPrintMargin(false);
|
||||
|
||||
$('form').on('submit', function (e) {
|
||||
$('textarea[name="script_install"]').val(InstallEditor.getValue());
|
||||
$('textarea[name="script_upgrade"]').val(UpgradeEditor.getValue());
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@endsection
|
|
@ -42,6 +42,7 @@
|
|||
<li><a href="{{ route('admin.services.option.view', $option->id) }}">Configuration</a></li>
|
||||
<li class="active"><a href="{{ route('admin.services.option.variables', $option->id) }}">Variables</a></li>
|
||||
<li class="tab-success"><a href="#modal" data-toggle="modal" data-target="#newVariableModal">New Variable</a></li>
|
||||
<li><a href="{{ route('admin.services.option.scripts', $option->id) }}">Scripts</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
<ul class="nav nav-tabs">
|
||||
<li class="active"><a href="{{ route('admin.services.option.view', $option->id) }}">Configuration</a></li>
|
||||
<li><a href="{{ route('admin.services.option.variables', $option->id) }}">Variables</a></li>
|
||||
<li><a href="{{ route('admin.services.option.scripts', $option->id) }}">Scripts</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue