Project

General

Profile

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

    
62
##|+PRIV
63
##|*IDENT=page-services-unbound
64
##|*NAME=Services: DNS Resolver page
65
##|*DESCR=Allow access to the 'Services: DNS Resolver' page.
66
##|*MATCH=services_unbound.php*
67
##|-PRIV
68

    
69
require_once("guiconfig.inc");
70
require_once("unbound.inc");
71
require_once("system.inc");
72

    
73
if (!is_array($config['unbound'])) {
74
	$config['unbound'] = array();
75
}
76

    
77
$a_unboundcfg =& $config['unbound'];
78

    
79
if (!is_array($config['unbound']['hosts'])) {
80
	$config['unbound']['hosts'] = array();
81
}
82

    
83
$a_hosts =& $config['unbound']['hosts'];
84

    
85
if (!is_array($config['unbound']['domainoverrides'])) {
86
	$config['unbound']['domainoverrides'] = array();
87
}
88

    
89
$a_domainOverrides = &$config['unbound']['domainoverrides'];
90

    
91
if (isset($config['unbound']['enable'])) {
92
	$pconfig['enable'] = true;
93
}
94
if (isset($config['unbound']['dnssec'])) {
95
	$pconfig['dnssec'] = true;
96
}
97
if (isset($config['unbound']['forwarding'])) {
98
	$pconfig['forwarding'] = true;
99
}
100
if (isset($config['unbound']['regdhcp'])) {
101
	$pconfig['regdhcp'] = true;
102
}
103
if (isset($config['unbound']['regdhcpstatic'])) {
104
	$pconfig['regdhcpstatic'] = true;
105
}
106
if (isset($config['unbound']['txtsupport'])) {
107
	$pconfig['txtsupport'] = true;
108
}
109

    
110
$pconfig['port'] = $config['unbound']['port'];
111
$pconfig['custom_options'] = base64_decode($config['unbound']['custom_options']);
112

    
113
if (empty($config['unbound']['active_interface'])) {
114
	$pconfig['active_interface'] = array();
115
} else {
116
	$pconfig['active_interface'] = explode(",", $config['unbound']['active_interface']);
117
}
118

    
119
if (empty($config['unbound']['outgoing_interface'])) {
120
	$pconfig['outgoing_interface'] = array();
121
} else {
122
	$pconfig['outgoing_interface'] = explode(",", $config['unbound']['outgoing_interface']);
123
}
124

    
125
if ($_POST) {
126
	$pconfig = $_POST;
127
	unset($input_errors);
128

    
129
	if ($_POST['apply']) {
130
		$retval = services_unbound_configure();
131
		$savemsg = get_std_save_message($retval);
132
		if ($retval == 0) {
133
			clear_subsystem_dirty('unbound');
134
		}
135
		/* Update resolv.conf in case the interface bindings exclude localhost. */
136
		system_resolvconf_generate();
137
		/* Start or restart dhcpleases when it's necessary */
138
		system_dhcpleases_configure();
139
	} else {
140
		if (isset($_POST['enable']) && isset($config['dnsmasq']['enable'])) {
141
			if ($_POST['port'] == $config['dnsmasq']['port']) {
142
				$input_errors[] = "The DNS Forwarder is enabled using this port. Choose a non-conflicting port, or disable the DNS Forwarder.";
143
			}
144
		}
145

    
146
		if (empty($_POST['active_interface'])) {
147
			$input_errors[] = "One or more Network Interfaces must be selected for binding.";
148
		} else if (!isset($config['system']['dnslocalhost']) && (!in_array("lo0", $_POST['active_interface']) && !in_array("all", $_POST['active_interface']))) {
149
			$input_errors[] = "This system is configured to use the DNS Resolver as its DNS server, so Localhost or All must be selected in Network Interfaces.";
150
		}
151

    
152
		if (empty($_POST['outgoing_interface'])) {
153
			$input_errors[] = "One or more Outgoing Network Interfaces must be selected.";
154
		}
155

    
156
		if ($_POST['port']) {
157
			if (is_port($_POST['port'])) {
158
				$a_unboundcfg['port'] = $_POST['port'];
159
			} else {
160
				$input_errors[] = gettext("You must specify a valid port number.");
161
			}
162
		} else if (isset($config['unbound']['port'])) {
163
			unset($config['unbound']['port']);
164
		}
165

    
166
		if (isset($_POST['enable'])) {
167
			$a_unboundcfg['enable'] = true;
168
		} else {
169
			unset($a_unboundcfg['enable']);
170
		}
171
		if (isset($_POST['dnssec'])) {
172
			$a_unboundcfg['dnssec'] = true;
173
		} else {
174
			unset($a_unboundcfg['dnssec']);
175
		}
176
		if (isset($_POST['forwarding'])) {
177
			$a_unboundcfg['forwarding'] = true;
178
		} else {
179
			unset($a_unboundcfg['forwarding']);
180
		}
181
		if (isset($_POST['regdhcp'])) {
182
			$a_unboundcfg['regdhcp'] = true;
183
		} else {
184
			unset($a_unboundcfg['regdhcp']);
185
		}
186
		if (isset($_POST['regdhcpstatic'])) {
187
			$a_unboundcfg['regdhcpstatic'] = true;
188
		} else {
189
			unset($a_unboundcfg['regdhcpstatic']);
190
		}
191
		if (isset($_POST['txtsupport'])) {
192
			$a_unboundcfg['txtsupport'] = true;
193
		} else {
194
			unset($a_unboundcfg['txtsupport']);
195
		}
196
		if (is_array($_POST['active_interface']) && !empty($_POST['active_interface'])) {
197
			$a_unboundcfg['active_interface'] = implode(",", $_POST['active_interface']);
198
		}
199

    
200
		if (is_array($_POST['outgoing_interface']) && !empty($_POST['outgoing_interface'])) {
201
			$a_unboundcfg['outgoing_interface'] = implode(",", $_POST['outgoing_interface']);
202
		}
203

    
204
		$a_unboundcfg['custom_options'] = base64_encode(str_replace("\r\n", "\n", $_POST['custom_options']));
205

    
206
		if (!$input_errors) {
207
			write_config("DNS Resolver configured.");
208
			mark_subsystem_dirty('unbound');
209
		}
210
	}
211
}
212

    
213
if ($_GET['act'] == "del") {
214
	if ($_GET['type'] == 'host') {
215
		if ($a_hosts[$_GET['id']]) {
216
			unset($a_hosts[$_GET['id']]);
217
			write_config();
218
			mark_subsystem_dirty('unbound');
219
			header("Location: services_unbound.php");
220
			exit;
221
		}
222
	} elseif ($_GET['type'] == 'doverride') {
223
		if ($a_domainOverrides[$_GET['id']]) {
224
			unset($a_domainOverrides[$_GET['id']]);
225
			write_config();
226
			mark_subsystem_dirty('unbound');
227
			header("Location: services_unbound.php");
228
			exit;
229
		}
230
	}
231
}
232

    
233
function build_if_list() {
234
	$interface_addresses = get_possible_listen_ips(true);
235
	$iflist = array('options' => array(), 'selected' => array());
236

    
237
	$iflist['options']['all']	= "All";
238
	if (empty($pconfig['interface']) || empty($pconfig['interface'][0]))
239
		array_push($iflist['selected'], "all");
240

    
241
	foreach ($interface_addresses as $laddr => $ldescr) {
242
		$iflist['options'][$laddr] = htmlspecialchars($ldescr);
243

    
244
		if ($pconfig['interface'] && in_array($laddr, $pconfig['interface']))
245
			array_push($iflist['selected'], $laddr);
246
	}
247

    
248
	unset($interface_addresses);
249

    
250
	return($iflist);
251
}
252

    
253
$closehead = false;
254
$pgtitle = array(gettext("Services"), gettext("DNS Resolver"));
255
$shortcut_section = "resolver";
256

    
257
include_once("head.inc");
258

    
259
if ($input_errors)
260
	print_input_errors($input_errors);
261

    
262
if ($savemsg)
263
	print_info_box($savemsg, 'success');
264

    
265
$tab_array = array();
266
$tab_array[] = array(gettext("General settings"), true, "services_unbound.php");
267
$tab_array[] = array(gettext("Advanced settings"), false, "services_unbound_advanced.php");
268
$tab_array[] = array(gettext("Access Lists"), false, "/services_unbound_acls.php");
269
display_top_tabs($tab_array, true);
270

    
271
require_once('classes/Form.class.php');
272

    
273
$form = new Form();
274

    
275
$section = new Form_Section('General DNS Resolver Options');
276

    
277
$section->addInput(new Form_Checkbox(
278
	'enable',
279
	'Enable',
280
	'Enable DNS resolver',
281
	$pconfig['enable']
282
));
283

    
284
$section->addInput(new Form_Input(
285
	'port',
286
	'Listen Port',
287
	'text',
288
	$pconfig['port']
289
))->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.');
290

    
291
$iflist = build_if_list();
292

    
293
$section->addInput(new Form_Select(
294
	'active_interface',
295
	'Network Interfaces',
296
	$iflist['selected'],
297
	$iflist['options'],
298
	true
299
))->setHelp('Interface IPs used by the DNS Resolver 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. ' .
300
			'The default behavior is to respond to queries on every available IPv4 and IPv6 address.');
301

    
302
$section->addInput(new Form_Select(
303
	'outgoing_interface',
304
	'Outgoing Network Interfaces',
305
	$iflist['selected'],
306
	$iflist['options'],
307
	true
308
))->setHelp('Utilize different network interface(s) that the DNS Resolver will use to send queries to authoritative servers and receive their replies. By default all interfaces are used.');
309

    
310
$section->addInput(new Form_Checkbox(
311
	'dnssec',
312
	'DNSSEC',
313
	'Enable DNSSEC Support',
314
	$pconfig['dnssec']
315
));
316

    
317
$section->addInput(new Form_Checkbox(
318
	'forwarding',
319
	'DNS Query Forwarding',
320
	'Enable Forwarding Mode',
321
	$pconfig['forwarding']
322
));
323

    
324
$section->addInput(new Form_Checkbox(
325
	'regdhcp',
326
	'DHCP Registration',
327
	'Register DHCP leases in the DNS Resolver',
328
	$pconfig['regdhcp']
329
))->setHelp(sprintf('If this option is set, then machines that specify their hostname when requesting a DHCP lease will be registered'.
330
					' in the DNS Resolver, so that their name can be resolved.'.
331
					' You should also set the domain in %sSystem: General setup%s to the proper value.','<a href="system.php">','</a>'));
332

    
333
$section->addInput(new Form_Checkbox(
334
	'regdhcpstatic',
335
	'Static DHCP',
336
	'Register DHCP static mappings in the DNS Resolver',
337
	$pconfig['regdhcpstatic']
338
))->setHelp(sprintf('If this option is set, then DHCP static mappings will be registered in the DNS Resolver, so that their name can be '.
339
					'resolved. You should also set the domain in %s'.
340
					'System: General setup%s to the proper value.','<a href="system.php">','</a>'));
341

    
342
$section->addInput(new Form_Checkbox(
343
	'txtsupport',
344
	'TXT Comment Support',
345
	'Register DHCP static mappings in the DNS Resolver',
346
	$pconfig['txtsupport']
347
))->setHelp('Any descriptions associated with Host entries and DHCP Static mappings will create a corresponding TXT record.');
348

    
349
$btnadvdns = new Form_Button(
350
	'btnadvdns',
351
	'Advanced'
352
);
353

    
354
$btnadvdns->removeClass('btn-primary')->addClass('btn-default btn-sm');
355

    
356
$section->addInput(new Form_StaticText(
357
	'Advanced',
358
	$btnadvdns . '&nbsp;' . 'Show advanced optionss'
359
));
360

    
361
$section->addInput(new Form_TextArea (
362
	'custom_options',
363
	'Custom options',
364
	$pconfig['custom_options']
365
))->setHelp('Enter any additional configuration parameters to add to the DNS Resolver configuration here, separated by a newline');
366

    
367
$form->add($section);
368
print($form);
369
?>
370
<script>
371
//<![CDATA[
372
events.push(function(){
373

    
374
	// If the enable checkbox is not checked, disable the next three checkboxes
375
	function disableDHCP() {
376
		var hide = ! $('#enable').prop('checked');
377

    
378
		disableInput('port', hide);
379
		disableInput('active_interface', hide);
380
		disableInput('outgoing_interface', hide);
381
		disableInput('regdhcpstatic', hide);
382
		disableInput('dnssec', hide);
383
		disableInput('forwarding', hide);
384
		disableInput('regdhcp', hide);
385
		disableInput('regdhcpstatic', hide);
386
		disableInput('txtsupport', hide);
387
		disableInput('btnadvdns', hide);
388
	}
389

    
390
	// Make the 'aditional options' button a plain button, not a submit button
391
	$("#btnadvdns").prop('type','button');
392

    
393
	// Un-hide aditional  controls
394
	$("#btnadvdns").click(function() {
395
		hideInput('custom_options', false);
396

    
397
	});
398

    
399
	// When 'enable' is clicked, diable/enable the following three checkboxes
400
	$('#enable').click(function() {
401
		disableDHCP();
402
	});
403

    
404
	// On initial load
405
	if($('#custom_options').val().length == 0) {
406
		hideInput('custom_options', true);
407
	}
408

    
409
	disableDHCP();
410

    
411
});
412
//]]>
413
</script>
414

    
415
<div class="panel panel-default">
416
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("Host Overrides")?></h2></div>
417
	<div class="panel-body table-responsive">
418
		<table class="table table-striped table-hover table-condensed">
419
			<thead>
420
				<tr>
421
					<th><?=gettext("Host")?></th>
422
					<th><?=gettext("Domain")?></th>
423
					<th><?=gettext("IP")?></th>
424
					<th><?=gettext("Description")?></th>
425
					<th></th>
426
				</tr>
427
			</thead>
428
			<tbody>
429
<?php
430
$i = 0;
431
foreach ($a_hosts as $hostent):
432
?>
433
				<tr>
434
					<td>
435
						<?=strtolower($hostent['host'])?>
436
					</td>
437
					<td>
438
						<?=strtolower($hostent['domain'])?>
439
					</td>
440
					<td>
441
						<?=$hostent['ip']?>&nbsp;
442
					</td>
443
					<td>
444
						<?=htmlspecialchars($hostent['descr'])?>
445
					</td>
446
					<td>
447
						<a class="fa fa-pencil"	title="<?=gettext('Edit host override')?>" href="services_unbound_host_edit.php?id=<?=$i?>"></a>
448
						<a class="fa fa-trash"	title="<?=gettext('Delete host override')?>" href="services_unbound.php?type=host&amp;act=del&amp;id=<?=$i?>"></a>
449
					</td>
450
				</tr>
451

    
452
<?php
453
	if ($hostent['aliases']['item'] && is_array($hostent['aliases']['item'])):
454
		foreach ($hostent['aliases']['item'] as $alias):
455
?>
456
				<tr>
457
					<td>
458
						<?=strtolower($alias['host'])?>
459
					</td>
460
					<td>
461
						<?=strtolower($alias['domain'])?>
462
					</td>
463
					<td>
464
						Alias for <?=$hostent['host'] ? $hostent['host'] . '.' . $hostent['domain'] : $hostent['domain']?>
465
					</td>
466
					<td>
467
						<?=htmlspecialchars($alias['description'])?>
468
					</td>
469
					<td>
470
						<a a class="fa fa-pencil"	title="<?=gettext('Edit host override')?>" 	href="services_unbound_host_edit.php?id=<?=$i?>"></a>
471
					</td>
472
				</tr>
473
<?php
474
		endforeach;
475
	endif;
476
	$i++;
477
endforeach;
478
?>
479
			</tbody>
480
		</table>
481
	</div>
482
</div>
483

    
484
<nav class="action-buttons">
485
	<a href="services_unbound_host_edit.php" class="btn btn-sm btn-success">
486
		<i class="fa fa-plus icon-embed-btn"></i>
487
		<?=gettext('Add')?>
488
	</a>
489
</nav>
490

    
491
<div class="panel panel-default">
492
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("Domain Overrides")?></h2></div>
493
	<div class="panel-body table-responsive">
494
		<table class="table table-striped table-hover table-condensed">
495
			<thead>
496
				<tr>
497
					<th><?=gettext("Domain")?></th>
498
					<th><?=gettext("IP")?></th>
499
					<th><?=gettext("Description")?></th>
500
					<th></th>
501
				</tr>
502
			</thead>
503

    
504
			<tbody>
505
<?php
506
$i = 0;
507
foreach ($a_domainOverrides as $doment):
508
?>
509
				<tr>
510
					<td>
511
						<?=strtolower($doment['domain'])?>&nbsp;
512
					</td>
513
					<td>
514
						<?=$doment['ip']?>&nbsp;
515
					</td>
516
					<td>
517
						<?=htmlspecialchars($doment['descr'])?>&nbsp;
518
					</td>
519
					<td>
520
						<a class="fa fa-pencil"	title="<?=gettext('Edit domain override')?>" href="services_unbound_domainoverride_edit.php?id=<?=$i?>"></a>
521
						<a class="fa fa-trash"	title="<?=gettext('Delete domain override')?>" href="services_unbound.php?act=del&amp;type=doverride&amp;id=<?=$i?>"></a>
522
					</td>
523
				</tr>
524
<?php
525
	$i++;
526
endforeach;
527
?>
528
			</tbody>
529
		</table>
530
	</div>
531
</div>
532

    
533
<nav class="action-buttons">
534
	<a href="services_unbound_domainoverride_edit.php" class="btn btn-sm btn-success">
535
		<i class="fa fa-plus icon-embed-btn"></i>
536
		<?=gettext('Add')?>
537
	</a>
538
</nav>
539

    
540
<div id="infoblock">
541
	<?=print_info_box(sprintf(gettext("If the DNS Resolver is enabled, the DHCP".
542
		" service (if enabled) will automatically serve the LAN IP".
543
		" address as a DNS server to DHCP clients so they will use".
544
		" the DNS Resolver. If Forwarding, is enabled, the DNS Resolver will use the DNS servers".
545
		" entered in %sSystem: General setup%s".
546
		" or those obtained via DHCP or PPP on WAN if the &quot;Allow".
547
		" DNS server list to be overridden by DHCP/PPP on WAN&quot;".
548
		" is checked."),'<a href="system.php">','</a>'), info)?>
549
</div>
550
<?php include("foot.inc");
(152-152/234)