Project

General

Profile

Download (13.9 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
<?php
2 b46bfcf5 Bill Marquette
/* $Id$ */
3 5b237745 Scott Ullrich
/*
4
	services_dnsmasq.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6 f0fe3d30 Scott Ullrich
7 5b237745 Scott Ullrich
	Copyright (C) 2003-2004 Bob Zoller <bob@kludgebox.com> and Manuel Kasper <mk@neon1.net>.
8
	All rights reserved.
9 f0fe3d30 Scott Ullrich
10 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12 f0fe3d30 Scott Ullrich
13 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15 f0fe3d30 Scott Ullrich
16 5b237745 Scott Ullrich
	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 f0fe3d30 Scott Ullrich
20 5b237745 Scott Ullrich
	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 70edf50d jim-p
/*
32 1d333258 Scott Ullrich
	pfSense_MODULE:	dnsforwarder
33
*/
34 5b237745 Scott Ullrich
35 6b07c15a Matthew Grooms
##|+PRIV
36
##|*IDENT=page-services-dnsforwarder
37
##|*NAME=Services: DNS Forwarder page
38
##|*DESCR=Allow access to the 'Services: DNS Forwarder' page.
39
##|*MATCH=services_dnsmasq.php*
40
##|-PRIV
41
42 5b237745 Scott Ullrich
require("guiconfig.inc");
43 7a927e67 Scott Ullrich
require_once("functions.inc");
44
require_once("filter.inc");
45
require_once("shaper.inc");
46 5b237745 Scott Ullrich
47 70edf50d jim-p
$pconfig['enable'] = isset($config['dnsmasq']['enable']);
48 5b237745 Scott Ullrich
$pconfig['regdhcp'] = isset($config['dnsmasq']['regdhcp']);
49 6a01ea44 Bill Marquette
$pconfig['regdhcpstatic'] = isset($config['dnsmasq']['regdhcpstatic']);
50 aa994814 Andrew Thompson
$pconfig['dhcpfirst'] = isset($config['dnsmasq']['dhcpfirst']);
51 8f9bffbc Andrew Thompson
$pconfig['custom_options'] = $config['dnsmasq']['custom_options'];
52 5b237745 Scott Ullrich
53 70edf50d jim-p
if (!is_array($config['dnsmasq']['hosts']))
54 5b237745 Scott Ullrich
	$config['dnsmasq']['hosts'] = array();
55 0c2b5df7 Scott Ullrich
56 70edf50d jim-p
if (!is_array($config['dnsmasq']['domainoverrides']))
57
	$config['dnsmasq']['domainoverrides'] = array();
58 0c2b5df7 Scott Ullrich
59 4d6ba181 Scott Ullrich
60 70edf50d jim-p
$a_hosts = &$config['dnsmasq']['hosts'];
61 0c2b5df7 Scott Ullrich
$a_domainOverrides = &$config['dnsmasq']['domainoverrides'];
62 5b237745 Scott Ullrich
63
if ($_POST) {
64
65
	$pconfig = $_POST;
66 8f9bffbc Andrew Thompson
	unset($input_errors);
67 5b237745 Scott Ullrich
68
	$config['dnsmasq']['enable'] = ($_POST['enable']) ? true : false;
69
	$config['dnsmasq']['regdhcp'] = ($_POST['regdhcp']) ? true : false;
70 6a01ea44 Bill Marquette
	$config['dnsmasq']['regdhcpstatic'] = ($_POST['regdhcpstatic']) ? true : false;
71 aa994814 Andrew Thompson
	$config['dnsmasq']['dhcpfirst'] = ($_POST['dhcpfirst']) ? true : false;
72 8f9bffbc Andrew Thompson
	$config['dnsmasq']['custom_options'] = str_replace("\r\n", "\n", $_POST['custom_options']);
73
74
	if ($config['dnsmasq']['custom_options']) {
75
		$args = '';
76
		foreach (preg_split('/\s+/', $config['dnsmasq']['custom_options']) as $c)
77
			$args .= "--$c ";
78
		exec("/usr/local/sbin/dnsmasq --test $args", $output, $rc);
79
		if ($rc != 0)
80
			$input_errors[] = gettext("Invalid custom options");
81
	}
82 5b237745 Scott Ullrich
83 8f9bffbc Andrew Thompson
	if (!$input_errors) {
84
		write_config();
85 f0fe3d30 Scott Ullrich
86 8f9bffbc Andrew Thompson
		$retval = 0;
87
		$retval = services_dnsmasq_configure();
88
		$savemsg = get_std_save_message($retval);
89 5b237745 Scott Ullrich
90 8f9bffbc Andrew Thompson
		// Relaod filter (we might need to sync to CARP hosts)
91
		filter_configure();
92 020d757a Scott Ullrich
93 8f9bffbc Andrew Thompson
		if ($retval == 0)
94
			clear_subsystem_dirty('hosts');
95
	}
96 5b237745 Scott Ullrich
}
97
98
if ($_GET['act'] == "del") {
99 70edf50d jim-p
	if ($_GET['type'] == 'host') {
100
		if ($a_hosts[$_GET['id']]) {
101
			unset($a_hosts[$_GET['id']]);
102
			write_config();
103 a368a026 Ermal Lu?i
			mark_subsystem_dirty('hosts');
104 70edf50d jim-p
			header("Location: services_dnsmasq.php");
105
			exit;
106
		}
107
	}
108
	elseif ($_GET['type'] == 'doverride') {
109
		if ($a_domainOverrides[$_GET['id']]) {
110
			unset($a_domainOverrides[$_GET['id']]);
111
			write_config();
112 a368a026 Ermal Lu?i
			mark_subsystem_dirty('hosts');
113 70edf50d jim-p
			header("Location: services_dnsmasq.php");
114
			exit;
115
		}
116
	}
117 5b237745 Scott Ullrich
}
118 0c2b5df7 Scott Ullrich
119 beb2bc00 Rafael Lucas
$pgtitle = array(gettext("Services"),gettext("DNS forwarder"));
120 b63695db Scott Ullrich
include("head.inc");
121 0c2b5df7 Scott Ullrich
122 5b237745 Scott Ullrich
?>
123
124 6a01ea44 Bill Marquette
<script language="JavaScript">
125
<!--
126
function enable_change(enable_over) {
127
	var endis;
128
	endis = !(document.iform.enable.checked || enable_over);
129
	document.iform.regdhcp.disabled = endis;
130
	document.iform.regdhcpstatic.disabled = endis;
131 aa994814 Andrew Thompson
	document.iform.dhcpfirst.disabled = endis;
132 6a01ea44 Bill Marquette
}
133 8f9bffbc Andrew Thompson
function show_advanced_dns() {
134
	document.getElementById("showadvbox").innerHTML='';
135
	aodiv = document.getElementById('showadv');
136
	aodiv.style.display = "block";
137
}
138 6a01ea44 Bill Marquette
//-->
139
</script>
140
141 5b237745 Scott Ullrich
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
142
<?php include("fbegin.inc"); ?>
143 6a01ea44 Bill Marquette
<form action="services_dnsmasq.php" method="post" name="iform" id="iform">
144 8f9bffbc Andrew Thompson
<?php if ($input_errors) print_input_errors($input_errors); ?>
145 5b237745 Scott Ullrich
<?php if ($savemsg) print_info_box($savemsg); ?>
146 a368a026 Ermal Lu?i
<?php if (is_subsystem_dirty('hosts')): ?><p>
147 619c72f9 Carlos Eduardo Ramos
<?php print_info_box_np(gettext("The DNS forwarder configuration has been changed") . ".<br>" . gettext("You must apply the changes in order for them to take effect."));?><br>
148 5b237745 Scott Ullrich
<?php endif; ?>
149 70edf50d jim-p
<table width="100%" border="0" cellpadding="6" cellspacing="0">
150
	<tr>
151 6661dbcf jim-p
		<td colspan="2" valign="top" class="listtopic"><?=gettext("General DNS Forwarder Options");?></td>
152
	</tr>
153
	<tr>
154
		<td width="22%" valign="top" class="vncellreq"><?=gettext("Enable");?></td>
155
		<td width="78%" class="vtable"><p>
156 70edf50d jim-p
			<input name="enable" type="checkbox" id="enable" value="yes" <?php if ($pconfig['enable'] == "yes") echo "checked";?> onClick="enable_change(false)">
157
			<strong><?=gettext("Enable DNS forwarder");?><br>
158
			</strong></p></td>
159 98776e04 jim-p
		</tr>
160 70edf50d jim-p
	<tr>
161 6661dbcf jim-p
		<td width="22%" valign="top" class="vncellreq"><?=gettext("DHCP Registration");?></td>
162
		<td width="78%" class="vtable"><p>
163 70edf50d jim-p
			<input name="regdhcp" type="checkbox" id="regdhcp" value="yes" <?php if ($pconfig['regdhcp'] == "yes") echo "checked";?>>
164
			<strong><?=gettext("Register DHCP leases in DNS forwarder");?><br>
165
			</strong><?php printf(gettext("If this option is set, then machines that specify".
166
			" their hostname when requesting a DHCP lease will be registered".
167
			" in the DNS forwarder, so that their name can be resolved.".
168
			" You should also set the domain in %sSystem:".
169
			" General setup%s to the proper value."),'<a href="system.php">','</a>')?></p>
170
		</td>
171
	</tr>
172
	<tr>
173 6661dbcf jim-p
		<td width="22%" valign="top" class="vncellreq"><?=gettext("Static DHCP");?></td>
174
		<td width="78%" class="vtable"><p>
175 70edf50d jim-p
			<input name="regdhcpstatic" type="checkbox" id="regdhcpstatic" value="yes" <?php if ($pconfig['regdhcpstatic'] == "yes") echo "checked";?>>
176
			<strong><?=gettext("Register DHCP static mappings in DNS forwarder");?><br>
177
			</strong><?php printf(gettext("If this option is set, then DHCP static mappings will ".
178
					"be registered in the DNS forwarder, so that their name can be ".
179
					"resolved. You should also set the domain in %s".
180
					"System: General setup%s to the proper value."),'<a href="system.php">','</a>');?></p>
181
		</td>
182
	</tr>
183 aa994814 Andrew Thompson
	<tr>
184 6661dbcf jim-p
		<td width="22%" valign="top" class="vncellreq"><?=gettext("Prefer DHCP");?></td>
185
		<td width="78%" class="vtable"><p>
186 aa994814 Andrew Thompson
			<input name="dhcpfirst" type="checkbox" id="dhcpfirst" value="yes" <?php if ($pconfig['dhcpfirst'] == "yes") echo "checked";?>>
187
			<strong><?=gettext("Resolve DHCP mappings first");?><br>
188
			</strong><?php printf(gettext("If this option is set, then DHCP mappings will ".
189
					"be resolved before the manual list of names below. This only ".
190 649ea752 Andrew Thompson
					"affects the name given for a reverse lookup (PTR)."));?></p>
191 aa994814 Andrew Thompson
		</td>
192
	</tr>
193 8f9bffbc Andrew Thompson
	<tr>
194 6661dbcf jim-p
		<td width="22%" valign="top" class="vncellreq"><?=gettext("Advanced");?></td>
195
		<td width="78%" class="vtable"><p>
196 8f9bffbc Andrew Thompson
			<div id="showadvbox" <?php if ($pconfig['custom_options']) echo "style='display:none'"; ?>>
197
				<input type="button" onClick="show_advanced_dns()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show advanced option");?></a>
198
			</div>
199
			<div id="showadv" <?php if (empty($pconfig['custom_options'])) echo "style='display:none'"; ?>>
200
				<strong><?=gettext("Advanced");?><br></strong>
201
				<textarea rows="6" cols="78" name="custom_options" id="custom_options"><?=htmlspecialchars($pconfig['custom_options']);?></textarea><br/>
202
				<?=gettext("Enter any additional options you would like to add to the dnsmasq configuration here, separated by a space or newline"); ?><br/>
203
			</div>
204
			</p>
205
		</td>
206
	</tr>
207 70edf50d jim-p
	<tr>
208 6661dbcf jim-p
		<td colspan="2">
209 70edf50d jim-p
			<input name="submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" onclick="enable_change(true)">
210
		</td>
211
	</tr>
212
</table>
213 6661dbcf jim-p
214
<p><span class="vexpl"><span class="red"><strong><?=gettext("Note:");?><br>
215
</strong></span><?php printf(gettext("If the DNS forwarder is enabled, the DHCP".
216
" service (if enabled) will automatically serve the LAN IP".
217
" address as a DNS server to DHCP clients so they will use".
218
" the forwarder. The DNS forwarder will use the DNS servers".
219
" entered in %sSystem: General setup%s".
220
" or those obtained via DHCP or PPP on WAN if the &quot;Allow".
221
" DNS server list to be overridden by DHCP/PPP on WAN&quot;".
222
" is checked. If you don't use that option (or if you use".
223
" a static IP address on WAN), you must manually specify at".
224
" least one DNS server on the %sSystem:".
225
"General setup%s page."),'<a href="system.php">','</a>','<a href="system.php">','</a>');?><br>
226
</span></p>
227
228 70edf50d jim-p
&nbsp;<br>
229 6661dbcf jim-p
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tabcont">
230
<tr>
231
	<td colspan="5" valign="top" class="listtopic"><?=gettext("Host Overrides");?></td>
232
</tr>
233
<tr>
234
	<td><br/>
235
	<?=gettext("Entries in this section override individual results from the forwarders.");?>
236
	<?=gettext("Use these for changing DNS results or for adding custom DNS records.");?>
237
	</td>
238
</tr>
239
</table>
240
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tabcont sortable">
241 70edf50d jim-p
	<thead>
242
	<tr>
243
		<td width="20%" class="listhdrr"><?=gettext("Host");?></td>
244
		<td width="25%" class="listhdrr"><?=gettext("Domain");?></td>
245
		<td width="20%" class="listhdrr"><?=gettext("IP");?></td>
246
		<td width="25%" class="listhdr"><?=gettext("Description");?></td>
247
		<td width="10%" class="list">
248 d415d821 Seth Mos
			<table border="0" cellspacing="0" cellpadding="1">
249 70edf50d jim-p
				<tr>
250
					<td width="17"></td>
251
					<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>
252
				</tr>
253 d415d821 Seth Mos
			</table>
254 70edf50d jim-p
		</td>
255
	</tr>
256
	</thead>
257
	<tbody>
258
	<?php $i = 0; foreach ($a_hosts as $hostent): ?>
259
	<tr>
260
		<td class="listlr" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
261
			<?=strtolower($hostent['host']);?>&nbsp;
262
		</td>
263
		<td class="listr" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
264
			<?=strtolower($hostent['domain']);?>&nbsp;
265
		</td>
266
		<td class="listr" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
267
			<?=$hostent['ip'];?>&nbsp;
268
		</td>
269
		<td class="listbg" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
270
			<?=htmlspecialchars($hostent['descr']);?>&nbsp;
271
		</td>
272
		<td valign="middle" nowrap class="list">
273 d415d821 Seth Mos
			<table border="0" cellspacing="0" cellpadding="1">
274 70edf50d jim-p
				<tr>
275
					<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>
276
					<td><a href="services_dnsmasq.php?type=host&act=del&id=<?=$i;?>" onclick="return confirm('<?=gettext("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>
277
				</tr>
278 d415d821 Seth Mos
			</table>
279 70edf50d jim-p
	</tr>
280
	<?php $i++; endforeach; ?>
281
	</tbody>
282
	<tfoot>
283
	<tr>
284
		<td class="list" colspan="4"></td>
285
		<td class="list">
286
			<table border="0" cellspacing="0" cellpadding="1">
287
				<tr>
288
					<td width="17"></td>
289
					<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>
290
				</tr>
291
			</table>
292
		</td>
293
	</tr>
294
	</tfoot>
295
</table>
296 6661dbcf jim-p
<br/>
297
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tabcont">
298
<tr>
299
	<td colspan="5" valign="top" class="listtopic"><?=gettext("Domain Overrides");?></td>
300
</tr>
301
<tr>
302 70edf50d jim-p
	<tr>
303 6661dbcf jim-p
		<td><p><?=gettext("Entries in this area override an entire domain by specifying an".
304 70edf50d jim-p
		" authoritative DNS server to be queried for that domain.");?></p></td>
305
	</tr>
306 6661dbcf jim-p
</tr>
307 70edf50d jim-p
</table>
308 6661dbcf jim-p
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tabcont sortable">
309 70edf50d jim-p
	<thead>
310
	<tr>
311
		<td width="35%" class="listhdrr"><?=gettext("Domain");?></td>
312
		<td width="20%" class="listhdrr"><?=gettext("IP");?></td>
313
		<td width="35%" class="listhdr"><?=gettext("Description");?></td>
314
		<td width="10%" class="list">
315
			<table border="0" cellspacing="0" cellpadding="1">
316
				<tr>
317
					<td width="17" heigth="17"></td>
318
					<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>
319
				</tr>
320
			</table>
321
		</td>
322
	</tr>
323
	</thead>
324
	<tbody>
325
	<?php $i = 0; foreach ($a_domainOverrides as $doment): ?>
326
	<tr>
327
		<td class="listlr">
328
			<?=strtolower($doment['domain']);?>&nbsp;
329
		</td>
330
		<td class="listr">
331
			<?=$doment['ip'];?>&nbsp;
332
		</td>
333
		<td class="listbg">
334
			<?=htmlspecialchars($doment['descr']);?>&nbsp;
335
		</td>
336
		<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>
337
			&nbsp;<a href="services_dnsmasq.php?act=del&type=doverride&id=<?=$i;?>" onclick="return confirm('<?=gettext("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>
338
	</tr>
339
	<?php $i++; endforeach; ?>
340
	</tbody>
341
	<tfoot>
342
	<tr>
343
		<td class="list" colspan="3"></td>
344
		<td class="list">
345
		<table border="0" cellspacing="0" cellpadding="1">
346
			<tr>
347
				<td width="17" heigth="17"></td>
348
				<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>
349
			</tr>
350
		</table>
351
		</td>
352
	</tr>
353
	</tfoot>
354
</table>
355
</form>
356 6a01ea44 Bill Marquette
<script language="JavaScript">
357
<!--
358
enable_change(false);
359
//-->
360
</script>
361 5b237745 Scott Ullrich
<?php include("fend.inc"); ?>
362
</body>
363
</html>