Handle hostnames with upper-case letters
[webmin.git] / sentry / edit_hostsentry.cgi
1 #!/usr/local/bin/perl
2 # edit_hostsentry.cgi
3 # Display hostsentry options
4
5 require './sentry-lib.pl';
6 &ui_print_header(undef, $text{'hostsentry_title'}, "", "hostsentry", 0, 0, undef,
7         &help_search_link("hostsentry", "man", "doc"));
8
9 if (!-r $config{'hostsentry'}) {
10         print "<p>",&text('hostsentry_ecommand',
11                           "<tt>$config{'hostsentry'}</tt>", 
12                           "$gconfig{'webprefix'}/config.cgi?$module_name"),"<p>\n";
13         &ui_print_footer("", $text{'index_return'});
14         exit;
15         }
16
17 # Show configuration form
18 $conf = &get_hostsentry_config();
19
20 print "<form action=save_hostsentry.cgi method=post>\n";
21 print "<table border width=100%>\n";
22 print "<tr $tb> <td><b>$text{'hostsentry_header'}</b></td> </tr>\n";
23 print "<tr $cb> <td><table width=100%>\n";
24
25 # Show wtmp file
26 print "<tr> <td><b>$text{'hostsentry_wtmp'}</b></td>\n";
27 printf "<td colspan=3><input name=wtmp size=50 value='%s'> %s</td> </tr>\n",
28         &find_value("WTMP_FILE", $conf),
29         &file_chooser_button("wtmp");
30
31 # Show users to ignore
32 $ign = &find_value("IGNORE_FILE", $conf);
33 print "<tr> <td valign=top><b>$text{'hostsentry_ignore'}</b></td>\n";
34 print "<td colspan=3><textarea name=ignore rows=5 cols=40>";
35 open(IGN, $ign);
36 while(<IGN>) {
37         s/#.*$//;
38         s/\r|\n//g;
39         print &html_escape($_),"\n" if (/\S/);
40         }
41 close(IGN);
42 print "</textarea></td> </tr>\n";
43
44 # Show configured modules
45 $mods = &find_value("MODULE_FILE", $conf);
46 open(MODS, $mods);
47 while(<MODS>) {
48         s/\r|\n//g;
49         s/#.*$//;
50         push(@mods, $_) if (/\S/);
51         }
52 close(MODS);
53 @allmods = &list_hostsentry_modules($conf);
54 print "<tr> <td valign=top><b>$text{'hostsentry_mods'}</b></td>\n";
55 print "<td colspan=3 nowrap>\n";
56 for($i=0; $i<@allmods || $i<@mods; $i++) {
57         print $i+1,". ";
58         print "<select name=mod_$i>\n";
59         printf "<option value='' %s>%s\n",
60                 $mods[$i] ? "" : "selected", "&nbsp;";
61         foreach $a (@allmods) {
62                 local $t = $text{'mod_'.$a};
63                 printf "<option value=%s %s>%s\n",
64                         $a, $mods[$i] eq $a ? "selected" : "",
65                         $t ? $t : $a;
66                 }
67         print "<option selected>$mods[$i]\n"
68                 if ($mods[$i] && &indexof($mods[$i], @allmods) < 0);
69         print "</select>\n";
70         print "<br>\n" if ($i%2);
71         print "&nbsp;&nbsp;" if (!($i%2));
72         }
73 print "</td> </tr>\n";
74
75 # Show module-specific options
76 print "</table><table width=100%>\n";
77 print "<tr>\n";
78 $basedir = &get_hostsentry_dir();
79 if (&indexof("moduleForeignDomain", @mods) >= 0) {
80         print "<td valign=top colspan=2 width=50%><b>$text{'hostsentry_foreign'}</b><br>\n";
81         print "<textarea name=foreign rows=5 cols=30>";
82         open(FOREIGN, "$basedir/moduleForeignDomain.allow");
83         while(<FOREIGN>) {
84                 s/\r|\n//g;
85                 s/#.*$//;
86                 print &html_escape($_),"\n" if (/\S/);
87                 }
88         close(FOREIGN);
89         print "</textarea></td>\n";
90         }
91 if (&indexof("moduleMultipleLogins", @mods) >= 0) {
92         print "<td valign=top colspan=2 width=50%><b>$text{'hostsentry_multiple'}</b><br>\n";
93         print "<textarea name=multiple rows=5 cols=30>";
94         open(MULTIPLE, "$basedir/moduleMultipleLogins.allow");
95         while(<MULTIPLE>) {
96                 s/\r|\n//g;
97                 s/#.*$//;
98                 print &html_escape($_),"\n" if (/\S/);
99                 }
100         close(MULTIPLE);
101         print "</textarea></td>\n";
102         }
103 print "</tr>\n";
104
105 print "</table></td></tr></table>\n";
106
107 $pid = &get_hostsentry_pid();
108 if ($pid) {
109         print "<input type=submit name=apply value='$text{'hostsentry_save'}'></form>\n";
110         }
111 else {
112         print "<input type=submit value='$text{'save'}'></form>\n";
113         }
114
115 # Show start/stop buttons
116 print &ui_hr();
117 print "<table width=100%>\n";
118 $cmd = &hostsentry_start_cmd();
119 if ($pid) {
120         # Running .. offer to stop
121         print "<form action=stop_hostsentry.cgi>\n";
122         print "<tr> <td><input type=submit ",
123               "value='$text{'hostsentry_stop'}'></td>\n";
124         print "<td>$text{'hostsentry_stopdesc'}</td> </tr>\n";
125         print "</form>\n";
126         }
127 else {
128         # Not running .. offer to start
129         print "<form action=start_hostsentry.cgi>\n";
130         print "<tr> <td><input type=submit ",
131               "value='$text{'hostsentry_start'}'></td>\n";
132         print "<td>",&text('hostsentry_startdesc', "<tt>$cmd</tt>"),
133               "</td> </tr> </form>\n";
134         }
135 print "</table>\n";
136
137 &ui_print_footer("", $text{'index_return'});
138