Project

General

Profile

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

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

    
67
require_once("guiconfig.inc");
68
require_once("unbound.inc");
69
require_once("system.inc");
70

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

    
75
$a_unboundcfg =& $config['unbound'];
76

    
77
if (!is_array($a_unboundcfg['hosts'])) {
78
	$a_unboundcfg['hosts'] = array();
79
}
80

    
81
$a_hosts =& $a_unboundcfg['hosts'];
82

    
83
if (!is_array($a_unboundcfg['domainoverrides'])) {
84
	$a_unboundcfg['domainoverrides'] = array();
85
}
86

    
87
$a_domainOverrides = &$a_unboundcfg['domainoverrides'];
88

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

    
108
$pconfig['port'] = $a_unboundcfg['port'];
109
$pconfig['custom_options'] = base64_decode($a_unboundcfg['custom_options']);
110

    
111
if (empty($a_unboundcfg['active_interface'])) {
112
	$pconfig['active_interface'] = array();
113
} else {
114
	$pconfig['active_interface'] = explode(",", $a_unboundcfg['active_interface']);
115
}
116

    
117
if (empty($a_unboundcfg['outgoing_interface'])) {
118
	$pconfig['outgoing_interface'] = array();
119
} else {
120
	$pconfig['outgoing_interface'] = explode(",", $a_unboundcfg['outgoing_interface']);
121
}
122

    
123
if ($_POST) {
124
	if ($_POST['apply']) {
125
		$retval = services_unbound_configure();
126
		$savemsg = get_std_save_message($retval);
127
		if ($retval == 0) {
128
			clear_subsystem_dirty('unbound');
129
		}
130
		/* Update resolv.conf in case the interface bindings exclude localhost. */
131
		system_resolvconf_generate();
132
		/* Start or restart dhcpleases when it's necessary */
133
		system_dhcpleases_configure();
134
	} else {
135
		$pconfig = $_POST;
136
		unset($input_errors);
137

    
138
		if (isset($pconfig['enable']) && isset($config['dnsmasq']['enable'])) {
139
			if ($pconfig['port'] == $config['dnsmasq']['port']) {
140
				$input_errors[] = "The DNS Forwarder is enabled using this port. Choose a non-conflicting port, or disable the DNS Forwarder.";
141
			}
142
		}
143

    
144
		if (empty($pconfig['active_interface'])) {
145
			$input_errors[] = "One or more Network Interfaces must be selected for binding.";
146
		} else if (!isset($config['system']['dnslocalhost']) && (!in_array("lo0", $pconfig['active_interface']) && !in_array("all", $pconfig['active_interface']))) {
147
			$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.";
148
		}
149

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

    
154
		if ($pconfig['port'] && !is_port($pconfig['port'])) {
155
			$input_errors[] = gettext("You must specify a valid port number.");
156
		}
157

    
158
		if (is_array($pconfig['active_interface']) && !empty($pconfig['active_interface'])) {
159
			$display_active_interface = $pconfig['active_interface'];
160
			$pconfig['active_interface'] = implode(",", $pconfig['active_interface']);
161
		}
162

    
163
		$display_custom_options = $pconfig['custom_options'];
164
		$pconfig['custom_options'] = base64_encode(str_replace("\r\n", "\n", $pconfig['custom_options']));
165

    
166
		if (is_array($pconfig['outgoing_interface']) && !empty($pconfig['outgoing_interface'])) {
167
			$display_outgoing_interface = $pconfig['outgoing_interface'];
168
			$pconfig['outgoing_interface'] = implode(",", $pconfig['outgoing_interface']);
169
		}
170

    
171
		$test_output = array();
172
		if (test_unbound_config($pconfig, $test_output)) {
173
			$input_errors[] = gettext("The generated config file cannot be parsed by unbound. Please correct the following errors:");
174
			$input_errors = array_merge($input_errors, $test_output);
175
		}
176

    
177
		if (!$input_errors) {
178
			$a_unboundcfg['enable'] = isset($pconfig['enable']);
179
			$a_unboundcfg['dnssec'] = isset($pconfig['dnssec']);
180
			$a_unboundcfg['forwarding'] = isset($pconfig['forwarding']);
181
			$a_unboundcfg['regdhcp'] = isset($pconfig['regdhcp']);
182
			$a_unboundcfg['regdhcpstatic'] = isset($pconfig['regdhcpstatic']);
183
			$a_unboundcfg['txtsupport'] = isset($pconfig['txtsupport']);
184
			$a_unboundcfg['active_interface'] = $pconfig['active_interface'];
185
			$a_unboundcfg['outgoing_interface'] = $pconfig['outgoing_interface'];
186
			$a_unboundcfg['custom_options'] = $pconfig['custom_options'];
187

    
188
			write_config("DNS Resolver configured.");
189
			mark_subsystem_dirty('unbound');
190
		}
191

    
192
		$pconfig['active_interface'] = $display_active_interface;
193
		$pconfig['outgoing_interface'] = $display_outgoing_interface;
194
		$pconfig['custom_options'] = $display_custom_options;
195
	}
196
}
197

    
198
if ($_GET['act'] == "del") {
199
	if ($_GET['type'] == 'host') {
200
		if ($a_hosts[$_GET['id']]) {
201
			unset($a_hosts[$_GET['id']]);
202
			write_config();
203
			mark_subsystem_dirty('unbound');
204
			header("Location: services_unbound.php");
205
			exit;
206
		}
207
	} elseif ($_GET['type'] == 'doverride') {
208
		if ($a_domainOverrides[$_GET['id']]) {
209
			unset($a_domainOverrides[$_GET['id']]);
210
			write_config();
211
			mark_subsystem_dirty('unbound');
212
			header("Location: services_unbound.php");
213
			exit;
214
		}
215
	}
216
}
217

    
218
function build_if_list($selectedifs) {
219
	$interface_addresses = get_possible_listen_ips(true);
220
	$iflist = array('options' => array(), 'selected' => array());
221

    
222
	$iflist['options']['all']	= "All";
223
	if (empty($selectedifs) || empty($selectedifs[0]) || in_array("all", $selectedifs)) {
224
		array_push($iflist['selected'], "all");
225
	}
226

    
227
	foreach ($interface_addresses as $laddr => $ldescr) {
228
		$iflist['options'][$laddr] = htmlspecialchars($ldescr);
229

    
230
		if ($selectedifs && in_array($laddr, $selectedifs))
231
			array_push($iflist['selected'], $laddr);
232
	}
233

    
234
	unset($interface_addresses);
235

    
236
	return($iflist);
237
}
238

    
239
$closehead = false;
240
$pgtitle = array(gettext("Services"), gettext("DNS Resolver"));
241
$shortcut_section = "resolver";
242

    
243
include_once("head.inc");
244

    
245
if ($input_errors)
246
	print_input_errors($input_errors);
247

    
248
if ($savemsg)
249
	print_info_box($savemsg, 'success');
250

    
251
if (is_subsystem_dirty('unbound')) {
252
	print_info_box_np(gettext("The configuration of the DNS Resolver has been changed. You must apply changes for them to take effect."));
253
}
254

    
255
$tab_array = array();
256
$tab_array[] = array(gettext("General settings"), true, "services_unbound.php");
257
$tab_array[] = array(gettext("Advanced settings"), false, "services_unbound_advanced.php");
258
$tab_array[] = array(gettext("Access Lists"), false, "/services_unbound_acls.php");
259
display_top_tabs($tab_array, true);
260

    
261
require_once('classes/Form.class.php');
262

    
263
$form = new Form();
264

    
265
$section = new Form_Section('General DNS Resolver Options');
266

    
267
$section->addInput(new Form_Checkbox(
268
	'enable',
269
	'Enable',
270
	'Enable DNS resolver',
271
	$pconfig['enable']
272
));
273

    
274
$section->addInput(new Form_Input(
275
	'port',
276
	'Listen Port',
277
	'text',
278
	$pconfig['port']
279
))->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.');
280

    
281
$activeiflist = build_if_list($pconfig['active_interface']);
282

    
283
$section->addInput(new Form_Select(
284
	'active_interface',
285
	'Network Interfaces',
286
	$activeiflist['selected'],
287
	$activeiflist['options'],
288
	true
289
))->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. ' .
290
			'The default behavior is to respond to queries on every available IPv4 and IPv6 address.');
291

    
292
$outiflist = build_if_list($pconfig['outgoing_interface']);
293

    
294
$section->addInput(new Form_Select(
295
	'outgoing_interface',
296
	'Outgoing Network Interfaces',
297
	$outiflist['selected'],
298
	$outiflist['options'],
299
	true
300
))->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.');
301

    
302
$section->addInput(new Form_Checkbox(
303
	'dnssec',
304
	'DNSSEC',
305
	'Enable DNSSEC Support',
306
	$pconfig['dnssec']
307
));
308

    
309
$section->addInput(new Form_Checkbox(
310
	'forwarding',
311
	'DNS Query Forwarding',
312
	'Enable Forwarding Mode',
313
	$pconfig['forwarding']
314
));
315

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

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

    
334
$section->addInput(new Form_Checkbox(
335
	'txtsupport',
336
	'TXT Comment Support',
337
	'Create TXT records',
338
	$pconfig['txtsupport']
339
))->setHelp('Any descriptions associated with Host entries and DHCP Static mappings will create a corresponding TXT record.');
340

    
341
$btnadvdns = new Form_Button(
342
	'btnadvdns',
343
	'Custom options'
344
);
345

    
346
$btnadvdns->removeClass('btn-primary')->addClass('btn-default btn-sm');
347

    
348
$section->addInput(new Form_StaticText(
349
	'Custom options',
350
	$btnadvdns . '&nbsp;' . 'Show custom options'
351
));
352

    
353
$section->addInput(new Form_TextArea (
354
	'custom_options',
355
	'Custom options',
356
	$pconfig['custom_options']
357
))->setHelp('Enter any additional configuration parameters to add to the DNS Resolver configuration here, separated by a newline');
358

    
359
$form->add($section);
360
print($form);
361
?>
362

    
363
<script>
364
//<![CDATA[
365
events.push(function(){
366

    
367
	// If the enable checkbox is not checked, disable the next three checkboxes
368
	function disableDHCP() {
369
		var hide = ! $('#enable').prop('checked');
370

    
371
		disableInput('port', hide);
372
		disableInput('active_interface', hide);
373
		disableInput('outgoing_interface', hide);
374
		disableInput('regdhcpstatic', hide);
375
		disableInput('dnssec', hide);
376
		disableInput('forwarding', hide);
377
		disableInput('regdhcp', hide);
378
		disableInput('regdhcpstatic', hide);
379
		disableInput('txtsupport', hide);
380
		disableInput('btnadvdns', hide);
381
	}
382

    
383
	// Make the 'additional options' button a plain button, not a submit button
384
	$("#btnadvdns").prop('type','button');
385

    
386
	// Un-hide additional  controls
387
	$("#btnadvdns").click(function() {
388
		hideInput('custom_options', false);
389

    
390
	});
391

    
392
	// When 'enable' is clicked, disable/enable the following three checkboxes
393
	$('#enable').click(function() {
394
		disableDHCP();
395
	});
396

    
397
	// On initial load
398
	if($('#custom_options').val().length == 0) {
399
		hideInput('custom_options', true);
400
	}
401

    
402
	disableDHCP();
403

    
404
});
405
//]]>
406
</script>
407

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

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

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

    
484
<div class="panel panel-default">
485
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("Domain Overrides")?></h2></div>
486
	<div class="panel-body table-responsive">
487
		<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
488
			<thead>
489
				<tr>
490
					<th><?=gettext("Domain")?></th>
491
					<th><?=gettext("IP")?></th>
492
					<th><?=gettext("Description")?></th>
493
					<th></th>
494
				</tr>
495
			</thead>
496

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

    
526
<nav class="action-buttons">
527
	<a href="services_unbound_domainoverride_edit.php" class="btn btn-sm btn-success">
528
		<i class="fa fa-plus icon-embed-btn"></i>
529
		<?=gettext('Add')?>
530
	</a>
531
</nav>
532

    
533
<div id="infoblock">
534
	<?=print_info_box(sprintf(gettext("If the DNS Resolver is enabled, the DHCP".
535
		" service (if enabled) will automatically serve the LAN IP".
536
		" address as a DNS server to DHCP clients so they will use".
537
		" the DNS Resolver. If Forwarding is enabled, the DNS Resolver will use the DNS servers".
538
		" entered in %sSystem: General setup%s".
539
		" or those obtained via DHCP or PPP on WAN if &quot;Allow".
540
		" DNS server list to be overridden by DHCP/PPP on WAN&quot;".
541
		" is checked."),'<a href="system.php">','</a>'), info)?>
542
</div>
543

    
544
<?php include("foot.inc");
(152-152/230)