Skip to content

Commit 68e9100

Browse files
authored
admin(eggs): add force_outgoing_ip option (pterodactyl#4323)
Closes pterodactyl#3841
1 parent b04a47a commit 68e9100

File tree

7 files changed

+81
-3
lines changed

7 files changed

+81
-3
lines changed

app/Http/Controllers/Admin/Nests/EggController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function create(): View
7373
*/
7474
public function store(EggFormRequest $request): RedirectResponse
7575
{
76-
$data = $request->normalize();
76+
$data = $request->validated();
7777
$data['docker_images'] = $this->normalizeDockerImages($data['docker_images'] ?? null);
7878

7979
$egg = $this->creationService->handle($data);
@@ -106,7 +106,7 @@ public function view(Egg $egg): View
106106
*/
107107
public function update(EggFormRequest $request, Egg $egg): RedirectResponse
108108
{
109-
$data = $request->normalize();
109+
$data = $request->validated();
110110
$data['docker_images'] = $this->normalizeDockerImages($data['docker_images'] ?? null);
111111

112112
$this->updateService->handle($egg, $data);

app/Http/Requests/Admin/Egg/EggFormRequest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public function rules()
2222
'name' => 'required|string|max:191',
2323
'description' => 'nullable|string',
2424
'docker_images' => 'required|string',
25+
'force_outgoing_ip' => 'sometimes|boolean',
2526
'file_denylist' => 'array',
2627
'startup' => 'required|string',
2728
'config_from' => 'sometimes|bail|nullable|numeric',
@@ -47,4 +48,13 @@ public function withValidator($validator)
4748
return (int) $this->input('config_from') !== 0;
4849
});
4950
}
51+
52+
public function validated(): array
53+
{
54+
$data = parent::validated();
55+
56+
return array_merge($data, [
57+
'force_outgoing_ip' => array_get($data, 'force_outgoing_ip', false),
58+
]);
59+
}
5060
}

app/Models/Egg.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
* @property string|null $description
1212
* @property array|null $features
1313
* @property string $docker_image -- deprecated, use $docker_images
14-
* @property string $update_url
1514
* @property array<string, string> $docker_images
15+
* @property string $update_url
16+
* @property bool $force_outgoing_ip
1617
* @property array|null $file_denylist
1718
* @property string|null $config_files
1819
* @property string|null $config_startup
@@ -84,6 +85,7 @@ class Egg extends Model
8485
'description',
8586
'features',
8687
'docker_images',
88+
'force_outgoing_ip',
8789
'file_denylist',
8890
'config_files',
8991
'config_startup',
@@ -107,6 +109,7 @@ class Egg extends Model
107109
'nest_id' => 'integer',
108110
'config_from' => 'integer',
109111
'script_is_privileged' => 'boolean',
112+
'force_outgoing_ip' => 'boolean',
110113
'copy_script_from' => 'integer',
111114
'features' => 'array',
112115
'docker_images' => 'array',
@@ -134,6 +137,7 @@ class Egg extends Model
134137
'config_logs' => 'required_without:config_from|nullable|json',
135138
'config_files' => 'required_without:config_from|nullable|json',
136139
'update_url' => 'sometimes|nullable|string',
140+
'force_outgoing_ip' => 'sometimes|boolean',
137141
];
138142

139143
/**

app/Services/Servers/ServerConfigurationStructureService.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ protected function returnCurrentFormat(Server $server): array
7373
'requires_rebuild' => false,
7474
],
7575
'allocations' => [
76+
'force_outgoing_ip' => $server->egg->force_outgoing_ip,
7677
'default' => [
7778
'ip' => $server->allocation->ip,
7879
'port' => $server->allocation->port,
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
class AddForceOutgoingIpColumnToEggsTable extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::table('eggs', function (Blueprint $table) {
17+
$table->boolean('force_outgoing_ip')->default(false);
18+
});
19+
}
20+
21+
/**
22+
* Reverse the migrations.
23+
*
24+
* @return void
25+
*/
26+
public function down()
27+
{
28+
Schema::table('eggs', function (Blueprint $table) {
29+
$table->dropColumn('force_outgoing_ip');
30+
});
31+
}
32+
}

resources/views/admin/eggs/new.blade.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,21 @@
5050
<textarea id="pDescription" name="description" class="form-control" rows="8">{{ old('description') }}</textarea>
5151
<p class="text-muted small">A description of this Egg.</p>
5252
</div>
53+
<div class="form-group">
54+
<div class="checkbox checkbox-primary no-margin-bottom">
55+
<input id="pForceOutgoingIp" name="force_outgoing_ip" type="checkbox" value="1" {{ \Pterodactyl\Helpers\Utilities::checked('force_outgoing_ip', 0) }} />
56+
<label for="pForceOutgoingIp" class="strong">Force Outgoing IP</label>
57+
<p class="text-muted small">
58+
Forces all outgoing network traffic to have its Source IP NATed to the IP of the server's primary allocation IP.
59+
Required for certain games to work properly when the Node has multiple public IP addresses.
60+
<br>
61+
<strong>
62+
Enabling this option will disable internal networking for any servers using this egg,
63+
causing them to be unable to internally access other servers on the same node.
64+
</strong>
65+
</p>
66+
</div>
67+
</div>
5368
</div>
5469
<div class="col-sm-6">
5570
<div class="form-group">

resources/views/admin/eggs/view.blade.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,22 @@
9191
followed by a pipe character, and then the image URL. Example: <code>Display Name|ghcr.io/my/egg</code>
9292
</p>
9393
</div>
94+
<div class="form-group">
95+
<div class="checkbox checkbox-primary no-margin-bottom">
96+
<input id="pForceOutgoingIp" name="force_outgoing_ip" type="checkbox" value="1" @if($egg->force_outgoing_ip) checked @endif />
97+
<label for="pForceOutgoingIp" class="strong">Force Outgoing IP</label>
98+
<p class="text-muted small">
99+
Forces all outgoing network traffic to have its Source IP NATed to the IP of the server's primary allocation IP.
100+
Required for certain games to work properly when the Node has multiple public IP addresses.
101+
<br>
102+
<strong>
103+
Enabling this option will disable internal networking for any servers using this egg,
104+
causing them to be unable to internally access other servers on the same node.
105+
</strong>
106+
</p>
107+
</div>
108+
</div>
109+
94110
</div>
95111
<div class="col-sm-6">
96112
<div class="form-group">

0 commit comments

Comments
 (0)