Fix to save miniserv websocket after we have the pid from PTY

This commit is contained in:
iliajie
2022-11-13 23:57:10 +02:00
parent b62fb504ac
commit 4907aeb2dd
3 changed files with 24 additions and 10 deletions

View File

@@ -139,7 +139,6 @@ EOF
print "<div data-label=\"$text{'index_connecting'}\" id=\"terminal\"></div>\n";
# Find ports already in use
&lock_file(&get_miniserv_config_file());
my %miniserv;
&get_miniserv_config(\%miniserv);
my %inuse;
@@ -159,12 +158,6 @@ while(1) {
}
$port++;
}
my $wspath = "/$module_name/ws-".$port;
my $now = time();
$miniserv{'websockets_'.$wspath} = "host=127.0.0.1 port=$port wspath=/ user=$remote_user time=$now";
&put_miniserv_config(\%miniserv);
&unlock_file(&get_miniserv_config_file());
&reload_miniserv();
# Check permissions for user to run as
my $user = $access{'user'};
@@ -197,7 +190,7 @@ $ENV{'SESSION_ID'} = $main::session_id;
" >$tmpdir/ws-$port.out 2>&1 </dev/null");
# Open the terminal
my $url = "wss://".$ENV{'HTTP_HOST'}.$wspath;
my $url = "wss://$ENV{'HTTP_HOST'}/$module_name/ws-$port";
my $term_script = <<EOF;
(function() {

View File

@@ -75,6 +75,10 @@ else {
print STDERR "Running shell $shcmd with pid $pid\n";
}
# Save new websocket info to miniserv.conf
# only after we get the pty pid
&save_miniserv_websocket($port);
# Detach from controlling terminal
if (fork()) {
exit(0);

View File

@@ -5,9 +5,26 @@ use WebminCore;
&init_config();
our %access = &get_module_acl();
# save_miniserv_websocket(port)
# Save new websocket info
# to miniserv.conf file
sub save_miniserv_websocket {
my ($port) = @_;
my %miniserv;
if ($port) {
my $wspath = "/$module_name/ws-".$port;
&lock_file(&get_miniserv_config_file());
&get_miniserv_config(\%miniserv);
$miniserv{'websockets_'.$wspath} = "host=127.0.0.1 port=$port wspath=/ user=$remote_user time=@{[time()]}";
&put_miniserv_config(\%miniserv);
&unlock_file(&get_miniserv_config_file());
&reload_miniserv();
}
}
# cleanup_miniserv(port)
# Remove websocket in miniserv.conf
# that is no longer being used
# Remove old websocket info
# from miniserv.conf
sub cleanup_miniserv
{
my ($port) = @_;