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.
This commit is contained in:
Caleb 2020-09-29 12:00:59 -04:00
parent d80660f047
commit fb33824e10
4 changed files with 9 additions and 6 deletions

View file

@ -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\NewAllocationRequest;
use Pterodactyl\Http\Requests\Api\Client\Servers\Network\SetPrimaryAllocationRequest; use Pterodactyl\Http\Requests\Api\Client\Servers\Network\SetPrimaryAllocationRequest;
use Pterodactyl\Services\Allocations\AssignmentService; use Pterodactyl\Services\Allocations\AssignmentService;
use Illuminate\Support\Facades\Log;
class NetworkAllocationController extends ClientApiController class NetworkAllocationController extends ClientApiController
{ {
@ -136,8 +137,8 @@ class NetworkAllocationController extends ClientApiController
public function addNew(NewAllocationRequest $request, Server $server): array public function addNew(NewAllocationRequest $request, Server $server): array
{ {
Log::info('addNew()'); Log::info('addNew()');
$topRange = config('pterodactyl.allocation.start'); $topRange = config('pterodactyl.allocation.stop',0);
$bottomRange = config('pterodactyl.allocation.stop'); $bottomRange = config('pterodactyl.allocation.start',0);
Log::error($bottomRange); Log::error($bottomRange);
Log::error($topRange); Log::error($topRange);
@ -151,7 +152,7 @@ class NetworkAllocationController extends ClientApiController
$allocation = $server->node->allocations()->where('ip',$server->allocation->ip)->whereNull('server_id')->first(); $allocation = $server->node->allocations()->where('ip',$server->allocation->ip)->whereNull('server_id')->first();
if(!$allocation) { 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!'); Log::error('No allocations available!');
throw new DisplayException( throw new DisplayException(
'No more allocations available!' 'No more allocations available!'
@ -163,7 +164,6 @@ class NetworkAllocationController extends ClientApiController
do { do {
$port = rand($bottomRange, $topRange); $port = rand($bottomRange, $topRange);
Log::info('Picking port....'); Log::info('Picking port....');
// TODO ADD ITERATOR THAT TIMES OUT AFTER SEARCHING FOR SO MUCH TIME?
} while(array_search($port, $allPorts)); } while(array_search($port, $allPorts));
$this->assignmentService->handle($server->node,[ $this->assignmentService->handle($server->node,[

View file

@ -30,6 +30,9 @@ class SettingsServiceProvider extends ServiceProvider
'pterodactyl:console:count', 'pterodactyl:console:count',
'pterodactyl:console:frequency', 'pterodactyl:console:frequency',
'pterodactyl:auth:2fa_required', 'pterodactyl:auth:2fa_required',
'allocation:enabled',
'pterodactyl:allocation:stop',
'pterodactyl:allocation:start',
]; ];
/** /**

View file

@ -115,7 +115,7 @@
<div> <div>
<input type="text" name="allocation_limit" class="form-control" value="{{ old('allocation_limit', $server->allocation_limit) }}"/> <input type="text" name="allocation_limit" class="form-control" value="{{ old('allocation_limit', $server->allocation_limit) }}"/>
</div> </div>
<p class="text-muted small"><strong>This feature is not currently implemented.</strong> The total number of allocations a user is allowed to create for this server.</p> <p class="text-muted small">The total number of allocations a user is allowed to create for this server.</p>
</div> </div>
<div class="form-group col-xs-6"> <div class="form-group col-xs-6">
<label for="backup_limit" class="control-label">Backup Limit</label> <label for="backup_limit" class="control-label">Backup Limit</label>

View file

@ -115,8 +115,8 @@
<label class="control-label">Status</label> <label class="control-label">Status</label>
<div> <div>
<select class="form-control" name="allocation:enabled"> <select class="form-control" name="allocation:enabled">
<option value="true" @if(old('allocation:enabled', config('allocation.enabled')) == '1') selected @endif>Enabled</option>
<option value="false">Disabled</option> <option value="false">Disabled</option>
<option value="true" @if(old('allocation:enabled', config('allocation.enabled'))) selected @endif>Enabled</option>
</select> </select>
<p class="text-muted small">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.</p> <p class="text-muted small">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.</p>
</div> </div>