Add separate port field for node connections (#1423)

This commit is contained in:
Boy132 2025-06-03 14:33:57 +02:00 committed by GitHub
parent 3b744f37dd
commit 0ba497a2eb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 77 additions and 15 deletions

View File

@ -24,6 +24,7 @@ class MakeNodeCommand extends Command
{--overallocateCpu= : Enter the amount of cpu to overallocate (% or -1 to overallocate the maximum).}
{--uploadSize= : Enter the maximum upload filesize.}
{--daemonListeningPort= : Enter the daemon listening port.}
{--daemonConnectingPort= : Enter the daemon connecting port.}
{--daemonSFTPPort= : Enter the daemon SFTP listening port.}
{--daemonSFTPAlias= : Enter the daemon SFTP alias.}
{--daemonBase= : Enter the base folder.}';
@ -57,6 +58,7 @@ class MakeNodeCommand extends Command
$data['cpu_overallocate'] = $this->option('overallocateCpu') ?? $this->ask(trans('commands.make_node.cpu_overallocate'), '-1');
$data['upload_size'] = $this->option('uploadSize') ?? $this->ask(trans('commands.make_node.upload_size'), '256');
$data['daemon_listen'] = $this->option('daemonListeningPort') ?? $this->ask(trans('commands.make_node.daemonListen'), '8080');
$data['daemon_connect'] = $this->option('daemonConnectingPort') ?? $this->ask(trans('commands.make_node.daemonConnect'), '8080');
$data['daemon_sftp'] = $this->option('daemonSFTPPort') ?? $this->ask(trans('commands.make_node.daemonSFTP'), '2022');
$data['daemon_sftp_alias'] = $this->option('daemonSFTPAlias') ?? $this->ask(trans('commands.make_node.daemonSFTPAlias'), '');
$data['daemon_base'] = $this->option('daemonBase') ?? $this->ask(trans('commands.make_node.daemonBase'), '/var/lib/pelican/volumes');

View File

@ -124,15 +124,10 @@ class CreateNode extends CreateRecord
'lg' => 1,
]),
TextInput::make('daemon_listen')
->columnSpan([
'default' => 1,
'sm' => 1,
'md' => 1,
'lg' => 1,
])
->label(trans('admin/node.port'))
->helperText(trans('admin/node.port_help'))
TextInput::make('daemon_connect')
->columnSpan(1)
->label(fn (Get $get) => $get('connection') === 'https_proxy' ? trans('admin/node.connect_port') : trans('admin/node.port'))
->helperText(fn (Get $get) => $get('connection') === 'https_proxy' ? trans('admin/node.connect_port_help') : trans('admin/node.port_help'))
->minValue(1)
->maxValue(65535)
->default(8080)
@ -193,7 +188,21 @@ class CreateNode extends CreateRecord
->afterStateUpdated(function ($state, Set $set) {
$set('scheme', $state === 'http' ? 'http' : 'https');
$set('behind_proxy', $state === 'https_proxy');
$set('daemon_connect', $state === 'https_proxy' ? 443 : 8080);
$set('daemon_listen', 8080);
}),
TextInput::make('daemon_listen')
->columnSpan(1)
->label(trans('admin/node.listen_port'))
->helperText(trans('admin/node.listen_port_help'))
->minValue(1)
->maxValue(65535)
->default(8080)
->required()
->integer()
->visible(fn (Get $get) => $get('connection') === 'https_proxy'),
]),
Step::make('advanced')
->label(trans('admin/node.tabs.advanced_settings'))

View File

@ -181,10 +181,10 @@ class EditNode extends EditRecord
false => 'danger',
])
->columnSpan(1),
TextInput::make('daemon_listen')
TextInput::make('daemon_connect')
->columnSpan(1)
->label(trans('admin/node.port'))
->helperText(trans('admin/node.port_help'))
->label(fn (Get $get) => $get('connection') === 'https_proxy' ? trans('admin/node.connect_port') : trans('admin/node.port'))
->helperText(fn (Get $get) => $get('connection') === 'https_proxy' ? trans('admin/node.connect_port_help') : trans('admin/node.port_help'))
->minValue(1)
->maxValue(65535)
->default(8080)
@ -239,7 +239,20 @@ class EditNode extends EditRecord
->afterStateUpdated(function ($state, Set $set) {
$set('scheme', $state === 'http' ? 'http' : 'https');
$set('behind_proxy', $state === 'https_proxy');
$set('daemon_connect', $state === 'https_proxy' ? 443 : 8080);
$set('daemon_listen', 8080);
}),
TextInput::make('daemon_listen')
->columnSpan(1)
->label(trans('admin/node.listen_port'))
->helperText(trans('admin/node.listen_port_help'))
->minValue(1)
->maxValue(65535)
->default(8080)
->required()
->integer()
->visible(fn (Get $get) => $get('connection') === 'https_proxy'),
]),
Tab::make('adv')
->label(trans('admin/node.tabs.advanced_settings'))

View File

@ -38,6 +38,7 @@ use Symfony\Component\Yaml\Yaml;
* @property string $daemon_token_id
* @property string $daemon_token
* @property int $daemon_listen
* @property int $daemon_connect
* @property int $daemon_sftp
* @property string|null $daemon_sftp_alias
* @property string $daemon_base
@ -83,7 +84,7 @@ class Node extends Model implements Validatable
'memory', 'memory_overallocate', 'disk',
'disk_overallocate', 'cpu', 'cpu_overallocate',
'upload_size', 'daemon_base',
'daemon_sftp', 'daemon_sftp_alias', 'daemon_listen',
'daemon_sftp', 'daemon_sftp_alias', 'daemon_listen', 'daemon_connect',
'description', 'maintenance_mode', 'tags',
];
@ -105,6 +106,7 @@ class Node extends Model implements Validatable
'daemon_sftp' => ['required', 'numeric', 'between:1,65535'],
'daemon_sftp_alias' => ['nullable', 'string'],
'daemon_listen' => ['required', 'numeric', 'between:1,65535'],
'daemon_connect' => ['required', 'numeric', 'between:1,65535'],
'maintenance_mode' => ['boolean'],
'upload_size' => ['int', 'between:1,1024'],
'tags' => ['array'],
@ -125,6 +127,7 @@ class Node extends Model implements Validatable
'daemon_base' => '/var/lib/pelican/volumes',
'daemon_sftp' => 2022,
'daemon_listen' => 8080,
'daemon_connect' => 8080,
'maintenance_mode' => false,
'tags' => '[]',
];
@ -136,6 +139,7 @@ class Node extends Model implements Validatable
'disk' => 'integer',
'cpu' => 'integer',
'daemon_listen' => 'integer',
'daemon_connect' => 'integer',
'daemon_sftp' => 'integer',
'daemon_token' => 'encrypted',
'behind_proxy' => 'boolean',
@ -171,7 +175,7 @@ class Node extends Model implements Validatable
*/
public function getConnectionAddress(): string
{
return "$this->scheme://$this->fqdn:$this->daemon_listen";
return "$this->scheme://$this->fqdn:$this->daemon_connect";
}
/**

View File

@ -47,7 +47,7 @@ class TransferServerService
// Check if the node is viable for the transfer.
$node = Node::query()
->select(['nodes.id', 'nodes.fqdn', 'nodes.scheme', 'nodes.daemon_token', 'nodes.daemon_listen', 'nodes.memory', 'nodes.disk', 'nodes.cpu', 'nodes.memory_overallocate', 'nodes.disk_overallocate', 'nodes.cpu_overallocate'])
->select(['nodes.id', 'nodes.fqdn', 'nodes.scheme', 'nodes.daemon_token', 'nodes.daemon_connect', 'nodes.memory', 'nodes.disk', 'nodes.cpu', 'nodes.memory_overallocate', 'nodes.disk_overallocate', 'nodes.cpu_overallocate'])
->withSum('servers', 'disk')
->withSum('servers', 'memory')
->withSum('servers', 'cpu')

View File

@ -38,6 +38,7 @@ class NodeFactory extends Factory
'daemon_token_id' => Str::random(Node::DAEMON_TOKEN_ID_LENGTH),
'daemon_token' => Str::random(Node::DAEMON_TOKEN_LENGTH),
'daemon_listen' => 8080,
'daemon_connect' => 8080,
'daemon_sftp' => 2022,
'daemon_base' => '/var/lib/panel/volumes',
'maintenance_mode' => false,

View File

@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('nodes', function (Blueprint $table) {
$table->smallInteger('daemon_connect')->unsigned()->default(8080);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('nodes', function (Blueprint $table) {
$table->dropColumn('daemon_connect');
});
}
};

View File

@ -45,6 +45,10 @@ return [
'port' => 'Port',
'ports' => 'Ports',
'port_help' => 'If you are running the daemon behind Cloudflare you should set the daemon port to 8443 to allow websocket proxying over SSL.',
'connect_port' => 'Connection Port',
'connect_port_help' => 'Connections to wings will use this port. If you are using a reverse proxy this can differ from the listen port. When using Cloudflare proxy you should use 8443.',
'listen_port' => 'Listening Port',
'listen_port_help' => 'Wings will listen on this port.',
'display_name' => 'Display Name',
'ssl' => 'Communicate over SSL',
'panel_on_ssl' => 'Your Panel is using a secure SSL connection,<br>so your Daemon must too.',

View File

@ -36,6 +36,7 @@ return [
'cpu_overallocate' => 'Enter the amount of cpu to over allocate by, -1 will disable checking and 0 will prevent creating new server',
'upload_size' => "'Enter the maximum filesize upload",
'daemonListen' => 'Enter the daemon listening port',
'daemonConnect' => 'Enter the daemon connecting port (can be same as listen port)',
'daemonSFTP' => 'Enter the daemon SFTP listening port',
'daemonSFTPAlias' => 'Enter the daemon SFTP alias (can be empty)',
'daemonBase' => 'Enter the base folder',