1 |
5b237745
|
Scott Ullrich
|
#!/usr/local/bin/php
|
2 |
|
|
<?php
|
3 |
b46bfcf5
|
Bill Marquette
|
/* $Id$ */
|
4 |
5b237745
|
Scott Ullrich
|
/*
|
5 |
|
|
services_dnsmasq.php
|
6 |
|
|
part of m0n0wall (http://m0n0.ch/wall)
|
7 |
f0fe3d30
|
Scott Ullrich
|
|
8 |
5b237745
|
Scott Ullrich
|
Copyright (C) 2003-2004 Bob Zoller <bob@kludgebox.com> and Manuel Kasper <mk@neon1.net>.
|
9 |
|
|
All rights reserved.
|
10 |
f0fe3d30
|
Scott Ullrich
|
|
11 |
5b237745
|
Scott Ullrich
|
Redistribution and use in source and binary forms, with or without
|
12 |
|
|
modification, are permitted provided that the following conditions are met:
|
13 |
f0fe3d30
|
Scott Ullrich
|
|
14 |
5b237745
|
Scott Ullrich
|
1. Redistributions of source code must retain the above copyright notice,
|
15 |
|
|
this list of conditions and the following disclaimer.
|
16 |
f0fe3d30
|
Scott Ullrich
|
|
17 |
5b237745
|
Scott Ullrich
|
2. Redistributions in binary form must reproduce the above copyright
|
18 |
|
|
notice, this list of conditions and the following disclaimer in the
|
19 |
|
|
documentation and/or other materials provided with the distribution.
|
20 |
f0fe3d30
|
Scott Ullrich
|
|
21 |
5b237745
|
Scott Ullrich
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
22 |
|
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
23 |
|
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
24 |
|
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
25 |
|
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
26 |
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
27 |
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
28 |
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
29 |
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30 |
|
|
POSSIBILITY OF SUCH DAMAGE.
|
31 |
|
|
*/
|
32 |
|
|
|
33 |
|
|
require("guiconfig.inc");
|
34 |
|
|
|
35 |
|
|
$pconfig['enable'] = isset($config['dnsmasq']['enable']);
|
36 |
|
|
$pconfig['regdhcp'] = isset($config['dnsmasq']['regdhcp']);
|
37 |
|
|
|
38 |
|
|
if (!is_array($config['dnsmasq']['hosts'])) {
|
39 |
|
|
$config['dnsmasq']['hosts'] = array();
|
40 |
|
|
}
|
41 |
0c2b5df7
|
Scott Ullrich
|
|
42 |
|
|
if (!is_array($config['dnsmasq']['domainoverrides'])) {
|
43 |
|
|
$config['dnsmasq']['domainoverrides'] = array();
|
44 |
|
|
}
|
45 |
|
|
|
46 |
5b237745
|
Scott Ullrich
|
hosts_sort();
|
47 |
|
|
$a_hosts = &$config['dnsmasq']['hosts'];
|
48 |
0c2b5df7
|
Scott Ullrich
|
$a_domainOverrides = &$config['dnsmasq']['domainoverrides'];
|
49 |
5b237745
|
Scott Ullrich
|
|
50 |
|
|
if ($_POST) {
|
51 |
|
|
|
52 |
|
|
$pconfig = $_POST;
|
53 |
|
|
|
54 |
|
|
$config['dnsmasq']['enable'] = ($_POST['enable']) ? true : false;
|
55 |
|
|
$config['dnsmasq']['regdhcp'] = ($_POST['regdhcp']) ? true : false;
|
56 |
|
|
|
57 |
|
|
write_config();
|
58 |
f0fe3d30
|
Scott Ullrich
|
|
59 |
5b237745
|
Scott Ullrich
|
$retval = 0;
|
60 |
|
|
if (!file_exists($d_sysrebootreqd_path)) {
|
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 |
0c2b5df7
|
Scott Ullrich
|
if ($_GET['type'] == 'host') {
|
75 |
|
|
if ($a_hosts[$_GET['id']]) {
|
76 |
|
|
unset($a_hosts[$_GET['id']]);
|
77 |
|
|
write_config();
|
78 |
|
|
touch($d_dnsmasqdirty_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_dnsmasqdirty_path);
|
88 |
|
|
header("Location: services_dnsmasq.php");
|
89 |
|
|
exit;
|
90 |
|
|
}
|
91 |
|
|
}
|
92 |
5b237745
|
Scott Ullrich
|
}
|
93 |
0c2b5df7
|
Scott Ullrich
|
|
94 |
|
|
|
95 |
5b237745
|
Scott Ullrich
|
?>
|
96 |
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
97 |
|
|
<html>
|
98 |
|
|
<head>
|
99 |
|
|
<title><?=gentitle("Services: DNS forwarder");?></title>
|
100 |
|
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
101 |
|
|
<link href="gui.css" rel="stylesheet" type="text/css">
|
102 |
|
|
</head>
|
103 |
|
|
|
104 |
|
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
105 |
|
|
<?php include("fbegin.inc"); ?>
|
106 |
|
|
<p class="pgtitle">Services: DNS forwarder</p>
|
107 |
|
|
<form action="services_dnsmasq.php" method="post">
|
108 |
|
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
109 |
|
|
<?php if (file_exists($d_hostsdirty_path)): ?><p>
|
110 |
|
|
<?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>
|
111 |
|
|
<input name="apply" type="submit" class="formbtn" id="apply" value="Apply changes"></p>
|
112 |
|
|
<?php endif; ?>
|
113 |
|
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
114 |
f0fe3d30
|
Scott Ullrich
|
<tr>
|
115 |
|
|
<td class="vtable"><p>
|
116 |
5b237745
|
Scott Ullrich
|
<input name="enable" type="checkbox" id="enable" value="yes" <?php if ($pconfig['enable'] == "yes") echo "checked";?>>
|
117 |
|
|
<strong>Enable DNS forwarder<br>
|
118 |
|
|
</strong></p></td>
|
119 |
|
|
</tr>
|
120 |
f0fe3d30
|
Scott Ullrich
|
<tr>
|
121 |
|
|
<td class="vtable"><p>
|
122 |
5b237745
|
Scott Ullrich
|
<input name="regdhcp" type="checkbox" id="regdhcp" value="yes" <?php if ($pconfig['regdhcp'] == "yes") echo "checked";?>>
|
123 |
|
|
<strong>Register DHCP leases in DNS forwarder<br>
|
124 |
f0fe3d30
|
Scott Ullrich
|
</strong>If this option is set, then machines that specify
|
125 |
|
|
their hostname when requesting a DHCP lease will be registered
|
126 |
|
|
in the DNS forwarder, so that their name can be resolved.
|
127 |
|
|
You should also set the domain in <a href="system.php">System:
|
128 |
5b237745
|
Scott Ullrich
|
General setup</a> to the proper value.</p>
|
129 |
|
|
</td>
|
130 |
|
|
</tr>
|
131 |
f0fe3d30
|
Scott Ullrich
|
<tr>
|
132 |
|
|
<td> <input name="submit" type="submit" class="formbtn" value="Save">
|
133 |
5b237745
|
Scott Ullrich
|
</td>
|
134 |
|
|
</tr>
|
135 |
f0fe3d30
|
Scott Ullrich
|
<tr>
|
136 |
5b237745
|
Scott Ullrich
|
<td><p><span class="vexpl"><span class="red"><strong>Note:<br>
|
137 |
f0fe3d30
|
Scott Ullrich
|
</strong></span>If the DNS forwarder is enabled, the DHCP
|
138 |
|
|
service (if enabled) will automatically serve the LAN IP
|
139 |
|
|
address as a DNS server to DHCP clients so they will use
|
140 |
|
|
the forwarder. The DNS forwarder will use the DNS servers
|
141 |
|
|
entered in <a href="system.php">System: General setup</a>
|
142 |
|
|
or those obtained via DHCP or PPP on WAN if the "Allow
|
143 |
|
|
DNS server list to be overridden by DHCP/PPP on WAN"</span>
|
144 |
|
|
is checked. If you don't use that option (or if you use
|
145 |
|
|
a static IP address on WAN), you must manually specify at
|
146 |
|
|
least one DNS server on the <a href="system.php">System:
|
147 |
5b237745
|
Scott Ullrich
|
General setup</a> page.<br>
|
148 |
|
|
<br>
|
149 |
f0fe3d30
|
Scott Ullrich
|
You may enter records that override the results from the
|
150 |
5b237745
|
Scott Ullrich
|
forwarders below.</p></td>
|
151 |
|
|
</tr>
|
152 |
|
|
</table>
|
153 |
|
|
<br>
|
154 |
|
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
155 |
|
|
<tr>
|
156 |
|
|
<td width="20%" class="listhdrr">Host</td>
|
157 |
|
|
<td width="25%" class="listhdrr">Domain</td>
|
158 |
|
|
<td width="20%" class="listhdrr">IP</td>
|
159 |
|
|
<td width="25%" class="listhdr">Description</td>
|
160 |
|
|
<td width="10%" class="list"></td>
|
161 |
|
|
</tr>
|
162 |
|
|
<?php $i = 0; foreach ($a_hosts as $hostent): ?>
|
163 |
|
|
<tr>
|
164 |
835f9aca
|
Bill Marquette
|
<td class="listlr" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
|
165 |
5b237745
|
Scott Ullrich
|
<?=strtolower($hostent['host']);?>
|
166 |
|
|
</td>
|
167 |
835f9aca
|
Bill Marquette
|
<td class="listr" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
|
168 |
5b237745
|
Scott Ullrich
|
<?=strtolower($hostent['domain']);?>
|
169 |
|
|
</td>
|
170 |
835f9aca
|
Bill Marquette
|
<td class="listr" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
|
171 |
5b237745
|
Scott Ullrich
|
<?=$hostent['ip'];?>
|
172 |
|
|
</td>
|
173 |
835f9aca
|
Bill Marquette
|
<td class="listbg" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
|
174 |
f0fe3d30
|
Scott Ullrich
|
<font color="#FFFFFF"><?=htmlspecialchars($hostent['descr']);?>
|
175 |
5b237745
|
Scott Ullrich
|
</td>
|
176 |
ebe566eb
|
Bill Marquette
|
<td valign="middle" nowrap class="list">
|
177 |
|
|
<table border="0" cellspacing="0" cellpadding="1">
|
178 |
|
|
<tr>
|
179 |
|
|
<td valign="middle"><a href="services_dnsmasq_edit.php?id=<?=$i;?>"><img src="e.gif" width="17" height="17" border="0"></a></td>
|
180 |
|
|
<td><a href="services_dnsmasq.php?act=del&id=<?=$i;?>" onclick="return confirm('Do you really want to delete this host?')"><img src="x.gif" width="17" height="17" border="0"></a></td>
|
181 |
|
|
</tr>
|
182 |
|
|
</table>
|
183 |
|
|
</tr>
|
184 |
|
|
<?php $i++; endforeach; ?>
|
185 |
f0fe3d30
|
Scott Ullrich
|
<tr>
|
186 |
5b237745
|
Scott Ullrich
|
<td class="list" colspan="4"></td>
|
187 |
ebe566eb
|
Bill Marquette
|
<td class="list">
|
188 |
|
|
<table border="0" cellspacing="0" cellpadding="1">
|
189 |
|
|
<tr>
|
190 |
|
|
<td valign="middle"><a href="services_dnsmasq_edit.php"><img src="plus.gif" width="17" height="17" border="0"></a></td>
|
191 |
|
|
</tr>
|
192 |
|
|
</table>
|
193 |
ed137452
|
Scott Ullrich
|
</td>
|
194 |
|
|
</table>
|
195 |
0c2b5df7
|
Scott Ullrich
|
<!-- update to enable domain overrides -->
|
196 |
ed137452
|
Scott Ullrich
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
197 |
c21d4582
|
Scott Ullrich
|
<tr><td> </td></tr>
|
198 |
0c2b5df7
|
Scott Ullrich
|
<tr>
|
199 |
|
|
<td><p>Below you can override an entire domain by specifying an
|
200 |
|
|
authoritative dns server to be queried for that domain.</p></td>
|
201 |
|
|
</tr>
|
202 |
|
|
</table>
|
203 |
ca1ac4dd
|
Scott Ullrich
|
<br>
|
204 |
0c2b5df7
|
Scott Ullrich
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
205 |
|
|
<tr>
|
206 |
|
|
<td width="35%" class="listhdrr">Domain</td>
|
207 |
|
|
<td width="20%" class="listhdrr">IP</td>
|
208 |
|
|
<td width="35%" class="listhdr">Description</td>
|
209 |
|
|
<td width="10%" class="list"></td>
|
210 |
|
|
</tr>
|
211 |
|
|
<?php $i = 0; foreach ($a_domainOverrides as $doment): ?>
|
212 |
|
|
<tr>
|
213 |
|
|
<td class="listlr">
|
214 |
|
|
<?=strtolower($doment['domain']);?>
|
215 |
|
|
</td>
|
216 |
|
|
<td class="listr">
|
217 |
|
|
<?=$doment['ip'];?>
|
218 |
|
|
</td>
|
219 |
5015bd61
|
Scott Ullrich
|
<td class="listbg"><font color="#FFFFFF">
|
220 |
0c2b5df7
|
Scott Ullrich
|
<?=htmlspecialchars($doment['descr']);?>
|
221 |
|
|
</td>
|
222 |
424dc67f
|
Scott Ullrich
|
<td valign="middle" nowrap class="list"> <a href="services_dnsmasq_domainoverride_edit.php?id=<?=$i;?>"><img src="e.gif" width="17" height="17" border="0"></a>
|
223 |
|
|
<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="x.gif" width="17" height="17" border="0"></a></td>
|
224 |
0c2b5df7
|
Scott Ullrich
|
</tr>
|
225 |
|
|
<?php $i++; endforeach; ?>
|
226 |
|
|
<tr>
|
227 |
|
|
<td class="list" colspan="3"></td>
|
228 |
|
|
<td class="list"> <a href="services_dnsmasq_domainoverride_edit.php"><img src="plus.gif" width="17" height="17" border="0"></a></td>
|
229 |
|
|
</tr>
|
230 |
5b237745
|
Scott Ullrich
|
</table>
|
231 |
|
|
</form>
|
232 |
|
|
<?php include("fend.inc"); ?>
|
233 |
|
|
</body>
|
234 |
|
|
</html>
|