From 68e9100e57212070bd81852e872a4c20572f3dc8 Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Sun, 25 Sep 2022 13:24:54 -0600 Subject: [PATCH] admin(eggs): add `force_outgoing_ip` option (#4323) Closes #3841 --- .../Controllers/Admin/Nests/EggController.php | 4 +-- .../Requests/Admin/Egg/EggFormRequest.php | 10 ++++++ app/Models/Egg.php | 6 +++- .../ServerConfigurationStructureService.php | 1 + ...force_outgoing_ip_column_to_eggs_table.php | 32 +++++++++++++++++++ resources/views/admin/eggs/new.blade.php | 15 +++++++++ resources/views/admin/eggs/view.blade.php | 16 ++++++++++ 7 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 database/migrations/2022_08_16_214400_add_force_outgoing_ip_column_to_eggs_table.php diff --git a/app/Http/Controllers/Admin/Nests/EggController.php b/app/Http/Controllers/Admin/Nests/EggController.php index 11f9c77ad..a67c51311 100644 --- a/app/Http/Controllers/Admin/Nests/EggController.php +++ b/app/Http/Controllers/Admin/Nests/EggController.php @@ -73,7 +73,7 @@ class EggController extends Controller */ public function store(EggFormRequest $request): RedirectResponse { - $data = $request->normalize(); + $data = $request->validated(); $data['docker_images'] = $this->normalizeDockerImages($data['docker_images'] ?? null); $egg = $this->creationService->handle($data); @@ -106,7 +106,7 @@ class EggController extends Controller */ public function update(EggFormRequest $request, Egg $egg): RedirectResponse { - $data = $request->normalize(); + $data = $request->validated(); $data['docker_images'] = $this->normalizeDockerImages($data['docker_images'] ?? null); $this->updateService->handle($egg, $data); diff --git a/app/Http/Requests/Admin/Egg/EggFormRequest.php b/app/Http/Requests/Admin/Egg/EggFormRequest.php index 065abaf13..2dbc01b51 100644 --- a/app/Http/Requests/Admin/Egg/EggFormRequest.php +++ b/app/Http/Requests/Admin/Egg/EggFormRequest.php @@ -22,6 +22,7 @@ class EggFormRequest extends AdminFormRequest 'name' => 'required|string|max:191', 'description' => 'nullable|string', 'docker_images' => 'required|string', + 'force_outgoing_ip' => 'sometimes|boolean', 'file_denylist' => 'array', 'startup' => 'required|string', 'config_from' => 'sometimes|bail|nullable|numeric', @@ -47,4 +48,13 @@ class EggFormRequest extends AdminFormRequest return (int) $this->input('config_from') !== 0; }); } + + public function validated(): array + { + $data = parent::validated(); + + return array_merge($data, [ + 'force_outgoing_ip' => array_get($data, 'force_outgoing_ip', false), + ]); + } } diff --git a/app/Models/Egg.php b/app/Models/Egg.php index dbb90d301..c7c08f117 100644 --- a/app/Models/Egg.php +++ b/app/Models/Egg.php @@ -11,8 +11,9 @@ namespace Pterodactyl\Models; * @property string|null $description * @property array|null $features * @property string $docker_image -- deprecated, use $docker_images - * @property string $update_url * @property array $docker_images + * @property string $update_url + * @property bool $force_outgoing_ip * @property array|null $file_denylist * @property string|null $config_files * @property string|null $config_startup @@ -84,6 +85,7 @@ class Egg extends Model 'description', 'features', 'docker_images', + 'force_outgoing_ip', 'file_denylist', 'config_files', 'config_startup', @@ -107,6 +109,7 @@ class Egg extends Model 'nest_id' => 'integer', 'config_from' => 'integer', 'script_is_privileged' => 'boolean', + 'force_outgoing_ip' => 'boolean', 'copy_script_from' => 'integer', 'features' => 'array', 'docker_images' => 'array', @@ -134,6 +137,7 @@ class Egg extends Model 'config_logs' => 'required_without:config_from|nullable|json', 'config_files' => 'required_without:config_from|nullable|json', 'update_url' => 'sometimes|nullable|string', + 'force_outgoing_ip' => 'sometimes|boolean', ]; /** diff --git a/app/Services/Servers/ServerConfigurationStructureService.php b/app/Services/Servers/ServerConfigurationStructureService.php index eca0320c1..0625f6891 100644 --- a/app/Services/Servers/ServerConfigurationStructureService.php +++ b/app/Services/Servers/ServerConfigurationStructureService.php @@ -73,6 +73,7 @@ class ServerConfigurationStructureService 'requires_rebuild' => false, ], 'allocations' => [ + 'force_outgoing_ip' => $server->egg->force_outgoing_ip, 'default' => [ 'ip' => $server->allocation->ip, 'port' => $server->allocation->port, diff --git a/database/migrations/2022_08_16_214400_add_force_outgoing_ip_column_to_eggs_table.php b/database/migrations/2022_08_16_214400_add_force_outgoing_ip_column_to_eggs_table.php new file mode 100644 index 000000000..eb3a56bf2 --- /dev/null +++ b/database/migrations/2022_08_16_214400_add_force_outgoing_ip_column_to_eggs_table.php @@ -0,0 +1,32 @@ +boolean('force_outgoing_ip')->default(false); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('eggs', function (Blueprint $table) { + $table->dropColumn('force_outgoing_ip'); + }); + } +} diff --git a/resources/views/admin/eggs/new.blade.php b/resources/views/admin/eggs/new.blade.php index 516ac861a..e630eab18 100644 --- a/resources/views/admin/eggs/new.blade.php +++ b/resources/views/admin/eggs/new.blade.php @@ -50,6 +50,21 @@

A description of this Egg.

+
+
+ + +

+ Forces all outgoing network traffic to have its Source IP NATed to the IP of the server's primary allocation IP. + Required for certain games to work properly when the Node has multiple public IP addresses. +
+ + Enabling this option will disable internal networking for any servers using this egg, + causing them to be unable to internally access other servers on the same node. + +

+
+
diff --git a/resources/views/admin/eggs/view.blade.php b/resources/views/admin/eggs/view.blade.php index a2cda15e8..f64fde659 100644 --- a/resources/views/admin/eggs/view.blade.php +++ b/resources/views/admin/eggs/view.blade.php @@ -91,6 +91,22 @@ followed by a pipe character, and then the image URL. Example: Display Name|ghcr.io/my/egg

+
+
+ force_outgoing_ip) checked @endif /> + +

+ Forces all outgoing network traffic to have its Source IP NATed to the IP of the server's primary allocation IP. + Required for certain games to work properly when the Node has multiple public IP addresses. +
+ + Enabling this option will disable internal networking for any servers using this egg, + causing them to be unable to internally access other servers on the same node. + +

+
+
+