2 # Show all firewall rules
4 require './ipfw-lib.pl';
7 # Make sure the ipfw command is installed
8 if (!&has_command($config{'ipfw'})) {
9 &ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1);
11 &ui_config_link('index_eipfw',
12 [ "<tt>$config{'ipfw'}</tt>", undef ]));
15 # Make sure ipfw works
16 $rules = &get_config();
17 $active = &get_config("$config{'ipfw'} show |", \$out);
19 &ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1);
21 &ui_config_link('index_elist',
22 [ "<tt>$config{'ipfw'} list</tt>",
23 "<pre>$out</pre>", undef ]));
26 # Get the version number
27 $vout = `$config{'ipfw'} 2>&1`;
28 $vouth = `$config{'ipfw'} -h 2>&1`;
29 if ($vout =~ /preproc/ || $vouth =~ /preproc/) {
35 open(VERSION, ">$module_config_directory/version");
36 print VERSION $ipfw_version,"\n";
38 &ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1, 0,
39 &help_search_link("ipfw", "man", "doc", "google"),
41 &text('index_version', $ipfw_version));
43 # Check for an active firewall that is not managed by this module
44 if (!@$rules && @$active > 1) {
45 # Yes .. offer to convert
46 print &text('index_existing', scalar(@$active),
47 "<tt>$ipfw_file</tt>"),"<p>\n";
48 print &ui_form_start("convert.cgi");
49 print "<center>",&ui_submit($text{'index_saveex'}),"<p>\n";
53 print "<table border width=100%>\n";
54 print "<tr $tb><td><b>$text{'index_headerex'}</b></td></tr>\n";
55 print "<tr $cb> <td><pre>";
57 print "</pre></td> </tr></table>\n";
59 elsif (@$rules && !$in{'reset'}) {
60 # Find last editable rule
61 if ($rules->[@$rules-1]->{'num'} == 65535 &&
63 $lastidx = $rules->[@$rules-2]->{'index'};
66 $lastidx = $rules->[@$rules-1]->{'index'};
69 # Build map of active rules
70 local %amap = map { int($_->{'num'}), $_ } @$active;
73 print &ui_form_start("edit_rule.cgi");
74 local @widths = ( "width=10", "width=5%", undef );
75 push(@widths, undef) if ($config{'view_condition'});
76 push(@widths, undef) if ($config{'view_comment'});
77 push(@widths, "width=5%", "width=5% nowrap") if ($config{'view_counters'});
78 push(@widths, "width=5%", "width=5%");
79 @links = ( &select_all_link("d", 0),
80 &select_invert_link("d", 0) );
81 print &ui_links_row(\@links);
82 print &ui_columns_start([ "",
84 $text{'index_action'},
85 $config{'view_condition'} ?
86 ( $text{'index_desc'} ) : ( ),
87 $config{'view_comment'} ?
88 ( $text{'index_cmt'} ) : ( ),
89 $config{'view_counters'} ?
90 ( $text{'index_count1'},
91 $text{'index_count2'} ) : ( ),
93 $text{'index_radd'} ], 100, 0,
95 foreach $r (@$rules) {
96 next if ($r->{'other'}); # Not displayable
97 local ($mover, $adder);
98 $mover = &ui_up_down_arrows(
99 "move.cgi?idx=$r->{'index'}&up=1",
100 "move.cgi?idx=$r->{'index'}&down=1",
101 $r->{'index'} != 0 && $r->{'index'} <= $lastidx,
102 $r->{'index'} < $lastidx);
103 if ($r->{'index'} <= $lastidx) {
104 $adder .= "<a href='edit_rule.cgi?new=1&".
105 "after=$r->{'index'}'>".
106 "<img src=images/after.gif border=0></a>";
107 $adder .= "<a href='edit_rule.cgi?new=1&".
108 "before=$r->{'index'}'>".
109 "<img src=images/before.gif border=0></a>";
113 if ($r->{'index'} <= $lastidx) {
114 $ls = "<a href='edit_rule.cgi?idx=$r->{'index'}'>";
117 local $act = $amap{int($r->{'num'})};
118 print &ui_checked_columns_row(
119 [ $ls.$r->{'num'}.$le,
120 $ls.($text{'action_'.&real_action($r->{'action'})} ||
122 (defined($r->{'aarg'}) ? " $r->{'aarg'}" : "").$le,
123 $config{'view_condition'} ? ( &describe_rule($r) ) : ( ),
124 $config{'view_comment'} ? ( $r->{'cmt'} || "<br>" ) : ( ),
125 $config{'view_counters'} ? ( $act->{'count1'}, &nice_size($act->{'count2'}) ) : ( ),
128 \@widths, "d", $r->{'num'});
130 print &ui_columns_end();
131 print &ui_links_row(\@links);
133 # Show delete and add buttons
134 print "<table width=100%><tr>\n";
135 print "<td align=left>",
136 &ui_submit($text{'index_delete'}, "delsel"),"</td>\n";
137 print "<td align=right>",
138 &ui_submit($text{'index_add2'}, "new"),"</td>\n";
139 print "</tr></table>\n";
140 print &ui_form_end();
142 # Show buttons to apply configuration and start at boot
145 $atboot = &check_boot();
146 print &ui_buttons_start();
147 if (&foreign_check("servers")) {
148 @servers = &list_cluster_servers();
150 print &ui_buttons_row("apply.cgi", $text{'index_apply'},
151 @servers ? $text{'index_applydesc2'}
152 : $text{'index_applydesc'});
153 print &ui_buttons_row("unapply.cgi", $text{'index_unapply'},
154 $text{'index_unapplydesc'});
156 print &ui_buttons_row("bootup.cgi", $text{'index_boot'},
157 $text{'index_bootdesc'}, undef,
158 &ui_radio("boot", $atboot ? 1 : 0,
159 [ [ 1, $text{'yes'} ],
160 [ 0, $text{'no'} ] ]));
162 print &ui_buttons_row("index.cgi", $text{'index_reset'},
163 $text{'index_resetdesc'}, undef,
164 &ui_hidden("reset", 1));
165 # Show button for cluster page
166 if (&foreign_check("servers")) {
167 &foreign_require("servers", "servers-lib.pl");
168 @allservers = grep { $_->{'user'} }
169 &servers::list_servers();
172 print &ui_buttons_row("cluster.cgi", $text{'index_cluster'},
173 $text{'index_clusterdesc'});
175 print &ui_buttons_end();
178 # Offer to setup simple firewall
179 print &text($in{'reset'} ? 'index_rsetup' : 'index_setup',
180 "<tt>$ipfw_file</tt>"),"<p>\n";
181 print "<form action=setup.cgi>\n";
182 print &ui_hidden("reset", $in{'reset'});
183 print "<center><table><tr><td>\n";
184 print "<input type=radio name=auto value=0 checked> ",
185 "$text{'index_auto0'}<p>\n";
186 foreach $a (2 .. 4) {
187 print "<input type=radio name=auto value=$a> ",
188 "$text{'index_auto'.$a} ",
189 &interface_choice("iface".$a, undef, 1),"<p>\n";
191 print "</td></tr></table>\n";
192 print "<input type=submit value='$text{'index_auto'}'><p>\n";
193 print "<input type=checkbox name=atboot value=1> ",
194 "$text{'index_atboot'}\n";
195 print "</center></form>\n";
198 &ui_print_footer("/", $text{'index'});