Implement server startup stuff
This commit is contained in:
parent
401d72a884
commit
4719b20a27
|
@ -29,11 +29,7 @@ use Uuid;
|
||||||
use Alert;
|
use Alert;
|
||||||
use Log;
|
use Log;
|
||||||
|
|
||||||
use Pterodactyl\Models\Server;
|
use Pterodactyl\Models;
|
||||||
use Pterodactyl\Models\Node;
|
|
||||||
use Pterodactyl\Models\Download;
|
|
||||||
use Pterodactyl\Models\Allocation;
|
|
||||||
|
|
||||||
use Pterodactyl\Exceptions\DisplayException;
|
use Pterodactyl\Exceptions\DisplayException;
|
||||||
use Pterodactyl\Exceptions\DisplayValidationException;
|
use Pterodactyl\Exceptions\DisplayValidationException;
|
||||||
use Pterodactyl\Repositories\Daemon\FileRepository;
|
use Pterodactyl\Repositories\Daemon\FileRepository;
|
||||||
|
@ -57,10 +53,10 @@ class ServerController extends Controller
|
||||||
|
|
||||||
public function getJavascript(Request $request, $uuid, $file)
|
public function getJavascript(Request $request, $uuid, $file)
|
||||||
{
|
{
|
||||||
$server = Server::getByUUID($uuid);
|
$server = Models\Server::getByUUID($uuid);
|
||||||
return response()->view('server.js.' . $server->a_serviceFile . '.' . basename($file, '.js'), [
|
return response()->view('server.js.' . $server->a_serviceFile . '.' . basename($file, '.js'), [
|
||||||
'server' => $server,
|
'server' => $server,
|
||||||
'node' => Node::find($server->node)
|
'node' => Models\Node::find($server->node)
|
||||||
])->header('Content-Type', 'application/javascript');
|
])->header('Content-Type', 'application/javascript');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,11 +68,11 @@ class ServerController extends Controller
|
||||||
*/
|
*/
|
||||||
public function getIndex(Request $request)
|
public function getIndex(Request $request)
|
||||||
{
|
{
|
||||||
$server = Server::getByUUID($request->route()->server);
|
$server = Models\Server::getByUUID($request->route()->server);
|
||||||
return view('server.index', [
|
return view('server.index', [
|
||||||
'server' => $server,
|
'server' => $server,
|
||||||
'allocations' => Allocation::where('assigned_to', $server->id)->orderBy('ip', 'asc')->orderBy('port', 'asc')->get(),
|
'allocations' => Models\Allocation::where('assigned_to', $server->id)->orderBy('ip', 'asc')->orderBy('port', 'asc')->get(),
|
||||||
'node' => Node::find($server->node)
|
'node' => Models\Node::find($server->node)
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,12 +85,12 @@ class ServerController extends Controller
|
||||||
public function getFiles(Request $request)
|
public function getFiles(Request $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
$server = Server::getByUUID($request->route()->server);
|
$server = Models\Server::getByUUID($request->route()->server);
|
||||||
$this->authorize('list-files', $server);
|
$this->authorize('list-files', $server);
|
||||||
|
|
||||||
return view('server.files.index', [
|
return view('server.files.index', [
|
||||||
'server' => $server,
|
'server' => $server,
|
||||||
'node' => Node::find($server->node)
|
'node' => Models\Node::find($server->node)
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,12 +103,12 @@ class ServerController extends Controller
|
||||||
public function getAddFile(Request $request)
|
public function getAddFile(Request $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
$server = Server::getByUUID($request->route()->server);
|
$server = Models\Server::getByUUID($request->route()->server);
|
||||||
$this->authorize('add-files', $server);
|
$this->authorize('add-files', $server);
|
||||||
|
|
||||||
return view('server.files.add', [
|
return view('server.files.add', [
|
||||||
'server' => $server,
|
'server' => $server,
|
||||||
'node' => Node::find($server->node),
|
'node' => Models\Node::find($server->node),
|
||||||
'directory' => (in_array($request->get('dir'), [null, '/', ''])) ? '' : trim($request->get('dir'), '/') . '/'
|
'directory' => (in_array($request->get('dir'), [null, '/', ''])) ? '' : trim($request->get('dir'), '/') . '/'
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
@ -128,7 +124,7 @@ class ServerController extends Controller
|
||||||
public function getEditFile(Request $request, $uuid, $file)
|
public function getEditFile(Request $request, $uuid, $file)
|
||||||
{
|
{
|
||||||
|
|
||||||
$server = Server::getByUUID($uuid);
|
$server = Models\Server::getByUUID($uuid);
|
||||||
$this->authorize('edit-files', $server);
|
$this->authorize('edit-files', $server);
|
||||||
|
|
||||||
$fileInfo = (object) pathinfo($file);
|
$fileInfo = (object) pathinfo($file);
|
||||||
|
@ -152,7 +148,7 @@ class ServerController extends Controller
|
||||||
|
|
||||||
return view('server.files.edit', [
|
return view('server.files.edit', [
|
||||||
'server' => $server,
|
'server' => $server,
|
||||||
'node' => Node::find($server->node),
|
'node' => Models\Node::find($server->node),
|
||||||
'file' => $file,
|
'file' => $file,
|
||||||
'contents' => $fileContent->content,
|
'contents' => $fileContent->content,
|
||||||
'directory' => (in_array($fileInfo->dirname, ['.', './', '/'])) ? '/' : trim($fileInfo->dirname, '/') . '/',
|
'directory' => (in_array($fileInfo->dirname, ['.', './', '/'])) ? '/' : trim($fileInfo->dirname, '/') . '/',
|
||||||
|
@ -172,8 +168,8 @@ class ServerController extends Controller
|
||||||
public function getDownloadFile(Request $request, $uuid, $file)
|
public function getDownloadFile(Request $request, $uuid, $file)
|
||||||
{
|
{
|
||||||
|
|
||||||
$server = Server::getByUUID($uuid);
|
$server = Models\Server::getByUUID($uuid);
|
||||||
$node = Node::find($server->node);
|
$node = Models\Node::find($server->node);
|
||||||
|
|
||||||
$this->authorize('download-files', $server);
|
$this->authorize('download-files', $server);
|
||||||
|
|
||||||
|
@ -197,16 +193,38 @@ class ServerController extends Controller
|
||||||
*/
|
*/
|
||||||
public function getSettings(Request $request, $uuid)
|
public function getSettings(Request $request, $uuid)
|
||||||
{
|
{
|
||||||
$server = Server::getByUUID($uuid);
|
$server = Models\Server::getByUUID($uuid);
|
||||||
|
$variables = Models\ServiceVariables::select('service_variables.*', 'server_variables.variable_value as a_serverValue')
|
||||||
|
->join('server_variables', 'server_variables.variable_id', '=', 'service_variables.id')
|
||||||
|
->where('service_variables.option_id', $server->option)
|
||||||
|
->where('server_variables.server_id', $server->id)
|
||||||
|
->get();
|
||||||
|
$service = Models\Service::findOrFail($server->service);
|
||||||
|
|
||||||
|
$serverVariables = [
|
||||||
|
'{{SERVER_MEMORY}}' => $server->memory,
|
||||||
|
'{{SERVER_IP}}' => $server->ip,
|
||||||
|
'{{SERVER_PORT}}' => $server->port,
|
||||||
|
];
|
||||||
|
|
||||||
|
$processed = str_replace(array_keys($serverVariables), array_values($serverVariables), $server->startup);
|
||||||
|
foreach($variables as &$variable) {
|
||||||
|
$replace = ($variable->user_viewable === 1) ? $variable->a_serverValue : '**';
|
||||||
|
$processed = str_replace('{{' . $variable->env_variable . '}}', $replace, $processed);
|
||||||
|
}
|
||||||
|
|
||||||
return view('server.settings', [
|
return view('server.settings', [
|
||||||
'server' => $server,
|
'server' => $server,
|
||||||
'node' => Node::find($server->node)
|
'node' => Models\Node::find($server->node),
|
||||||
|
'variables' => $variables,
|
||||||
|
'service' => $service,
|
||||||
|
'processedStartup' => $processed,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function postSettingsSFTP(Request $request, $uuid)
|
public function postSettingsSFTP(Request $request, $uuid)
|
||||||
{
|
{
|
||||||
$server = Server::getByUUID($uuid);
|
$server = Models\Server::getByUUID($uuid);
|
||||||
$this->authorize('reset-sftp', $server);
|
$this->authorize('reset-sftp', $server);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -224,4 +242,28 @@ class ServerController extends Controller
|
||||||
return redirect()->route('server.settings', $uuid);
|
return redirect()->route('server.settings', $uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function postSettingsStartup(Request $request, $uuid)
|
||||||
|
{
|
||||||
|
$server = Models\Server::getByUUID($uuid);
|
||||||
|
$this->authorize('edit-startup', $server);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$repo = new ServerRepository;
|
||||||
|
$repo->updateStartup($server->id, $request->except([
|
||||||
|
'_token'
|
||||||
|
]));
|
||||||
|
Alert::success('Server startup variables were successfully updated.')->flash();
|
||||||
|
} catch (DisplayException $ex) {
|
||||||
|
Alert::danger($ex->getMessage())->flash();
|
||||||
|
} catch(\Exception $ex) {
|
||||||
|
Log::error($ex);
|
||||||
|
Alert::danger('An unhandled exception occured while attemping to update startup variables for this server. Please try again.')->flash();
|
||||||
|
} finally {
|
||||||
|
return redirect()->route('server.settings', [
|
||||||
|
'uuid' => $uuid,
|
||||||
|
'tab' => 'tab_startup'
|
||||||
|
])->withInput();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,11 @@ class ServerRoutes {
|
||||||
'uses' => 'Server\ServerController@postSettingsSFTP'
|
'uses' => 'Server\ServerController@postSettingsSFTP'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$router->post('/settings/startup', [
|
||||||
|
'as' => 'server.settings.startup',
|
||||||
|
'uses' => 'Server\ServerController@postSettingsStartup'
|
||||||
|
]);
|
||||||
|
|
||||||
// File Manager Routes
|
// File Manager Routes
|
||||||
$router->get('/files', [
|
$router->get('/files', [
|
||||||
'as' => 'files.index',
|
'as' => 'files.index',
|
||||||
|
|
|
@ -78,19 +78,75 @@
|
||||||
@endcan
|
@endcan
|
||||||
@can('view-startup', $server)
|
@can('view-startup', $server)
|
||||||
<div class="tab-pane" id="tab_startup">
|
<div class="tab-pane" id="tab_startup">
|
||||||
|
<form action="{{ route('server.settings.startup', $server->uuidShort) }}" method="POST">
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading"></div>
|
<div class="panel-heading"></div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
Startup
|
<div class="row">
|
||||||
|
<div class="form-group col-md-12">
|
||||||
|
<label class="control-label">Startup Command:</label>
|
||||||
|
<div class="input-group">
|
||||||
|
<span class="input-group-addon">{{ $service->executable }}</span>
|
||||||
|
<input type="text" class="form-control" readonly="readonly" value="{{ $processedStartup }}" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
@can('edit-startup', $server)
|
||||||
|
<div class="panel-heading" style="border-top: 1px solid #ddd;"></div>
|
||||||
|
<div class="panel-body">
|
||||||
|
<div class="row">
|
||||||
|
@foreach($variables as $item)
|
||||||
|
<div class="form-group col-md-6">
|
||||||
|
<label class="control-label">
|
||||||
|
@if($item->required === 1)<span class="label label-primary">Required</span> @endif
|
||||||
|
{{ $item->name }}
|
||||||
|
</label>
|
||||||
|
<div>
|
||||||
|
<input type="text"
|
||||||
|
@if($item->user_editable === 1)
|
||||||
|
name="{{ $item->env_variable }}"
|
||||||
|
@else
|
||||||
|
readonly="readonly"
|
||||||
|
@endif
|
||||||
|
class="form-control" value="{{ old($item->env_variable, $item->a_serverValue) }}" data-action="matchRegex" data-regex="{{ $item->regex }}" />
|
||||||
|
</div>
|
||||||
|
<p class="text-muted"><small>{{ $item->description }}<br />Regex: <code>{{ $item->regex }}</code><br />Access as: <code>{{{{$item->env_variable}}}}</code></small></p>
|
||||||
|
</div>
|
||||||
|
@endforeach
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="panel-heading" style="border-top: 1px solid #ddd;"></div>
|
||||||
|
<div class="panel-body">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
{!! csrf_field() !!}
|
||||||
|
<input type="submit" class="btn btn-primary btn-sm" value="Update Startup Arguments" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endcan
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
@endcan
|
@endcan
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
$('.server-settings').addClass('active');
|
$('.server-settings').addClass('active');
|
||||||
|
$('[data-action="matchRegex"]').keyup(function (event) {
|
||||||
|
if (!$(this).data('regex')) return;
|
||||||
|
var input = $(this).val();
|
||||||
|
console.log(escapeRegExp($(this).data('regex')));
|
||||||
|
var regex = new RegExp(escapeRegExp($(this).data('regex')));
|
||||||
|
console.log(regex);
|
||||||
|
if (!regex.test(input)) {
|
||||||
|
$(this).parent().parent().removeClass('has-success').addClass('has-error');
|
||||||
|
} else {
|
||||||
|
$(this).parent().parent().removeClass('has-error').addClass('has-success');
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
@endsection
|
@endsection
|
||||||
|
|
Loading…
Reference in New Issue