From fb33824e10902cab35285d6c42fe572de7534760 Mon Sep 17 00:00:00 2001 From: Caleb Date: Tue, 29 Sep 2020 12:00:59 -0400 Subject: [PATCH] Added admin controls. Removed the note in the server settings that stated that the allocations feature is currently not implemented. Properly check to make sure that there are allocations available in range before trying to create it. --- .../Api/Client/Servers/NetworkAllocationController.php | 8 ++++---- app/Providers/SettingsServiceProvider.php | 3 +++ resources/views/admin/servers/view/build.blade.php | 2 +- resources/views/admin/settings/advanced.blade.php | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/Api/Client/Servers/NetworkAllocationController.php b/app/Http/Controllers/Api/Client/Servers/NetworkAllocationController.php index a4890e0c1..341d4e926 100644 --- a/app/Http/Controllers/Api/Client/Servers/NetworkAllocationController.php +++ b/app/Http/Controllers/Api/Client/Servers/NetworkAllocationController.php @@ -17,6 +17,7 @@ use Pterodactyl\Http\Requests\Api\Client\Servers\Network\UpdateAllocationRequest use Pterodactyl\Http\Requests\Api\Client\Servers\Network\NewAllocationRequest; use Pterodactyl\Http\Requests\Api\Client\Servers\Network\SetPrimaryAllocationRequest; use Pterodactyl\Services\Allocations\AssignmentService; +use Illuminate\Support\Facades\Log; class NetworkAllocationController extends ClientApiController { @@ -136,8 +137,8 @@ class NetworkAllocationController extends ClientApiController public function addNew(NewAllocationRequest $request, Server $server): array { Log::info('addNew()'); - $topRange = config('pterodactyl.allocation.start'); - $bottomRange = config('pterodactyl.allocation.stop'); + $topRange = config('pterodactyl.allocation.stop',0); + $bottomRange = config('pterodactyl.allocation.start',0); Log::error($bottomRange); Log::error($topRange); @@ -151,7 +152,7 @@ class NetworkAllocationController extends ClientApiController $allocation = $server->node->allocations()->where('ip',$server->allocation->ip)->whereNull('server_id')->first(); if(!$allocation) { - if($server->node->allocations()->where('ip',$server->allocation->ip)->where([['port', '>=', $bottomRange ], ['port', '<=', $topRange],])->count() >= $topRange-$bottomRange || config('pterodactyl.allocation.enabled', 0)) { + if($server->node->allocations()->where('ip',$server->allocation->ip)->where([['port', '>=', $bottomRange ], ['port', '<=', $topRange],])->count() >= $topRange-$bottomRange+1 || !config('allocation.enabled', false)) { Log::error('No allocations available!'); throw new DisplayException( 'No more allocations available!' @@ -163,7 +164,6 @@ class NetworkAllocationController extends ClientApiController do { $port = rand($bottomRange, $topRange); Log::info('Picking port....'); - // TODO ADD ITERATOR THAT TIMES OUT AFTER SEARCHING FOR SO MUCH TIME? } while(array_search($port, $allPorts)); $this->assignmentService->handle($server->node,[ diff --git a/app/Providers/SettingsServiceProvider.php b/app/Providers/SettingsServiceProvider.php index abd88c04b..042c12bf9 100644 --- a/app/Providers/SettingsServiceProvider.php +++ b/app/Providers/SettingsServiceProvider.php @@ -30,6 +30,9 @@ class SettingsServiceProvider extends ServiceProvider 'pterodactyl:console:count', 'pterodactyl:console:frequency', 'pterodactyl:auth:2fa_required', + 'allocation:enabled', + 'pterodactyl:allocation:stop', + 'pterodactyl:allocation:start', ]; /** diff --git a/resources/views/admin/servers/view/build.blade.php b/resources/views/admin/servers/view/build.blade.php index c1f8defca..338d2c9e0 100644 --- a/resources/views/admin/servers/view/build.blade.php +++ b/resources/views/admin/servers/view/build.blade.php @@ -115,7 +115,7 @@
-

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

+

The total number of allocations a user is allowed to create for this server.

diff --git a/resources/views/admin/settings/advanced.blade.php b/resources/views/admin/settings/advanced.blade.php index fee99b359..f749511f3 100644 --- a/resources/views/admin/settings/advanced.blade.php +++ b/resources/views/admin/settings/advanced.blade.php @@ -115,8 +115,8 @@

If enabled, the panel will attempt to auto create a new allocation in the range specified if there are no more allocations already created on the node.