1
|
<?php
|
2
|
/* $Id$ */
|
3
|
/*
|
4
|
services_dnsmasq.php
|
5
|
part of m0n0wall (http://m0n0.ch/wall)
|
6
|
|
7
|
Copyright (C) 2003-2004 Bob Zoller <bob@kludgebox.com> and Manuel Kasper <mk@neon1.net>.
|
8
|
All rights reserved.
|
9
|
|
10
|
Redistribution and use in source and binary forms, with or without
|
11
|
modification, are permitted provided that the following conditions are met:
|
12
|
|
13
|
1. Redistributions of source code must retain the above copyright notice,
|
14
|
this list of conditions and the following disclaimer.
|
15
|
|
16
|
2. Redistributions in binary form must reproduce the above copyright
|
17
|
notice, this list of conditions and the following disclaimer in the
|
18
|
documentation and/or other materials provided with the distribution.
|
19
|
|
20
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
21
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
22
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
23
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
24
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
25
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
26
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
27
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
28
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
29
|
POSSIBILITY OF SUCH DAMAGE.
|
30
|
*/
|
31
|
|
32
|
require("guiconfig.inc");
|
33
|
|
34
|
$pconfig['enable'] = isset($config['dnsmasq']['enable']);
|
35
|
$pconfig['regdhcp'] = isset($config['dnsmasq']['regdhcp']);
|
36
|
$pconfig['regdhcpstatic'] = isset($config['dnsmasq']['regdhcpstatic']);
|
37
|
|
38
|
if (!is_array($config['dnsmasq']['hosts']))
|
39
|
$config['dnsmasq']['hosts'] = array();
|
40
|
|
41
|
if (!is_array($config['dnsmasq']['domainoverrides']))
|
42
|
$config['dnsmasq']['domainoverrides'] = array();
|
43
|
|
44
|
hosts_sort();
|
45
|
|
46
|
$a_hosts = &$config['dnsmasq']['hosts'];
|
47
|
$a_domainOverrides = &$config['dnsmasq']['domainoverrides'];
|
48
|
|
49
|
if ($_POST) {
|
50
|
|
51
|
$pconfig = $_POST;
|
52
|
|
53
|
$config['dnsmasq']['enable'] = ($_POST['enable']) ? true : false;
|
54
|
$config['dnsmasq']['regdhcp'] = ($_POST['regdhcp']) ? true : false;
|
55
|
$config['dnsmasq']['regdhcpstatic'] = ($_POST['regdhcpstatic']) ? true : false;
|
56
|
|
57
|
write_config();
|
58
|
|
59
|
$retval = 0;
|
60
|
|
61
|
config_lock();
|
62
|
$retval = services_dnsmasq_configure();
|
63
|
config_unlock();
|
64
|
|
65
|
$savemsg = get_std_save_message($retval);
|
66
|
|
67
|
if ($retval == 0) {
|
68
|
if (file_exists($d_hostsdirty_path))
|
69
|
unlink($d_hostsdirty_path);
|
70
|
}
|
71
|
}
|
72
|
|
73
|
if ($_GET['act'] == "del") {
|
74
|
if ($_GET['type'] == 'host') {
|
75
|
if ($a_hosts[$_GET['id']]) {
|
76
|
unset($a_hosts[$_GET['id']]);
|
77
|
write_config();
|
78
|
touch($d_hostsdirty_path);
|
79
|
header("Location: services_dnsmasq.php");
|
80
|
exit;
|
81
|
}
|
82
|
}
|
83
|
elseif ($_GET['type'] == 'doverride') {
|
84
|
if ($a_domainOverrides[$_GET['id']]) {
|
85
|
unset($a_domainOverrides[$_GET['id']]);
|
86
|
write_config();
|
87
|
touch($d_hostsdirty_path);
|
88
|
header("Location: services_dnsmasq.php");
|
89
|
exit;
|
90
|
}
|
91
|
}
|
92
|
}
|
93
|
|
94
|
$pgtitle = "Services: DNS forwarder";
|
95
|
include("head.inc");
|
96
|
|
97
|
?>
|
98
|
|
99
|
<script language="JavaScript">
|
100
|
<!--
|
101
|
function enable_change(enable_over) {
|
102
|
var endis;
|
103
|
endis = !(document.iform.enable.checked || enable_over);
|
104
|
document.iform.regdhcp.disabled = endis;
|
105
|
document.iform.regdhcpstatic.disabled = endis;
|
106
|
}
|
107
|
//-->
|
108
|
</script>
|
109
|
|
110
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
111
|
<?php include("fbegin.inc"); ?>
|
112
|
<p class="pgtitle"><?=$pgtitle?></p>
|
113
|
<form action="services_dnsmasq.php" method="post" name="iform" id="iform">
|
114
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
115
|
<?php if (file_exists($d_hostsdirty_path)): ?><p>
|
116
|
<?php print_info_box_np("The DNS forwarder configuration has been changed.<br>You must apply the changes in order for them to take effect.");?><br>
|
117
|
<?php endif; ?>
|
118
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
119
|
<tr>
|
120
|
<td class="vtable"><p>
|
121
|
<input name="enable" type="checkbox" id="enable" value="yes" <?php if ($pconfig['enable'] == "yes") echo "checked";?> onClick="enable_change(false)">
|
122
|
<strong>Enable DNS forwarder<br>
|
123
|
</strong></p></td>
|
124
|
</tr>
|
125
|
<tr>
|
126
|
<td class="vtable"><p>
|
127
|
<input name="regdhcp" type="checkbox" id="regdhcp" value="yes" <?php if ($pconfig['regdhcp'] == "yes") echo "checked";?>>
|
128
|
<strong>Register DHCP leases in DNS forwarder<br>
|
129
|
</strong>If this option is set, then machines that specify
|
130
|
their hostname when requesting a DHCP lease will be registered
|
131
|
in the DNS forwarder, so that their name can be resolved.
|
132
|
You should also set the domain in <a href="system.php">System:
|
133
|
General setup</a> to the proper value.</p>
|
134
|
</td>
|
135
|
</tr>
|
136
|
<tr>
|
137
|
<td class="vtable"><p>
|
138
|
<input name="regdhcpstatic" type="checkbox" id="regdhcpstatic" value="yes" <?php if ($pconfig['regdhcpstatic'] == "yes") echo "checked";?>>
|
139
|
<strong>Register DHCP static mappings in DNS forwarder<br>
|
140
|
</strong>If this option is set, then DHCP static mappings will
|
141
|
be registered in the DNS forwarder, so that their name can be
|
142
|
resolved. You should also set the domain in <a href="system.php">
|
143
|
System: General setup</a> to the proper value.</p>
|
144
|
</td>
|
145
|
</tr>
|
146
|
<tr>
|
147
|
<td> <input name="submit" type="submit" class="formbtn" value="Save" onclick="enable_change(true)">
|
148
|
</td>
|
149
|
</tr>
|
150
|
<tr>
|
151
|
<td><p><span class="vexpl"><span class="red"><strong>Note:<br>
|
152
|
</strong></span>If the DNS forwarder is enabled, the DHCP
|
153
|
service (if enabled) will automatically serve the LAN IP
|
154
|
address as a DNS server to DHCP clients so they will use
|
155
|
the forwarder. The DNS forwarder will use the DNS servers
|
156
|
entered in <a href="system.php">System: General setup</a>
|
157
|
or those obtained via DHCP or PPP on WAN if the "Allow
|
158
|
DNS server list to be overridden by DHCP/PPP on WAN"
|
159
|
is checked. If you don't use that option (or if you use
|
160
|
a static IP address on WAN), you must manually specify at
|
161
|
least one DNS server on the <a href="system.php">System:
|
162
|
General setup</a> page.<br>
|
163
|
<br>
|
164
|
You may enter records that override the results from the
|
165
|
forwarders below.</span></p></td>
|
166
|
</tr>
|
167
|
</table>
|
168
|
<br>
|
169
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
170
|
<tr>
|
171
|
<td width="20%" class="listhdrr">Host</td>
|
172
|
<td width="25%" class="listhdrr">Domain</td>
|
173
|
<td width="20%" class="listhdrr">IP</td>
|
174
|
<td width="25%" class="listhdr">Description</td>
|
175
|
<td width="10%" class="list">
|
176
|
<table border="0" cellspacing="0" cellpadding="1">
|
177
|
<tr>
|
178
|
<td width="17"></td>
|
179
|
<td valign="middle"><a href="services_dnsmasq_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td>
|
180
|
</tr>
|
181
|
</table>
|
182
|
</td>
|
183
|
</tr>
|
184
|
<?php $i = 0; foreach ($a_hosts as $hostent): ?>
|
185
|
<tr>
|
186
|
<td class="listlr" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
|
187
|
<?=strtolower($hostent['host']);?>
|
188
|
</td>
|
189
|
<td class="listr" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
|
190
|
<?=strtolower($hostent['domain']);?>
|
191
|
</td>
|
192
|
<td class="listr" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
|
193
|
<?=$hostent['ip'];?>
|
194
|
</td>
|
195
|
<td class="listbg" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
|
196
|
<font color="#FFFFFF"><?=htmlspecialchars($hostent['descr']);?>
|
197
|
</td>
|
198
|
<td valign="middle" nowrap class="list">
|
199
|
<table border="0" cellspacing="0" cellpadding="1">
|
200
|
<tr>
|
201
|
<td valign="middle"><a href="services_dnsmasq_edit.php?id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0"></a></td>
|
202
|
<td><a href="services_dnsmasq.php?type=host&act=del&id=<?=$i;?>" onclick="return confirm('Do you really want to delete this host?')"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0"></a></td>
|
203
|
</tr>
|
204
|
</table>
|
205
|
</tr>
|
206
|
<?php $i++; endforeach; ?>
|
207
|
<tr>
|
208
|
<td class="list" colspan="4"></td>
|
209
|
<td class="list">
|
210
|
<table border="0" cellspacing="0" cellpadding="1">
|
211
|
<tr>
|
212
|
<td width="17"></td>
|
213
|
<td valign="middle"><a href="services_dnsmasq_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td>
|
214
|
</tr>
|
215
|
</table>
|
216
|
</td>
|
217
|
</table>
|
218
|
<!-- update to enable domain overrides -->
|
219
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
220
|
<tr><td> </td></tr>
|
221
|
<tr>
|
222
|
<td><p>Below you can override an entire domain by specifying an
|
223
|
authoritative dns server to be queried for that domain.</p></td>
|
224
|
</tr>
|
225
|
</table>
|
226
|
<br>
|
227
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
228
|
<tr>
|
229
|
<td width="35%" class="listhdrr">Domain</td>
|
230
|
<td width="20%" class="listhdrr">IP</td>
|
231
|
<td width="35%" class="listhdr">Description</td>
|
232
|
<td width="10%" class="list">
|
233
|
<table border="0" cellspacing="0" cellpadding="1">
|
234
|
<tr>
|
235
|
<td width="17" heigth="17"></td>
|
236
|
<td><a href="services_dnsmasq_domainoverride_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td>
|
237
|
</tr>
|
238
|
</table>
|
239
|
</td>
|
240
|
</tr>
|
241
|
<?php $i = 0; foreach ($a_domainOverrides as $doment): ?>
|
242
|
<tr>
|
243
|
<td class="listlr">
|
244
|
<?=strtolower($doment['domain']);?>
|
245
|
</td>
|
246
|
<td class="listr">
|
247
|
<?=$doment['ip'];?>
|
248
|
</td>
|
249
|
<td class="listbg"><font color="#FFFFFF">
|
250
|
<?=htmlspecialchars($doment['descr']);?>
|
251
|
</td>
|
252
|
<td valign="middle" nowrap class="list"> <a href="services_dnsmasq_domainoverride_edit.php?id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0"></a>
|
253
|
<a href="services_dnsmasq.php?act=del&type=doverride&id=<?=$i;?>" onclick="return confirm('Do you really want to delete this domain override?')"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0"></a></td>
|
254
|
</tr>
|
255
|
<?php $i++; endforeach; ?>
|
256
|
<tr>
|
257
|
<td class="list" colspan="3"></td>
|
258
|
<td class="list">
|
259
|
<table border="0" cellspacing="0" cellpadding="1">
|
260
|
<tr>
|
261
|
<td width="17" heigth="17"></td>
|
262
|
<td><a href="services_dnsmasq_domainoverride_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td>
|
263
|
</tr>
|
264
|
</table>
|
265
|
</td>
|
266
|
</tr>
|
267
|
</table>
|
268
|
</form>
|
269
|
<script language="JavaScript">
|
270
|
<!--
|
271
|
enable_change(false);
|
272
|
//-->
|
273
|
</script>
|
274
|
<?php include("fend.inc"); ?>
|
275
|
</body>
|
276
|
</html>
|