Project

General

Profile

Download (16.5 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	services_dnsmasq.php
5
*/
6
/* ====================================================================
7
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
8
 *  Copyright (c)  2003-2004 Bob Zoller <bob@kludgebox.com> and Manuel Kasper <mk@neon1.net
9
 *
10
 *  Some or all of this file is based on the m0n0wall project which is
11
 *  Copyright (c)  2004 Manuel Kasper (BSD 2 clause)
12
 *
13
 *	Redistribution and use in source and binary forms, with or without modification,
14
 *	are permitted provided that the following conditions are met:
15
 *
16
 *	1. Redistributions of source code must retain the above copyright notice,
17
 *		this list of conditions and the following disclaimer.
18
 *
19
 *	2. Redistributions in binary form must reproduce the above copyright
20
 *		notice, this list of conditions and the following disclaimer in
21
 *		the documentation and/or other materials provided with the
22
 *		distribution.
23
 *
24
 *	3. All advertising materials mentioning features or use of this software
25
 *		must display the following acknowledgment:
26
 *		"This product includes software developed by the pfSense Project
27
 *		 for use in the pfSense software distribution. (http://www.pfsense.org/).
28
 *
29
 *	4. The names "pfSense" and "pfSense Project" must not be used to
30
 *		 endorse or promote products derived from this software without
31
 *		 prior written permission. For written permission, please contact
32
 *		 coreteam@pfsense.org.
33
 *
34
 *	5. Products derived from this software may not be called "pfSense"
35
 *		nor may "pfSense" appear in their names without prior written
36
 *		permission of the Electric Sheep Fencing, LLC.
37
 *
38
 *	6. Redistributions of any form whatsoever must retain the following
39
 *		acknowledgment:
40
 *
41
 *	"This product includes software developed by the pfSense Project
42
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
43
 *
44
 *	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
45
 *	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
47
 *	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
48
 *	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
49
 *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
50
 *	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
51
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
53
 *	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54
 *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
55
 *	OF THE POSSIBILITY OF SUCH DAMAGE.
56
 *
57
 *	====================================================================
58
 *
59
 */
60
/*
61
	pfSense_MODULE: dnsforwarder
62
*/
63

    
64
##|+PRIV
65
##|*IDENT=page-services-dnsforwarder
66
##|*NAME=Services: DNS Forwarder page
67
##|*DESCR=Allow access to the 'Services: DNS Forwarder' page.
68
##|*MATCH=services_dnsmasq.php*
69
##|-PRIV
70

    
71
require("guiconfig.inc");
72
require_once("functions.inc");
73
require_once("filter.inc");
74
require_once("shaper.inc");
75
require_once("system.inc");
76

    
77
$pconfig['enable'] = isset($config['dnsmasq']['enable']);
78
$pconfig['regdhcp'] = isset($config['dnsmasq']['regdhcp']);
79
$pconfig['regdhcpstatic'] = isset($config['dnsmasq']['regdhcpstatic']);
80
$pconfig['dhcpfirst'] = isset($config['dnsmasq']['dhcpfirst']);
81
$pconfig['strict_order'] = isset($config['dnsmasq']['strict_order']);
82
$pconfig['domain_needed'] = isset($config['dnsmasq']['domain_needed']);
83
$pconfig['no_private_reverse'] = isset($config['dnsmasq']['no_private_reverse']);
84
$pconfig['port'] = $config['dnsmasq']['port'];
85
$pconfig['custom_options'] = $config['dnsmasq']['custom_options'];
86

    
87
$pconfig['strictbind'] = isset($config['dnsmasq']['strictbind']);
88
if (!empty($config['dnsmasq']['interface'])) {
89
	$pconfig['interface'] = explode(",", $config['dnsmasq']['interface']);
90
} else {
91
	$pconfig['interface'] = array();
92
}
93

    
94
if (!is_array($config['dnsmasq']['hosts'])) {
95
	$config['dnsmasq']['hosts'] = array();
96
}
97

    
98
if (!is_array($config['dnsmasq']['domainoverrides'])) {
99
	$config['dnsmasq']['domainoverrides'] = array();
100
}
101

    
102
$a_hosts = &$config['dnsmasq']['hosts'];
103
$a_domainOverrides = &$config['dnsmasq']['domainoverrides'];
104

    
105
if ($_POST) {
106
	$pconfig = $_POST;
107
	unset($input_errors);
108

    
109
	$config['dnsmasq']['enable'] = ($_POST['enable']) ? true : false;
110
	$config['dnsmasq']['regdhcp'] = ($_POST['regdhcp']) ? true : false;
111
	$config['dnsmasq']['regdhcpstatic'] = ($_POST['regdhcpstatic']) ? true : false;
112
	$config['dnsmasq']['dhcpfirst'] = ($_POST['dhcpfirst']) ? true : false;
113
	$config['dnsmasq']['strict_order'] = ($_POST['strict_order']) ? true : false;
114
	$config['dnsmasq']['domain_needed'] = ($_POST['domain_needed']) ? true : false;
115
	$config['dnsmasq']['no_private_reverse'] = ($_POST['no_private_reverse']) ? true : false;
116
	$config['dnsmasq']['custom_options'] = str_replace("\r\n", "\n", $_POST['custom_options']);
117
	$config['dnsmasq']['strictbind'] = ($_POST['strictbind']) ? true : false;
118

    
119
	if (isset($_POST['enable']) && isset($config['unbound']['enable'])) {
120
		if ($_POST['port'] == $config['unbound']['port']) {
121
			$input_errors[] = "The DNS Resolver is enabled using this port. Choose a non-conflicting port, or disable DNS Resolver.";
122
		}
123
	}
124

    
125
	if ($_POST['port']) {
126
		if (is_port($_POST['port'])) {
127
			$config['dnsmasq']['port'] = $_POST['port'];
128
		} else {
129
			$input_errors[] = gettext("You must specify a valid port number");
130
		}
131
	} else if (isset($config['dnsmasq']['port'])) {
132
		unset($config['dnsmasq']['port']);
133
	}
134

    
135
	if (is_array($_POST['interface'])) {
136
		$config['dnsmasq']['interface'] = implode(",", $_POST['interface']);
137
	} elseif (isset($config['dnsmasq']['interface'])) {
138
		unset($config['dnsmasq']['interface']);
139
	}
140

    
141
	if ($config['dnsmasq']['custom_options']) {
142
		$args = '';
143
		foreach (preg_split('/\s+/', $config['dnsmasq']['custom_options']) as $c) {
144
			$args .= escapeshellarg("--{$c}") . " ";
145
		}
146
		exec("/usr/local/sbin/dnsmasq --test $args", $output, $rc);
147
		if ($rc != 0) {
148
			$input_errors[] = gettext("Invalid custom options");
149
		}
150
	}
151

    
152
	if (!$input_errors) {
153
		write_config();
154

    
155
		$retval = 0;
156
		$retval = services_dnsmasq_configure();
157
		$savemsg = get_std_save_message($retval);
158

    
159
		// Reload filter (we might need to sync to CARP hosts)
160
		filter_configure();
161
		/* Update resolv.conf in case the interface bindings exclude localhost. */
162
		system_resolvconf_generate();
163
		/* Start or restart dhcpleases when it's necessary */
164
		system_dhcpleases_configure();
165

    
166
		if ($retval == 0) {
167
			clear_subsystem_dirty('hosts');
168
		}
169
	}
170
}
171

    
172
if ($_GET['act'] == "del") {
173
	if ($_GET['type'] == 'host') {
174
		if ($a_hosts[$_GET['id']]) {
175
			unset($a_hosts[$_GET['id']]);
176
			write_config();
177
			mark_subsystem_dirty('hosts');
178
			header("Location: services_dnsmasq.php");
179
			exit;
180
		}
181
	}
182
	elseif ($_GET['type'] == 'doverride') {
183
		if ($a_domainOverrides[$_GET['id']]) {
184
			unset($a_domainOverrides[$_GET['id']]);
185
			write_config();
186
			mark_subsystem_dirty('hosts');
187
			header("Location: services_dnsmasq.php");
188
			exit;
189
		}
190
	}
191
}
192

    
193
function build_if_list() {
194
	$interface_addresses = get_possible_listen_ips(true);
195
	$iflist = array('options' => array(), 'selected' => array());
196

    
197
	$iflist['options'][""]	= "All";
198
	if (empty($pconfig['interface']) || empty($pconfig['interface'][0]))
199
		array_push($iflist['selected'], "");
200

    
201
	foreach ($interface_addresses as $laddr => $ldescr) {
202
		$iflist['options'][$laddr] = htmlspecialchars($ldescr);
203

    
204
		if ($pconfig['interface'] && in_array($laddr, $pconfig['interface']))
205
			array_push($iflist['selected'], $laddr);
206
	}
207

    
208
	unset($interface_addresses);
209

    
210
	return($iflist);
211
}
212

    
213
$closehead = false;
214
$pgtitle = array(gettext("Services"), gettext("DNS Forwarder"));
215
$shortcut_section = "forwarder";
216
include("head.inc");
217

    
218
if ($input_errors)
219
	print_input_errors($input_errors);
220

    
221
if ($savemsg)
222
	print_info_box($savemsg, 'success');
223

    
224
if (is_subsystem_dirty('hosts'))
225
	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."));
226

    
227
require_once('classes/Form.class.php');
228

    
229
$form = new Form();
230

    
231
$section = new Form_Section('General DNS Forwarder Options');
232

    
233
$section->addInput(new Form_Checkbox(
234
	'enable',
235
	'Enable',
236
	'Enable DNS forwarder',
237
	$pconfig['enable']
238
))->toggles('.toggle-dhcp', 'disable');
239

    
240
$section->addInput(new Form_Checkbox(
241
	'regdhcp',
242
	'DHCP Registration',
243
	'Register DHCP leases in DNS forwarder',
244
	$pconfig['regdhcp']
245
))->setHelp(sprintf("If this option is set, then machines that specify".
246
			" their hostname when requesting a DHCP lease will be registered".
247
			" in the DNS forwarder, so that their name can be resolved.".
248
			" You should also set the domain in %sSystem:".
249
			" General setup%s to the proper value.",'<a href="system.php">','</a>'))
250
	->addClass('toggle-dhcp');
251

    
252
$section->addInput(new Form_Checkbox(
253
	'regdhcpstatic',
254
	'Static DHCP',
255
	'Register DHCP static mappings in DNS forwarder',
256
	$pconfig['regdhcpstatic']
257
))->setHelp(sprintf("If this option is set, then DHCP static mappings will ".
258
					"be registered in the DNS forwarder, so that their name can be ".
259
					"resolved. You should also set the domain in %s".
260
					"System: General setup%s to the proper value.",'<a href="system.php">','</a>'))
261
	->addClass('toggle-dhcp');
262

    
263
$section->addInput(new Form_Checkbox(
264
	'dhcpfirst',
265
	'Prefer DHCP',
266
	'Resolve DHCP mappings first',
267
	$pconfig['dhcpfirst']
268
))->setHelp(sprintf("If this option is set, then DHCP mappings will ".
269
					"be resolved before the manual list of names below. This only ".
270
					"affects the name given for a reverse lookup (PTR)."))
271
	->addClass('toggle-dhcp');
272

    
273
$group = new Form_Group('DNS Query Forwarding');
274

    
275
$group->add(new Form_Checkbox(
276
	'strict_order',
277
	'DNS Query Forwarding',
278
	'Query DNS servers sequentially',
279
	$pconfig['strict_order']
280
))->setHelp(sprintf("If this option is set, %s DNS Forwarder (dnsmasq) will ".
281
					"query the DNS servers sequentially in the order specified (<i>System - General Setup - DNS Servers</i>), ".
282
					"rather than all at once in parallel. ", $g['product_name']));
283

    
284
$group->add(new Form_Checkbox(
285
	'domain_needed',
286
	null,
287
	'Require domain',
288
	$pconfig['domain_needed']
289
))->setHelp(sprintf("If this option is set, %s DNS Forwarder (dnsmasq) will ".
290
					"not forward A or AAAA queries for plain names, without dots or domain parts, to upstream name servers.	 ".
291
					"If the name is not known from /etc/hosts or DHCP then a \"not found\" answer is returned. ", $g['product_name']));
292

    
293
$group->add(new Form_Checkbox(
294
	'no_private_reverse',
295
	null,
296
	'Do not forward private reverse lookups',
297
	$pconfig['no_private_reverse']
298
))->setHelp(sprintf("If this option is set, %s DNS Forwarder (dnsmasq) will ".
299
					"not forward reverse DNS lookups (PTR) for private addresses (RFC 1918) to upstream name servers.  ".
300
					"Any entries in the Domain Overrides section forwarding private \"n.n.n.in-addr.arpa\" names to a specific server are still forwarded. ".
301
					"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. ", $g['product_name']));
302

    
303
$section->add($group);
304

    
305
$section->addInput(new Form_Input(
306
	'port',
307
	'Listen Port',
308
	'number',
309
	$pconfig['port'],
310
	['placeholder' => '53']
311
))->setHelp('The port used for responding to DNS queries. It should normally be left blank unless another service needs to bind to TCP/UDP port 53.');
312

    
313
$iflist = build_if_list();
314

    
315
$section->addInput(new Form_Select(
316
	'interface',
317
	'Interfaces',
318
	$iflist['selected'],
319
	$iflist['options'],
320
	true
321
))->setHelp('Interface IPs used by the DNS Forwarder for responding to queries from clients. If an interface has both IPv4 and IPv6 IPs, both are used. Queries to other interface IPs not selected below are discarded. ' .
322
			'The default behavior is to respond to queries on every available IPv4 and IPv6 address.');
323

    
324
$section->addInput(new Form_Checkbox(
325
	'strictbind',
326
	'Strict binding',
327
	'Strict interface binding',
328
	$pconfig['strictbind']
329
))->setHelp('If this option is set, the DNS forwarder will only bind to the interfaces containing the IP addresses selected above, ' .
330
					'rather than binding to all interfaces and discarding queries to other addresses.' . '<br /><br />' .
331
					'This option does NOT work with IPv6. If set, dnsmasq will not bind to IPv6 addresses.');
332

    
333
$section->addInput(new Form_TextArea(
334
	'custom_options',
335
	'Custom options',
336
	$pconfig['custom_options']
337
))->setHelp('Enter any additional options you would like to add to the dnsmasq configuration here, separated by a space or newline')
338
	->addClass('advanced');
339

    
340
$form->add($section);
341
print($form);
342

    
343
print_info_box(sprintf("If the DNS forwarder is enabled, the DHCP".
344
	" service (if enabled) will automatically serve the LAN IP".
345
	" address as a DNS server to DHCP clients so they will use".
346
	" the forwarder. The DNS forwarder will use the DNS servers".
347
	" entered in %sSystem: General setup%s".
348
	" or those obtained via DHCP or PPP on WAN if the &quot;Allow".
349
	" DNS server list to be overridden by DHCP/PPP on WAN&quot;".
350
	" is checked. If you don't use that option (or if you use".
351
	" a static IP address on WAN), you must manually specify at".
352
	" least one DNS server on the %sSystem:".
353
	"General setup%s page.",'<a href="system.php">','</a>','<a href="system.php">','</a>'), info);
354
?>
355

    
356
<div class="panel panel-default">
357
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("Host Overrides")?></h2></div>
358
	<div class="panel-body table-responsive">
359
		<table class="table table-striped table-hover table-condensed">
360
			<thead>
361
				<tr>
362
					<th><?=gettext("Host")?></th>
363
					<th><?=gettext("Domain")?></th>
364
					<th><?=gettext("IP")?></th>
365
					<th><?=gettext("Description")?></th>
366
					<th></th>
367
				</tr>
368
			</thead>
369
			<tbody>
370
<?php
371
foreach ($a_hosts as $i => $hostent):
372
?>
373
				<tr>
374
					<td>
375
						<?=strtolower($hostent['host'])?>
376
					</td>
377
					<td>
378
						<?=strtolower($hostent['domain'])?>
379
					</td>
380
					<td>
381
						<?=$hostent['ip']?>
382
					</td>
383
					<td>
384
						<?=htmlspecialchars($hostent['descr'])?>
385
					</td>
386
					<td>
387
						<a class="fa fa-pencil"	title="<?=gettext('Edit host override')?>" 	href="services_dnsmasq_edit.php?id=<?=$i?>"></a>
388
						<a class="fa fa-trash"	title="<?=gettext('Delete host override')?>"	href="services_dnsmasq.php?type=host&amp;act=del&amp;id=<?=$i?>"></a>
389
					</td>
390
				</tr>
391

    
392
<?php
393
	if ($hostent['aliases']['item'] && is_array($hostent['aliases']['item'])):
394
		foreach ($hostent['aliases']['item'] as $i => $alias):
395
?>
396
				<tr>
397
					<td>
398
						<?=strtolower($alias['host'])?>
399
					</td>
400
					<td>
401
						<?=strtolower($alias['domain'])?>
402
					</td>
403
					<td>
404
						Alias for <?=$hostent['host'] ? $hostent['host'] . '.' . $hostent['domain'] : $hostent['domain']?>
405
					</td>
406
					<td>
407
						<?=htmlspecialchars($alias['description'])?>
408
					</td>
409
					<td>
410
						<a class="fa fa-pencil"	title="<?=gettext('Edit host override')?>" 	href="services_dnsmasq_edit.php?id=<?=$i?>"></a>
411
					</td>
412
				</tr>
413
<?php
414
		endforeach;
415
	endif;
416
endforeach;
417
?>
418
			</tbody>
419
		</table>
420
	</div>
421
</div>
422

    
423
<nav class="action-buttons">
424
	<a href="services_dnsmasq_edit.php" class="btn btn-sm btn-success btn-sm">
425
		<i class="fa fa-plus icon-embed-btn"></i>
426
		<?=gettext('Add')?>
427
	</a>
428
</nav>
429

    
430
<?php
431
print_info_box(gettext("Entries in this section override individual results from the forwarders.") .
432
				gettext("Use these for changing DNS results or for adding custom DNS records."), info);
433
?>
434

    
435
<div class="panel panel-default">
436
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("Domain Overrides")?></h2></div>
437
	<div class="panel-body table-responsive">
438
		<table class="table table-striped table-hover table-condensed">
439
			<thead>
440
				<tr>
441
					<th><?=gettext("Domain")?></th>
442
					<th><?=gettext("IP")?></th>
443
					<th><?=gettext("Description")?></th>
444
					<th></th>
445
				</tr>
446
			</thead>
447

    
448
			<tbody>
449
<?php
450
foreach ($a_domainOverrides as $i => $doment):
451
?>
452
				<tr>
453
					<td>
454
						<?=strtolower($doment['domain'])?>
455
					</td>
456
					<td>
457
						<?=$doment['ip']?>
458
					</td>
459
					<td>
460
						<?=htmlspecialchars($doment['descr'])?>
461
					</td>
462
					<td>
463
						<a class="fa fa-pencil"	title="<?=gettext('Edit domain override')?>" href="services_dnsmasq_domainoverride_edit.php?id=<?=$i?>"></a>
464
						<a class="fa fa-trash"	title="<?=gettext('Delete domain override')?>" href="services_dnsmasq.php?act=del&amp;type=doverride&amp;id=<?=$i?>"></a>
465
					</td>
466
				</tr>
467
<?php
468
endforeach;
469
?>
470
			</tbody>
471
		</table>
472
	</div>
473
</div>
474

    
475
<nav class="action-buttons">
476
	<a href="services_dnsmasq_domainoverride_edit.php" class="btn btn-sm btn-success btn-sm">
477
		<i class="fa fa-plus icon-embed-btn"></i>
478
		<?=gettext('Add')?>
479
	</a>
480
</nav>
481

    
482
<?php
483
print_info_box(gettext("Entries in this area override an entire domain, and subdomains, by specifying an".
484
						" authoritative DNS server to be queried for that domain."), info);
485

    
486
include("foot.inc");
(138-138/234)