Handle hostnames with upper-case letters
[webmin.git] / sentry / edit_logcheck.cgi
1 #!/usr/local/bin/perl
2 # edit_logcheck.cgi
3 # Display logcheck configuration menu
4
5 require './sentry-lib.pl';
6
7 # Check if logcheck is installed
8 if (!-x $config{'logcheck'}) {
9         &ui_print_header(undef, $text{'logcheck_title'}, "");
10         print "<p>",&text('logcheck_ecommand',
11                   "<tt>$config{'logcheck'}</tt>", 
12                   "$gconfig{'webprefix'}/config.cgi?$module_name"),"<p>\n";
13         &ui_print_footer("", $text{'index_return'});
14         exit;
15         }
16
17 # Check if it is the right version
18 $conf = &get_logcheck_config();
19 $hacking = &find_value("HACKING_FILE", $conf, 1);
20 $hacking = &find_value("CRACKING_FILE", $conf, 1) if (!$hacking);
21 if (!$hacking) {
22         &ui_print_header(undef, $text{'logcheck_title'}, "");
23         print "<p>",&text('logcheck_eversion',
24                           "<tt>$config{'logcheck'}</tt>"),"<p>\n";
25         &ui_print_footer("", $text{'index_return'});
26         exit;
27         }
28
29 &ui_print_header(undef, $text{'logcheck_title'}, "", "logcheck", 0, 0, undef,
30         &help_search_link("logcheck", "man", "doc"));
31
32 # Show configuration form
33 print "<form action=save_logcheck.cgi method=post>\n";
34 print "<table border width=100%>\n";
35 print "<tr $tb> <td><b>$text{'logcheck_header'}</b></td> </tr>\n";
36 print "<tr $cb> <td><table width=100%>\n";
37
38 $to = &find_value("SYSADMIN", $conf, 1);
39 print "<tr> <td><b>$text{'logcheck_to'}</b></td>\n";
40 printf "<td colspan=2><input name=to size=50 value='%s'></td> </tr>\n", $to;
41
42 print "<tr> <td width=33% valign=top><b>$text{'logcheck_hacking'}</b><br>\n";
43 print "<textarea name=hacking rows=20 cols=30>";
44 open(HACKING, $hacking);
45 while(<HACKING>) {
46         s/\r|\n//g;
47         print &html_escape($_),"\n";
48         }
49 close(HACKING);
50 print "</textarea></td>\n";
51
52 $violations = &find_value("VIOLATIONS_FILE", $conf, 1);
53 print "<td width=33% valign=top><b>$text{'logcheck_violations'}</b><br>\n";
54 print "<textarea name=violations rows=10 cols=30>";
55 open(VIOLATIONS, $violations);
56 while(<VIOLATIONS>) {
57         s/\r|\n//g;
58         print &html_escape($_),"\n";
59         }
60 close(VIOLATIONS);
61 print "</textarea><br>\n";
62 $violations_ign = &find_value("VIOLATIONS_IGNORE_FILE", $conf, 1);
63 print "<b>$text{'logcheck_violations_ign'}</b><br>\n";
64 print "<textarea name=violations_ign rows=7 cols=30>";
65 open(IGNORE, $violations_ign);
66 while(<IGNORE>) {
67         s/\r|\n//g;
68         print &html_escape($_),"\n";
69         }
70 close(IGNORE);
71 print "</textarea></td>\n";
72
73 $ignore = &find_value("IGNORE_FILE", $conf, 1);
74 print "<td width=33% valign=top><b>$text{'logcheck_ignore'}</b><br>\n";
75 print "<textarea name=ignore rows=20 cols=20>";
76 open(IGNORE, $ignore);
77 while(<IGNORE>) {
78         s/\r|\n//g;
79         print &html_escape($_),"\n";
80         }
81 close(IGNORE);
82 print "</textarea></td> </tr>\n";
83
84 # Display files being monitored
85 open(CHECK, $config{'logcheck'});
86 while(<CHECK>) {
87         s/\r|\n//g;
88         s/#.*$//;
89         if (/^\s*(\$LOGTAIL|\S*logtail)\s+(\S+)/) {
90                 push(@logfiles, $2);
91                 }
92         }
93 close(CHECK);
94 if (@logfiles) {
95         print "<tr> <td valign=top><b>$text{'logcheck_files'}</b></td>\n";
96         print "<td colspan=2>",join(" ",
97                         map { "<tt>$_</tt>" } @logfiles),"</td> </tr>\n";
98         }
99
100 # Display run times for logcheck
101 &foreign_require("cron", "cron-lib.pl");
102 @jobs = &cron::list_cron_jobs();
103 JOB: foreach $j (@jobs) {
104         local $rpd;
105         if ($j->{'command'} =~ /$config{'logcheck'}/) {
106                 $job = $j;
107                 last;
108                 }
109         elsif ($rpd = &cron::is_run_parts($j->{'command'})) {
110                 local @exp = &cron::expand_run_parts($rpd);
111                 foreach $e (@exp) {
112                         if ($e =~ /logcheck/) {
113                                 # Cannot change this :(
114                                 $runparts = $e;
115                                 last JOB;
116                                 }
117                         }
118                 }
119         }
120 if ($runparts) {
121         print "<tr> <td colspan=3>",&text('logcheck_runparts',
122                                 "<tt>$runparts</tt>"),"</td> </tr>\n";
123         print "<input type=hidden name=runparts value='1'>\n";
124         }
125 else {
126         print "<input type=hidden name=job value='$job->{'index'}'>\n"
127                 if ($job);
128         print "<tr> <td colspan=3>\n";
129         $job = { 'mins' => 0,
130                  'hours' => '*',
131                  'days' => '*',
132                  'months' => '*',
133                  'weekdays' => '*' } if (!$job);
134         printf "<input type=radio name=active value=0 %s> %s\n",
135                 $job->{'active'} ? "" : "checked", $text{'logcheck_disabled'};
136         printf "<input type=radio name=active value=1 %s> %s<br>\n",
137                 $job->{'active'} ? "checked" : "", $text{'logcheck_enabled'};
138         print "<table border width=100%>\n";
139         &cron::show_times_input($job);
140         print "</table></td> </tr>\n";
141         }
142
143 print "</table></td></tr></table><br>\n";
144 print "<input type=submit value='$text{'logcheck_save'}'></form>\n";
145
146 &ui_print_footer("", $text{'index_return'});
147