]>
git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - html/cgi-bin/dnsforward.cgi
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2013 IPFire Development 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 ###############################################################################
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
::colouryellow
} );
39 my $errormessage = '';
40 my $filename = "${General::swroot}/dnsforward/config";
44 my %mainsettings = ();
45 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
46 &General
::readhash
("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \
%color);
48 &Header
::showhttpheaders
();
50 $cgiparams{'ENABLED'} = 'off';
51 $cgiparams{'ACTION'} = '';
52 $cgiparams{'ZONE'} = '';
53 $cgiparams{'FORWARD_SERVER'} = '';
54 $cgiparams{'REMARK'} ='';
55 &Header
::getcgihash
(\
%cgiparams);
56 open(FILE
, $filename) or die 'Unable to open config file.';
63 if ($cgiparams{'ACTION'} eq $Lang::tr
{'add'})
65 # Check if the entered domainname is valid.
66 unless (&General
::validdomainname
($cgiparams{'ZONE'})) {
67 $errormessage = $Lang::tr
{'invalid domain name'};
70 # Check if the settings for the forward server are valid.
71 unless(&General
::validip
($cgiparams{'FORWARD_SERVER'})) {
72 $errormessage = $Lang::tr
{'invalid ip'};
75 # Go further if there was no error.
78 # Check if a remark has been entered.
79 $cgiparams{'REMARK'} = &Header
::cleanhtml
($cgiparams{'REMARK'});
81 # Check if we want to edit an existing or add a new entry.
82 if($cgiparams{'EDITING'} eq 'no') {
83 open(FILE
,">>$filename") or die 'Unable to open config file.';
85 print FILE
"$cgiparams{'ENABLED'},$cgiparams{'ZONE'},$cgiparams{'FORWARD_SERVER'},$cgiparams{'REMARK'}\n";
87 open(FILE
, ">$filename") or die 'Unable to open config file.';
90 foreach my $line (@current)
93 if ($cgiparams{'EDITING'} eq $id) {
94 print FILE
"$cgiparams{'ENABLED'},$cgiparams{'ZONE'},$cgiparams{'FORWARD_SERVER'},$cgiparams{'REMARK'}\n";
95 } else { print FILE
"$line"; }
102 # stay on edit mode if an error occur
103 if ($cgiparams{'EDITING'} ne 'no')
105 $cgiparams{'ACTION'} = $Lang::tr
{'edit'};
106 $cgiparams{'ID'} = $cgiparams{'EDITING'};
110 system('/usr/local/bin/dnsmasqctrl restart >/dev/null');
114 # Remove existing entries.
116 if ($cgiparams{'ACTION'} eq $Lang::tr
{'remove'})
119 open(FILE
, ">$filename") or die 'Unable to open config file.';
121 foreach my $line (@current)
124 unless ($cgiparams{'ID'} eq $id) { print FILE
"$line"; }
128 system('/usr/local/bin/dnsmasqctrl restart >/dev/null');
132 # Toggle Enable/Disable for entries.
134 if ($cgiparams{'ACTION'} eq $Lang::tr
{'toggle enable disable'})
136 open(FILE
, ">$filename") or die 'Unable to open config file.';
139 foreach my $line (@current)
142 unless ($cgiparams{'ID'} eq $id) { print FILE
"$line"; }
146 my @temp = split(/\,/,$line);
147 print FILE
"$cgiparams{'ENABLE'},$temp[1],$temp[2],$temp[3]\n";
152 system('/usr/local/bin/dnsmasqctrl restart >/dev/null');
156 # Read items for edit mode.
158 if ($cgiparams{'ACTION'} eq $Lang::tr
{'edit'})
161 foreach my $line (@current)
164 if ($cgiparams{'ID'} eq $id)
167 my @temp = split(/\,/,$line);
168 $cgiparams{'ENABLED'} = $temp[0];
169 $cgiparams{'ZONE'} = $temp[1];
170 $cgiparams{'FORWARD_SERVER'} = $temp[2];
171 $cgiparams{'REMARK'} = $temp[3];
176 $checked{'ENABLED'}{'off'} = '';
177 $checked{'ENABLED'}{'on'} = '';
178 $checked{'ENABLED'}{$cgiparams{'ENABLED'}} = "checked='checked'";
180 &Header
::openpage
($Lang::tr
{'dnsforward configuration'}, 1, '');
182 &Header
::openbigbox
('100%', 'left', '', $errormessage);
185 # Error messages layout.
188 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
189 print "<class name='base'>$errormessage\n";
190 print " </class>\n";
194 print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n";
196 my $buttontext = $Lang::tr
{'add'};
197 if ($cgiparams{'ACTION'} eq $Lang::tr
{'edit'}) {
198 &Header
::openbox
('100%', 'left', $Lang::tr
{'dnsforward edit an entry'});
199 $buttontext = $Lang::tr
{'update'};
201 &Header
::openbox
('100%', 'left', $Lang::tr
{'dnsforward add a new entry'});
205 # Content of the main page.
210 <td width='20%' class='base'><font>$Lang::tr{'dnsforward zone'}:</font></td>
211 <td><input type='text' name='ZONE' value='$cgiparams{'ZONE'}' size='24' /></td>
212 <td width='30%' class='base'>$Lang::tr{'enabled'}<input type='checkbox' name='ENABLED' $checked{'ENABLED'}{'on'} /></td>
216 <td width='20%' class='base'><font>$Lang::tr{'dnsforward forward_server'}:</font></td>
217 <td><input type='text' name='FORWARD_SERVER' value='$cgiparams{'FORWARD_SERVER'}' size='24' /></td>
223 <td width ='20%' class='base'><font class='boldbase'>$Lang::tr{'remark'}:</font> <img src='/blob.gif' alt='*' /></td>
224 <td><input type='text' name='REMARK' value='$cgiparams{'REMARK'}' size='40' maxlength='50' /></td>
232 <td class='base' width='55%'><img src='/blob.gif' alt ='*' align='top' /> <font class='base'>$Lang::tr{'this field may be blank'}</font></td>
233 <td width='40%' align='center'>
234 <input type='hidden' name='ACTION' value='$Lang::tr{'add'}' />
235 <input type='submit' name='SUBMIT' value='$buttontext' />
241 if ($cgiparams{'ACTION'} eq $Lang::tr
{'edit'}) {
242 print "<input type='hidden' name='EDITING' value='$cgiparams{'ID'}' />\n";
244 print "<input type='hidden' name='EDITING' value='no' />\n";
253 &Header
::openbox
('100%', 'left', $Lang::tr
{'dnsforward entries'});
257 <td width='35%' class='boldbase' align='center'><b>$Lang::tr{'dnsforward zone'}</b></td>
258 <td width='30%' class='boldbase' align='center'><b>$Lang::tr{'dnsforward forward_server'}</b></td>
259 <td width='30%' class='boldbase' align='center'><b>$Lang::tr{'remark'}</b></td>
260 <td width='5%' class='boldbase' colspan='3' align='center'><b>$Lang::tr{'action'}</b></td>
265 # If something has happened re-read config
266 if($cgiparams{'ACTION'} ne '' or $changed ne 'no')
268 open(FILE
, $filename) or die 'Unable to open config file.';
274 # Re-read entries and highlight selected item for editing.
277 foreach my $line (@current)
281 my @temp = split(/\,/,$line);
287 if($cgiparams{'ACTION'} eq $Lang::tr
{'edit'} && $cgiparams{'ID'} eq $id) {
288 print "<tr bgcolor='${Header::colouryellow}'>\n"; }
290 print "<tr bgcolor='$color{'color22'}'>\n"; }
292 print "<tr bgcolor='$color{'color20'}'>\n"; }
294 if ($temp[0] eq 'on') { $gif='on.gif'; $toggle='off'; $gdesc=$Lang::tr
{'click to disable'};}
295 else { $gif='off.gif'; $toggle='on'; $gdesc=$Lang::tr
{'click to enable'}; }
301 <td align='center'>$temp[1]</td>
302 <td align='center'>$temp[2]</td>
303 <td align='center'>$temp[3]</td>
305 <form method='post' name='frma$id' action='$ENV{'SCRIPT_NAME'}'>
306 <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gif' title='$gdesc' alt='$gdesc' />
307 <input type='hidden' name='ID' value='$id' />
308 <input type='hidden' name='ENABLE' value='$toggle' />
309 <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}' />
313 <form method='post' name='frmb$id' action='$ENV{'SCRIPT_NAME'}'>
314 <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' title='$Lang::tr{'edit'}' alt='$Lang::tr{'edit'}' />
315 <input type='hidden' name='ID' value='$id' />
316 <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}' />
320 <form method='post' name='frmc$id' action='$ENV{'SCRIPT_NAME'}'>
321 <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' title='$Lang::tr{'remove'}' alt='$Lang::tr{'remove'}' />
322 <input type='hidden' name='ID' value='$id' />
323 <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}' />
333 # Print the legend at the bottom if there are any configured entries.
335 # Check if the file size is zero - no existing entries.
336 if ( ! -z
"$filename") {
340 <td class='boldbase'> <b>$Lang::tr{'legend'}:</b></td>
341 <td> <img src='/images/on.gif' alt='$Lang::tr{'click to disable'}' /></td>
342 <td class='base'>$Lang::tr{'click to disable'}</td>
343 <td> <img src='/images/off.gif' alt='$Lang::tr{'click to enable'}' /></td>
344 <td class='base'>$Lang::tr{'click to enable'}</td>
345 <td> <img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td>
346 <td class='base'>$Lang::tr{'edit'}</td>
347 <td> <img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td>
348 <td class='base'>$Lang::tr{'remove'}</td>
357 &Header
::closebigbox
();
359 &Header
::closepage
();