Change that iptv-mac field could also empty for save
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / dns.cgi
CommitLineData
e0639d80
JPT
1#!/usr/bin/perl
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2007 Michael Tremer & Christian Schmidt #
6# #
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. #
11# #
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. #
16# #
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/>. #
19# #
20###############################################################################
21
22use strict;
23
24# enable only the following on debugging purpose
25#use warnings;
26#use CGI::Carp 'fatalsToBrowser';
27
28require '/var/ipfire/general-functions.pl';
29require "${General::swroot}/lang.pl";
30require "${General::swroot}/header.pl";
31
32my %dnssettings=();
33my $errormessage = '';
34
35&Header::showhttpheaders();
36
37&General::readhash("${General::swroot}/dns/settings", \%dnssettings);
38
39&Header::getcgihash(\%dnssettings);
40
41&Header::openpage($Lang::tr{'dns title'}, 1, );
42
43&Header::openbigbox('100%', 'left', '', $errormessage);
44
45if ($dnssettings{'ACTION'} eq $Lang::tr{'save'}) {
46 if ((&General::validip($dnssettings{"DNS0"}) == 1)&&(&General::validip($dnssettings{"DNS1"}) == 1)) {
47 if ($errormessage eq "") {
48 &General::writehash("${General::swroot}/dns/settings", \%dnssettings);
49 &Header::openbox('100%', 'left', $Lang::tr{'dns saved'});
50 print "<font class='base'>$Lang::tr{'dns saved txt'}</font>\n";
51 &Header::closebox();
52 }
53 } else {
54 if ((&General::validip($dnssettings{"DNS0"}) == 0)&&(&General::validip($dnssettings{"DNS1"}) == 1)){
55 $errormessage = $Lang::tr{'dns error 0'};
56 }
57 if ((&General::validip($dnssettings{"DNS1"}) == 0)&&(&General::validip($dnssettings{"DNS0"}) == 1)){
58 $errormessage = $Lang::tr{'dns error 1'};
59 }
60 if ((&General::validip($dnssettings{"DNS1"}) == 0)&&(&General::validip($dnssettings{"DNS0"}) == 0)){
61 $errormessage = $Lang::tr{'dns error 01'};
62 }
63 }
64}
65
830f6177 66if ($dnssettings{'ACTION'} eq $Lang::tr{'reconnect'}) {
e0639d80
JPT
67 system("/usr/local/bin/redctrl restart >/dev/null 2>&1 &");
68 &Header::openbox('100%', 'left', $Lang::tr{'dns address recon'} );
69 print "<font class='base'>$Lang::tr{'dns address done'}</font>\n";
70 &Header::closebox();
71}
72
830f6177 73if ($dnssettings{'ACTION'} eq $Lang::tr{'delete'}) {
2e1432c4
JPT
74 system("cat /dev/null > ${General::swroot}/dns/settings &");
75 &Header::openbox('100%', 'left', $Lang::tr{'dns address deleted'} );
76 print "<font class='base'>$Lang::tr{'dns address deleted txt'}</font>\n";
77 &Header::closebox();
78}
79
e0639d80
JPT
80# DPC move error message to top so it is seen!
81if ($errormessage) {
82 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
83 print "<font class='base'>$errormessage&nbsp;</font>\n";
84 &Header::closebox();
85}
86
87print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n";
88
89&Header::openbox('100%', 'left', $Lang::tr{'dns header'});
90print <<END
91
92<table border="0" width='100%'>
93 <tr>
94 <td colspan="2"><font class='base'>$Lang::tr{'dns desc'}<br /><img src="/images/dns_link.png" border="0" align="absmiddle"/><a href="http://wiki.ipfire.org/$Lang::tr{'lang'}/configuration/dns_list" target="_blank">$Lang::tr{'dns list'}</a></font></td>
95 </tr>
96 <tr>
97 <td colspan="2">&nbsp;</td>
98 </tr>
99 <tr>
100 <td width="25%"><font class='base'>$Lang::tr{'dns new 0'}</font></td>
830f6177
JPT
101END
102;
103if ($dnssettings{'ACTION'} eq $Lang::tr{'delete'}) {
104print <<END
105 <td width="75%"><input type="text" name="DNS0" maxlength="15" value=""/></td>
106END
107;
108} else {
109print <<END
e0639d80 110 <td width="75%"><input type="text" name="DNS0" maxlength="15" value="$dnssettings{"DNS0"}"/></td>
830f6177
JPT
111END
112;
113}
114print <<END
e0639d80
JPT
115 </tr>
116 <tr>
117 <td><font class='base'>$Lang::tr{'dns new 1'}</font></td>
830f6177
JPT
118END
119;
120if ($dnssettings{'ACTION'} eq $Lang::tr{'delete'}) {
121print <<END
122 <td><input type="text" name="DNS1" maxlength="15" value=""/></td>
123END
124;
125} else {
126print <<END
e0639d80 127 <td><input type="text" name="DNS1" maxlength="15" value="$dnssettings{"DNS1"}"/></td>
830f6177
JPT
128END
129;
130}
131print <<END
e0639d80
JPT
132 </tr>
133 <tr>
134 <td colspan="2"><hr /></td>
135 </tr>
136 <tr>
137 <td colspan="2"><div align="center">
830f6177
JPT
138END
139;
140if ($dnssettings{'ACTION'} eq $Lang::tr{'save'} && $errormessage eq "") {
141print <<END
142 <input type='submit' name='ACTION' value='$Lang::tr{'save'}' />
143 &nbsp;&nbsp;&nbsp;&nbsp;
144 <input type='submit' name='ACTION' value='$Lang::tr{'delete'}' />
145 &nbsp;&nbsp;&nbsp;&nbsp;
146 <input type='submit' name='ACTION' value='$Lang::tr{'reconnect'}' />
147END
148;
149} elsif ($dnssettings{'ACTION'} eq $Lang::tr{'delete'}) {
150print <<END
e0639d80
JPT
151 <input type='submit' name='ACTION' value='$Lang::tr{'save'}' />
152 &nbsp;&nbsp;&nbsp;&nbsp;
830f6177
JPT
153 <input type='submit' name='ACTION' value='$Lang::tr{'reconnect'}' />
154END
155;
156} elsif ($dnssettings{'ACTION'} eq $Lang::tr{'save'}) {
157print <<END
158 <input type='submit' name='ACTION' value='$Lang::tr{'save'}' />
159END
160;
161} else {
162print <<END
163 <input type='submit' name='ACTION' value='$Lang::tr{'save'}' />
2e1432c4 164 &nbsp;&nbsp;&nbsp;&nbsp;
830f6177
JPT
165 <input type='submit' name='ACTION' value='$Lang::tr{'delete'}' />
166END
167;
168}
169print <<END
e0639d80
JPT
170 </div>
171 </td>
172 </tr>
173</table>
174
175END
176;
177
178&Header::closebox();
179
180print "</form>\n";
181
182&Header::closebigbox();
183
184&Header::closepage();
185