Handle hostnames with upper-case letters
[webmin.git] / sentry / save_hostsentry.cgi
1 #!/usr/local/bin/perl
2 # save_hostsentry.cgi
3 # Save hostsentry options
4
5 require './sentry-lib.pl';
6 &ReadParse();
7 &error_setup($text{'hostsentry_err'});
8
9 # Validate inputs
10 -r $in{'wtmp'} || &error($text{'hostsentry_ewtmp'});
11 @ignore = split(/\s+/, $in{'ignore'});
12 foreach $u (@ignore) {
13         defined(getpwnam($u)) || &error(&text('hostsentry_eignore', $u));
14         }
15 for($i=0; defined($in{"mod_$i"}); $i++) {
16         push(@mods, $in{"mod_$i"}) if ($in{"mod_$i"});
17         }
18 if (defined($in{'foreign'})) {
19         @foreign = split(/\s+/, $in{'foreign'});
20         }
21 if (defined($in{'multiple'})) {
22         @multiple = split(/\s+/, $in{'multiple'});
23         foreach $m (@multiple) {
24                 &to_ipaddress($m) ||
25                         &error(&text('hostsentry_emultiple', $m));
26                 }
27         }
28
29 # Write to the appropriate files
30 $conf = &get_hostsentry_config();
31 &lock_config_files($conf);
32 &save_config($conf, "WTMP_FILE", $in{'wtmp'});
33 &flush_file_lines();
34 &unlock_config_files($conf);
35
36 $ign = &find_value("IGNORE_FILE", $conf);
37 &lock_file($ign);
38 &open_tempfile(IGN, ">$ign");
39 foreach $i (@ignore) {
40         &print_tempfile(IGN, $i,"\n");
41         }
42 &close_tempfile(IGN);
43 &unlock_file($ign);
44
45 $mods = &find_value("MODULE_FILE", $conf);
46 &lock_file($mods);
47 &open_tempfile(MODS, ">$mods");
48 foreach $m (@mods) {
49         &print_tempfile(MODS, $m,"\n");
50         }
51 &close_tempfile(MODS);
52 &unlock_file($mods);
53
54 $basedir = &get_hostsentry_dir();
55 if (scalar(@foreign)) {
56         &lock_file("$basedir/moduleForeignDomain.allow");
57         &open_tempfile(FOREIGN, ">$basedir/moduleForeignDomain.allow");
58         foreach $f (@foreign) {
59                 &print_tempfile(FOREIGN, $f,"\n");
60                 }
61         &close_tempfile(FOREIGN);
62         &unlock_file("$basedir/moduleForeignDomain.allow");
63         }
64 if (scalar(@multiple)) {
65         &lock_file("$basedir/moduleMultipleLogins.allow");
66         &open_tempfile(MULTIPLE, ">$basedir/moduleMultipleLogins.allow");
67         foreach $m (@multiple) {
68                 &print_tempfile(MULTIPLE, $m,"\n");
69                 }
70         &close_tempfile(MULTIPLE);
71         &unlock_file("$basedir/moduleMultipleLogins.allow");
72         }
73
74 if ($in{'apply'}) {
75         # Attempt to restart
76         &stop_hostsentry();
77         $err = &start_hostsentry();
78         &error($err) if ($err);
79         }
80 &webmin_log("hostsentry");
81
82 &redirect("");
83