]>
git.ipfire.org Git - ipfire-2.x.git/blob - html/cgi-bin/iptables.cgi
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2010 IPFire Team #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
22 require '/var/ipfire/general-functions.pl';
23 require "${General::swroot}/lang.pl";
24 require "${General::swroot}/header.pl";
27 #use CGI::Carp 'fatalsToBrowser';
45 &Header
::getcgihash
(\
%cgiparams);
47 system('/usr/local/bin/getipstat');
49 &Header
::showhttpheaders
();
50 &Header
::openpage
($Lang::tr
{'ipts'}, 1, '');
51 &Header
::openbigbox
('100%', 'LEFT');
53 # This debug is used to see what inputs are done via the cgi and
54 # what parameters are to be executed
57 &Header
::openbox
('100%', 'center', 'DEBUG');
59 foreach my $line (sort keys %cgiparams) {
60 print "$line = '$cgiparams{$line}'<br />\n";
63 print " Count: $debugCount\n";
67 &Header
::openbox
('100%', 'LEFT', $Lang::tr
{'ipts'}.':');
69 # If the cgi is called the first time the default chain is
70 # used, otherwise if user selected a chains in the selectboxes
71 # those one are displayed, it is possible to change all 3 at
74 if ( $cgiparams{'selectedchain'} ne "" ){
75 my @multi = split(/\|/,$cgiparams{'selectedchain'});
76 $selectedchain = $multi[0];
78 $selectedchain = "INPUT";
87 # We´ll open the txt files and extract each line, if the line
88 # start with an Chain the the name, start- and endline of the
89 # chain is extracted into a hash
91 open (FILE
, '/srv/web/ipfire/html/iptables.txt');
94 $iplines[$lines] = $_;
96 if ( $_ =~ /^Chain/ ){
98 my @chainstring = split(/ /,$_);
100 if ( $chainname ne "" ){
101 $chains{$chainname."end"} = $lines-2;
104 $chainname = $chainstring[1];
105 $chains{$chainname."start"} = $lines;
111 $chains{$chainname."end"} = $lines-1;
114 # now the chain hash is extracted to get the correct name of the chain
115 # all chains are displayed as a select box and can be choosen for display
116 # after this all corresponding lines for the chain are extraced and seperated
117 # into table rows, sometimes we need to handle leading blank so the offset is
118 # needed, some lines need to chomp trailing seperators. The interfaces and
119 # network addresses should be colorized by an extra function to make a nice
122 print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n<select name='selectedchain' style='width: 250px'>\n";
123 foreach (sort(keys(%chains))){
131 print " <option value='".$_;
132 if ( $_ eq $selectedchain ){
133 print "' selected='selected' >".$_."</option>\n";
135 print "'>".$_."</option>\n";
138 print "</select><input type='submit' name='ACTION' value='$Lang::tr{'update'}' /><form><br /><br />\n\n";
140 $string = $iplines[$chains{$selectedchain."start"}];
141 $string =~ s/\s$//gi;
143 print "<strong>".$string."</strong><br />\n\n";
144 print "<table width='100%' cellspacing='1'>\n<tr>\n";
145 foreach (split(/ +/,$iplines[$chains{$selectedchain."start"}+1])){
146 if ( $_ =~ /[^a-zA-Z]/ ){chomp($_);}
147 print " <th align='left'><strong>".$_."</strong></th>\n";
153 print " <td width='0'></td>\n <td width='35'></td>\n <td width='35'></td>\n";
154 print " <td width='130'></td>\n <td width='30'></td>\n";
155 print " <td width='30'></td>\n <td width='40'></td>\n";
156 print " <td width='40'></td>\n <td width='95'></td>\n";
157 print " <td width='95'></td>\n <td width='260'></td>\n";
161 for(my $i = $chains{$selectedchain."start"}+2; $i <= $chains{$selectedchain."end"}; $i++) {
164 my @iptablesline = split(/ +/,$iplines[$i]);
167 if ( $iptablesline[0] eq "" ){
171 print " <td></td>\n <td>".$iptablesline[0+$offset]."</td>\n <td>".$iptablesline[1+$offset]."</td>\n";
172 print " <td>".$iptablesline[2+$offset]."</td>\n <td>".$iptablesline[3+$offset]."</td>\n";
173 print " <td>".$iptablesline[4+$offset]."</td>\n <td>".&Header
::colorize
($iptablesline[5+$offset])."</td>\n";
174 print " <td>".&Header
::colorize
($iptablesline[6+$offset])."</td>\n";
175 print " <td>".&Header
::colorize
($iptablesline[7+$offset])."</td>\n";
176 print " <td>".&Header
::colorize
($iptablesline[8+$offset])."</td>\n <td>";
178 for (my $i=9+$offset; $i <= $#iptablesline; $i++){
179 $string = $iptablesline[$i];
180 $string =~ s/\s$//gi;
183 print "</td>\n</tr>\n";
185 print "</table></div><br />";
189 &Header
::openbox
('100%', 'LEFT', $Lang::tr
{'iptmangles'}.':');
191 # If the cgi is called the first time the default chain is
192 # used, otherwise if user selected a chains in the selectboxes
193 # those one are displayed, it is possible to change all 3 at
196 if ( $cgiparams{'selectedchain'} ne "" ){
197 my @multi = split(/\|/,$cgiparams{'selectedchain'});
198 $selectedchain = $multi[1];
200 $selectedchain = "PREROUTING";
209 # We´ll open the txt files and extract each line, if the line
210 # start with an Chain the the name, start- and endline of the
211 # chain is extracted into a hash
213 open (FILE
, '/srv/web/ipfire/html/iptablesmangle.txt');
216 $ipmlines[$manlines] = $_;
218 if ( $_ =~ /^Chain/ ){
220 my @chainstring = split(/ /,$_);
222 if ( $chainname ne "" ){
223 $chainsman{$chainname."end"} = $manlines-2;
226 $chainname = $chainstring[1];
227 $chainsman{$chainname."start"} = $manlines;
233 $chainsman{$chainname."end"} = $manlines-1;
236 # now the chain hash is extracted to get the correct name of the chain
237 # all chains are displayed as a select box and can be choosen for display
238 # after this all corresponding lines for the chain are extraced and seperated
239 # into table rows, sometimes we need to handle leading blank so the offset is
240 # needed, some lines need to chomp trailing seperators. The interfaces and
241 # network addresses should be colorized by an extra function to make a nice
244 print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n<select name='selectedchain' style='width: 250px'>\n";
245 foreach (sort(keys(%chainsman))){
253 print " <option value='".$_;
254 if ( $_ eq $selectedchain ){
255 print "' selected='selected' >".$_."</option>\n";
257 print "'>".$_."</option>\n";
260 print "</select><input type='submit' name='ACTION' value='$Lang::tr{'update'}' /><form><br /><br />\n\n";
262 $string = $ipmanlines[$chainsman{$selectedchain."start"}];
263 $string =~ s/\s$//gi;
265 print "<strong>".$string."</strong><br />\n\n";
266 print "<table width='100%' cellspacing='1'>\n<tr>\n";
267 foreach (split(/ +/,$ipmlines[$chainsman{$selectedchain."start"}+1])){
268 if ( $_ =~ /[^a-zA-Z]/ ){chomp($_);}
269 print " <th align='left'><strong>".$_."</strong></th>\n";
275 print " <td width='0'></td>\n <td width='35'></td>\n <td width='35'></td>\n";
276 print " <td width='130'></td>\n <td width='30'></td>\n";
277 print " <td width='30'></td>\n <td width='40'></td>\n";
278 print " <td width='40'></td>\n <td width='95'></td>\n";
279 print " <td width='95'></td>\n <td width='260'></td>\n";
282 for(my $i = $chainsman{$selectedchain."start"}+2; $i <= $chainsman{$selectedchain."end"}; $i++) {
284 my @iptablesline = split(/ +/,$ipmlines[$i]);
287 if ( $iptablesline[0] eq "" ){
291 print " <td></td>\n <td>".$iptablesline[0+$offset]."</td>\n <td>".$iptablesline[1+$offset]."</td>\n";
292 print " <td>".$iptablesline[2+$offset]."</td>\n <td>".$iptablesline[3+$offset]."</td>\n";
293 print " <td>".$iptablesline[4+$offset]."</td>\n <td>".&Header
::colorize
($iptablesline[5+$offset])."</td>\n";
294 print " <td>".&Header
::colorize
($iptablesline[6+$offset])."</td>\n";
295 print " <td>".&Header
::colorize
($iptablesline[7+$offset])."</td>\n";
296 print " <td>".&Header
::colorize
($iptablesline[8+$offset])."</td>\n <td>";
298 for (my $i=9+$offset; $i <= $#iptablesline; $i++){
299 $string = $iptablesline[$i];
300 $string =~ s/\s$//gi;
302 # mangles with marks need to be converted from hex to number to show the correct qos class
304 if ( $string =~ /^0x/){
305 $string = hex($string);
310 print "</td>\n</tr>\n";
312 print "</table></div><br />";
316 &Header
::openbox
('100%', 'LEFT', $Lang::tr
{'iptnats'}.':');
318 # If the cgi is called the first time the default chain is
319 # used, otherwise if user selected a chains in the selectboxes
320 # those one are displayed, it is possible to change all 3 at
323 if ( $cgiparams{'selectedchain'} ne "" ){
324 my @multi = split(/\|/,$cgiparams{'selectedchain'});
325 $selectedchain = $multi[2];
327 $selectedchain = "PREROUTING";
336 # We´ll open the txt files and extract each line, if the line
337 # start with an Chain the the name, start- and endline of the
338 # chain is extracted into a hash
340 open (FILE
, '/srv/web/ipfire/html/iptablesnat.txt');
343 $ipnatlines[$natlines] = $_;
345 if ( $_ =~ /^Chain/ ){
347 my @chainstring = split(/ /,$_);
349 if ( $chainname ne "" ){
350 $chainsnat{$chainname."end"} = $natlines-2;
353 $chainname = $chainstring[1];
354 $chainsnat{$chainname."start"} = $natlines;
360 $chainsnat{$chainname."end"} = $natlines-1;
363 # now the chain hash is extracted to get the correct name of the chain
364 # all chains are displayed as a select box and can be choosen for display
365 # after this all corresponding lines for the chain are extraced and seperated
366 # into table rows, sometimes we need to handle leading blank so the offset is
367 # needed, some lines need to chomp trailing seperators. The interfaces and
368 # network addresses should be colorized by an extra function to make a nice
371 print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n<select name='selectedchain' style='width: 250px'>\n";
372 foreach (sort(keys(%chainsnat))){
380 print " <option value='".$_;
381 if ( $_ eq $selectedchain ){
382 print "' selected='selected' >".$_."</option>\n";
384 print "'>".$_."</option>\n";
387 print "</select><input type='submit' name='ACTION' value='$Lang::tr{'update'}' /><form><br /><br />\n\n";
389 $string = $ipnatlines[$chainsnat{$selectedchain."start"}];
390 $string =~ s/\s$//gi;
392 print "<strong>".$string."</strong><br />\n\n";
393 print "<table width='100%' cellspacing='1'>\n<tr>\n";
394 foreach (split(/ +/,$ipnatlines[$chainsnat{$selectedchain."start"}+1])){
395 if ( $_ =~ /[^a-zA-Z]/ ){chomp($_);}
396 print "<th align='left'><strong>".$_."</strong></th>\n";
402 print " <td width='0'></td>\n <td width='35'></td>\n <td width='35'></td>\n";
403 print " <td width='130'></td>\n <td width='30'></td>\n";
404 print " <td width='30'></td>\n <td width='40'></td>\n";
405 print " <td width='40'></td>\n <td width='95'></td>\n";
406 print " <td width='95'></td>\n <td width='260'></td>\n";
409 for(my $i = $chainsnat{$selectedchain."start"}+2; $i <= $chainsnat{$selectedchain."end"}; $i++) {
411 my @iptablesline = split(/ +/,$ipnatlines[$i]);
414 if ( $iptablesline[0] eq "" ){
418 print " <td></td>\n<td>".$iptablesline[0+$offset]."</td>\n <td>".$iptablesline[1+$offset]."</td>\n";
419 print " <td>".$iptablesline[2+$offset]."</td>\n <td>".$iptablesline[3+$offset]."</td>\n";
420 print " <td>".$iptablesline[4+$offset]."</td>\n <td>".&Header
::colorize
($iptablesline[5+$offset])."</td>\n";
421 print " <td>".&Header
::colorize
($iptablesline[6+$offset])."</td>\n";
422 print " <td>".&Header
::colorize
($iptablesline[7+$offset])."</td>\n";
423 print " <td>".&Header
::colorize
($iptablesline[8+$offset])."</td>\n <td>";
425 for (my $i=9+$offset; $i <= $#iptablesline; $i++){
426 $string = $iptablesline[$i];
427 $string =~ s/\s$//gi;
430 print "</td>\n</tr>\n";
432 print "</table></div><br />";
434 &Header
::closebigbox
();
435 &Header
::closepage
();
437 system(rm
-f
"/srv/web/ipfire/html/iptables.txt");
438 system(rm
-f
"/srv/web/ipfire/html/iptablesmangle.txt");
439 system(rm
-f
"/srv/web/ipfire/html/iptablesnat.txt");