]>
git.ipfire.org Git - people/teissler/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 'CONFIG_ROOT/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";
35 &Header
::showhttpheaders
();
37 $cgiparams{'ENABLED'} = 'off';
38 $cgiparams{'ACTION'} = '';
39 $cgiparams{'SRC'} = '';
40 $cgiparams{'DEST_PORT'} = '';
41 $cgiparams{'REMARK'} ='';
42 &Header
::getcgihash
(\
%cgiparams);
43 open(FILE
, $filename) or die 'Unable to open config file.';
47 if ($cgiparams{'ACTION'} eq $Lang::tr
{'add'})
49 unless($cgiparams{'PROTOCOL'} =~ /^(tcp|udp)$/) { $errormessage = $Lang::tr
{'invalid input'}; }
50 unless(&General
::validipormask
($cgiparams{'SRC'}))
52 if ($cgiparams{'SRC'} ne '') {
53 $errormessage = $Lang::tr
{'source ip bad'}; }
55 $cgiparams{'SRC'} = '0.0.0.0/0'; }
57 unless($errormessage){ $errormessage = &General
::validportrange
($cgiparams{'DEST_PORT'},'dst'); }
60 $cgiparams{'REMARK'} = &Header
::cleanhtml
($cgiparams{'REMARK'});
62 if($cgiparams{'EDITING'} eq 'no') {
63 open(FILE
,">>$filename") or die 'Unable to open config file.';
65 print FILE
"$cgiparams{'PROTOCOL'},$cgiparams{'SRC'},$cgiparams{'DEST_PORT'},$cgiparams{'ENABLED'},$cgiparams{'DEST'},$cgiparams{'REMARK'}\n";
67 open(FILE
, ">$filename") or die 'Unable to open config file.';
70 foreach my $line (@current)
73 if ($cgiparams{'EDITING'} eq $id) {
74 print FILE
"$cgiparams{'PROTOCOL'},$cgiparams{'SRC'},$cgiparams{'DEST_PORT'},$cgiparams{'ENABLED'},$cgiparams{'DEST'},$cgiparams{'REMARK'}\n";
75 } else { print FILE
"$line"; }
81 &General
::log($Lang::tr
{'external access rule added'});
82 system('/usr/local/bin/setxtaccess');
84 # stay on edit mode if an error occur
85 if ($cgiparams{'EDITING'} ne 'no')
87 $cgiparams{'ACTION'} = $Lang::tr
{'edit'};
88 $cgiparams{'ID'} = $cgiparams{'EDITING'};
92 if ($cgiparams{'ACTION'} eq $Lang::tr
{'remove'})
95 open(FILE
, ">$filename") or die 'Unable to open config file.';
97 foreach my $line (@current)
100 unless ($cgiparams{'ID'} eq $id) { print FILE
"$line"; }
103 system('/usr/local/bin/setxtaccess');
104 &General
::log($Lang::tr
{'external access rule removed'});
106 if ($cgiparams{'ACTION'} eq $Lang::tr
{'toggle enable disable'})
108 open(FILE
, ">$filename") or die 'Unable to open config file.';
111 foreach my $line (@current)
114 unless ($cgiparams{'ID'} eq $id) { print FILE
"$line"; }
118 my @temp = split(/\,/,$line);
119 print FILE
"$temp[0],$temp[1],$temp[2],$cgiparams{'ENABLE'},$temp[4],$temp[5]\n";
123 system('/usr/local/bin/setxtaccess');
125 if ($cgiparams{'ACTION'} eq $Lang::tr
{'edit'})
128 foreach my $line (@current)
131 if ($cgiparams{'ID'} eq $id)
134 my @temp = split(/\,/,$line);
135 $cgiparams{'PROTOCOL'} = $temp[0];
136 $cgiparams{'SRC'} = $temp[1];
137 $cgiparams{'DEST_PORT'} = $temp[2];
138 $cgiparams{'ENABLED'} = $temp[3];
139 $cgiparams{'DEST'} = $temp[4];
140 $cgiparams{'REMARK'} = $temp[5];
145 if ($cgiparams{'ACTION'} eq '')
147 $cgiparams{'PROTOCOL'} = 'tcp';
148 $cgiparams{'DEST'} = '0.0.0.0';
149 $cgiparams{'ENABLED'} = 'on';
152 $selected{'PROTOCOL'}{'udp'} = '';
153 $selected{'PROTOCOL'}{'tcp'} = '';
154 $selected{'PROTOCOL'}{$cgiparams{'PROTOCOL'}} = "selected='selected'";
156 $selected{'DEST'}{$cgiparams{'DEST'}} = "selected='selected'";
158 $checked{'ENABLED'}{'off'} = '';
159 $checked{'ENABLED'}{'on'} = '';
160 $checked{'ENABLED'}{$cgiparams{'ENABLED'}} = "checked='checked'";
162 &Header
::openpage
($Lang::tr
{'external access configuration'}, 1, '');
164 &Header
::openbigbox
('100%', 'left', '', $errormessage);
167 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
168 print "<class name='base'>$errormessage\n";
169 print " </class>\n";
173 print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n";
175 my $buttontext = $Lang::tr
{'add'};
176 if ($cgiparams{'ACTION'} eq $Lang::tr
{'edit'}) {
177 &Header
::openbox
('100%', 'left', $Lang::tr
{'edit a rule'});
178 $buttontext = $Lang::tr
{'update'};
180 &Header
::openbox
('100%', 'left', $Lang::tr
{'add a new rule'});
186 <select name='PROTOCOL'>
187 <option value='udp' $selected{'PROTOCOL'}{'udp'}>UDP</option>
188 <option value='tcp' $selected{'PROTOCOL'}{'tcp'}>TCP</option>
191 <td class='base'><font color='${Header::colourred}'>$Lang::tr{'source network'}</font></td>
192 <td><input type='text' name='SRC' value='$cgiparams{'SRC'}' size='32' /></td>
193 <td class='base'><font color='${Header::colourred}'>$Lang::tr{'destination port'}:</font></td>
194 <td><input type='text' name='DEST_PORT' value='$cgiparams{'DEST_PORT'}' size='5' /></td>
199 <td width='10%' class='base'>$Lang::tr{'enabled'}<input type='checkbox' name='ENABLED' $checked{'ENABLED'}{'on'} /></td>
200 <td class='base'><font color='${Header::colourred}'>$Lang::tr{'destination ip'}: </font>
202 <option value='0.0.0.0' $selected{'DEST'}{'0.0.0.0'}>DEFAULT IP</option>
206 open(ALIASES
, "$aliasfile") or die 'Unable to open aliases file.';
210 my @temp = split(/\,/,$_);
211 if ($temp[1] eq 'on') {
212 print "<option value='$temp[0]' $selected{'DEST'}{$temp[0]}>$temp[0]";
213 if (defined $temp[2] and ($temp[2] ne '')) { print " ($temp[2])"; }
225 <td width ='10%' class='base'>
226 <font class='boldbase'>$Lang::tr{'remark'}:</font> <img src='/blob.gif' alt='*' />
229 <input type='text' name='REMARK' value='$cgiparams{'REMARK'}' size='55' maxlength='50' />
231 <td width='25%' align='center'>
232 <input type='hidden' name='ACTION' value='$Lang::tr{'add'}' />
233 <input type='submit' name='SUBMIT' value='$buttontext' />
239 <td class='base' width='30%'><img src='/blob.gif' alt ='*' align='top' /> <font class='base'>$Lang::tr{'this field may be blank'}</font>
245 if ($cgiparams{'ACTION'} eq $Lang::tr
{'edit'}) {
246 print "<input type='hidden' name='EDITING' value='$cgiparams{'ID'}' />\n";
248 print "<input type='hidden' name='EDITING' value='no' />\n";
254 &Header
::openbox
('100%', 'left', $Lang::tr
{'current rules'});
258 <td width='10%' class='boldbase' align='center'><b>$Lang::tr{'proto'}</b></td>
259 <td width='20%' class='boldbase' align='center'><b>$Lang::tr{'source ip'}</b></td>
260 <td width='20%' class='boldbase' align='center'><b>$Lang::tr{'destination ip'}</b></td>
261 <td width='15%' class='boldbase' align='center'><b>$Lang::tr{'destination port'}</b></td>
262 <td width='30%' class='boldbase' align='center'><b>$Lang::tr{'remark'}</b></td>
263 <td width='5%' class='boldbase' colspan='3' align='center'><b>$Lang::tr{'action'}</b></td>
268 # If something has happened re-read config
269 if($cgiparams{'ACTION'} ne '' or $changed ne 'no')
271 open(FILE
, $filename) or die 'Unable to open config file.';
276 foreach my $line (@current)
280 my @temp = split(/\,/,$line);
285 if ($temp[0] eq 'udp') {
289 if($cgiparams{'ACTION'} eq $Lang::tr
{'edit'} && $cgiparams{'ID'} eq $id) {
290 print "<tr bgcolor='${Header::colouryellow}'>\n"; }
292 print "<tr bgcolor='${Header::table1colour}'>\n"; }
294 print "<tr bgcolor='${Header::table2colour}'>\n"; }
295 if ($temp[3] eq 'on') { $gif='on.gif'; $toggle='off'; $gdesc=$Lang::tr
{'click to disable'};}
296 else { $gif='off.gif'; $toggle='on'; $gdesc=$Lang::tr
{'click to enable'}; }
297 if ($temp[1] eq '0.0.0.0/0') {
298 $temp[1] = $Lang::tr
{'caps all'}; }
299 # catch for 'old-style' rules file - assume default ip if
301 if (!&General
::validip
($temp[4]) || $temp[4] eq '0.0.0.0') {
302 $temp[4] = 'DEFAULT IP'; }
303 $temp[5] = '' unless defined $temp[5];
305 <td align='center'>$protocol</td>
306 <td align='center'>$temp[1]</td>
307 <td align='center'>$temp[4]</td>
308 <td align='center'>$temp[2]</td>
309 <td align='left'> $temp[5]</td>
311 <form method='post' name='frma$id' action='$ENV{'SCRIPT_NAME'}'>
312 <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gif' title='$gdesc' alt='$gdesc' />
313 <input type='hidden' name='ID' value='$id' />
314 <input type='hidden' name='ENABLE' value='$toggle' />
315 <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}' />
319 <form method='post' name='frmb$id' action='$ENV{'SCRIPT_NAME'}'>
320 <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' title='$Lang::tr{'edit'}' alt='$Lang::tr{'edit'}' />
321 <input type='hidden' name='ID' value='$id' />
322 <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}' />
326 <form method='post' name='frmc$id' action='$ENV{'SCRIPT_NAME'}'>
327 <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' title='$Lang::tr{'remove'}' alt='$Lang::tr{'remove'}' />
328 <input type='hidden' name='ID' value='$id' />
329 <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}' />
339 # If the xt access file contains entries, print Key to action icons
340 if ( ! -z
"$filename") {
344 <td class='boldbase'> <b>$Lang::tr{'legend'}:</b></td>
345 <td> <img src='/images/on.gif' alt='$Lang::tr{'click to disable'}' /></td>
346 <td class='base'>$Lang::tr{'click to disable'}</td>
347 <td> <img src='/images/off.gif' alt='$Lang::tr{'click to enable'}' /></td>
348 <td class='base'>$Lang::tr{'click to enable'}</td>
349 <td> <img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td>
350 <td class='base'>$Lang::tr{'edit'}</td>
351 <td> <img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td>
352 <td class='base'>$Lang::tr{'remove'}</td>
361 &Header
::closebigbox
();
363 &Header
::closepage
();