diff --git a/CHANGELOG.md b/CHANGELOG.md index 24334cf27..261bb67a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines. * API now returns a 404 error when deleting a user that doesn't exist, rather than saying it was successful. * Service variables that allow empty input now allow you to empty out the assigned value and set it back to blank. * Fixes a bug where changing the default allocation for a server would not actually apply that allocation as the default on the daemon. +* Newly created service variables are now backfilled and assigned to existing servers properly. ### Added * Added a `Vagrantfile` to the repository to help speed up development and testing for those who don't want to do a full dedicated install. diff --git a/app/Http/Controllers/Server/ServerController.php b/app/Http/Controllers/Server/ServerController.php index 04066b7a3..ce6f59595 100644 --- a/app/Http/Controllers/Server/ServerController.php +++ b/app/Http/Controllers/Server/ServerController.php @@ -242,10 +242,11 @@ class ServerController extends Controller public function getStartup(Request $request, $uuid) { $server = Models\Server::byUuid($uuid); - $server->load(['node', 'allocation', 'variables.variable']); - $this->authorize('view-startup', $server); + $server->load(['node', 'allocation', 'variables']); + $variables = Models\ServiceVariable::where('option_id', $server->option_id)->get(); + $replacements = [ '{{SERVER_MEMORY}}' => $server->memory, '{{SERVER_IP}}' => $server->allocation->ip, @@ -253,9 +254,16 @@ class ServerController extends Controller ]; $processed = str_replace(array_keys($replacements), array_values($replacements), $server->startup); - foreach ($server->variables as $v) { - $replace = ($v->user_can_view) ? $v->variable_value : '[hidden]'; - $processed = str_replace('{{' . $v->variable->env_variable . '}}', $replace, $processed); + + foreach ($variables as $var) { + if ($var->user_viewable) { + $serverVar = $server->variables->where('variable_id', $var->id)->first(); + $var->server_set_value = $serverVar->variable_value ?? $var->default_value; + } else { + $var->server_set_value = '[hidden]'; + } + + $processed = str_replace('{{' . $var->env_variable . '}}', $var->server_set_value, $processed); } $server->js(); @@ -263,7 +271,7 @@ class ServerController extends Controller return view('server.settings.startup', [ 'server' => $server, 'node' => $server->node, - 'variables' => $server->variables->where('user_can_view', true), + 'variables' => $variables->where('user_viewable', 1), 'service' => $server->service, 'processedStartup' => $processed, ]); diff --git a/resources/themes/pterodactyl/server/settings/startup.blade.php b/resources/themes/pterodactyl/server/settings/startup.blade.php index b9377fa6e..021f540b8 100644 --- a/resources/themes/pterodactyl/server/settings/startup.blade.php +++ b/resources/themes/pterodactyl/server/settings/startup.blade.php @@ -59,31 +59,31 @@
-

{{ $v->variable->name }}

+

{{ $v->name }}

user_can_edit) - name="env_{{ $v->variable->id }}" + @if($v->user_editable) + name="env_{{ $v->id }}" @else readonly @endif - class="form-control" type="text" value="{{ old('env_' . $v->id, $v->variable_value) }}" /> -

{{ $v->variable->description }}

+ class="form-control" type="text" value="{{ old('env_' . $v->id, $v->server_set_value) }}" /> +

{{ $v->description }}

- @if($v->required && $v->user_can_edit) + @if($v->required && $v->user_editable ) @lang('strings.required') - @elseif(! $v->required && $v->user_can_edit) + @elseif(! $v->required && $v->user_editable) @lang('strings.optional') @endif - @if(! $v->user_can_edit) + @if(! $v->user_editable) @lang('strings.read_only') @endif