Project

General

Profile

Download (16.8 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($config['unbound']['hosts'])) {
78
	$config['unbound']['hosts'] = array();
79
}
80

    
81
$a_hosts =& $config['unbound']['hosts'];
82

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

    
87
$a_domainOverrides = &$config['unbound']['domainoverrides'];
88

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

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

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

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

    
123
if ($_POST) {
124

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

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

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

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

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

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

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

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

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

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

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

    
236
	$iflist['options']['all']	= "All";
237
	if (empty($selectedifs) || empty($selectedifs[0]) || in_array("all", $selectedifs)) {
238
		array_push($iflist['selected'], "all");
239
	}
240

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

    
244
		if ($selectedifs && in_array($laddr, $selectedifs))
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
if (is_subsystem_dirty('unbound')) {
266
	print_info_box_np(gettext("The configuration of the DNS Resolver has been changed. You must apply changes for them to take effect."));
267
}
268

    
269
$tab_array = array();
270
$tab_array[] = array(gettext("General settings"), true, "services_unbound.php");
271
$tab_array[] = array(gettext("Advanced settings"), false, "services_unbound_advanced.php");
272
$tab_array[] = array(gettext("Access Lists"), false, "/services_unbound_acls.php");
273
display_top_tabs($tab_array, true);
274

    
275
require_once('classes/Form.class.php');
276

    
277
$form = new Form();
278

    
279
$section = new Form_Section('General DNS Resolver Options');
280

    
281
$section->addInput(new Form_Checkbox(
282
	'enable',
283
	'Enable',
284
	'Enable DNS resolver',
285
	$pconfig['enable']
286
));
287

    
288
$section->addInput(new Form_Input(
289
	'port',
290
	'Listen Port',
291
	'text',
292
	$pconfig['port']
293
))->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.');
294

    
295
$activeiflist = build_if_list($pconfig['active_interface']);
296

    
297
$section->addInput(new Form_Select(
298
	'active_interface',
299
	'Network Interfaces',
300
	$activeiflist['selected'],
301
	$activeiflist['options'],
302
	true
303
))->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. ' .
304
			'The default behavior is to respond to queries on every available IPv4 and IPv6 address.');
305

    
306
$outiflist = build_if_list($pconfig['outgoing_interface']);
307

    
308
$section->addInput(new Form_Select(
309
	'outgoing_interface',
310
	'Outgoing Network Interfaces',
311
	$outiflist['selected'],
312
	$outiflist['options'],
313
	true
314
))->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.');
315

    
316
$section->addInput(new Form_Checkbox(
317
	'dnssec',
318
	'DNSSEC',
319
	'Enable DNSSEC Support',
320
	$pconfig['dnssec']
321
));
322

    
323
$section->addInput(new Form_Checkbox(
324
	'forwarding',
325
	'DNS Query Forwarding',
326
	'Enable Forwarding Mode',
327
	$pconfig['forwarding']
328
));
329

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

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

    
348
$section->addInput(new Form_Checkbox(
349
	'txtsupport',
350
	'TXT Comment Support',
351
	'Register DHCP static mappings in the DNS Resolver',
352
	$pconfig['txtsupport']
353
))->setHelp('Any descriptions associated with Host entries and DHCP Static mappings will create a corresponding TXT record.');
354

    
355
$btnadvdns = new Form_Button(
356
	'btnadvdns',
357
	'Advanced'
358
);
359

    
360
$btnadvdns->removeClass('btn-primary')->addClass('btn-default btn-sm');
361

    
362
$section->addInput(new Form_StaticText(
363
	'Advanced',
364
	$btnadvdns . '&nbsp;' . 'Show advanced optionss'
365
));
366

    
367
$section->addInput(new Form_TextArea (
368
	'custom_options',
369
	'Custom options',
370
	$pconfig['custom_options']
371
))->setHelp('Enter any additional configuration parameters to add to the DNS Resolver configuration here, separated by a newline');
372

    
373
$form->add($section);
374
print($form);
375
?>
376
<script>
377
//<![CDATA[
378
events.push(function(){
379

    
380
	// If the enable checkbox is not checked, disable the next three checkboxes
381
	function disableDHCP() {
382
		var hide = ! $('#enable').prop('checked');
383

    
384
		disableInput('port', hide);
385
		disableInput('active_interface', hide);
386
		disableInput('outgoing_interface', hide);
387
		disableInput('regdhcpstatic', hide);
388
		disableInput('dnssec', hide);
389
		disableInput('forwarding', hide);
390
		disableInput('regdhcp', hide);
391
		disableInput('regdhcpstatic', hide);
392
		disableInput('txtsupport', hide);
393
		disableInput('btnadvdns', hide);
394
	}
395

    
396
	// Make the 'aditional options' button a plain button, not a submit button
397
	$("#btnadvdns").prop('type','button');
398

    
399
	// Un-hide aditional  controls
400
	$("#btnadvdns").click(function() {
401
		hideInput('custom_options', false);
402

    
403
	});
404

    
405
	// When 'enable' is clicked, diable/enable the following three checkboxes
406
	$('#enable').click(function() {
407
		disableDHCP();
408
	});
409

    
410
	// On initial load
411
	if($('#custom_options').val().length == 0) {
412
		hideInput('custom_options', true);
413
	}
414

    
415
	disableDHCP();
416

    
417
});
418
//]]>
419
</script>
420

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

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

    
490
<nav class="action-buttons">
491
	<a href="services_unbound_host_edit.php" class="btn btn-sm btn-success">
492
		<i class="fa fa-plus icon-embed-btn"></i>
493
		<?=gettext('Add')?>
494
	</a>
495
</nav>
496

    
497
<div class="panel panel-default">
498
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("Domain Overrides")?></h2></div>
499
	<div class="panel-body table-responsive">
500
		<table class="table table-striped table-hover table-condensed">
501
			<thead>
502
				<tr>
503
					<th><?=gettext("Domain")?></th>
504
					<th><?=gettext("IP")?></th>
505
					<th><?=gettext("Description")?></th>
506
					<th></th>
507
				</tr>
508
			</thead>
509

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

    
539
<nav class="action-buttons">
540
	<a href="services_unbound_domainoverride_edit.php" class="btn btn-sm btn-success">
541
		<i class="fa fa-plus icon-embed-btn"></i>
542
		<?=gettext('Add')?>
543
	</a>
544
</nav>
545

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