]>
git.ipfire.org Git - people/mfischer/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;
113 # now the chain hash is extracted to get the correct name of the chain
114 # all chains are displayed as a select box and can be choosen for display
115 # after this all corresponding lines for the chain are extraced and seperated
116 # into table rows, sometimes we need to handle leading blank so the offset is
117 # needed, some lines need to chomp trailing seperators. The interfaces and
118 # network addresses should be colorized by an extra function to make a nice
121 print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n<select name='selectedchain' style='width: 250px'>\n";
122 foreach (keys(%chains)){
130 print " <option value='".$_;
131 if ( $_ eq $selectedchain ){
132 print "' selected='selected' >".$_."</option>\n";
134 print "'>".$_."</option>\n";
137 print "</select><input type='submit' name='ACTION' value='$Lang::tr{'update'}' /><form><br /><br />\n\n";
139 $string = $iplines[$chains{$selectedchain."start"}];
140 $string =~ s/\s$//gi;
142 print "<strong>".$string."</strong><br />\n\n";
143 print "<table width='100%' cellspacing='1'>\n<tr>\n";
144 foreach (split(/ +/,$iplines[$chains{$selectedchain."start"}+1])){
145 if ( $_ =~ /[^a-zA-Z]/ ){chomp($_);}
146 print " <th align='left'><strong>".$_."</strong></th>\n";
152 print " <td width='0'></td>\n <td width='35'></td>\n <td width='35'></td>\n";
153 print " <td width='130'></td>\n <td width='30'></td>\n";
154 print " <td width='30'></td>\n <td width='40'></td>\n";
155 print " <td width='40'></td>\n <td width='95'></td>\n";
156 print " <td width='95'></td>\n <td width='260'></td>\n";
160 for(my $i = $chains{$selectedchain."start"}+2; $i <= $chains{$selectedchain."end"}; $i++) {
163 my @iptablesline = split(/ +/,$iplines[$i]);
166 if ( $iptablesline[0] eq "" ){
170 print " <td></td>\n <td>".$iptablesline[0+$offset]."</td>\n <td>".$iptablesline[1+$offset]."</td>\n";
171 print " <td>".$iptablesline[2+$offset]."</td>\n <td>".$iptablesline[3+$offset]."</td>\n";
172 print " <td>".$iptablesline[4+$offset]."</td>\n <td>".&Header
::colorize
($iptablesline[5+$offset])."</td>\n";
173 print " <td>".&Header
::colorize
($iptablesline[6+$offset])."</td>\n";
174 print " <td>".&Header
::colorize
($iptablesline[7+$offset])."</td>\n";
175 print " <td>".&Header
::colorize
($iptablesline[8+$offset])."</td>\n <td>";
177 for (my $i=9+$offset; $i <= $#iptablesline; $i++){
178 $string = $iptablesline[$i];
179 $string =~ s/\s$//gi;
182 print "</td>\n</tr>\n";
184 print "</table></DIV><br />";
188 &Header
::openbox
('100%', 'LEFT', $Lang::tr
{'iptmangles'}.':');
190 # If the cgi is called the first time the default chain is
191 # used, otherwise if user selected a chains in the selectboxes
192 # those one are displayed, it is possible to change all 3 at
195 if ( $cgiparams{'selectedchain'} ne "" ){
196 my @multi = split(/\|/,$cgiparams{'selectedchain'});
197 $selectedchain = $multi[1];
199 $selectedchain = "PREROUTING";
208 # We´ll open the txt files and extract each line, if the line
209 # start with an Chain the the name, start- and endline of the
210 # chain is extracted into a hash
212 open (FILE
, '/srv/web/ipfire/html/iptablesmangle.txt');
215 $ipmlines[$manlines] = $_;
217 if ( $_ =~ /^Chain/ ){
219 my @chainstring = split(/ /,$_);
221 if ( $chainname ne "" ){
222 $chainsman{$chainname."end"} = $manlines-2;
225 $chainname = $chainstring[1];
226 $chainsman{$chainname."start"} = $manlines;
234 # now the chain hash is extracted to get the correct name of the chain
235 # all chains are displayed as a select box and can be choosen for display
236 # after this all corresponding lines for the chain are extraced and seperated
237 # into table rows, sometimes we need to handle leading blank so the offset is
238 # needed, some lines need to chomp trailing seperators. The interfaces and
239 # network addresses should be colorized by an extra function to make a nice
242 print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n<select name='selectedchain' style='width: 250px'>\n";
243 foreach (keys(%chainsman)){
251 print " <option value='".$_;
252 if ( $_ eq $selectedchain ){
253 print "' selected='selected' >".$_."</option>\n";
255 print "'>".$_."</option>\n";
258 print "</select><input type='submit' name='ACTION' value='$Lang::tr{'update'}' /><form><br /><br />\n\n";
260 $string = $ipmanlines[$chainsman{$selectedchain."start"}];
261 $string =~ s/\s$//gi;
263 print "<strong>".$string."</strong><br />\n\n";
264 print "<table width='100%' cellspacing='1'>\n<tr>\n";
265 foreach (split(/ +/,$ipmlines[$chainsman{$selectedchain."start"}+1])){
266 if ( $_ =~ /[^a-zA-Z]/ ){chomp($_);}
267 print " <th align='left'><strong>".$_."</strong></th>\n";
273 print " <td width='0'></td>\n <td width='35'></td>\n <td width='35'></td>\n";
274 print " <td width='130'></td>\n <td width='30'></td>\n";
275 print " <td width='30'></td>\n <td width='40'></td>\n";
276 print " <td width='40'></td>\n <td width='95'></td>\n";
277 print " <td width='95'></td>\n <td width='260'></td>\n";
280 for(my $i = $chainsman{$selectedchain."start"}+2; $i <= $chainsman{$selectedchain."end"}; $i++) {
282 my @iptablesline = split(/ +/,$ipmlines[$i]);
285 if ( $iptablesline[0] eq "" ){
289 print " <td></td>\n <td>".$iptablesline[0+$offset]."</td>\n <td>".$iptablesline[1+$offset]."</td>\n";
290 print " <td>".$iptablesline[2+$offset]."</td>\n <td>".$iptablesline[3+$offset]."</td>\n";
291 print " <td>".$iptablesline[4+$offset]."</td>\n <td>".&Header
::colorize
($iptablesline[5+$offset])."</td>\n";
292 print " <td>".&Header
::colorize
($iptablesline[6+$offset])."</td>\n";
293 print " <td>".&Header
::colorize
($iptablesline[7+$offset])."</td>\n";
294 print " <td>".&Header
::colorize
($iptablesline[8+$offset])."</td>\n <td>";
296 for (my $i=9+$offset; $i <= $#iptablesline; $i++){
297 $string = $iptablesline[$i];
298 $string =~ s/\s$//gi;
300 # mangles with marks need to be converted from hex to number to show the correct qos class
302 if ( $string =~ /^0x/){
303 $string = hex($string);
308 print "</td>\n</tr>\n";
310 print "</table></DIV><br />";
314 &Header
::openbox
('100%', 'LEFT', $Lang::tr
{'iptnats'}.':');
316 # If the cgi is called the first time the default chain is
317 # used, otherwise if user selected a chains in the selectboxes
318 # those one are displayed, it is possible to change all 3 at
321 if ( $cgiparams{'selectedchain'} ne "" ){
322 my @multi = split(/\|/,$cgiparams{'selectedchain'});
323 $selectedchain = $multi[2];
325 $selectedchain = "PREROUTING";
334 # We´ll open the txt files and extract each line, if the line
335 # start with an Chain the the name, start- and endline of the
336 # chain is extracted into a hash
338 open (FILE
, '/srv/web/ipfire/html/iptablesnat.txt');
341 $ipnatlines[$natlines] = $_;
343 if ( $_ =~ /^Chain/ ){
345 my @chainstring = split(/ /,$_);
347 if ( $chainname ne "" ){
348 $chainsnat{$chainname."end"} = $natlines-2;
351 $chainname = $chainstring[1];
352 $chainsnat{$chainname."start"} = $natlines;
360 # now the chain hash is extracted to get the correct name of the chain
361 # all chains are displayed as a select box and can be choosen for display
362 # after this all corresponding lines for the chain are extraced and seperated
363 # into table rows, sometimes we need to handle leading blank so the offset is
364 # needed, some lines need to chomp trailing seperators. The interfaces and
365 # network addresses should be colorized by an extra function to make a nice
368 print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n<select name='selectedchain' style='width: 250px'>\n";
369 foreach (keys(%chainsnat)){
377 print " <option value='".$_;
378 if ( $_ eq $selectedchain ){
379 print "' selected='selected' >".$_."</option>\n";
381 print "'>".$_."</option>\n";
384 print "</select><input type='submit' name='ACTION' value='$Lang::tr{'update'}' /><form><br /><br />\n\n";
386 $string = $ipnatlines[$chainsnat{$selectedchain."start"}];
387 $string =~ s/\s$//gi;
389 print "<strong>".$string."</strong><br />\n\n";
390 print "<table width='100%' cellspacing='1'>\n<tr>\n";
391 foreach (split(/ +/,$ipnatlines[$chainsnat{$selectedchain."start"}+1])){
392 if ( $_ =~ /[^a-zA-Z]/ ){chomp($_);}
393 print "<th align='left'><strong>".$_."</strong></th>\n";
399 print " <td width='0'></td>\n <td width='35'></td>\n <td width='35'></td>\n";
400 print " <td width='130'></td>\n <td width='30'></td>\n";
401 print " <td width='30'></td>\n <td width='40'></td>\n";
402 print " <td width='40'></td>\n <td width='95'></td>\n";
403 print " <td width='95'></td>\n <td width='260'></td>\n";
406 for(my $i = $chainsnat{$selectedchain."start"}+2; $i <= $chainsnat{$selectedchain."end"}; $i++) {
408 my @iptablesline = split(/ +/,$ipnatlines[$i]);
411 if ( $iptablesline[0] eq "" ){
415 print " <td></td>\n<td>".$iptablesline[0+$offset]."</td>\n <td>".$iptablesline[1+$offset]."</td>\n";
416 print " <td>".$iptablesline[2+$offset]."</td>\n <td>".$iptablesline[3+$offset]."</td>\n";
417 print " <td>".$iptablesline[4+$offset]."</td>\n <td>".&Header
::colorize
($iptablesline[5+$offset])."</td>\n";
418 print " <td>".&Header
::colorize
($iptablesline[6+$offset])."</td>\n";
419 print " <td>".&Header
::colorize
($iptablesline[7+$offset])."</td>\n";
420 print " <td>".&Header
::colorize
($iptablesline[8+$offset])."</td>\n <td>";
422 for (my $i=9+$offset; $i <= $#iptablesline; $i++){
423 $string = $iptablesline[$i];
424 $string =~ s/\s$//gi;
427 print "</td>\n</tr>\n";
429 print "</table></DIV><br />";
431 &Header
::closebigbox
();
432 &Header
::closepage
();
434 system(rm
-f
"/srv/web/ipfire/html/iptables.txt");
435 system(rm
-f
"/srv/web/ipfire/html/iptablesmangle.txt");
436 system(rm
-f
"/srv/web/ipfire/html/iptablesnat.txt");