Project

General

Profile

Download (17.5 KB) Statistics
| Branch: | Tag: | Revision:
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
	pfSense_MODULE:	dnsforwarder
33
*/
34

    
35
##|+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
require("guiconfig.inc");
43
require_once("functions.inc");
44
require_once("filter.inc");
45
require_once("shaper.inc");
46

    
47
$pconfig['enable'] = isset($config['dnsmasq']['enable']);
48
$pconfig['regdhcp'] = isset($config['dnsmasq']['regdhcp']);
49
$pconfig['regdhcpstatic'] = isset($config['dnsmasq']['regdhcpstatic']);
50
$pconfig['dhcpfirst'] = isset($config['dnsmasq']['dhcpfirst']);
51
$pconfig['strict_order'] = isset($config['dnsmasq']['strict_order']);
52
$pconfig['domain_needed'] = isset($config['dnsmasq']['domain_needed']);
53
$pconfig['no_private_reverse'] = isset($config['dnsmasq']['no_private_reverse']);
54
$pconfig['custom_options'] = $config['dnsmasq']['custom_options'];
55

    
56
if (!is_array($config['dnsmasq']['hosts']))
57
	$config['dnsmasq']['hosts'] = array();
58

    
59
if (!is_array($config['dnsmasq']['domainoverrides']))
60
	$config['dnsmasq']['domainoverrides'] = array();
61

    
62

    
63
$a_hosts = &$config['dnsmasq']['hosts'];
64
$a_domainOverrides = &$config['dnsmasq']['domainoverrides'];
65

    
66
if ($_POST) {
67

    
68
	$pconfig = $_POST;
69
	unset($input_errors);
70

    
71
	$config['dnsmasq']['enable'] = ($_POST['enable']) ? true : false;
72
	$config['dnsmasq']['regdhcp'] = ($_POST['regdhcp']) ? true : false;
73
	$config['dnsmasq']['regdhcpstatic'] = ($_POST['regdhcpstatic']) ? true : false;
74
	$config['dnsmasq']['dhcpfirst'] = ($_POST['dhcpfirst']) ? true : false;
75
	$config['dnsmasq']['strict_order'] = ($_POST['strict_order']) ? true : false;
76
	$config['dnsmasq']['domain_needed'] = ($_POST['domain_needed']) ? true : false;
77
	$config['dnsmasq']['no_private_reverse'] = ($_POST['no_private_reverse']) ? true : false;
78
	$config['dnsmasq']['custom_options'] = str_replace("\r\n", "\n", $_POST['custom_options']);
79

    
80
	if ($config['dnsmasq']['custom_options']) {
81
		$args = '';
82
		foreach (preg_split('/\s+/', $config['dnsmasq']['custom_options']) as $c)
83
			$args .= "--$c ";
84
		exec("/usr/local/sbin/dnsmasq --test $args", $output, $rc);
85
		if ($rc != 0)
86
			$input_errors[] = gettext("Invalid custom options");
87
	}
88

    
89
	if (!$input_errors) {
90
		write_config();
91

    
92
		$retval = 0;
93
		$retval = services_dnsmasq_configure();
94
		$savemsg = get_std_save_message($retval);
95

    
96
		// Relaod filter (we might need to sync to CARP hosts)
97
		filter_configure();
98

    
99
		if ($retval == 0)
100
			clear_subsystem_dirty('hosts');
101
	}
102
}
103

    
104
if ($_GET['act'] == "del") {
105
	if ($_GET['type'] == 'host') {
106
		if ($a_hosts[$_GET['id']]) {
107
			unset($a_hosts[$_GET['id']]);
108
			write_config();
109
			mark_subsystem_dirty('hosts');
110
			header("Location: services_dnsmasq.php");
111
			exit;
112
		}
113
	}
114
	elseif ($_GET['type'] == 'doverride') {
115
		if ($a_domainOverrides[$_GET['id']]) {
116
			unset($a_domainOverrides[$_GET['id']]);
117
			write_config();
118
			mark_subsystem_dirty('hosts');
119
			header("Location: services_dnsmasq.php");
120
			exit;
121
		}
122
	}
123
}
124

    
125
$pgtitle = array(gettext("Services"),gettext("DNS forwarder"));
126
$shortcut_section = "resolver";
127
include("head.inc");
128

    
129
?>
130

    
131
<script language="JavaScript">
132
<!--
133
function enable_change(enable_over) {
134
	var endis;
135
	endis = !(document.iform.enable.checked || enable_over);
136
	document.iform.regdhcp.disabled = endis;
137
	document.iform.regdhcpstatic.disabled = endis;
138
	document.iform.dhcpfirst.disabled = endis;
139
}
140
function show_advanced_dns() {
141
	document.getElementById("showadvbox").innerHTML='';
142
	aodiv = document.getElementById('showadv');
143
	aodiv.style.display = "block";
144
}
145
//-->
146
</script>
147

    
148
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
149
<?php include("fbegin.inc"); ?>
150
<form action="services_dnsmasq.php" method="post" name="iform" id="iform">
151
<?php if ($input_errors) print_input_errors($input_errors); ?>
152
<?php if ($savemsg) print_info_box($savemsg); ?>
153
<?php if (is_subsystem_dirty('hosts')): ?><p>
154
<?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>
155
<?php endif; ?>
156
<table width="100%" border="0" cellpadding="6" cellspacing="0">
157
	<tr>
158
		<td colspan="2" valign="top" class="listtopic"><?=gettext("General DNS Forwarder Options");?></td>
159
	</tr>
160
	<tr>
161
		<td width="22%" valign="top" class="vncellreq"><?=gettext("Enable");?></td>
162
		<td width="78%" class="vtable"><p>
163
			<input name="enable" type="checkbox" id="enable" value="yes" <?php if ($pconfig['enable'] == "yes") echo "checked";?> onClick="enable_change(false)">
164
			<strong><?=gettext("Enable DNS forwarder");?><br>
165
			</strong></p></td>
166
		</tr>
167
	<tr>
168
		<td width="22%" valign="top" class="vncellreq"><?=gettext("DHCP Registration");?></td>
169
		<td width="78%" class="vtable"><p>
170
			<input name="regdhcp" type="checkbox" id="regdhcp" value="yes" <?php if ($pconfig['regdhcp'] == "yes") echo "checked";?>>
171
			<strong><?=gettext("Register DHCP leases in DNS forwarder");?><br>
172
			</strong><?php printf(gettext("If this option is set, then machines that specify".
173
			" their hostname when requesting a DHCP lease will be registered".
174
			" in the DNS forwarder, so that their name can be resolved.".
175
			" You should also set the domain in %sSystem:".
176
			" General setup%s to the proper value."),'<a href="system.php">','</a>')?></p>
177
		</td>
178
	</tr>
179
	<tr>
180
		<td width="22%" valign="top" class="vncellreq"><?=gettext("Static DHCP");?></td>
181
		<td width="78%" class="vtable"><p>
182
			<input name="regdhcpstatic" type="checkbox" id="regdhcpstatic" value="yes" <?php if ($pconfig['regdhcpstatic'] == "yes") echo "checked";?>>
183
			<strong><?=gettext("Register DHCP static mappings in DNS forwarder");?><br>
184
			</strong><?php printf(gettext("If this option is set, then DHCP static mappings will ".
185
					"be registered in the DNS forwarder, so that their name can be ".
186
					"resolved. You should also set the domain in %s".
187
					"System: General setup%s to the proper value."),'<a href="system.php">','</a>');?></p>
188
		</td>
189
	</tr>
190
	<tr>
191
		<td width="22%" valign="top" class="vncellreq"><?=gettext("Prefer DHCP");?></td>
192
		<td width="78%" class="vtable"><p>
193
			<input name="dhcpfirst" type="checkbox" id="dhcpfirst" value="yes" <?php if ($pconfig['dhcpfirst'] == "yes") echo "checked";?>>
194
			<strong><?=gettext("Resolve DHCP mappings first");?><br>
195
			</strong><?php printf(gettext("If this option is set, then DHCP mappings will ".
196
					"be resolved before the manual list of names below. This only ".
197
					"affects the name given for a reverse lookup (PTR)."));?></p>
198
		</td>
199
	</tr>
200
	<tr>
201
		<td rowspan="3" width="22%" valign="top" class="vncellreq"><?=gettext("DNS Query Forwarding");?></td>
202
		<td width="78%" class="vtable"><p>
203
			<input name="strict_order" type="checkbox" id="strict_order" value="yes" <?php if ($pconfig['strict_order'] == "yes") echo "checked";?>>
204
			<strong><?=gettext("Query DNS servers sequentially");?><br>
205
			</strong><?php printf(gettext("If this option is set, %s DNS Forwarder (dnsmasq) will ".
206
					"query the DNS servers sequentially in the order specified (<i>System - General Setup - DNS Servers</i>), ".
207
					"rather than all at once in parallel. ".
208
					""), $g['product_name']); ?></p>
209
		</td>
210
	</tr>
211
	<tr>
212
		<td width="78%" class="vtable"><p>
213
			<input name="domain_needed" type="checkbox" id="domain_needed" value="yes" <?php if ($pconfig['domain_needed'] == "yes") echo "checked";?>>
214
			<strong><?=gettext("Require domain");?><br>
215
			</strong><?php printf(gettext("If this option is set, %s DNS Forwarder (dnsmasq) will ".
216
					"not forward A or AAAA queries for plain names, without dots or domain parts, to upstream name servers.  ".
217
					"If the name is not known from /etc/hosts or DHCP then a \"not found\" answer is returned. ".
218
					""), $g['product_name']); ?></p>
219
		</td>
220
	</tr>
221
	<tr>
222
		<td width="78%" class="vtable"><p>
223
			<input name="no_private_reverse" type="checkbox" id="no_private_reverse" value="yes" <?php if ($pconfig['no_private_reverse'] == "yes") echo "checked";?>>
224
			<strong><?=gettext("Do not forward private reverse lookups");?><br>
225
			</strong><?php printf(gettext("If this option is set, %s DNS Forwarder (dnsmasq) will ".
226
					"not forward reverse DNS lookups (PTR) for private addresses (RFC 1918) to upstream name servers.  ".
227
					"Any entries in the Domain Overrides section forwarding private \"n.n.n.in-addr.arpa\" names to a specific server are still forwarded. ".
228
					"If the IP to name is not known from /etc/hosts, DHCP or a specific domain override then a \"not found\" answer is immediately returned. ".
229
					""), $g['product_name']); ?></p>
230
		</td>
231
	</tr>
232
	<tr>
233
		<td width="22%" valign="top" class="vncellreq"><?=gettext("Advanced");?></td>
234
		<td width="78%" class="vtable"><p>
235
			<div id="showadvbox" <?php if ($pconfig['custom_options']) echo "style='display:none'"; ?>>
236
				<input type="button" onClick="show_advanced_dns()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show advanced option");?></a>
237
			</div>
238
			<div id="showadv" <?php if (empty($pconfig['custom_options'])) echo "style='display:none'"; ?>>
239
				<strong><?=gettext("Advanced");?><br></strong>
240
				<textarea rows="6" cols="78" name="custom_options" id="custom_options"><?=htmlspecialchars($pconfig['custom_options']);?></textarea><br/>
241
				<?=gettext("Enter any additional options you would like to add to the dnsmasq configuration here, separated by a space or newline"); ?><br/>
242
			</div>
243
			</p>
244
		</td>
245
	</tr>
246
	<tr>
247
		<td colspan="2">
248
			<input name="submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" onclick="enable_change(true)">
249
		</td>
250
	</tr>
251
</table>
252

    
253
<p><span class="vexpl"><span class="red"><strong><?=gettext("Note:");?><br>
254
</strong></span><?php printf(gettext("If the DNS forwarder is enabled, the DHCP".
255
" service (if enabled) will automatically serve the LAN IP".
256
" address as a DNS server to DHCP clients so they will use".
257
" the forwarder. The DNS forwarder will use the DNS servers".
258
" entered in %sSystem: General setup%s".
259
" or those obtained via DHCP or PPP on WAN if the &quot;Allow".
260
" DNS server list to be overridden by DHCP/PPP on WAN&quot;".
261
" is checked. If you don't use that option (or if you use".
262
" a static IP address on WAN), you must manually specify at".
263
" least one DNS server on the %sSystem:".
264
"General setup%s page."),'<a href="system.php">','</a>','<a href="system.php">','</a>');?><br>
265
</span></p>
266

    
267
&nbsp;<br>
268
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tabcont">
269
<tr>
270
	<td colspan="5" valign="top" class="listtopic"><?=gettext("Host Overrides");?></td>
271
</tr>
272
<tr>
273
	<td><br/>
274
	<?=gettext("Entries in this section override individual results from the forwarders.");?>
275
	<?=gettext("Use these for changing DNS results or for adding custom DNS records.");?>
276
	</td>
277
</tr>
278
</table>
279
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tabcont sortable">
280
	<thead>
281
	<tr>
282
		<td width="20%" class="listhdrr"><?=gettext("Host");?></td>
283
		<td width="25%" class="listhdrr"><?=gettext("Domain");?></td>
284
		<td width="20%" class="listhdrr"><?=gettext("IP");?></td>
285
		<td width="25%" class="listhdr"><?=gettext("Description");?></td>
286
		<td width="10%" class="list">
287
			<table border="0" cellspacing="0" cellpadding="1">
288
				<tr>
289
					<td width="17"></td>
290
					<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>
291
				</tr>
292
			</table>
293
		</td>
294
	</tr>
295
	</thead>
296
	<tbody>
297
	<?php $i = 0; foreach ($a_hosts as $hostent): ?>
298
	<tr>
299
		<td class="listlr" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
300
			<?=strtolower($hostent['host']);?>&nbsp;
301
		</td>
302
		<td class="listr" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
303
			<?=strtolower($hostent['domain']);?>&nbsp;
304
		</td>
305
		<td class="listr" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
306
			<?=$hostent['ip'];?>&nbsp;
307
		</td>
308
		<td class="listbg" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
309
			<?=htmlspecialchars($hostent['descr']);?>&nbsp;
310
		</td>
311
		<td valign="middle" nowrap class="list">
312
			<table border="0" cellspacing="0" cellpadding="1">
313
				<tr>
314
					<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>
315
					<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>
316
				</tr>
317
			</table>
318
	</tr>
319
	<?php if ($hostent['aliases']['item'] && is_array($hostent['aliases']['item'])): ?>
320
	<?php foreach ($hostent['aliases']['item'] as $alias): ?>
321
	<tr>
322
		<td class="listlr" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
323
			<?=strtolower($alias['host']);?>&nbsp;
324
		</td>
325
		<td class="listr" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
326
			<?=strtolower($alias['domain']);?>&nbsp;
327
		</td>
328
		<td class="listr" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
329
			Alias for <?=$hostent['host'] ? $hostent['host'] . '.' . $hostent['domain'] : $hostent['domain'];?>&nbsp;
330
		</td>
331
		<td class="listbg" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
332
			<?=htmlspecialchars($alias['description']);?>&nbsp;
333
		</td>
334
		<td valign="middle" nowrap class="list">
335
			<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>
336
		</td>
337
	</tr>
338
	<?php endforeach; ?>
339
	<?php endif; ?>
340
	<?php $i++; endforeach; ?>
341
	</tbody>
342
	<tfoot>
343
	<tr>
344
		<td class="list" colspan="4"></td>
345
		<td class="list">
346
			<table border="0" cellspacing="0" cellpadding="1">
347
				<tr>
348
					<td width="17"></td>
349
					<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>
350
				</tr>
351
			</table>
352
		</td>
353
	</tr>
354
	</tfoot>
355
</table>
356
<br/>
357
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tabcont">
358
<tr>
359
	<td colspan="5" valign="top" class="listtopic"><?=gettext("Domain Overrides");?></td>
360
</tr>
361
<tr>
362
	<tr>
363
		<td><p><?=gettext("Entries in this area override an entire domain by specifying an".
364
		" authoritative DNS server to be queried for that domain.");?></p></td>
365
	</tr>
366
</tr>
367
</table>
368
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tabcont sortable">
369
	<thead>
370
	<tr>
371
		<td width="35%" class="listhdrr"><?=gettext("Domain");?></td>
372
		<td width="20%" class="listhdrr"><?=gettext("IP");?></td>
373
		<td width="35%" class="listhdr"><?=gettext("Description");?></td>
374
		<td width="10%" class="list">
375
			<table border="0" cellspacing="0" cellpadding="1">
376
				<tr>
377
					<td width="17" heigth="17"></td>
378
					<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>
379
				</tr>
380
			</table>
381
		</td>
382
	</tr>
383
	</thead>
384
	<tbody>
385
	<?php $i = 0; foreach ($a_domainOverrides as $doment): ?>
386
	<tr>
387
		<td class="listlr">
388
			<?=strtolower($doment['domain']);?>&nbsp;
389
		</td>
390
		<td class="listr">
391
			<?=$doment['ip'];?>&nbsp;
392
		</td>
393
		<td class="listbg">
394
			<?=htmlspecialchars($doment['descr']);?>&nbsp;
395
		</td>
396
		<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>
397
			&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>
398
	</tr>
399
	<?php $i++; endforeach; ?>
400
	</tbody>
401
	<tfoot>
402
	<tr>
403
		<td class="list" colspan="3"></td>
404
		<td class="list">
405
		<table border="0" cellspacing="0" cellpadding="1">
406
			<tr>
407
				<td width="17" heigth="17"></td>
408
				<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>
409
			</tr>
410
		</table>
411
		</td>
412
	</tr>
413
	</tfoot>
414
</table>
415
</form>
416
<script language="JavaScript">
417
<!--
418
enable_change(false);
419
//-->
420
</script>
421
<?php include("fend.inc"); ?>
422
</body>
423
</html>
(154-154/246)