]>
git.ipfire.org Git - ipfire-2.x.git/blob - html/cgi-bin/dmzholes.cgi
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007 Michael Tremer & Christian Schmidt #
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 ###############################################################################
24 # enable only the following on debugging purpose
26 #use CGI::Carp 'fatalsToBrowser';
28 require '/var/ipfire/general-functions.pl';
29 require "${General::swroot}/lang.pl";
30 require "${General::swroot}/header.pl";
32 #workaround to suppress a warning when a variable is used only once
33 my @dummy = ( ${Header
::table2colour
}, ${Header
::colouryellow
} );
40 my $errormessage = '';
41 my $filename = "${General::swroot}/dmzholes/config";
43 &General
::readhash
("${General::swroot}/ethernet/settings", \
%netsettings);
45 &Header
::showhttpheaders
();
47 $cgiparams{'ENABLED'} = 'off';
48 $cgiparams{'REMARK'} = '';
49 $cgiparams{'ACTION'} = '';
50 $cgiparams{'SRC_IP'} = '';
51 $cgiparams{'DEST_IP'} ='';
52 $cgiparams{'DEST_PORT'} = '';
53 &Header
::getcgihash
(\
%cgiparams);
55 open(FILE
, $filename) or die 'Unable to open config file.';
59 if ($cgiparams{'ACTION'} eq $Lang::tr
{'add'})
61 unless($cgiparams{'PROTOCOL'} =~ /^(tcp|udp)$/) { $errormessage = $Lang::tr
{'invalid input'}; }
62 unless(&General
::validipormask
($cgiparams{'SRC_IP'})) { $errormessage = $Lang::tr
{'source ip bad'}; }
63 unless($errormessage){$errormessage = &General
::validportrange
($cgiparams{'DEST_PORT'},'dst');}
64 unless(&General
::validipormask
($cgiparams{'DEST_IP'})) { $errormessage = $Lang::tr
{'destination ip bad'}; }
65 unless ($errormessage) {
66 $errormessage = &validNet
($cgiparams{'SRC_NET'},$cgiparams{'DEST_NET'}); }
67 # Darren Critchley - Remove commas from remarks
68 $cgiparams{'REMARK'} = &Header
::cleanhtml
($cgiparams{'REMARK'});
70 unless ($errormessage)
72 if($cgiparams{'EDITING'} eq 'no') {
73 open(FILE
,">>$filename") or die 'Unable to open config file.';
75 print FILE
"$cgiparams{'PROTOCOL'},"; # [0]
76 print FILE
"$cgiparams{'SRC_IP'},"; # [1]
77 print FILE
"$cgiparams{'DEST_IP'},"; # [2]
78 print FILE
"$cgiparams{'DEST_PORT'},"; # [3]
79 print FILE
"$cgiparams{'ENABLED'},"; # [4]
80 print FILE
"$cgiparams{'SRC_NET'},"; # [5]
81 print FILE
"$cgiparams{'DEST_NET'},"; # [6]
82 print FILE
"$cgiparams{'REMARK'}\n"; # [7]
84 open(FILE
,">$filename") or die 'Unable to open config file.';
87 foreach my $line (@current)
90 if ($cgiparams{'EDITING'} eq $id) {
91 print FILE
"$cgiparams{'PROTOCOL'},"; # [0]
92 print FILE
"$cgiparams{'SRC_IP'},"; # [1]
93 print FILE
"$cgiparams{'DEST_IP'},"; # [2]
94 print FILE
"$cgiparams{'DEST_PORT'},"; # [3]
95 print FILE
"$cgiparams{'ENABLED'},"; # [4]
96 print FILE
"$cgiparams{'SRC_NET'},"; # [5]
97 print FILE
"$cgiparams{'DEST_NET'},"; # [6]
98 print FILE
"$cgiparams{'REMARK'}\n"; # [7]
99 } else { print FILE
"$line"; }
104 &General
::log($Lang::tr
{'dmz pinhole rule added'});
105 system('/usr/local/bin/setdmzholes');
108 if ($cgiparams{'ACTION'} eq $Lang::tr
{'remove'})
111 open(FILE
, ">$filename") or die 'Unable to open config file.';
113 foreach my $line (@current)
116 unless ($cgiparams{'ID'} eq $id) { print FILE
"$line"; }
119 system('/usr/local/bin/setdmzholes');
120 &General
::log($Lang::tr
{'dmz pinhole rule removed'});
122 if ($cgiparams{'ACTION'} eq $Lang::tr
{'toggle enable disable'})
125 open(FILE
, ">$filename") or die 'Unable to open config file.';
127 foreach my $line (@current)
130 unless ($cgiparams{'ID'} eq $id) { print FILE
"$line"; }
134 my @temp = split(/\,/,$line);
135 print FILE
"$temp[0],$temp[1],$temp[2],$temp[3],$cgiparams{'ENABLE'},$temp[5],$temp[6],$temp[7]\n";
139 system('/usr/local/bin/setdmzholes');
141 if ($cgiparams{'ACTION'} eq $Lang::tr
{'edit'})
144 foreach my $line (@current)
147 if ($cgiparams{'ID'} eq $id)
150 my @temp = split(/\,/,$line);
151 $cgiparams{'PROTOCOL'} = $temp[0];
152 $cgiparams{'SRC_IP'} = $temp[1];
153 $cgiparams{'DEST_IP'} = $temp[2];
154 $cgiparams{'DEST_PORT'} = $temp[3];
155 $cgiparams{'ENABLED'} = $temp[4];
156 $cgiparams{'SRC_NET'} = $temp[5];
157 $cgiparams{'DEST_NET'} = $temp[6];
158 $cgiparams{'REMARK'} = $temp[7];
163 if ($cgiparams{'ACTION'} eq '')
165 $cgiparams{'PROTOCOL'} = 'tcp';
166 $cgiparams{'ENABLED'} = 'on';
167 $cgiparams{'SRC_NET'} = 'orange';
168 $cgiparams{'DEST_NET'} = 'blue';
171 $selected{'PROTOCOL'}{'udp'} = '';
172 $selected{'PROTOCOL'}{'tcp'} = '';
173 $selected{'PROTOCOL'}{$cgiparams{'PROTOCOL'}} = "selected='selected'";
175 $selected{'SRC_NET'}{'orange'} = '';
176 $selected{'SRC_NET'}{'blue'} = '';
177 $selected{'SRC_NET'}{$cgiparams{'SRC_NET'}} = "selected='selected'";
179 $selected{'DEST_NET'}{'blue'} = '';
180 $selected{'DEST_NET'}{'green'} = '';
181 $selected{'DEST_NET'}{$cgiparams{'DEST_NET'}} = "selected='selected'";
183 $checked{'ENABLED'}{'off'} = '';
184 $checked{'ENABLED'}{'on'} = '';
185 $checked{'ENABLED'}{$cgiparams{'ENABLED'}} = "checked='checked'";
187 &Header
::openpage
($Lang::tr
{'dmz pinhole configuration'}, 1, '');
189 &Header
::openbigbox
('100%', 'left', '', $errormessage);
192 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
193 print "<class name='base'>$errormessage\n";
194 print " </class>\n";
198 print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n";
200 my $buttonText = $Lang::tr
{'add'};
201 if ($cgiparams{'ACTION'} eq $Lang::tr
{'edit'}) {
202 &Header
::openbox
('100%', 'left', $Lang::tr
{'edit a rule'});
203 $buttonText = $Lang::tr
{'update'};
205 &Header
::openbox
('100%', 'left', $Lang::tr
{'add a new rule'});
211 <select name='PROTOCOL'>
212 <option value='udp' $selected{'PROTOCOL'}{'udp'}>UDP</option>
213 <option value='tcp' $selected{'PROTOCOL'}{'tcp'}>TCP</option>
217 $Lang::tr{'source net'}:</td>
219 <select name='SRC_NET'>
222 if (&haveOrangeNet
()) {
223 print "<option value='orange' $selected{'SRC_NET'}{'orange'}>$Lang::tr{'orange'}</option>";
225 if (&haveBlueNet
()) {
226 print "<option value='blue' $selected{'SRC_NET'}{'blue'}>$Lang::tr{'blue'}</option>";
231 <td class='base'>$Lang::tr{'source ip or net'}:</td>
232 <td><input type='text' name='SRC_IP' value='$cgiparams{'SRC_IP'}' size='15' /></td>
238 $Lang::tr{'destination net'}:</td>
240 <select name='DEST_NET'>
243 if (&haveOrangeNet
() && &haveBlueNet
()) {
244 print "<option value='blue' $selected{'DEST_NET'}{'blue'}>$Lang::tr{'blue'}</option>";
248 <option value='green' $selected{'DEST_NET'}{'green'}>$Lang::tr{'green'}</option>
252 $Lang::tr{'destination ip or net'}:</td>
254 <input type='text' name='DEST_IP' value='$cgiparams{'DEST_IP'}' size='15' />
257 $Lang::tr{'destination port'}:
258 <input type='text' name='DEST_PORT' value='$cgiparams{'DEST_PORT'}' size='5' />
264 <td colspan='3' width='50%' class='base'>
265 <font class='boldbase'>$Lang::tr{'remark title'} <img src='/blob.gif' alt='*' /></font>
266 <input type='text' name='REMARK' value='$cgiparams{'REMARK'}' size='55' maxlength='50' />
270 <td class='base' width='50%'>
271 <img src='/blob.gif' alt ='*' align='top' />
272 <font class='base'>$Lang::tr{'this field may be blank'}</font>
274 <td class='base' width='25%' align='center'>$Lang::tr{'enabled'}<input type='checkbox' name='ENABLED' $checked{'ENABLED'}{'on'} /></td>
275 <td width='25%' align='center'>
276 <input type='hidden' name='ACTION' value='$Lang::tr{'add'}' />
277 <input type='submit' name='SUBMIT' value='$buttonText' />
283 if ($cgiparams{'ACTION'} eq $Lang::tr
{'edit'}) {
284 print "<input type='hidden' name='EDITING' value='$cgiparams{'ID'}' />\n";
286 print "<input type='hidden' name='EDITING' value='no' />\n";
291 &Header
::openbox
('100%', 'left', $Lang::tr
{'current rules'});
295 <td width='7%' class='boldbase' align='center'><b>$Lang::tr{'proto'}</b></td>
296 <td width='3%' class='boldbase' align='center'><b>$Lang::tr{'net'}</b></td>
297 <td width='25%' class='boldbase' align='center'><b>$Lang::tr{'source'}</b></td>
298 <td width='2%' class='boldbase' align='center'> </td>
299 <td width='3%' class='boldbase' align='center'><b>$Lang::tr{'net'}</b></td>
300 <td width='25%' class='boldbase' align='center'><b>$Lang::tr{'destination'}</b></td>
301 <td width='30%' class='boldbase' align='center'><b>$Lang::tr{'remark'}</b></td>
302 <td width='1%' class='boldbase' align='center'> </td>
303 <td width='4%' class='boldbase' colspan='3' align='center'><b>$Lang::tr{'action'}</b></td>
307 # Achim Weber: if i add a new rule, this rule is not displayed?!?
308 # we re-read always config.
309 # If something has happeened re-read config
310 #if($cgiparams{'ACTION'} ne '')
312 open(FILE
, $filename) or die 'Unable to open config file.';
317 foreach my $line (@current)
325 my @temp = split(/\,/,$line);
326 if ($temp[0] eq 'udp') { $protocol = 'UDP'; } else { $protocol = 'TCP' }
328 my $srcnetcolor = ($temp[5] eq 'blue')?
${Header
::colourblue
} : ${Header
::colourorange
};
329 my $destnetcolor = ($temp[6] eq 'blue')?
${Header
::colourblue
} : ${Header
::colourgreen
};
331 if ($cgiparams{'ACTION'} eq $Lang::tr
{'edit'} && $cgiparams{'ID'} eq $id) {
332 print "<tr bgcolor='${Header::colouryellow}'>\n"; }
334 print "<tr bgcolor='${Header::table1colour}'>\n"; }
336 print "<tr bgcolor='${Header::table2colour}'>\n"; }
337 if ($temp[4] eq 'on') { $gif='on.gif'; $toggle='off'; $gdesc=$Lang::tr
{'click to disable'};}
338 else { $gif = 'off.gif'; $toggle='on'; $gdesc=$Lang::tr
{'click to enable'}; }
340 # Darren Critchley - Get Port Service Name if we can - code borrowed from firewalllog.dat
341 my $dstprt =$temp[3];
344 my $servi = uc(getservbyport($temp[3], lc($temp[0])));
345 if ($servi ne '' && $temp[3] < 1024) {
346 $dstprt = "$dstprt($servi)"; }
348 # Darren Critchley - If the line is too long, wrap the port numbers
349 my $dstaddr = "$temp[2] : $dstprt";
350 if (length($dstaddr) > 26) {
351 $dstaddr = "$temp[2] :<br /> $dstprt";
354 <td align='center'>$protocol</td>
355 <td bgcolor='$srcnetcolor'></td>
356 <td align='center'>$temp[1]</td>
357 <td align='center'><img src='/images/forward.gif' /></td>
358 <td bgcolor='$destnetcolor'></td>
359 <td align='center'>$dstaddr</td>
360 <td align='center'>$temp[7]</td>
363 <form method='post' name='frma$id' action='$ENV{'SCRIPT_NAME'}'>
364 <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gif' alt='$gdesc' />
365 <input type='hidden' name='ID' value='$id' />
366 <input type='hidden' name='ENABLE' value='$toggle' />
367 <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}' />
372 <form method='post' name='frmb$id' action='$ENV{'SCRIPT_NAME'}'>
373 <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' alt='$Lang::tr{'edit'}' />
374 <input type='hidden' name='ID' value='$id' />
375 <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}' />
380 <form method='post' name='frmc$id' action='$ENV{'SCRIPT_NAME'}'>
381 <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' alt='$Lang::tr{'remove'}' />
382 <input type='hidden' name='ID' value='$id' />
383 <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}' />
393 # If the fixed lease file contains entries, print Key to action icons
394 if ( ! -z
"$filename") {
398 <td class='boldbase'> <b>$Lang::tr{'legend'}:</b></td>
399 <td> <img src='/images/on.gif' alt='$Lang::tr{'click to disable'}' /></td>
400 <td class='base'>$Lang::tr{'click to disable'}</td>
401 <td> <img src='/images/off.gif' alt='$Lang::tr{'click to enable'}' /></td>
402 <td class='base'>$Lang::tr{'click to enable'}</td>
403 <td> <img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td>
404 <td class='base'>$Lang::tr{'edit'}</td>
405 <td> <img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td>
406 <td class='base'>$Lang::tr{'remove'}</td>
415 &Header
::closebigbox
();
417 &Header
::closepage
();
424 if ($srcNet eq $destNet) {
425 return $Lang::tr
{'dmzpinholes for same net not necessary'}; }
426 unless ($srcNet =~ /^(blue|orange)$/) {
427 return $Lang::tr
{'select source net'}; }
428 unless ($destNet =~ /^(blue|green)$/) {
429 return $Lang::tr
{'select dest net'}; }
436 if ($netsettings{'CONFIG_TYPE'} == 2) {return 1;}
437 if ($netsettings{'CONFIG_TYPE'} == 4) {return 1;}
443 if ($netsettings{'CONFIG_TYPE'} == 3) {return 1;}
444 if ($netsettings{'CONFIG_TYPE'} == 4) {return 1;}