From 87b96bdfc86045135ba74a7439aa7c7bced13930 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Thu, 1 Mar 2018 20:08:27 -0600 Subject: [PATCH] Add core logic to allow for limited databases and allocations --- .../UpdateServerBuildConfigurationRequest.php | 11 +- app/Models/Server.php | 6 + .../Servers/BuildModificationService.php | 2 + .../Api/Application/ServerTransformer.php | 4 + .../Api/Client/ServerTransformer.php | 4 + ...nd_port_limit_columns_to_servers_table.php | 33 ++++++ .../pterodactyl/admin/servers/new.blade.php | 2 +- .../admin/servers/view/build.blade.php | 109 +++++++++++------- 8 files changed, 128 insertions(+), 43 deletions(-) create mode 100644 database/migrations/2018_03_01_192831_add_database_and_port_limit_columns_to_servers_table.php diff --git a/app/Http/Requests/Api/Application/Servers/UpdateServerBuildConfigurationRequest.php b/app/Http/Requests/Api/Application/Servers/UpdateServerBuildConfigurationRequest.php index 893ff5ff7..076abdf4a 100644 --- a/app/Http/Requests/Api/Application/Servers/UpdateServerBuildConfigurationRequest.php +++ b/app/Http/Requests/Api/Application/Servers/UpdateServerBuildConfigurationRequest.php @@ -13,7 +13,7 @@ class UpdateServerBuildConfigurationRequest extends ServerWriteRequest */ public function rules(): array { - $rules = Server::getUpdateRulesForId($this->route()->parameter('server')->id); + $rules = Server::getUpdateRulesForId($this->getModel(Server::class)->id); return [ 'allocation' => $rules['allocation_id'], @@ -26,6 +26,9 @@ class UpdateServerBuildConfigurationRequest extends ServerWriteRequest 'add_allocations.*' => 'integer', 'remove_allocations' => 'bail|array', 'remove_allocations.*' => 'integer', + 'feature_limits' => 'required|array', + 'feature_limits.databases' => $rules['database_limit'], + 'feature_limits.allocations' => $rules['allocation_limit'], ]; } @@ -39,7 +42,9 @@ class UpdateServerBuildConfigurationRequest extends ServerWriteRequest $data = parent::validated(); $data['allocation_id'] = $data['allocation']; - unset($data['allocation']); + $data['database_limit'] = $data['feature_limits']['databases']; + $data['allocation_limit'] = $data['feature_limits']['allocations']; + unset($data['allocation'], $data['feature_limits']); return $data; } @@ -56,6 +61,8 @@ class UpdateServerBuildConfigurationRequest extends ServerWriteRequest 'remove_allocations' => 'allocations to remove', 'add_allocations.*' => 'allocation to add', 'remove_allocations.*' => 'allocation to remove', + 'feature_limits.databases' => 'Database Limit', + 'feature_limits.allocations' => 'Allocation Limit', ]; } } diff --git a/app/Models/Server.php b/app/Models/Server.php index 458bff1d6..d5c6b3a8d 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -69,6 +69,8 @@ class Server extends Model implements CleansAttributes, ValidableContract 'skip_scripts' => 'sometimes', 'image' => 'required', 'startup' => 'required', + 'database_limit' => 'present', + 'allocation_limit' => 'present', ]; /** @@ -93,6 +95,8 @@ class Server extends Model implements CleansAttributes, ValidableContract 'skip_scripts' => 'boolean', 'image' => 'string|max:255', 'installed' => 'boolean', + 'database_limit' => 'nullable|integer|min:0', + 'allocation_limit' => 'nullable|integer|min:0', ]; /** @@ -116,6 +120,8 @@ class Server extends Model implements CleansAttributes, ValidableContract 'egg_id' => 'integer', 'pack_id' => 'integer', 'installed' => 'integer', + 'database_limit' => 'integer', + 'allocation_limit' => 'integer', ]; /** diff --git a/app/Services/Servers/BuildModificationService.php b/app/Services/Servers/BuildModificationService.php index 8924b2a04..5d36b4c5c 100644 --- a/app/Services/Servers/BuildModificationService.php +++ b/app/Services/Servers/BuildModificationService.php @@ -91,6 +91,8 @@ class BuildModificationService 'cpu' => array_get($data, 'cpu'), 'disk' => array_get($data, 'disk'), 'allocation_id' => array_get($data, 'allocation_id'), + 'database_limit' => array_get($data, 'database_limit'), + 'allocation_limit' => array_get($data, 'allocation_limit'), ]); $allocations = $this->allocationRepository->findWhere([['server_id', '=', $server->id]]); diff --git a/app/Transformers/Api/Application/ServerTransformer.php b/app/Transformers/Api/Application/ServerTransformer.php index 6a003b4dc..2a542dbcd 100644 --- a/app/Transformers/Api/Application/ServerTransformer.php +++ b/app/Transformers/Api/Application/ServerTransformer.php @@ -75,6 +75,10 @@ class ServerTransformer extends BaseTransformer 'io' => $server->io, 'cpu' => $server->cpu, ], + 'feature_limits' => [ + 'databases' => $server->database_limit, + 'allocations' => $server->allocation_limit, + ], 'user' => $server->owner_id, 'node' => $server->node_id, 'allocation' => $server->allocation_id, diff --git a/app/Transformers/Api/Client/ServerTransformer.php b/app/Transformers/Api/Client/ServerTransformer.php index 4f08c208d..6816d6d74 100644 --- a/app/Transformers/Api/Client/ServerTransformer.php +++ b/app/Transformers/Api/Client/ServerTransformer.php @@ -36,6 +36,10 @@ class ServerTransformer extends BaseClientTransformer 'io' => $server->io, 'cpu' => $server->cpu, ], + 'feature_limits' => [ + 'databases' => $server->database_limit, + 'allocations' => $server->allocation_limit, + ], ]; } } diff --git a/database/migrations/2018_03_01_192831_add_database_and_port_limit_columns_to_servers_table.php b/database/migrations/2018_03_01_192831_add_database_and_port_limit_columns_to_servers_table.php new file mode 100644 index 000000000..4e85e8aeb --- /dev/null +++ b/database/migrations/2018_03_01_192831_add_database_and_port_limit_columns_to_servers_table.php @@ -0,0 +1,33 @@ +unsignedInteger('database_limit')->after('installed')->nullable()->default(0); + $table->unsignedInteger('allocation_limit')->after('installed')->nullable()->default(0); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('servers', function (Blueprint $table) { + $table->dropColumn(['database_limit', 'allocation_limit']); + }); + } +} diff --git a/resources/themes/pterodactyl/admin/servers/new.blade.php b/resources/themes/pterodactyl/admin/servers/new.blade.php index bfb6760b4..bad452312 100644 --- a/resources/themes/pterodactyl/admin/servers/new.blade.php +++ b/resources/themes/pterodactyl/admin/servers/new.blade.php @@ -111,7 +111,7 @@
- + MB
diff --git a/resources/themes/pterodactyl/admin/servers/view/build.blade.php b/resources/themes/pterodactyl/admin/servers/view/build.blade.php index f6e9e607b..8900bf90a 100644 --- a/resources/themes/pterodactyl/admin/servers/view/build.blade.php +++ b/resources/themes/pterodactyl/admin/servers/view/build.blade.php @@ -89,50 +89,79 @@
-
-
-

Allocation Management

-
-
-
- - -

The default connection address that will be used for this game server.

-
-
- -
- +
+
+
+
+

Application Feature Limits

-

Please note that due to software limitations you cannot assign identical ports on different IPs to the same server.

-
-
- -
- +
+
+
+ +
+ +
+

The total number of databases a user is allowed to create for this server. Leave blank to allow unlimmited.

+
+
+ +
+ +
+

This feature is not currently implemented. The total number of allocations a user is allowed to create for this server. Leave blank to allow unlimited.

+
+
-

Simply select which ports you would like to remove from the list above. If you want to assign a port on a different IP that is already in use you can select it from the left and delete it here.

-