]>
git.ipfire.org Git - people/pmueller/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_SERVERS'} = '';
54 $cgiparams{'REMARK'} ='';
55 $cgiparams{'DISABLE_DNSSEC'} = 'off';
56 &Header
::getcgihash
(\
%cgiparams);
57 open(FILE
, $filename) or die 'Unable to open config file.';
64 if ($cgiparams{'ACTION'} eq $Lang::tr
{'add'})
66 # Check if the entered domainname is valid.
67 unless (&General
::validdomainname
($cgiparams{'ZONE'})) {
68 $errormessage = $Lang::tr
{'invalid domain name'};
71 my @forward_servers = split(/\,/, $cgiparams{'FORWARD_SERVERS'});
72 foreach my $forward_server (@forward_servers) {
73 # Check if the settings for the forward server are valid.
74 unless(&General
::validip
($forward_server) || &General
::validfqdn
($forward_server)) {
75 $errormessage = "$Lang::tr{'invalid ip or hostname'}: $forward_server";
80 if ($cgiparams{'DISABLE_DNSSEC'} !~ /^(on|off)?$/) {
81 $errormessage = $Lang::tr
{'invalid input'};
84 # Go further if there was no error.
87 # Save servers separated by |
88 $cgiparams{'FORWARD_SERVERS'} = join("|", @forward_servers);
90 # Check if a remark has been entered.
91 $cgiparams{'REMARK'} = &Header
::cleanhtml
($cgiparams{'REMARK'});
93 # Set to off if not enabled
94 if (!$cgiparams{'DISABLE_DNSSEC'}) {
95 $cgiparams{'DISABLE_DNSSEC'} = "off";
98 # Check if we want to edit an existing or add a new entry.
99 if($cgiparams{'EDITING'} eq 'no') {
100 open(FILE
,">>$filename") or die 'Unable to open config file.';
102 print FILE
"$cgiparams{'ENABLED'},$cgiparams{'ZONE'},$cgiparams{'FORWARD_SERVERS'},$cgiparams{'REMARK'},$cgiparams{'DISABLE_DNSSEC'}\n";
104 open(FILE
, ">$filename") or die 'Unable to open config file.';
107 foreach my $line (@current)
110 if ($cgiparams{'EDITING'} eq $id) {
111 print FILE
"$cgiparams{'ENABLED'},$cgiparams{'ZONE'},$cgiparams{'FORWARD_SERVERS'},$cgiparams{'REMARK'},$cgiparams{'DISABLE_DNSSEC'}\n";
112 } else { print FILE
"$line"; }
119 # stay on edit mode if an error occur
120 if ($cgiparams{'EDITING'} ne 'no')
122 $cgiparams{'ACTION'} = $Lang::tr
{'edit'};
123 $cgiparams{'ID'} = $cgiparams{'EDITING'};
127 system('/usr/local/bin/unboundctrl restart >/dev/null');
131 # Remove existing entries.
133 if ($cgiparams{'ACTION'} eq $Lang::tr
{'remove'})
136 open(FILE
, ">$filename") or die 'Unable to open config file.';
138 foreach my $line (@current)
141 unless ($cgiparams{'ID'} eq $id) { print FILE
"$line"; }
145 system('/usr/local/bin/unboundctrl restart >/dev/null');
149 # Toggle Enable/Disable for entries.
151 if ($cgiparams{'ACTION'} eq $Lang::tr
{'toggle enable disable'})
153 open(FILE
, ">$filename") or die 'Unable to open config file.';
156 foreach my $line (@current)
159 unless ($cgiparams{'ID'} eq $id) { print FILE
"$line"; }
163 my @temp = split(/\,/,$line);
165 $temp[0] = $cgiparams{'ENABLE'};
167 print FILE
join(",", @temp) . "\n";
172 system('/usr/local/bin/unboundctrl restart >/dev/null');
176 # Read items for edit mode.
178 if ($cgiparams{'ACTION'} eq $Lang::tr
{'edit'})
181 foreach my $line (@current)
184 if ($cgiparams{'ID'} eq $id)
187 my @temp = split(/\,/,$line);
188 $cgiparams{'ENABLED'} = $temp[0];
189 $cgiparams{'ZONE'} = $temp[1];
190 $cgiparams{'FORWARD_SERVERS'} = join(",", split(/\|/, $temp[2]));
191 $cgiparams{'REMARK'} = $temp[3];
192 $cgiparams{'DISABLE_DNSSEC'} = ($temp[4] eq "on") ?
"on" : "off";
197 $checked{'ENABLED'}{'off'} = '';
198 $checked{'ENABLED'}{'on'} = '';
199 $checked{'ENABLED'}{$cgiparams{'ENABLED'}} = "checked='checked'";
201 $checked{'DISABLE_DNSSEC'}{'off'} = '';
202 $checked{'DISABLE_DNSSEC'}{'on'} = '';
203 $checked{'DISABLE_DNSSEC'}{$cgiparams{'DISABLE_DNSSEC'}} = "checked='checked'";
205 &Header
::openpage
($Lang::tr
{'dnsforward configuration'}, 1, '');
207 &Header
::openbigbox
('100%', 'left', '', $errormessage);
210 # Error messages layout.
213 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
214 print "<class name='base'>$errormessage\n";
215 print " </class>\n";
219 print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n";
221 my $buttontext = $Lang::tr
{'add'};
222 if ($cgiparams{'ACTION'} eq $Lang::tr
{'edit'}) {
223 &Header
::openbox
('100%', 'left', $Lang::tr
{'dnsforward edit an entry'});
224 $buttontext = $Lang::tr
{'update'};
226 &Header
::openbox
('100%', 'left', $Lang::tr
{'dnsforward add a new entry'});
230 # Content of the main page.
235 <td width='20%' class='base'>$Lang::tr{'dnsforward zone'}: <img src='/blob.gif' alt='*' /></td>
236 <td><input type='text' name='ZONE' value='$cgiparams{'ZONE'}' size='24' /></td>
237 <td width='30%' class='base'>$Lang::tr{'enabled'}<input type='checkbox' name='ENABLED' $checked{'ENABLED'}{'on'} /></td>
241 <td width='20%' class='base'>$Lang::tr{'dnsforward forward_servers'}: <img src='/blob.gif' alt='*' /></td>
242 <td><input type='text' name='FORWARD_SERVERS' value='$cgiparams{'FORWARD_SERVERS'}' size='24' /></td>
248 <td width ='20%' class='base'>$Lang::tr{'remark'}:</td>
249 <td><input type='text' name='REMARK' value='$cgiparams{'REMARK'}' size='40' maxlength='50' /></td>
252 <td width ='20%' class='base'>$Lang::tr{'dns forward disable dnssec'}:</td>
253 <td><input type='checkbox' name='DISABLE_DNSSEC' $checked{'DISABLE_DNSSEC'}{'on'} /></td>
261 <td class='base' width='55%'><img src='/blob.gif' alt ='*' align='top' /> $Lang::tr{'required field'}</td>
262 <td width='40%' align='right'>
263 <input type='hidden' name='ACTION' value='$Lang::tr{'add'}' />
264 <input type='submit' name='SUBMIT' value='$buttontext' />
270 if ($cgiparams{'ACTION'} eq $Lang::tr
{'edit'}) {
271 print "<input type='hidden' name='EDITING' value='$cgiparams{'ID'}' />\n";
273 print "<input type='hidden' name='EDITING' value='no' />\n";
282 &Header
::openbox
('100%', 'left', $Lang::tr
{'dnsforward entries'});
284 <table width='100%' class='tbl'>
286 <th width='35%' class='boldbase' align='center'><b>$Lang::tr{'dnsforward zone'}</b></th>
287 <th width='30%' class='boldbase' align='center'><b>$Lang::tr{'dnsforward forward_servers'}</b></th>
288 <th width='30%' class='boldbase' align='center'><b>$Lang::tr{'remark'}</b></th>
289 <th width='5%' class='boldbase' colspan='3' align='center'><b>$Lang::tr{'action'}</b></th>
294 # If something has happened re-read config
295 if($cgiparams{'ACTION'} ne '' or $changed ne 'no')
297 open(FILE
, $filename) or die 'Unable to open config file.';
303 # Re-read entries and highlight selected item for editing.
307 foreach my $line (@current)
311 my @temp = split(/\,/,$line);
318 # Format lists of servers
319 my $servers = join(", ", split(/\|/, $temp[2]));
321 my $disable_dnssec = $temp[4];
323 if($cgiparams{'ACTION'} eq $Lang::tr
{'edit'} && $cgiparams{'ID'} eq $id) {
325 $col="bgcolor='${Header::colouryellow}'"; }
326 elsif ($disable_dnssec eq 'on') {
328 $col="bgcolor='${Header::colourred}' style='color: white'"; }
331 $col="bgcolor='$color{'color22'}'"; }
334 $col="bgcolor='$color{'color20'}'"; }
336 if ($temp[0] eq 'on') { $gif='on.gif'; $toggle='off'; $gdesc=$Lang::tr
{'click to disable'};}
337 else { $gif='off.gif'; $toggle='on'; $gdesc=$Lang::tr
{'click to enable'}; }
339 if ($disable_dnssec eq "on") {
340 $notice = $Lang::tr
{'dns forwarding dnssec disabled notice'};
347 <td align='center' $col>$temp[1] $notice</td>
348 <td align='center' $col>$servers</td>
349 <td align='center' $col>$temp[3]</td>
350 <td align='center' $col>
351 <form method='post' name='frma$id' action='$ENV{'SCRIPT_NAME'}'>
352 <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gif' title='$gdesc' alt='$gdesc' />
353 <input type='hidden' name='ID' value='$id' />
354 <input type='hidden' name='ENABLE' value='$toggle' />
355 <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}' />
358 <td align='center' $col>
359 <form method='post' name='frmb$id' action='$ENV{'SCRIPT_NAME'}'>
360 <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' title='$Lang::tr{'edit'}' alt='$Lang::tr{'edit'}' />
361 <input type='hidden' name='ID' value='$id' />
362 <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}' />
365 <td align='center' $col>
366 <form method='post' name='frmc$id' action='$ENV{'SCRIPT_NAME'}'>
367 <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' title='$Lang::tr{'remove'}' alt='$Lang::tr{'remove'}' />
368 <input type='hidden' name='ID' value='$id' />
369 <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}' />
379 # Print the legend at the bottom if there are any configured entries.
381 # Check if the file size is zero - no existing entries.
382 if ( ! -z
"$filename") {
386 <td class='boldbase'> <b>$Lang::tr{'legend'}:</b></td>
387 <td> <img src='/images/on.gif' alt='$Lang::tr{'click to disable'}' /></td>
388 <td class='base'>$Lang::tr{'click to disable'}</td>
389 <td> <img src='/images/off.gif' alt='$Lang::tr{'click to enable'}' /></td>
390 <td class='base'>$Lang::tr{'click to enable'}</td>
391 <td> <img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td>
392 <td class='base'>$Lang::tr{'edit'}</td>
393 <td> <img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td>
394 <td class='base'>$Lang::tr{'remove'}</td>
395 <td> <span style="background-color: $Header::colourred"> </span></td>
396 <td class='base'>$Lang::tr{'dnsforward dnssec disabled'}</td>
405 &Header
::closebigbox
();
407 &Header
::closepage
();