Handle hostnames with upper-case letters
[webmin.git] / webmin / change_access.cgi
1 #!/usr/local/bin/perl
2 # change_access.cgi
3 # Update IP allow and deny parameters
4
5 require './webmin-lib.pl';
6 &ReadParse();
7 &error_setup($text{'access_err'});
8
9 $raddr = $ENV{'REMOTE_ADDR'};
10 if ($in{"access"}) {
11         @hosts = split(/\s+/, $in{"ip"});
12         push(@hosts, "LOCAL") if ($in{'local'});
13         if (!@hosts) { &error($text{'access_enone'}); }
14         foreach $h (@hosts) {
15                 $err = &valid_allow($h);
16                 &error($err) if ($err);
17                 push(@ip, $h);
18                 }
19         if ($in{"access"} == 1 && !&ip_match($raddr, @ip) ||
20             $in{"access"} == 2 && &ip_match($raddr, @ip)) {
21                 &error(&text('access_eself', $raddr));
22                 }
23         }
24
25 eval "use Authen::Libwrap qw(hosts_ctl STRING_UNKNOWN)";
26 if (!$@ && $in{'libwrap'}) {
27         # Check if the current address would be denied
28         if (!hosts_ctl("webmin", STRING_UNKNOWN, $raddr, STRING_UNKNOWN)) {
29                 &error(&text('access_eself', $raddr));
30                 }
31         }
32
33 &lock_file($ENV{'MINISERV_CONFIG'});
34 &get_miniserv_config(\%miniserv);
35 delete($miniserv{"allow"});
36 delete($miniserv{"deny"});
37 if ($in{"access"} == 1) { $miniserv{"allow"} = join(' ', @hosts); }
38 elsif ($in{"access"} == 2) { $miniserv{"deny"} = join(' ', @hosts); }
39 $miniserv{'libwrap'} = $in{'libwrap'};
40 $miniserv{'alwaysresolve'} = $in{'alwaysresolve'};
41 &put_miniserv_config(\%miniserv);
42 &unlock_file($ENV{'MINISERV_CONFIG'});
43 &show_restart_page();
44 &webmin_log("access", undef, undef, \%in);
45