]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/xtaccess.cgi
5 # This code is distributed under the terms of the GPL
7 # (c) The SmoothWall Team
8 # Copyright (c) 2002/04/13 Steve Bootes - Add destination IP support
10 # $Id: xtaccess.cgi,v 1.6.2.15 2005/03/05 08:44:32 eoberlander Exp $
15 # enable only the following on debugging purpose
17 #use CGI::Carp 'fatalsToBrowser';
19 require '/var/ipfire/general-functions.pl';
20 require "${General::swroot}/lang.pl";
21 require "${General::swroot}/header.pl";
23 #workaround to suppress a warning when a variable is used only once
24 my @dummy = ( ${Header
::colouryellow
} );
30 my $errormessage = '';
31 my $filename = "${General::swroot}/xtaccess/config";
32 my $aliasfile = "${General::swroot}/ethernet/aliases";
36 my %mainsettings = ();
37 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
38 &General
::readhash
("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \
%color);
40 &Header
::showhttpheaders
();
42 $cgiparams{'ENABLED'} = 'off';
43 $cgiparams{'ACTION'} = '';
44 $cgiparams{'SRC'} = '';
45 $cgiparams{'DEST_PORT'} = '';
46 $cgiparams{'REMARK'} ='';
47 &Header
::getcgihash
(\
%cgiparams);
48 open(FILE
, $filename) or die 'Unable to open config file.';
52 if ($cgiparams{'ACTION'} eq $Lang::tr
{'add'})
54 unless($cgiparams{'PROTOCOL'} =~ /^(tcp|udp)$/) { $errormessage = $Lang::tr
{'invalid input'}; }
55 unless(&General
::validipormask
($cgiparams{'SRC'}))
57 if ($cgiparams{'SRC'} ne '') {
58 $errormessage = $Lang::tr
{'source ip bad'}; }
60 $cgiparams{'SRC'} = '0.0.0.0/0'; }
62 unless($errormessage){ $errormessage = &General
::validportrange
($cgiparams{'DEST_PORT'},'dst'); }
65 $cgiparams{'REMARK'} = &Header
::cleanhtml
($cgiparams{'REMARK'});
67 if($cgiparams{'EDITING'} eq 'no') {
68 open(FILE
,">>$filename") or die 'Unable to open config file.';
70 print FILE
"$cgiparams{'PROTOCOL'},$cgiparams{'SRC'},$cgiparams{'DEST_PORT'},$cgiparams{'ENABLED'},$cgiparams{'DEST'},$cgiparams{'REMARK'}\n";
72 open(FILE
, ">$filename") or die 'Unable to open config file.';
75 foreach my $line (@current)
78 if ($cgiparams{'EDITING'} eq $id) {
79 print FILE
"$cgiparams{'PROTOCOL'},$cgiparams{'SRC'},$cgiparams{'DEST_PORT'},$cgiparams{'ENABLED'},$cgiparams{'DEST'},$cgiparams{'REMARK'}\n";
80 } else { print FILE
"$line"; }
86 &General
::log($Lang::tr
{'external access rule added'});
87 system('/usr/local/bin/setxtaccess');
89 # stay on edit mode if an error occur
90 if ($cgiparams{'EDITING'} ne 'no')
92 $cgiparams{'ACTION'} = $Lang::tr
{'edit'};
93 $cgiparams{'ID'} = $cgiparams{'EDITING'};
97 if ($cgiparams{'ACTION'} eq $Lang::tr
{'remove'})
100 open(FILE
, ">$filename") or die 'Unable to open config file.';
102 foreach my $line (@current)
105 unless ($cgiparams{'ID'} eq $id) { print FILE
"$line"; }
108 system('/usr/local/bin/setxtaccess');
109 &General
::log($Lang::tr
{'external access rule removed'});
111 if ($cgiparams{'ACTION'} eq $Lang::tr
{'toggle enable disable'})
113 open(FILE
, ">$filename") or die 'Unable to open config file.';
116 foreach my $line (@current)
119 unless ($cgiparams{'ID'} eq $id) { print FILE
"$line"; }
123 my @temp = split(/\,/,$line);
124 print FILE
"$temp[0],$temp[1],$temp[2],$cgiparams{'ENABLE'},$temp[4],$temp[5]\n";
128 system('/usr/local/bin/setxtaccess');
130 if ($cgiparams{'ACTION'} eq $Lang::tr
{'edit'})
133 foreach my $line (@current)
136 if ($cgiparams{'ID'} eq $id)
139 my @temp = split(/\,/,$line);
140 $cgiparams{'PROTOCOL'} = $temp[0];
141 $cgiparams{'SRC'} = $temp[1];
142 $cgiparams{'DEST_PORT'} = $temp[2];
143 $cgiparams{'ENABLED'} = $temp[3];
144 $cgiparams{'DEST'} = $temp[4];
145 $cgiparams{'REMARK'} = $temp[5];
150 if ($cgiparams{'ACTION'} eq '')
152 $cgiparams{'PROTOCOL'} = 'tcp';
153 $cgiparams{'DEST'} = '0.0.0.0';
154 $cgiparams{'ENABLED'} = 'on';
157 $selected{'PROTOCOL'}{'udp'} = '';
158 $selected{'PROTOCOL'}{'tcp'} = '';
159 $selected{'PROTOCOL'}{$cgiparams{'PROTOCOL'}} = "selected='selected'";
161 $selected{'DEST'}{$cgiparams{'DEST'}} = "selected='selected'";
163 $checked{'ENABLED'}{'off'} = '';
164 $checked{'ENABLED'}{'on'} = '';
165 $checked{'ENABLED'}{$cgiparams{'ENABLED'}} = "checked='checked'";
167 &Header
::openpage
($Lang::tr
{'external access configuration'}, 1, '');
169 &Header
::openbigbox
('100%', 'left', '', $errormessage);
172 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
173 print "<class name='base'>$errormessage\n";
174 print " </class>\n";
178 print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n";
180 my $buttontext = $Lang::tr
{'add'};
181 if ($cgiparams{'ACTION'} eq $Lang::tr
{'edit'}) {
182 &Header
::openbox
('100%', 'left', $Lang::tr
{'edit a rule'});
183 $buttontext = $Lang::tr
{'update'};
185 &Header
::openbox
('100%', 'left', $Lang::tr
{'add a new rule'});
191 <select name='PROTOCOL'>
192 <option value='udp' $selected{'PROTOCOL'}{'udp'}>UDP</option>
193 <option value='tcp' $selected{'PROTOCOL'}{'tcp'}>TCP</option>
196 <td class='base'><font color='${Header::colourred}'>$Lang::tr{'source network'}</font></td>
197 <td><input type='text' name='SRC' value='$cgiparams{'SRC'}' size='32' /></td>
198 <td class='base'><font color='${Header::colourred}'>$Lang::tr{'destination port'}:</font></td>
199 <td><input type='text' name='DEST_PORT' value='$cgiparams{'DEST_PORT'}' size='5' /></td>
204 <td width='10%' class='base'>$Lang::tr{'enabled'}<input type='checkbox' name='ENABLED' $checked{'ENABLED'}{'on'} /></td>
205 <td class='base'><font color='${Header::colourred}'>$Lang::tr{'destination ip'}: </font>
207 <option value='0.0.0.0' $selected{'DEST'}{'0.0.0.0'}>DEFAULT IP</option>
211 open(ALIASES
, "$aliasfile") or die 'Unable to open aliases file.';
215 my @temp = split(/\,/,$_);
216 if ($temp[1] eq 'on') {
217 print "<option value='$temp[0]' $selected{'DEST'}{$temp[0]}>$temp[0]";
218 if (defined $temp[2] and ($temp[2] ne '')) { print " ($temp[2])"; }
230 <td width ='10%' class='base'>
231 <font class='boldbase'>$Lang::tr{'remark'}:</font> <img src='/blob.gif' alt='*' />
234 <input type='text' name='REMARK' value='$cgiparams{'REMARK'}' size='55' maxlength='50' />
236 <td width='25%' align='center'>
237 <input type='hidden' name='ACTION' value='$Lang::tr{'add'}' />
238 <input type='submit' name='SUBMIT' value='$buttontext' />
244 <td class='base' width='30%'><img src='/blob.gif' alt ='*' align='top' /> <font class='base'>$Lang::tr{'this field may be blank'}</font>
250 if ($cgiparams{'ACTION'} eq $Lang::tr
{'edit'}) {
251 print "<input type='hidden' name='EDITING' value='$cgiparams{'ID'}' />\n";
253 print "<input type='hidden' name='EDITING' value='no' />\n";
259 &Header
::openbox
('100%', 'left', $Lang::tr
{'current rules'});
263 <td width='10%' class='boldbase' align='center'><b>$Lang::tr{'proto'}</b></td>
264 <td width='20%' class='boldbase' align='center'><b>$Lang::tr{'source ip'}</b></td>
265 <td width='20%' class='boldbase' align='center'><b>$Lang::tr{'destination ip'}</b></td>
266 <td width='15%' class='boldbase' align='center'><b>$Lang::tr{'destination port'}</b></td>
267 <td width='30%' class='boldbase' align='center'><b>$Lang::tr{'remark'}</b></td>
268 <td width='5%' class='boldbase' colspan='3' align='center'><b>$Lang::tr{'action'}</b></td>
273 # If something has happened re-read config
274 if($cgiparams{'ACTION'} ne '' or $changed ne 'no')
276 open(FILE
, $filename) or die 'Unable to open config file.';
281 foreach my $line (@current)
285 my @temp = split(/\,/,$line);
290 if ($temp[0] eq 'udp') {
294 if($cgiparams{'ACTION'} eq $Lang::tr
{'edit'} && $cgiparams{'ID'} eq $id) {
295 print "<tr bgcolor='${Header::colouryellow}'>\n"; }
297 print "<tr bgcolor='$color{'color22'}'>\n"; }
299 print "<tr bgcolor='$color{'color20'}'>\n"; }
300 if ($temp[3] eq 'on') { $gif='on.gif'; $toggle='off'; $gdesc=$Lang::tr
{'click to disable'};}
301 else { $gif='off.gif'; $toggle='on'; $gdesc=$Lang::tr
{'click to enable'}; }
302 if ($temp[1] eq '0.0.0.0/0') {
303 $temp[1] = $Lang::tr
{'caps all'}; }
304 # catch for 'old-style' rules file - assume default ip if
306 if (!&General
::validip
($temp[4]) || $temp[4] eq '0.0.0.0') {
307 $temp[4] = 'DEFAULT IP'; }
308 $temp[5] = '' unless defined $temp[5];
310 <td align='center'>$protocol</td>
311 <td align='center'>$temp[1]</td>
312 <td align='center'>$temp[4]</td>
313 <td align='center'>$temp[2]</td>
314 <td align='left'> $temp[5]</td>
316 <form method='post' name='frma$id' action='$ENV{'SCRIPT_NAME'}'>
317 <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gif' title='$gdesc' alt='$gdesc' />
318 <input type='hidden' name='ID' value='$id' />
319 <input type='hidden' name='ENABLE' value='$toggle' />
320 <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}' />
324 <form method='post' name='frmb$id' action='$ENV{'SCRIPT_NAME'}'>
325 <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' title='$Lang::tr{'edit'}' alt='$Lang::tr{'edit'}' />
326 <input type='hidden' name='ID' value='$id' />
327 <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}' />
331 <form method='post' name='frmc$id' action='$ENV{'SCRIPT_NAME'}'>
332 <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' title='$Lang::tr{'remove'}' alt='$Lang::tr{'remove'}' />
333 <input type='hidden' name='ID' value='$id' />
334 <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}' />
344 # If the xt access file contains entries, print Key to action icons
345 if ( ! -z
"$filename") {
349 <td class='boldbase'> <b>$Lang::tr{'legend'}:</b></td>
350 <td> <img src='/images/on.gif' alt='$Lang::tr{'click to disable'}' /></td>
351 <td class='base'>$Lang::tr{'click to disable'}</td>
352 <td> <img src='/images/off.gif' alt='$Lang::tr{'click to enable'}' /></td>
353 <td class='base'>$Lang::tr{'click to enable'}</td>
354 <td> <img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td>
355 <td class='base'>$Lang::tr{'edit'}</td>
356 <td> <img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td>
357 <td class='base'>$Lang::tr{'remove'}</td>
366 &Header
::closebigbox
();
368 &Header
::closepage
();