Skip to content

Commit cba5463

Browse files
committed
Fixes bug with newly created variables not being assigned to existing servers properly, closes pterodactyl#478
1 parent 1f88024 commit cba5463

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
1010
* API now returns a 404 error when deleting a user that doesn't exist, rather than saying it was successful.
1111
* Service variables that allow empty input now allow you to empty out the assigned value and set it back to blank.
1212
* Fixes a bug where changing the default allocation for a server would not actually apply that allocation as the default on the daemon.
13+
* Newly created service variables are now backfilled and assigned to existing servers properly.
1314

1415
### Added
1516
* 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.

app/Http/Controllers/Server/ServerController.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,28 +242,36 @@ public function getAllocation(Request $request, $uuid)
242242
public function getStartup(Request $request, $uuid)
243243
{
244244
$server = Models\Server::byUuid($uuid);
245-
$server->load(['node', 'allocation', 'variables.variable']);
246-
247245
$this->authorize('view-startup', $server);
248246

247+
$server->load(['node', 'allocation', 'variables']);
248+
$variables = Models\ServiceVariable::where('option_id', $server->option_id)->get();
249+
249250
$replacements = [
250251
'{{SERVER_MEMORY}}' => $server->memory,
251252
'{{SERVER_IP}}' => $server->allocation->ip,
252253
'{{SERVER_PORT}}' => $server->allocation->port,
253254
];
254255

255256
$processed = str_replace(array_keys($replacements), array_values($replacements), $server->startup);
256-
foreach ($server->variables as $v) {
257-
$replace = ($v->user_can_view) ? $v->variable_value : '[hidden]';
258-
$processed = str_replace('{{' . $v->variable->env_variable . '}}', $replace, $processed);
257+
258+
foreach ($variables as $var) {
259+
if ($var->user_viewable) {
260+
$serverVar = $server->variables->where('variable_id', $var->id)->first();
261+
$var->server_set_value = $serverVar->variable_value ?? $var->default_value;
262+
} else {
263+
$var->server_set_value = '[hidden]';
264+
}
265+
266+
$processed = str_replace('{{' . $var->env_variable . '}}', $var->server_set_value, $processed);
259267
}
260268

261269
$server->js();
262270

263271
return view('server.settings.startup', [
264272
'server' => $server,
265273
'node' => $server->node,
266-
'variables' => $server->variables->where('user_can_view', true),
274+
'variables' => $variables->where('user_viewable', 1),
267275
'service' => $server->service,
268276
'processedStartup' => $processed,
269277
]);

resources/themes/pterodactyl/server/settings/startup.blade.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,31 +59,31 @@
5959
<div class="col-xs-12 col-md-4 col-sm-6">
6060
<div class="box">
6161
<div class="box-header with-border">
62-
<h3 class="box-title">{{ $v->variable->name }}</h3>
62+
<h3 class="box-title">{{ $v->name }}</h3>
6363
</div>
6464
<div class="box-body">
6565
<input
66-
@if($v->user_can_edit)
67-
name="env_{{ $v->variable->id }}"
66+
@if($v->user_editable)
67+
name="env_{{ $v->id }}"
6868
@else
6969
readonly
7070
@endif
71-
class="form-control" type="text" value="{{ old('env_' . $v->id, $v->variable_value) }}" />
72-
<p class="small text-muted">{{ $v->variable->description }}</p>
71+
class="form-control" type="text" value="{{ old('env_' . $v->id, $v->server_set_value) }}" />
72+
<p class="small text-muted">{{ $v->description }}</p>
7373
<p class="no-margin">
74-
@if($v->required && $v->user_can_edit)
74+
@if($v->required && $v->user_editable )
7575
<span class="label label-danger">@lang('strings.required')</span>
76-
@elseif(! $v->required && $v->user_can_edit)
76+
@elseif(! $v->required && $v->user_editable)
7777
<span class="label label-default">@lang('strings.optional')</span>
7878
@endif
79-
@if(! $v->user_can_edit)
79+
@if(! $v->user_editable)
8080
<span class="label label-warning">@lang('strings.read_only')</span>
8181
@endif
8282
</p>
8383
</div>
8484
<div class="box-footer">
85-
<p class="no-margin text-muted small"><strong>@lang('server.config.startup.startup_var'):</strong> <code>{{ $v->variable->env_variable }}</code></p>
86-
<p class="no-margin text-muted small"><strong>@lang('server.config.startup.startup_regex'):</strong> <code>{{ $v->variable->rules }}</code></p>
85+
<p class="no-margin text-muted small"><strong>@lang('server.config.startup.startup_var'):</strong> <code>{{ $v->env_variable }}</code></p>
86+
<p class="no-margin text-muted small"><strong>@lang('server.config.startup.startup_regex'):</strong> <code>{{ $v->rules }}</code></p>
8787
</div>
8888
</div>
8989
</div>

0 commit comments

Comments
 (0)