3 # Update the binding IP address and port for miniserv
5 require './webmin-lib.pl';
7 &get_miniserv_config(\%miniserv);
8 %oldminiserv = %miniserv;
9 &error_setup($text{'bind_err'});
12 for($i=0; defined($in{"ip_def_$i"}); $i++) {
13 next if (!$in{"ip_def_$i"});
14 if ($in{"ip_def_$i"} == 1) {
19 &check_ipaddress($ip) ||
20 $in{'ipv6'} && &check_ip6address($ip) ||
21 &error(&text('bind_eip2', $ip));
23 if ($in{"port_def_$i"} == 1) {
24 $port = $in{"port_$i"};
25 $port =~ /^\d+$/ && $port < 65536 ||
26 &error(&text('bind_eport2', $port));
31 push(@sockets, [ $ip, $port ]);
32 push(@ports, $port) if ($port && $port ne "*");
34 @sockets || &error($text{'bind_enone'});
35 $in{'listen_def'} || $in{'listen'} =~ /^\d+$/ || &error($text{'bind_elisten'});
36 $in{'hostname_def'} || $in{'hostname'} =~ /^[a-z0-9\.\-]+$/i ||
37 &error($text{'bind_ehostname'});
40 $@ && &error(&text('bind_eipv6', "<tt>Socket6</tt>"));
44 &lock_file($ENV{'MINISERV_CONFIG'});
45 $first = shift(@sockets);
46 $miniserv{'port'} = $first->[1];
47 if ($first->[0] eq "*") {
48 delete($miniserv{'bind'});
51 $miniserv{'bind'} = $first->[0];
53 $miniserv{'sockets'} = join(" ", map { "$_->[0]:$_->[1]" } @sockets);
54 $miniserv{'ipv6'} = $in{'ipv6'};
55 if ($in{'listen_def'}) {
56 delete($miniserv{'listen'});
59 $miniserv{'listen'} = $in{'listen'};
61 if ($in{'hostname_def'}) {
62 delete($miniserv{'host'});
65 $miniserv{'host'} = $in{'hostname'};
67 $miniserv{'no_resolv_myname'} = $in{'no_resolv_myname'};
68 &put_miniserv_config(\%miniserv);
69 &unlock_file($ENV{'MINISERV_CONFIG'});
71 # Attempt to re-start miniserv
72 $SIG{'TERM'} = 'ignore';
73 &system_logged("$config_directory/stop >/dev/null 2>&1 </dev/null");
75 $rv = &system_logged("$config_directory/start >$temp 2>&1 </dev/null");
77 $out =~ s/^Starting Webmin server in.*\n//;
78 $out =~ s/at.*line.*//;
81 # Failed! Roll back config and start again
82 &lock_file($ENV{'MINISERV_CONFIG'});
83 &put_miniserv_config(\%oldminiserv);
84 &unlock_file($ENV{'MINISERV_CONFIG'});
85 &system_logged("$config_directory/start >/dev/null 2>&1 </dev/null");
86 &error(&text('bind_erestart', $out));
89 # If possible, open the new ports
90 if (&foreign_check("firewall") && $in{'firewall'}) {
91 @oldports = split(/\s+/, $in{'oldports'});
92 @newports = &unique(grep { &indexof($_, @oldports) < 0 } @ports);
95 $ENV{'WEBMIN_CONFIG'} = $config_directory;
96 &system_logged(&module_root_directory("firewall").
98 join(" ", map { $_.":".($_+10) } @newports).
100 &reset_environment();
104 &webmin_log("bind", undef, undef, \%in);
106 # Work out redirect URL
107 if ($miniserv{'musthost'}) { $miniserv{'musthost'}; }
108 elsif ($miniserv{'bind'}) { $url = $miniserv{'bind'}; }
109 else { $url = $ENV{'SERVER_NAME'}; }
110 if ($ENV{'HTTPS'} eq "ON") { $url = "https://$url"; }
111 else { $url = "http://$url"; }
113 if ($tconfig{'inframe'}) {
114 # Theme uses frames, so we need to redirect the whole frameset
115 $url .= ":$miniserv{'port'}";
116 &ui_print_header(undef, $text{'bind_title'}, "");
117 print $text{'bind_redirecting'},"<p>\n";
119 print "top.location = '$url';\n";
121 &ui_print_footer("", $text{'index_return'});
124 $url .= ":$miniserv{'port'}/webmin/";