Handle hostnames with upper-case letters
[webmin.git] / itsecur-firewall / status_monitor.pl
1
2 do 'itsecur-lib.pl';
3
4 # status_monitor_list()
5 # Just one type is supported
6 sub status_monitor_list
7 {
8 return ( [ "rule", $text{'monitor_type'} ] );
9 }
10
11 # status_monitor_status(type, &monitor, from-ui)
12 # Check the logs to see if the rule has been hit recently
13 sub status_monitor_status
14 {
15 local $rv;
16 if ($_[2]) {
17         # If this call is from the UI, then just return the current status
18         local %oldstatus;
19         &read_file("$config_directory/status/oldstatus", \%oldstatus);
20         $rv = { 'up' => defined($oldstatus{$_[1]->{'id'}}) ?
21                         $oldstatus{$_[1]->{'id'}} : -1 };
22         }
23 else {
24         # Actually check the logs
25         local %lasttime;
26         &read_file("$module_config_directory/lasttime", \%lasttime);
27         local $l;
28         local $stime;
29         $rv = { 'up' => 1 };
30         foreach $l (reverse(&parse_all_logs(1))) {
31                 if ($l->{'time'} > $lasttime{$_[1]->{'id'}}) {
32                         # Consider this line
33                         if ($l->{'rule'} == $_[1]->{'rule'}) {
34                                 # Got a hit!
35                                 $rv = { 'up' => 0 };
36                                 }
37                         }
38                 $stime = $l->{'time'};
39                 }
40         $lasttime{$_[1]->{'id'}} = $stime || time();
41         &write_file("$module_config_directory/lasttime", \%lasttime);
42         }
43 return $rv;
44 }
45
46 # status_monitor_dialog(type, &monitor)
47 # Return form for selecting a rule
48 sub status_monitor_dialog
49 {
50 local $rv;
51 $rv = "<tr> <td><b>$text{'monitor_rule'}</b></td>\n";
52 $rv .= "<td colspan=3><select name=rule>\n";
53 local $r;
54 foreach $r (&list_rules()) {
55         if ($r->{'log'}) {
56                 $rv .= sprintf "<option value=%s %s>%s\n",
57                         $r->{'num'},
58                         $_[1]->{'rule'} == $r->{'num'} ? "selected" : "",
59                         &text('monitor_num', $r->{'num'},
60                                 &group_name($r->{'source'}),
61                                 &group_name($r->{'dest'}));
62                 }
63         }
64 $rv .= "</select></td> </tr>\n";
65 return $rv;
66 }
67
68 # status_monitor_parse(type, &monitor, &in)
69 # Parse form for selecting a rule
70 sub status_monitor_parse
71 {
72 $_[1]->{'rule'} = $_[2]->{'rule'};
73 }
74
75 1;
76