mirror of
https://github.com/webmin/webmin.git
synced 2026-05-14 10:40:29 +01:00
Check ports in use in miniserv.conf, even if they haven't been opened yet
This commit is contained in:
@@ -142,19 +142,31 @@ if ($@) {
|
||||
return;
|
||||
}
|
||||
|
||||
# Find ports already in use
|
||||
&lock_file(&get_miniserv_config_file());
|
||||
my %miniserv;
|
||||
&get_miniserv_config(\%miniserv);
|
||||
my %inuse;
|
||||
foreach my $k (keys %miniserv) {
|
||||
if ($k =~ /^websockets_/ && $miniserv{$k} =~ /port=(\d+)/) {
|
||||
$inuse{$1} = 1;
|
||||
}
|
||||
}
|
||||
|
||||
# Pick a port and configure Webmin to proxy it
|
||||
my $port = $config{'base_port'} || 555;
|
||||
while(1) {
|
||||
&open_socket("127.0.0.1", $port, my $fh, \$err);
|
||||
last if ($err);
|
||||
close($fh);
|
||||
if (!$inuse{$port}) {
|
||||
&open_socket("127.0.0.1", $port, my $fh, \$err);
|
||||
last if ($err);
|
||||
close($fh);
|
||||
}
|
||||
$port++;
|
||||
}
|
||||
my %miniserv;
|
||||
&get_miniserv_config(\%miniserv);
|
||||
my $wspath = "/$module_name/ws-".$port;
|
||||
$miniserv{'websockets_'.$wspath} = "host=127.0.0.1 port=$port wspath=/ user=$remote_user";
|
||||
&put_miniserv_config(\%miniserv);
|
||||
&unlock_file(&get_miniserv_config_file());
|
||||
&reload_miniserv();
|
||||
|
||||
# Launch the shell server on that port
|
||||
|
||||
Reference in New Issue
Block a user