mirror of
https://github.com/pelican-dev/panel.git
synced 2025-06-19 12:31:11 +02:00
More updates
This commit is contained in:
parent
bbe09ced1d
commit
768a45bbb8
@ -140,86 +140,35 @@ class CreateServer extends CreateRecord
|
|||||||
You would typically port forward these on your home network.
|
You would typically port forward these on your home network.
|
||||||
'))
|
'))
|
||||||
->label('Ports')
|
->label('Ports')
|
||||||
->afterStateUpdated(function ($state, Forms\Set $set) {
|
->afterStateUpdated(self::ports(...))
|
||||||
$ports = collect();
|
|
||||||
$update = false;
|
|
||||||
foreach ($state as $portEntry) {
|
|
||||||
if (!str_contains($portEntry, '-')) {
|
|
||||||
if (is_numeric($portEntry)) {
|
|
||||||
$ports->push((int) $portEntry);
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Do not add non-numerical ports
|
|
||||||
$update = true;
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$update = true;
|
|
||||||
[$start, $end] = explode('-', $portEntry);
|
|
||||||
if (!is_numeric($start) || !is_numeric($end)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$start = max((int) $start, 0);
|
|
||||||
$end = min((int) $end, 2 ** 16 - 1);
|
|
||||||
for ($i = $start; $i <= $end; $i++) {
|
|
||||||
$ports->push($i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$uniquePorts = $ports->unique()->values();
|
|
||||||
if ($ports->count() > $uniquePorts->count()) {
|
|
||||||
$update = true;
|
|
||||||
$ports = $uniquePorts;
|
|
||||||
}
|
|
||||||
|
|
||||||
$sortedPorts = $ports->sort()->values();
|
|
||||||
if ($sortedPorts->all() !== $ports->all()) {
|
|
||||||
$update = true;
|
|
||||||
$ports = $sortedPorts;
|
|
||||||
}
|
|
||||||
|
|
||||||
$ports = $ports->filter(fn ($port) => $port > 1024 && $port < 65535)->values();
|
|
||||||
|
|
||||||
if ($update) {
|
|
||||||
$set('allocation_ports', $ports->all());
|
|
||||||
}
|
|
||||||
})
|
|
||||||
->live(),
|
->live(),
|
||||||
|
|
||||||
Forms\Components\Select::make('primary_port')
|
Forms\Components\Repeater::make('assignments')
|
||||||
|
->columnSpan(3)
|
||||||
|
->label('Port Assignments')
|
||||||
->live()
|
->live()
|
||||||
->helperText(fn (Forms\Get $get) => match (true) {
|
->default(function () {
|
||||||
!str_contains($get('startup'), '{{SERVER_PORT}}') => 'This is disabled because there is no primary server port in the startup command.',
|
$ports = ['SERVER_PORT' => null];
|
||||||
empty($get('ports')) => 'This is disabled because you haven\'t entered any ports yet.',
|
|
||||||
true => 'This port will take the place of {{SERVER_PORT}} in your startup command.',
|
if (!$this->egg) {
|
||||||
|
return $ports;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ports;
|
||||||
})
|
})
|
||||||
->columnSpan(3)
|
->addable(false)
|
||||||
->selectablePlaceholder(false)
|
->deletable(false)
|
||||||
->disabled(fn (Forms\Get $get) => empty($get('ports')) || !str_contains($get('startup'), '{{SERVER_PORT}}'))
|
->simple(
|
||||||
->options(fn (Forms\Get $get) => $get('ports'))
|
Forms\Components\Select::make('port')
|
||||||
->label('Primary Port'),
|
->live()
|
||||||
|
// ->selectablePlaceholder(false)
|
||||||
Forms\Components\KeyValue::make('pts')
|
// ->disabled(fn (Forms\Get $get) => empty($get('ports')))
|
||||||
// ->deletable(fn ($state) => empty($state) || dd('SERVER_PORT', array_keys($state), $state) || !in_array('SERVER_PORT', array_keys($state)))
|
->prefix('SERVER_PORT')
|
||||||
// ->addable(false)
|
// ->email()
|
||||||
// ->editableKeys(false)
|
->disableOptionsWhenSelectedInSiblingRepeaterItems()
|
||||||
->columnSpan(3)
|
->options(fn (Forms\Get $get) => $get('../../ports'))
|
||||||
->keyLabel('Name')
|
->required(),
|
||||||
->valueLabel('Port')
|
),
|
||||||
->label('Ports')
|
|
||||||
->live(),
|
|
||||||
|
|
||||||
Forms\Components\Placeholder::make('instructions')
|
|
||||||
->label(new HtmlString('Port Instructions:<br><br>
|
|
||||||
These are the ports that users can connect to this Server through.
|
|
||||||
<br>
|
|
||||||
You would typically port forward these on your home network.
|
|
||||||
'))
|
|
||||||
->columnSpan(3),
|
|
||||||
|
|
||||||
Forms\Components\Textarea::make('startup')
|
Forms\Components\Textarea::make('startup')
|
||||||
->hintIcon('tabler-code')
|
->hintIcon('tabler-code')
|
||||||
@ -642,4 +591,53 @@ class CreateServer extends CreateRecord
|
|||||||
->mapWithKeys(fn ($value) => [$value => $value])
|
->mapWithKeys(fn ($value) => [$value => $value])
|
||||||
->all();
|
->all();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function ports ($state, Forms\Set $set) {
|
||||||
|
$ports = collect();
|
||||||
|
$update = false;
|
||||||
|
foreach ($state as $portEntry) {
|
||||||
|
if (!str_contains($portEntry, '-')) {
|
||||||
|
if (is_numeric($portEntry)) {
|
||||||
|
$ports->push((int) $portEntry);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Do not add non-numerical ports
|
||||||
|
$update = true;
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$update = true;
|
||||||
|
[$start, $end] = explode('-', $portEntry);
|
||||||
|
if (!is_numeric($start) || !is_numeric($end)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$start = max((int) $start, 0);
|
||||||
|
$end = min((int) $end, 2 ** 16 - 1);
|
||||||
|
for ($i = $start; $i <= $end; $i++) {
|
||||||
|
$ports->push($i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$uniquePorts = $ports->unique()->values();
|
||||||
|
if ($ports->count() > $uniquePorts->count()) {
|
||||||
|
$update = true;
|
||||||
|
$ports = $uniquePorts;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sortedPorts = $ports->sort()->values();
|
||||||
|
if ($sortedPorts->all() !== $ports->all()) {
|
||||||
|
$update = true;
|
||||||
|
$ports = $sortedPorts;
|
||||||
|
}
|
||||||
|
|
||||||
|
$ports = $ports->filter(fn ($port) => $port > 1024 && $port < 65535)->values();
|
||||||
|
|
||||||
|
if ($update) {
|
||||||
|
$set('ports', $ports->all());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user