]>
git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - html/cgi-bin/dmzholes.cgi
5 # This code is distributed under the terms of the GPL
7 # (c) The SmoothWall Team
9 # $Id: dmzholes.cgi,v 1.9.2.16 2005/10/18 17:05:27 franck78 Exp $
14 # enable only the following on debugging purpose
16 #use CGI::Carp 'fatalsToBrowser';
18 require '/var/ipfire/general-functions.pl';
19 require "${General::swroot}/lang.pl";
20 require "${General::swroot}/header.pl";
22 #workaround to suppress a warning when a variable is used only once
23 my @dummy = ( ${Header
::table2colour
}, ${Header
::colouryellow
} );
30 my $errormessage = '';
31 my $filename = "${General::swroot}/dmzholes/config";
33 &General
::readhash
("${General::swroot}/ethernet/settings", \
%netsettings);
35 &Header
::showhttpheaders
();
37 $cgiparams{'ENABLED'} = 'off';
38 $cgiparams{'REMARK'} = '';
39 $cgiparams{'ACTION'} = '';
40 $cgiparams{'SRC_IP'} = '';
41 $cgiparams{'DEST_IP'} ='';
42 $cgiparams{'DEST_PORT'} = '';
43 &Header
::getcgihash
(\
%cgiparams);
45 open(FILE
, $filename) or die 'Unable to open config file.';
49 if ($cgiparams{'ACTION'} eq $Lang::tr
{'add'})
51 unless($cgiparams{'PROTOCOL'} =~ /^(tcp|udp)$/) { $errormessage = $Lang::tr
{'invalid input'}; }
52 unless(&General
::validipormask
($cgiparams{'SRC_IP'})) { $errormessage = $Lang::tr
{'source ip bad'}; }
53 unless($errormessage){$errormessage = &General
::validportrange
($cgiparams{'DEST_PORT'},'dst');}
54 unless(&General
::validipormask
($cgiparams{'DEST_IP'})) { $errormessage = $Lang::tr
{'destination ip bad'}; }
55 unless ($errormessage) {
56 $errormessage = &validNet
($cgiparams{'SRC_NET'},$cgiparams{'DEST_NET'}); }
57 # Darren Critchley - Remove commas from remarks
58 $cgiparams{'REMARK'} = &Header
::cleanhtml
($cgiparams{'REMARK'});
60 unless ($errormessage)
62 if($cgiparams{'EDITING'} eq 'no') {
63 open(FILE
,">>$filename") or die 'Unable to open config file.';
65 print FILE
"$cgiparams{'PROTOCOL'},"; # [0]
66 print FILE
"$cgiparams{'SRC_IP'},"; # [1]
67 print FILE
"$cgiparams{'DEST_IP'},"; # [2]
68 print FILE
"$cgiparams{'DEST_PORT'},"; # [3]
69 print FILE
"$cgiparams{'ENABLED'},"; # [4]
70 print FILE
"$cgiparams{'SRC_NET'},"; # [5]
71 print FILE
"$cgiparams{'DEST_NET'},"; # [6]
72 print FILE
"$cgiparams{'REMARK'}\n"; # [7]
74 open(FILE
,">$filename") or die 'Unable to open config file.';
77 foreach my $line (@current)
80 if ($cgiparams{'EDITING'} eq $id) {
81 print FILE
"$cgiparams{'PROTOCOL'},"; # [0]
82 print FILE
"$cgiparams{'SRC_IP'},"; # [1]
83 print FILE
"$cgiparams{'DEST_IP'},"; # [2]
84 print FILE
"$cgiparams{'DEST_PORT'},"; # [3]
85 print FILE
"$cgiparams{'ENABLED'},"; # [4]
86 print FILE
"$cgiparams{'SRC_NET'},"; # [5]
87 print FILE
"$cgiparams{'DEST_NET'},"; # [6]
88 print FILE
"$cgiparams{'REMARK'}\n"; # [7]
89 } else { print FILE
"$line"; }
94 &General
::log($Lang::tr
{'dmz pinhole rule added'});
95 system('/usr/local/bin/setdmzholes');
98 if ($cgiparams{'ACTION'} eq $Lang::tr
{'remove'})
101 open(FILE
, ">$filename") or die 'Unable to open config file.';
103 foreach my $line (@current)
106 unless ($cgiparams{'ID'} eq $id) { print FILE
"$line"; }
109 system('/usr/local/bin/setdmzholes');
110 &General
::log($Lang::tr
{'dmz pinhole rule removed'});
112 if ($cgiparams{'ACTION'} eq $Lang::tr
{'toggle enable disable'})
115 open(FILE
, ">$filename") or die 'Unable to open config file.';
117 foreach my $line (@current)
120 unless ($cgiparams{'ID'} eq $id) { print FILE
"$line"; }
124 my @temp = split(/\,/,$line);
125 print FILE
"$temp[0],$temp[1],$temp[2],$temp[3],$cgiparams{'ENABLE'},$temp[5],$temp[6],$temp[7]\n";
129 system('/usr/local/bin/setdmzholes');
131 if ($cgiparams{'ACTION'} eq $Lang::tr
{'edit'})
134 foreach my $line (@current)
137 if ($cgiparams{'ID'} eq $id)
140 my @temp = split(/\,/,$line);
141 $cgiparams{'PROTOCOL'} = $temp[0];
142 $cgiparams{'SRC_IP'} = $temp[1];
143 $cgiparams{'DEST_IP'} = $temp[2];
144 $cgiparams{'DEST_PORT'} = $temp[3];
145 $cgiparams{'ENABLED'} = $temp[4];
146 $cgiparams{'SRC_NET'} = $temp[5];
147 $cgiparams{'DEST_NET'} = $temp[6];
148 $cgiparams{'REMARK'} = $temp[7];
153 if ($cgiparams{'ACTION'} eq '')
155 $cgiparams{'PROTOCOL'} = 'tcp';
156 $cgiparams{'ENABLED'} = 'on';
157 $cgiparams{'SRC_NET'} = 'orange';
158 $cgiparams{'DEST_NET'} = 'blue';
161 $selected{'PROTOCOL'}{'udp'} = '';
162 $selected{'PROTOCOL'}{'tcp'} = '';
163 $selected{'PROTOCOL'}{$cgiparams{'PROTOCOL'}} = "selected='selected'";
165 $selected{'SRC_NET'}{'orange'} = '';
166 $selected{'SRC_NET'}{'blue'} = '';
167 $selected{'SRC_NET'}{$cgiparams{'SRC_NET'}} = "selected='selected'";
169 $selected{'DEST_NET'}{'blue'} = '';
170 $selected{'DEST_NET'}{'green'} = '';
171 $selected{'DEST_NET'}{$cgiparams{'DEST_NET'}} = "selected='selected'";
173 $checked{'ENABLED'}{'off'} = '';
174 $checked{'ENABLED'}{'on'} = '';
175 $checked{'ENABLED'}{$cgiparams{'ENABLED'}} = "checked='checked'";
177 &Header
::openpage
($Lang::tr
{'dmz pinhole configuration'}, 1, '');
179 &Header
::openbigbox
('100%', 'left', '', $errormessage);
182 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
183 print "<class name='base'>$errormessage\n";
184 print " </class>\n";
188 print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n";
190 my $buttonText = $Lang::tr
{'add'};
191 if ($cgiparams{'ACTION'} eq $Lang::tr
{'edit'}) {
192 &Header
::openbox
('100%', 'left', $Lang::tr
{'edit a rule'});
193 $buttonText = $Lang::tr
{'update'};
195 &Header
::openbox
('100%', 'left', $Lang::tr
{'add a new rule'});
201 <select name='PROTOCOL'>
202 <option value='udp' $selected{'PROTOCOL'}{'udp'}>UDP</option>
203 <option value='tcp' $selected{'PROTOCOL'}{'tcp'}>TCP</option>
207 $Lang::tr{'source net'}:</td>
209 <select name='SRC_NET'>
212 if (&haveOrangeNet
()) {
213 print "<option value='orange' $selected{'SRC_NET'}{'orange'}>$Lang::tr{'orange'}</option>";
215 if (&haveBlueNet
()) {
216 print "<option value='blue' $selected{'SRC_NET'}{'blue'}>$Lang::tr{'blue'}</option>";
221 <td class='base'>$Lang::tr{'source ip or net'}:</td>
222 <td><input type='text' name='SRC_IP' value='$cgiparams{'SRC_IP'}' size='15' /></td>
228 $Lang::tr{'destination net'}:</td>
230 <select name='DEST_NET'>
233 if (&haveOrangeNet
() && &haveBlueNet
()) {
234 print "<option value='blue' $selected{'DEST_NET'}{'blue'}>$Lang::tr{'blue'}</option>";
238 <option value='green' $selected{'DEST_NET'}{'green'}>$Lang::tr{'green'}</option>
242 $Lang::tr{'destination ip or net'}:</td>
244 <input type='text' name='DEST_IP' value='$cgiparams{'DEST_IP'}' size='15' />
247 $Lang::tr{'destination port'}:
248 <input type='text' name='DEST_PORT' value='$cgiparams{'DEST_PORT'}' size='5' />
254 <td colspan='3' width='50%' class='base'>
255 <font class='boldbase'>$Lang::tr{'remark title'} <img src='/blob.gif' alt='*' /></font>
256 <input type='text' name='REMARK' value='$cgiparams{'REMARK'}' size='55' maxlength='50' />
260 <td class='base' width='50%'>
261 <img src='/blob.gif' alt ='*' align='top' />
262 <font class='base'>$Lang::tr{'this field may be blank'}</font>
264 <td class='base' width='25%' align='center'>$Lang::tr{'enabled'}<input type='checkbox' name='ENABLED' $checked{'ENABLED'}{'on'} /></td>
265 <td width='25%' align='center'>
266 <input type='hidden' name='ACTION' value='$Lang::tr{'add'}' />
267 <input type='submit' name='SUBMIT' value='$buttonText' />
273 if ($cgiparams{'ACTION'} eq $Lang::tr
{'edit'}) {
274 print "<input type='hidden' name='EDITING' value='$cgiparams{'ID'}' />\n";
276 print "<input type='hidden' name='EDITING' value='no' />\n";
281 &Header
::openbox
('100%', 'left', $Lang::tr
{'current rules'});
285 <td width='7%' class='boldbase' align='center'><b>$Lang::tr{'proto'}</b></td>
286 <td width='3%' class='boldbase' align='center'><b>$Lang::tr{'net'}</b></td>
287 <td width='25%' class='boldbase' align='center'><b>$Lang::tr{'source'}</b></td>
288 <td width='2%' class='boldbase' align='center'> </td>
289 <td width='3%' class='boldbase' align='center'><b>$Lang::tr{'net'}</b></td>
290 <td width='25%' class='boldbase' align='center'><b>$Lang::tr{'destination'}</b></td>
291 <td width='30%' class='boldbase' align='center'><b>$Lang::tr{'remark'}</b></td>
292 <td width='1%' class='boldbase' align='center'> </td>
293 <td width='4%' class='boldbase' colspan='3' align='center'><b>$Lang::tr{'action'}</b></td>
297 # Achim Weber: if i add a new rule, this rule is not displayed?!?
298 # we re-read always config.
299 # If something has happeened re-read config
300 #if($cgiparams{'ACTION'} ne '')
302 open(FILE
, $filename) or die 'Unable to open config file.';
307 foreach my $line (@current)
315 my @temp = split(/\,/,$line);
316 if ($temp[0] eq 'udp') { $protocol = 'UDP'; } else { $protocol = 'TCP' }
318 my $srcnetcolor = ($temp[5] eq 'blue')?
${Header
::colourblue
} : ${Header
::colourorange
};
319 my $destnetcolor = ($temp[6] eq 'blue')?
${Header
::colourblue
} : ${Header
::colourgreen
};
321 if ($cgiparams{'ACTION'} eq $Lang::tr
{'edit'} && $cgiparams{'ID'} eq $id) {
322 print "<tr bgcolor='${Header::colouryellow}'>\n"; }
324 print "<tr bgcolor='${Header::table1colour}'>\n"; }
326 print "<tr bgcolor='${Header::table2colour}'>\n"; }
327 if ($temp[4] eq 'on') { $gif='on.gif'; $toggle='off'; $gdesc=$Lang::tr
{'click to disable'};}
328 else { $gif = 'off.gif'; $toggle='on'; $gdesc=$Lang::tr
{'click to enable'}; }
330 # Darren Critchley - Get Port Service Name if we can - code borrowed from firewalllog.dat
331 my $dstprt =$temp[3];
334 my $servi = uc(getservbyport($temp[3], lc($temp[0])));
335 if ($servi ne '' && $temp[3] < 1024) {
336 $dstprt = "$dstprt($servi)"; }
338 # Darren Critchley - If the line is too long, wrap the port numbers
339 my $dstaddr = "$temp[2] : $dstprt";
340 if (length($dstaddr) > 26) {
341 $dstaddr = "$temp[2] :<br /> $dstprt";
344 <td align='center'>$protocol</td>
345 <td bgcolor='$srcnetcolor'></td>
346 <td align='center'>$temp[1]</td>
347 <td align='center'><img src='/images/forward.gif' /></td>
348 <td bgcolor='$destnetcolor'></td>
349 <td align='center'>$dstaddr</td>
350 <td align='center'>$temp[7]</td>
353 <form method='post' name='frma$id' action='$ENV{'SCRIPT_NAME'}'>
354 <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gif' alt='$gdesc' />
355 <input type='hidden' name='ID' value='$id' />
356 <input type='hidden' name='ENABLE' value='$toggle' />
357 <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}' />
362 <form method='post' name='frmb$id' action='$ENV{'SCRIPT_NAME'}'>
363 <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' alt='$Lang::tr{'edit'}' />
364 <input type='hidden' name='ID' value='$id' />
365 <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}' />
370 <form method='post' name='frmc$id' action='$ENV{'SCRIPT_NAME'}'>
371 <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' alt='$Lang::tr{'remove'}' />
372 <input type='hidden' name='ID' value='$id' />
373 <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}' />
383 # If the fixed lease file contains entries, print Key to action icons
384 if ( ! -z
"$filename") {
388 <td class='boldbase'> <b>$Lang::tr{'legend'}:</b></td>
389 <td> <img src='/images/on.gif' alt='$Lang::tr{'click to disable'}' /></td>
390 <td class='base'>$Lang::tr{'click to disable'}</td>
391 <td> <img src='/images/off.gif' alt='$Lang::tr{'click to enable'}' /></td>
392 <td class='base'>$Lang::tr{'click to enable'}</td>
393 <td> <img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td>
394 <td class='base'>$Lang::tr{'edit'}</td>
395 <td> <img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td>
396 <td class='base'>$Lang::tr{'remove'}</td>
405 &Header
::closebigbox
();
407 &Header
::closepage
();
414 if ($srcNet eq $destNet) {
415 return $Lang::tr
{'dmzpinholes for same net not necessary'}; }
416 unless ($srcNet =~ /^(blue|orange)$/) {
417 return $Lang::tr
{'select source net'}; }
418 unless ($destNet =~ /^(blue|green)$/) {
419 return $Lang::tr
{'select dest net'}; }
426 if ($netsettings{'CONFIG_TYPE'} == 2) {return 1;}
427 if ($netsettings{'CONFIG_TYPE'} == 4) {return 1;}
433 if ($netsettings{'CONFIG_TYPE'} == 3) {return 1;}
434 if ($netsettings{'CONFIG_TYPE'} == 4) {return 1;}