]>
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 &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 my @forward_servers = split(/\,/, $cgiparams{'FORWARD_SERVERS'});
71 foreach my $forward_server (@forward_servers) {
72 # Check if the settings for the forward server are valid.
73 unless(&General
::validip
($forward_server)) {
74 $errormessage = "$Lang::tr{'invalid ip'}: $forward_server";
79 # Go further if there was no error.
82 # Save servers separated by |
83 $cgiparams{'FORWARD_SERVERS'} = join("|", @forward_servers);
85 # Check if a remark has been entered.
86 $cgiparams{'REMARK'} = &Header
::cleanhtml
($cgiparams{'REMARK'});
88 # Check if we want to edit an existing or add a new entry.
89 if($cgiparams{'EDITING'} eq 'no') {
90 open(FILE
,">>$filename") or die 'Unable to open config file.';
92 print FILE
"$cgiparams{'ENABLED'},$cgiparams{'ZONE'},$cgiparams{'FORWARD_SERVERS'},$cgiparams{'REMARK'}\n";
94 open(FILE
, ">$filename") or die 'Unable to open config file.';
97 foreach my $line (@current)
100 if ($cgiparams{'EDITING'} eq $id) {
101 print FILE
"$cgiparams{'ENABLED'},$cgiparams{'ZONE'},$cgiparams{'FORWARD_SERVERS'},$cgiparams{'REMARK'}\n";
102 } else { print FILE
"$line"; }
109 # stay on edit mode if an error occur
110 if ($cgiparams{'EDITING'} ne 'no')
112 $cgiparams{'ACTION'} = $Lang::tr
{'edit'};
113 $cgiparams{'ID'} = $cgiparams{'EDITING'};
117 system('/usr/local/bin/unboundctrl restart >/dev/null');
121 # Remove existing entries.
123 if ($cgiparams{'ACTION'} eq $Lang::tr
{'remove'})
126 open(FILE
, ">$filename") or die 'Unable to open config file.';
128 foreach my $line (@current)
131 unless ($cgiparams{'ID'} eq $id) { print FILE
"$line"; }
135 system('/usr/local/bin/unboundctrl restart >/dev/null');
139 # Toggle Enable/Disable for entries.
141 if ($cgiparams{'ACTION'} eq $Lang::tr
{'toggle enable disable'})
143 open(FILE
, ">$filename") or die 'Unable to open config file.';
146 foreach my $line (@current)
149 unless ($cgiparams{'ID'} eq $id) { print FILE
"$line"; }
153 my @temp = split(/\,/,$line);
154 print FILE
"$cgiparams{'ENABLE'},$temp[1],$temp[2],$temp[3]\n";
159 system('/usr/local/bin/unboundctrl restart >/dev/null');
163 # Read items for edit mode.
165 if ($cgiparams{'ACTION'} eq $Lang::tr
{'edit'})
168 foreach my $line (@current)
171 if ($cgiparams{'ID'} eq $id)
174 my @temp = split(/\,/,$line);
175 $cgiparams{'ENABLED'} = $temp[0];
176 $cgiparams{'ZONE'} = $temp[1];
177 $cgiparams{'FORWARD_SERVERS'} = join(",", split(/\|/, $temp[2]));
178 $cgiparams{'REMARK'} = $temp[3];
183 $checked{'ENABLED'}{'off'} = '';
184 $checked{'ENABLED'}{'on'} = '';
185 $checked{'ENABLED'}{$cgiparams{'ENABLED'}} = "checked='checked'";
187 &Header
::openpage
($Lang::tr
{'dnsforward configuration'}, 1, '');
189 &Header
::openbigbox
('100%', 'left', '', $errormessage);
192 # Error messages layout.
195 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
196 print "<class name='base'>$errormessage\n";
197 print " </class>\n";
201 print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n";
203 my $buttontext = $Lang::tr
{'add'};
204 if ($cgiparams{'ACTION'} eq $Lang::tr
{'edit'}) {
205 &Header
::openbox
('100%', 'left', $Lang::tr
{'dnsforward edit an entry'});
206 $buttontext = $Lang::tr
{'update'};
208 &Header
::openbox
('100%', 'left', $Lang::tr
{'dnsforward add a new entry'});
212 # Content of the main page.
217 <td width='20%' class='base'>$Lang::tr{'dnsforward zone'}: <img src='/blob.gif' alt='*' /></td>
218 <td><input type='text' name='ZONE' value='$cgiparams{'ZONE'}' size='24' /></td>
219 <td width='30%' class='base'>$Lang::tr{'enabled'}<input type='checkbox' name='ENABLED' $checked{'ENABLED'}{'on'} /></td>
223 <td width='20%' class='base'>$Lang::tr{'dnsforward forward_server'}: <img src='/blob.gif' alt='*' /></td>
224 <td><input type='text' name='FORWARD_SERVERS' value='$cgiparams{'FORWARD_SERVERS'}' size='24' /></td>
230 <td width ='20%' class='base'>$Lang::tr{'remark'}:</td>
231 <td><input type='text' name='REMARK' value='$cgiparams{'REMARK'}' size='40' maxlength='50' /></td>
239 <td class='base' width='55%'><img src='/blob.gif' alt ='*' align='top' /> $Lang::tr{'required field'}</td>
240 <td width='40%' align='right'>
241 <input type='hidden' name='ACTION' value='$Lang::tr{'add'}' />
242 <input type='submit' name='SUBMIT' value='$buttontext' />
248 if ($cgiparams{'ACTION'} eq $Lang::tr
{'edit'}) {
249 print "<input type='hidden' name='EDITING' value='$cgiparams{'ID'}' />\n";
251 print "<input type='hidden' name='EDITING' value='no' />\n";
260 &Header
::openbox
('100%', 'left', $Lang::tr
{'dnsforward entries'});
262 <table width='100%' class='tbl'>
264 <th width='35%' class='boldbase' align='center'><b>$Lang::tr{'dnsforward zone'}</b></th>
265 <th width='30%' class='boldbase' align='center'><b>$Lang::tr{'dnsforward forward_servers'}</b></th>
266 <th width='30%' class='boldbase' align='center'><b>$Lang::tr{'remark'}</b></th>
267 <th width='5%' class='boldbase' colspan='3' align='center'><b>$Lang::tr{'action'}</b></th>
272 # If something has happened re-read config
273 if($cgiparams{'ACTION'} ne '' or $changed ne 'no')
275 open(FILE
, $filename) or die 'Unable to open config file.';
281 # Re-read entries and highlight selected item for editing.
285 foreach my $line (@current)
289 my @temp = split(/\,/,$line);
295 # Format lists of servers
296 my $servers = join(", ", split(/\|/, $temp[2]));
298 if($cgiparams{'ACTION'} eq $Lang::tr
{'edit'} && $cgiparams{'ID'} eq $id) {
300 $col="bgcolor='${Header::colouryellow}'"; }
303 $col="bgcolor='$color{'color22'}'"; }
306 $col="bgcolor='$color{'color20'}'"; }
308 if ($temp[0] eq 'on') { $gif='on.gif'; $toggle='off'; $gdesc=$Lang::tr
{'click to disable'};}
309 else { $gif='off.gif'; $toggle='on'; $gdesc=$Lang::tr
{'click to enable'}; }
315 <td align='center' $col>$temp[1]</td>
316 <td align='center' $col>$servers</td>
317 <td align='center' $col>$temp[3]</td>
318 <td align='center' $col>
319 <form method='post' name='frma$id' action='$ENV{'SCRIPT_NAME'}'>
320 <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gif' title='$gdesc' alt='$gdesc' />
321 <input type='hidden' name='ID' value='$id' />
322 <input type='hidden' name='ENABLE' value='$toggle' />
323 <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}' />
326 <td align='center' $col>
327 <form method='post' name='frmb$id' action='$ENV{'SCRIPT_NAME'}'>
328 <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' title='$Lang::tr{'edit'}' alt='$Lang::tr{'edit'}' />
329 <input type='hidden' name='ID' value='$id' />
330 <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}' />
333 <td align='center' $col>
334 <form method='post' name='frmc$id' action='$ENV{'SCRIPT_NAME'}'>
335 <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' title='$Lang::tr{'remove'}' alt='$Lang::tr{'remove'}' />
336 <input type='hidden' name='ID' value='$id' />
337 <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}' />
347 # Print the legend at the bottom if there are any configured entries.
349 # Check if the file size is zero - no existing entries.
350 if ( ! -z
"$filename") {
354 <td class='boldbase'> <b>$Lang::tr{'legend'}:</b></td>
355 <td> <img src='/images/on.gif' alt='$Lang::tr{'click to disable'}' /></td>
356 <td class='base'>$Lang::tr{'click to disable'}</td>
357 <td> <img src='/images/off.gif' alt='$Lang::tr{'click to enable'}' /></td>
358 <td class='base'>$Lang::tr{'click to enable'}</td>
359 <td> <img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td>
360 <td class='base'>$Lang::tr{'edit'}</td>
361 <td> <img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td>
362 <td class='base'>$Lang::tr{'remove'}</td>
371 &Header
::closebigbox
();
373 &Header
::closepage
();