Handle hostnames with upper-case letters
[webmin.git] / itsecur-firewall / list_rules.cgi
1 #!/usr/bin/perl
2 # list_rules.cgi
3 # Display a list of all active rules
4 require './itsecur-lib.pl';
5
6 &can_use_error("rules");
7 &header($text{'rules_title'}, "",
8         undef, undef, undef, undef, &apply_button());
9 print "<hr>\n";
10
11
12 #                               0-No.   1-Source,2-Destination, 3-Services,     4-Time, 5-Action,       6-Enabled,      7-Comment
13 local @CW=(     "5%",   "15%",  "15%",                  "20%",          "5%",           "5%",                   "5%",                   "20%");
14 $C_drop="#FFCCcc";
15 $C_reject="#FFDDAA";
16 $C_accept="";
17 $C_disabled="#FF3333";
18 $C_separator="#ffffcc";
19
20 local $Row_Color="";
21
22 @rules = &list_rules();
23 @servs = &list_services();
24 $edit = &can_edit("rules");
25 $times = &supports_time() && &list_times() > 0;
26 if (@rules) {
27         if ($edit) {
28                 print "<a href='edit_rule.cgi?new=1'>$text{'rules_add'}</a>\n";
29                 print "&nbsp;" x 2;
30                 print "<a href='edit_sep.cgi?new=1'>$text{'rules_sadd'}</a>\n";
31                 print "<br>\n";
32                 print "<form action=enable_rules.cgi method=post>\n";
33                 }
34         $cols = $times ? 8 : 7;
35         print "<table border>\n";
36         print "<tr $tb> ",
37               "<td width=$CW[0]><b>$text{'rule_num'}</b></td> ",
38               "<td width=$CW[1]><b>$text{'rule_source'}</b></td> ",
39               "<td width=$CW[2]><b>$text{'rule_dest'}</b></td> ",
40               "<td width=$CW[3]><b>$text{'rules_service'}</b></td> ",
41               ($times ? "<td><b>$text{'rule_time'}</b></td> " : ""),
42               "<td width=$CW[5]><b>$text{'rule_action'}</b></td> ",
43               "<td width=$CW[6]><b>$text{'rule_enabled'}</b></td> ",
44               ($config{'show_desc'} ? "<td width=$CW[7]><b>$text{'rules_desc'}</b></td> " :
45                         "<td width=10><b>$text{'rules_move'}</b></td>"),
46               "</tr>\n";
47         foreach $r (@rules) {
48                 if ($r->{'sep'}){
49                                 $Row_Color="bgcolor=\"$C_separator\" ";                         
50                 } elsif (!$r->{'enabled'}){
51                                 $Row_Color="bgcolor=\"$C_disabled\" ";
52                 } elsif ( $r->{'action'} eq "drop" ){
53                                 $Row_Color="bgcolor=\"$C_drop\" ";
54                 } elsif ( $r->{'action'} eq "reject" ){
55                                 $Row_Color="bgcolor=\"$C_reject\" ";                            
56                 } else {
57                            $Row_Color=""; 
58                 }
59
60                                         # case('accept') {}
61                                         # case('allow') {}
62                                 # case('drop') {}
63                                         #case('reject') {}
64                                         #case('ignore') {}
65                         
66
67                                 
68                 print "<tr $Row_Color $cb>\n";
69                 if ($r->{'sep'}) {
70                         # Actually a separator - just show it's description
71                         print "<td colspan=$cols><b><a href='edit_sep.cgi?idx=$r->{'index'}'>$r->{'desc'}</b></a></td>\n";
72                         }
73                 else {
74                         # Show full rule details                        
75
76                         
77                         print "<td width=$CW[0]>";
78                         if ($edit) {
79                                 print "<input type=checkbox name=r value=$r->{'index'}>&nbsp;";
80                                 }
81                         print "<a href='edit_rule.cgi?",
82                               "idx=$r->{'index'}'>$r->{'num'}</a></td>\n";
83                         print "<td width=$CW[1]>",
84                                 &group_names_link($r->{'source'}, 'rules'),
85                                 "</td>\n";
86                         print "<td width=$CW[2]>",
87                                 &group_names_link($r->{'dest'}, 'rules',
88                                                   &allow_action($r) ? 'dest' : undef),
89                                 "</td>\n";
90                         print "<td width=$CW[3]>",&protocol_names($r->{'service'},\@servs),"</td>\n";
91                         if ($times) {
92                                 print "<td>",$r->{'time'} eq '*' ?
93                                         $text{'rule_anytime'} :
94                                         $r->{'time'},"</td>\n";
95                                 }
96                         print "<td width=$CW[5]>",$text{'rule_'.$r->{'action'}},
97                               $r->{'log'} ? " $text{'rules_log'}" : "","</td>\n";
98                         print "<td width=$CW[6]>",$r->{'enabled'} ? $text{'yes'} :
99                                 "<font color=#ff0000>$text{'no'}</font>",
100                               "</td>\n";
101                         if ($config{'show_desc'}) {
102                                 print "<td width=$CW[7]>",$r->{'desc'} eq "*" ? "<br>"
103                                                         : $r->{'desc'},"</td>\n";
104                                 }
105                         else {
106                                 if ($r eq $rules[0] || !$edit) {
107                                         print "<td><img src=images/gap.gif>\n";
108                                         }
109                                 else {
110                                         print "<td><a href='up.cgi?idx=$r->{'index'}'>",
111                                               "<img src=images/up.gif border=0></a>\n";
112                                         }
113                                 if ($r eq $rules[$#rules] || !$edit) {
114                                         print "<img src=images/gap.gif></td>\n";
115                                         }
116                                 else {
117                                         print "<a href='down.cgi?idx=$r->{'index'}'>",
118                                               "<img src=images/down.gif border=0></a></td>\n";
119                                         }
120                                 }
121                         }
122                 print "</tr>\n";
123                 }
124         print "</table>\n";
125         }
126 else {
127         print "<b>$text{'rules_none'}</b><p>\n";
128         }
129 if ($edit) {
130         print "<a href='edit_rule.cgi?new=1'>$text{'rules_add'}</a>\n";
131         print "&nbsp;" x 2;
132         print "<a href='edit_sep.cgi?new=1'>$text{'rules_sadd'}</a>\n";
133         print "<p>\n";
134         }
135 if ($edit && @rules) {
136         print "<input type=submit name=enable value='$text{'rules_enable'}'>\n";
137         print "<input type=submit name=disable value='$text{'rules_disable'}'>\n";
138
139         print "&nbsp;\n";
140         print "<input type=submit name=logon value='$text{'rules_logon'}'>\n";
141         print "<input type=submit name=logoff value='$text{'rules_logoff'}'>\n";
142         print "&nbsp;\n";
143         print "<input type=submit name=delete value='$text{'rules_delete'}'>\n";
144         print "</form>\n";
145         }
146
147 print "<hr>\n";
148 &footer("", $text{'index_return'});
149