Added admin configuration
This is not working just yet but the fields have been added to the admin control area.
This commit is contained in:
parent
da30977364
commit
d80660f047
5 changed files with 85 additions and 25 deletions
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
|
namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Config\Repository;
|
||||||
use Pterodactyl\Models\Server;
|
use Pterodactyl\Models\Server;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Pterodactyl\Models\Allocation;
|
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\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
|
||||||
{
|
{
|
||||||
|
@ -41,17 +41,27 @@ class NetworkAllocationController extends ClientApiController
|
||||||
* @param \Pterodactyl\Repositories\Eloquent\AllocationRepository $repository
|
* @param \Pterodactyl\Repositories\Eloquent\AllocationRepository $repository
|
||||||
* @param \Pterodactyl\Repositories\Eloquent\ServerRepository $serverRepository
|
* @param \Pterodactyl\Repositories\Eloquent\ServerRepository $serverRepository
|
||||||
* @param \Pterodactyl\Services\Allocations\AssignmentService $assignmentService
|
* @param \Pterodactyl\Services\Allocations\AssignmentService $assignmentService
|
||||||
|
* @param \Illuminate\Contracts\Config\Repository $config
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \Illuminate\Contracts\Config\Repository
|
||||||
|
*/
|
||||||
|
private $config;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
AllocationRepository $repository,
|
AllocationRepository $repository,
|
||||||
ServerRepository $serverRepository,
|
ServerRepository $serverRepository,
|
||||||
AssignmentService $assignmentService
|
AssignmentService $assignmentService,
|
||||||
|
Repository $config
|
||||||
|
|
||||||
) {
|
) {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
$this->repository = $repository;
|
$this->repository = $repository;
|
||||||
$this->serverRepository = $serverRepository;
|
$this->serverRepository = $serverRepository;
|
||||||
$this->assignmentService = $assignmentService;
|
$this->assignmentService = $assignmentService;
|
||||||
|
$this->config = $config;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -126,8 +136,10 @@ 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 = 25700;
|
$topRange = config('pterodactyl.allocation.start');
|
||||||
$bottomRange = 25565;
|
$bottomRange = config('pterodactyl.allocation.stop');
|
||||||
|
Log::error($bottomRange);
|
||||||
|
Log::error($topRange);
|
||||||
|
|
||||||
if($server->allocation_limit <= $server->allocations->count()) {
|
if($server->allocation_limit <= $server->allocations->count()) {
|
||||||
Log::error('You have created the maximum number of allocations!');
|
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();
|
$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)->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!');
|
Log::error('No allocations available!');
|
||||||
throw new DisplayException(
|
throw new DisplayException(
|
||||||
'No more allocations available!'
|
'No more allocations available!'
|
||||||
|
|
|
@ -21,6 +21,9 @@ class AdvancedSettingsFormRequest extends AdminFormRequest
|
||||||
'pterodactyl:guzzle:connect_timeout' => 'required|integer|between:1,60',
|
'pterodactyl:guzzle:connect_timeout' => 'required|integer|between:1,60',
|
||||||
'pterodactyl:console:count' => 'required|integer|min:1',
|
'pterodactyl:console:count' => 'required|integer|min:1',
|
||||||
'pterodactyl:console:frequency' => 'required|integer|min:10',
|
'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:guzzle:connect_timeout' => 'HTTP Connection Timeout',
|
||||||
'pterodactyl:console:count' => 'Console Message Count',
|
'pterodactyl:console:count' => 'Console Message Count',
|
||||||
'pterodactyl:console:frequency' => 'Console Frequency Tick',
|
'pterodactyl:console:frequency' => 'Console Frequency Tick',
|
||||||
|
'allocation:enabled' => 'Auto Create Allocations Enabled',
|
||||||
|
'pterodactyl:allocation:start' => 'Starting Port',
|
||||||
|
'pterodactyl:allocation:stop' => 'Ending Port',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,7 +109,7 @@
|
||||||
"watch": "cross-env NODE_ENV=development ./node_modules/.bin/webpack --watch --progress",
|
"watch": "cross-env NODE_ENV=development ./node_modules/.bin/webpack --watch --progress",
|
||||||
"build": "cross-env NODE_ENV=development ./node_modules/.bin/webpack --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",
|
"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": [
|
"browserslist": [
|
||||||
"> 0.5%",
|
"> 0.5%",
|
||||||
|
|
|
@ -16,6 +16,7 @@ import GreyRowBox from '@/components/elements/GreyRowBox';
|
||||||
|
|
||||||
const NetworkContainer = () => {
|
const NetworkContainer = () => {
|
||||||
const uuid = ServerContext.useStoreState(state => state.server.data!.uuid);
|
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 allocations = useDeepMemoize(ServerContext.useStoreState(state => state.server.data!.allocations));
|
||||||
const [ addingAllocation, setAddingAllocation ] = useState(false);
|
const [ addingAllocation, setAddingAllocation ] = useState(false);
|
||||||
|
|
||||||
|
@ -48,14 +49,16 @@ const NetworkContainer = () => {
|
||||||
clearFlashes('server:network');
|
clearFlashes('server:network');
|
||||||
setAddingAllocation(true);
|
setAddingAllocation(true);
|
||||||
|
|
||||||
|
const initial = data;
|
||||||
|
|
||||||
newServerAllocation(uuid)
|
newServerAllocation(uuid)
|
||||||
.then(allocation => {
|
.then(allocation => {
|
||||||
mutate(data => ({ ...data, items: data.concat(allocation) }), false);
|
mutate(data?.concat(allocation), false);
|
||||||
setAddingAllocation(false);
|
setAddingAllocation(false);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
clearAndAddHttpError({ key: 'server:network', error });
|
clearAndAddHttpError({ key: 'server:network', error });
|
||||||
mutate(data, false);
|
mutate(initial, false);
|
||||||
setAddingAllocation(false);
|
setAddingAllocation(false);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -78,6 +81,7 @@ const NetworkContainer = () => {
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
{allocationLimit > data!.length ?
|
||||||
<GreyRowBox
|
<GreyRowBox
|
||||||
$hoverable={false}
|
$hoverable={false}
|
||||||
css={tw`mt-2 overflow-x-auto flex items-center justify-center`}
|
css={tw`mt-2 overflow-x-auto flex items-center justify-center`}
|
||||||
|
@ -95,6 +99,11 @@ const NetworkContainer = () => {
|
||||||
</Button>
|
</Button>
|
||||||
}
|
}
|
||||||
</GreyRowBox>
|
</GreyRowBox>
|
||||||
|
:
|
||||||
|
<p css={tw`mt-2 text-center text-sm text-neutral-400`}>
|
||||||
|
You have reached the max number of allocations allowed for your server.
|
||||||
|
</p>
|
||||||
|
}
|
||||||
</ServerContentBlock>
|
</ServerContentBlock>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -105,6 +105,39 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="box">
|
||||||
|
<div class="box-header with-border">
|
||||||
|
<h3 class="box-title">Automatic Allocation Creation</h3>
|
||||||
|
</div>
|
||||||
|
<div class="box-body">
|
||||||
|
<div class="row">
|
||||||
|
<div class="form-group col-md-4">
|
||||||
|
<label class="control-label">Status</label>
|
||||||
|
<div>
|
||||||
|
<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>
|
||||||
|
</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>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group col-md-4">
|
||||||
|
<label class="control-label">Starting Port</label>
|
||||||
|
<div>
|
||||||
|
<input type="number" required class="form-control" name="pterodactyl:allocation:start" value="{{ old('pterodactyl:allocation:start', config('pterodactyl.allocation.start')) }}">
|
||||||
|
<p class="text-muted small">The starting port in the range that can be automatically allocated.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group col-md-4">
|
||||||
|
<label class="control-label">Ending Port</label>
|
||||||
|
<div>
|
||||||
|
<input type="number" required class="form-control" name="pterodactyl:allocation:stop" value="{{ old('pterodactyl:allocation:stop', config('pterodactyl.allocation.stop')) }}">
|
||||||
|
<p class="text-muted small">The ending port in the range that can be automatically allocated.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="box box-primary">
|
<div class="box box-primary">
|
||||||
<div class="box-footer">
|
<div class="box-footer">
|
||||||
{{ csrf_field() }}
|
{{ csrf_field() }}
|
||||||
|
|
Loading…
Reference in a new issue