Handle hostnames with upper-case letters
[webmin.git] / jabber / save_ips.cgi
1 #!/usr/local/bin/perl
2 # save_ips.cgi
3 # Save allowed and denied IP addresses
4
5 require './jabber-lib.pl';
6 &ReadParse();
7 &error_setup($text{'ips_err'});
8
9 $conf = &get_jabber_config();
10 $io = &find("io", $conf);
11 @oldallow = &find("allow", $io);
12 @olddeny = &find("deny", $io);
13
14 # Validate and store inputs
15 if (!$in{'allow_def'}) {
16         foreach $a (split(/\s+/, $in{'allow'})) {
17                 push(@allow, &check_addr($a, "allow"));
18                 }
19         }
20 if (!$in{'deny_def'}) {
21         foreach $a (split(/\s+/, $in{'deny'})) {
22                 push(@deny, &check_addr($a, "deny"));
23                 }
24         }
25 &save_directive($io, "allow", \@allow);
26 &save_directive($io, "deny", \@deny);
27 &save_jabber_config($conf);
28 &redirect("");
29
30 sub check_addr
31 {
32 if (&check_ipaddress($_[0])) {
33         return [ $_[1], [ {}, "ip", [ { }, "0", $_[0] ] ] ];
34         }
35 elsif ($_[0] =~ /^(\S+)\/(\S+)$/ &&
36        &check_ipaddress($1) && &check_ipaddress($2)) {
37         return [ $_[1], [ {}, "ip", [ { }, "0", $1 ],
38                               "mask", [ { }, "0", $2 ] ] ];
39         }
40 else {
41         &error(&text('ips_eaddr', $_[0]));
42         }
43 }