Open new usermin port on firewall https://virtualmin.com/node/35448

This commit is contained in:
Jamie Cameron
2014-11-30 20:27:23 -08:00
parent 7ac3b37d14
commit e8232c6be1
2 changed files with 34 additions and 1 deletions

View File

@@ -31,6 +31,7 @@ for($i=0; defined($in{"ip_def_$i"}); $i++) {
$port = "*";
}
push(@sockets, [ $ip, $port ]);
push(@ports, $port) if ($port && $port ne "*");
}
@sockets || &error($text{'bind_enone'});
$in{'hostname_def'} || $in{'hostname'} =~ /^[a-z0-9\.\-]+$/i ||
@@ -40,6 +41,18 @@ if ($in{'ipv6'}) {
$@ && &error(&text('bind_eipv6', "<tt>Socket6</tt>"));
}
# For any new ports, check if they are already in use
@oldports = split(/\s+/, $in{'oldports'});
@newports = &unique(grep { &indexof($_, @oldports) < 0 } @ports);
if (&has_command("lsof")) {
foreach my $p (@newports) {
$out = &backquote_command("lsof -t -i tcp:$p 2>/dev/null");
if ($out =~ /\d+/) {
&error(&text('bind_elsof', $p));
}
}
}
# Update config file
&lock_file($usermin_miniserv_config);
$first = shift(@sockets);
@@ -72,7 +85,7 @@ $SIG{'TERM'} = 'ignore';
&system_logged("$config{'usermin_dir'}/stop >/dev/null 2>&1 </dev/null");
$temp = &transname();
$rv = &system_logged("$config{'usermin_dir'}/start >$temp 2>&1 </dev/null");
$out = `cat $temp`;
$out = &read_file_contents($temp);
$out =~ s/^Starting Usermin server in.*\n//;
$out =~ s/at.*line.*//;
unlink($temp);
@@ -84,6 +97,20 @@ if ($rv) {
&system_logged("$config{'usermin_dir'}/start >/dev/null 2>&1 </dev/null");
&error(&text('bind_erestart', $out));
}
# If possible, open the new ports
if (&foreign_check("firewall") && $in{'firewall'}) {
if (@newports) {
&clean_environment();
$ENV{'WEBMIN_CONFIG'} = $config_directory;
&system_logged(&module_root_directory("firewall").
"/open-ports.pl ".
join(" ", map { $_.":".($_+10) } @newports).
" >/dev/null 2>&1");
&reset_environment();
}
}
&webmin_log("bind", undef, undef, \%in);
&redirect("");

View File

@@ -18,6 +18,7 @@ my @sockets = &webmin::get_miniserv_sockets(\%miniserv);
# Show table of all bound IPs and ports
my $stable = &ui_columns_start([ $text{'bind_sip'}, $text{'bind_sport'} ]);
my $i = 0;
my @ports;
foreach $s (@sockets, [ undef, "*" ]) {
# IP address
my @cols;
@@ -36,9 +37,14 @@ foreach $s (@sockets, [ undef, "*" ]) {
[ 1, $text{'bind_sport1'} ] ])." ".
&ui_textbox("port_$i", $s->[1] eq "*" ? undef : $s->[1],5));
$stable .= &ui_columns_row(\@cols, [ "nowrap", "nowrap" ]);
push(@ports, $s->[1]) if ($s->[1] && $s->[1] ne "*");
$i++;
}
$stable .= &ui_columns_end();
if (&foreign_check("firewall")) {
print &ui_hidden("oldports", join(" ", @ports));
$stable .= &ui_checkbox("firewall", 1, $text{'bind_firewall'}, 1);
}
print &ui_table_row($text{'bind_sockets'}, $stable);
# IPv6 enabled?