diff --git a/app/Http/Controllers/Api/Client/Servers/NetworkAllocationController.php b/app/Http/Controllers/Api/Client/Servers/NetworkAllocationController.php
index edaa8dc67..a4890e0c1 100644
--- a/app/Http/Controllers/Api/Client/Servers/NetworkAllocationController.php
+++ b/app/Http/Controllers/Api/Client/Servers/NetworkAllocationController.php
@@ -2,6 +2,7 @@
namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
+use Illuminate\Contracts\Config\Repository;
use Pterodactyl\Models\Server;
use Illuminate\Http\JsonResponse;
use Pterodactyl\Models\Allocation;
@@ -16,7 +17,6 @@ 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
{
@@ -41,17 +41,27 @@ class NetworkAllocationController extends ClientApiController
* @param \Pterodactyl\Repositories\Eloquent\AllocationRepository $repository
* @param \Pterodactyl\Repositories\Eloquent\ServerRepository $serverRepository
* @param \Pterodactyl\Services\Allocations\AssignmentService $assignmentService
+ * @param \Illuminate\Contracts\Config\Repository $config
*/
+
+ /**
+ * @var \Illuminate\Contracts\Config\Repository
+ */
+ private $config;
+
public function __construct(
AllocationRepository $repository,
ServerRepository $serverRepository,
- AssignmentService $assignmentService
+ AssignmentService $assignmentService,
+ Repository $config
+
) {
parent::__construct();
$this->repository = $repository;
$this->serverRepository = $serverRepository;
$this->assignmentService = $assignmentService;
+ $this->config = $config;
}
/**
@@ -126,8 +136,10 @@ class NetworkAllocationController extends ClientApiController
public function addNew(NewAllocationRequest $request, Server $server): array
{
Log::info('addNew()');
- $topRange = 25700;
- $bottomRange = 25565;
+ $topRange = config('pterodactyl.allocation.start');
+ $bottomRange = config('pterodactyl.allocation.stop');
+ Log::error($bottomRange);
+ Log::error($topRange);
if($server->allocation_limit <= $server->allocations->count()) {
Log::error('You have created the maximum number of allocations!');
@@ -139,7 +151,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)->count() >= $topRange-$bottomRange) {
+ if($server->node->allocations()->where('ip',$server->allocation->ip)->where([['port', '>=', $bottomRange ], ['port', '<=', $topRange],])->count() >= $topRange-$bottomRange || config('pterodactyl.allocation.enabled', 0)) {
Log::error('No allocations available!');
throw new DisplayException(
'No more allocations available!'
diff --git a/app/Http/Requests/Admin/Settings/AdvancedSettingsFormRequest.php b/app/Http/Requests/Admin/Settings/AdvancedSettingsFormRequest.php
index a80d8dab9..023b2d89a 100644
--- a/app/Http/Requests/Admin/Settings/AdvancedSettingsFormRequest.php
+++ b/app/Http/Requests/Admin/Settings/AdvancedSettingsFormRequest.php
@@ -21,6 +21,9 @@ class AdvancedSettingsFormRequest extends AdminFormRequest
'pterodactyl:guzzle:connect_timeout' => 'required|integer|between:1,60',
'pterodactyl:console:count' => 'required|integer|min:1',
'pterodactyl:console:frequency' => 'required|integer|min:10',
+ 'allocation:enabled' => 'required|in:true,false',
+ 'pterodactyl:allocation:start' => 'required|integer|between:2000,65535',
+ 'pterodactyl:allocation:stop' => 'required|integer|between:2000,65535',
];
}
@@ -37,6 +40,9 @@ class AdvancedSettingsFormRequest extends AdminFormRequest
'pterodactyl:guzzle:connect_timeout' => 'HTTP Connection Timeout',
'pterodactyl:console:count' => 'Console Message Count',
'pterodactyl:console:frequency' => 'Console Frequency Tick',
+ 'allocation:enabled' => 'Auto Create Allocations Enabled',
+ 'pterodactyl:allocation:start' => 'Starting Port',
+ 'pterodactyl:allocation:stop' => 'Ending Port',
];
}
}
diff --git a/package.json b/package.json
index 0456b3676..15e96c4bd 100644
--- a/package.json
+++ b/package.json
@@ -109,7 +109,7 @@
"watch": "cross-env NODE_ENV=development ./node_modules/.bin/webpack --watch --progress",
"build": "cross-env NODE_ENV=development ./node_modules/.bin/webpack --progress",
"build:production": "yarn run clean && cross-env NODE_ENV=production ./node_modules/.bin/webpack --mode production",
- "serve": "yarn run clean && cross-env PUBLIC_PATH=https://ptero.test:8080 NODE_ENV=development TSC_WATCHFILE=UseFsEventsWithFallbackDynamicPolling webpack-dev-server --host 0.0.0.0 --hot"
+ "serve": "yarn run clean && cross-env PUBLIC_PATH=https://pterodactyl.test:8080 NODE_ENV=development TSC_WATCHFILE=UseFsEventsWithFallbackDynamicPolling webpack-dev-server --host 0.0.0.0 --hot --https --key /etc/ssl/private/pterodactyl.test-key.pem --cert /etc/ssl/private/pterodactyl.test.pem"
},
"browserslist": [
"> 0.5%",
diff --git a/resources/scripts/components/server/network/NetworkContainer.tsx b/resources/scripts/components/server/network/NetworkContainer.tsx
index d64b11de4..d28e10c60 100644
--- a/resources/scripts/components/server/network/NetworkContainer.tsx
+++ b/resources/scripts/components/server/network/NetworkContainer.tsx
@@ -16,6 +16,7 @@ import GreyRowBox from '@/components/elements/GreyRowBox';
const NetworkContainer = () => {
const uuid = ServerContext.useStoreState(state => state.server.data!.uuid);
+ const allocationLimit = ServerContext.useStoreState(state => state.server.data!.featureLimits.allocations);
const allocations = useDeepMemoize(ServerContext.useStoreState(state => state.server.data!.allocations));
const [ addingAllocation, setAddingAllocation ] = useState(false);
@@ -48,14 +49,16 @@ const NetworkContainer = () => {
clearFlashes('server:network');
setAddingAllocation(true);
+ const initial = data;
+
newServerAllocation(uuid)
.then(allocation => {
- mutate(data => ({ ...data, items: data.concat(allocation) }), false);
+ mutate(data?.concat(allocation), false);
setAddingAllocation(false);
})
.catch(error => {
clearAndAddHttpError({ key: 'server:network', error });
- mutate(data, false);
+ mutate(initial, false);
setAddingAllocation(false);
});
};
@@ -78,23 +81,29 @@ const NetworkContainer = () => {
/>
))
}
-
+ You have reached the max number of allocations allowed for your server. +
+ } ); }; diff --git a/resources/views/admin/settings/advanced.blade.php b/resources/views/admin/settings/advanced.blade.php index 7a1d616c5..fee99b359 100644 --- a/resources/views/admin/settings/advanced.blade.php +++ b/resources/views/admin/settings/advanced.blade.php @@ -105,6 +105,39 @@ +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.
+The starting port in the range that can be automatically allocated.
+The ending port in the range that can be automatically allocated.
+