Skip to content

Commit d80660f

Browse files
committed
Added admin configuration
This is not working just yet but the fields have been added to the admin control area.
1 parent da30977 commit d80660f

File tree

5 files changed

+85
-25
lines changed

5 files changed

+85
-25
lines changed

app/Http/Controllers/Api/Client/Servers/NetworkAllocationController.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
44

5+
use Illuminate\Contracts\Config\Repository;
56
use Pterodactyl\Models\Server;
67
use Illuminate\Http\JsonResponse;
78
use Pterodactyl\Models\Allocation;
@@ -16,7 +17,6 @@
1617
use Pterodactyl\Http\Requests\Api\Client\Servers\Network\NewAllocationRequest;
1718
use Pterodactyl\Http\Requests\Api\Client\Servers\Network\SetPrimaryAllocationRequest;
1819
use Pterodactyl\Services\Allocations\AssignmentService;
19-
use Illuminate\Support\Facades\Log;
2020

2121
class NetworkAllocationController extends ClientApiController
2222
{
@@ -41,17 +41,27 @@ class NetworkAllocationController extends ClientApiController
4141
* @param \Pterodactyl\Repositories\Eloquent\AllocationRepository $repository
4242
* @param \Pterodactyl\Repositories\Eloquent\ServerRepository $serverRepository
4343
* @param \Pterodactyl\Services\Allocations\AssignmentService $assignmentService
44+
* @param \Illuminate\Contracts\Config\Repository $config
4445
*/
46+
47+
/**
48+
* @var \Illuminate\Contracts\Config\Repository
49+
*/
50+
private $config;
51+
4552
public function __construct(
4653
AllocationRepository $repository,
4754
ServerRepository $serverRepository,
48-
AssignmentService $assignmentService
55+
AssignmentService $assignmentService,
56+
Repository $config
57+
4958
) {
5059
parent::__construct();
5160

5261
$this->repository = $repository;
5362
$this->serverRepository = $serverRepository;
5463
$this->assignmentService = $assignmentService;
64+
$this->config = $config;
5565
}
5666

5767
/**
@@ -126,8 +136,10 @@ public function setPrimary(SetPrimaryAllocationRequest $request, Server $server,
126136
public function addNew(NewAllocationRequest $request, Server $server): array
127137
{
128138
Log::info('addNew()');
129-
$topRange = 25700;
130-
$bottomRange = 25565;
139+
$topRange = config('pterodactyl.allocation.start');
140+
$bottomRange = config('pterodactyl.allocation.stop');
141+
Log::error($bottomRange);
142+
Log::error($topRange);
131143

132144
if($server->allocation_limit <= $server->allocations->count()) {
133145
Log::error('You have created the maximum number of allocations!');
@@ -139,7 +151,7 @@ public function addNew(NewAllocationRequest $request, Server $server): array
139151
$allocation = $server->node->allocations()->where('ip',$server->allocation->ip)->whereNull('server_id')->first();
140152

141153
if(!$allocation) {
142-
if($server->node->allocations()->where('ip',$server->allocation->ip)->count() >= $topRange-$bottomRange) {
154+
if($server->node->allocations()->where('ip',$server->allocation->ip)->where([['port', '>=', $bottomRange ], ['port', '<=', $topRange],])->count() >= $topRange-$bottomRange || config('pterodactyl.allocation.enabled', 0)) {
143155
Log::error('No allocations available!');
144156
throw new DisplayException(
145157
'No more allocations available!'

app/Http/Requests/Admin/Settings/AdvancedSettingsFormRequest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ public function rules()
2121
'pterodactyl:guzzle:connect_timeout' => 'required|integer|between:1,60',
2222
'pterodactyl:console:count' => 'required|integer|min:1',
2323
'pterodactyl:console:frequency' => 'required|integer|min:10',
24+
'allocation:enabled' => 'required|in:true,false',
25+
'pterodactyl:allocation:start' => 'required|integer|between:2000,65535',
26+
'pterodactyl:allocation:stop' => 'required|integer|between:2000,65535',
2427
];
2528
}
2629

@@ -37,6 +40,9 @@ public function attributes()
3740
'pterodactyl:guzzle:connect_timeout' => 'HTTP Connection Timeout',
3841
'pterodactyl:console:count' => 'Console Message Count',
3942
'pterodactyl:console:frequency' => 'Console Frequency Tick',
43+
'allocation:enabled' => 'Auto Create Allocations Enabled',
44+
'pterodactyl:allocation:start' => 'Starting Port',
45+
'pterodactyl:allocation:stop' => 'Ending Port',
4046
];
4147
}
4248
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
"watch": "cross-env NODE_ENV=development ./node_modules/.bin/webpack --watch --progress",
110110
"build": "cross-env NODE_ENV=development ./node_modules/.bin/webpack --progress",
111111
"build:production": "yarn run clean && cross-env NODE_ENV=production ./node_modules/.bin/webpack --mode production",
112-
"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"
112+
"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"
113113
},
114114
"browserslist": [
115115
"> 0.5%",

resources/scripts/components/server/network/NetworkContainer.tsx

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import GreyRowBox from '@/components/elements/GreyRowBox';
1616

1717
const NetworkContainer = () => {
1818
const uuid = ServerContext.useStoreState(state => state.server.data!.uuid);
19+
const allocationLimit = ServerContext.useStoreState(state => state.server.data!.featureLimits.allocations);
1920
const allocations = useDeepMemoize(ServerContext.useStoreState(state => state.server.data!.allocations));
2021
const [ addingAllocation, setAddingAllocation ] = useState(false);
2122

@@ -48,14 +49,16 @@ const NetworkContainer = () => {
4849
clearFlashes('server:network');
4950
setAddingAllocation(true);
5051

52+
const initial = data;
53+
5154
newServerAllocation(uuid)
5255
.then(allocation => {
53-
mutate(data => ({ ...data, items: data.concat(allocation) }), false);
56+
mutate(data?.concat(allocation), false);
5457
setAddingAllocation(false);
5558
})
5659
.catch(error => {
5760
clearAndAddHttpError({ key: 'server:network', error });
58-
mutate(data, false);
61+
mutate(initial, false);
5962
setAddingAllocation(false);
6063
});
6164
};
@@ -78,23 +81,29 @@ const NetworkContainer = () => {
7881
/>
7982
))
8083
}
81-
<GreyRowBox
82-
$hoverable={false}
83-
css={tw`mt-2 overflow-x-auto flex items-center justify-center`}
84-
>
85-
{addingAllocation ?
86-
<Spinner size={'base'} centered/>
87-
:
88-
<Button
89-
color={'primary'}
90-
isSecondary
91-
onClick={() => getNewAllocation() }
92-
css={tw`my-2`}
93-
>
94-
Add New Allocation
95-
</Button>
96-
}
97-
</GreyRowBox>
84+
{allocationLimit > data!.length ?
85+
<GreyRowBox
86+
$hoverable={false}
87+
css={tw`mt-2 overflow-x-auto flex items-center justify-center`}
88+
>
89+
{addingAllocation ?
90+
<Spinner size={'base'} centered/>
91+
:
92+
<Button
93+
color={'primary'}
94+
isSecondary
95+
onClick={() => getNewAllocation()}
96+
css={tw`my-2`}
97+
>
98+
Add New Allocation
99+
</Button>
100+
}
101+
</GreyRowBox>
102+
:
103+
<p css={tw`mt-2 text-center text-sm text-neutral-400`}>
104+
You have reached the max number of allocations allowed for your server.
105+
</p>
106+
}
98107
</ServerContentBlock>
99108
);
100109
};

resources/views/admin/settings/advanced.blade.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,39 @@
105105
</div>
106106
</div>
107107
</div>
108+
<div class="box">
109+
<div class="box-header with-border">
110+
<h3 class="box-title">Automatic Allocation Creation</h3>
111+
</div>
112+
<div class="box-body">
113+
<div class="row">
114+
<div class="form-group col-md-4">
115+
<label class="control-label">Status</label>
116+
<div>
117+
<select class="form-control" name="allocation:enabled">
118+
<option value="true" @if(old('allocation:enabled', config('allocation.enabled')) == '1') selected @endif>Enabled</option>
119+
<option value="false">Disabled</option>
120+
</select>
121+
<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>
122+
</div>
123+
</div>
124+
<div class="form-group col-md-4">
125+
<label class="control-label">Starting Port</label>
126+
<div>
127+
<input type="number" required class="form-control" name="pterodactyl:allocation:start" value="{{ old('pterodactyl:allocation:start', config('pterodactyl.allocation.start')) }}">
128+
<p class="text-muted small">The starting port in the range that can be automatically allocated.</p>
129+
</div>
130+
</div>
131+
<div class="form-group col-md-4">
132+
<label class="control-label">Ending Port</label>
133+
<div>
134+
<input type="number" required class="form-control" name="pterodactyl:allocation:stop" value="{{ old('pterodactyl:allocation:stop', config('pterodactyl.allocation.stop')) }}">
135+
<p class="text-muted small">The ending port in the range that can be automatically allocated.</p>
136+
</div>
137+
</div>
138+
</div>
139+
</div>
140+
</div>
108141
<div class="box box-primary">
109142
<div class="box-footer">
110143
{{ csrf_field() }}

0 commit comments

Comments
 (0)