Project

General

Profile

Download (16.6 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
print_info_box(sprintf(gettext("If the DNS Resolver is enabled, the DHCP".
371
" service (if enabled) will automatically serve the LAN IP".
372
" address as a DNS server to DHCP clients so they will use".
373
" the DNS Resolver. If Forwarding, is enabled, the DNS Resolver will use the DNS servers".
374
" entered in %sSystem: General setup%s".
375
" or those obtained via DHCP or PPP on WAN if the &quot;Allow".
376
" DNS server list to be overridden by DHCP/PPP on WAN&quot;".
377
" is checked."),'<a href="system.php">','</a>'));
378
?>
379

    
380
<script>
381
//<![CDATA[
382
events.push(function(){
383

    
384
	// If the enable checkbox is not checked, disable the next three checkboxes
385
	function disableDHCP() {
386
		var hide = ! $('#enable').prop('checked');
387

    
388
		disableInput('port', hide);
389
		disableInput('active_interface', hide);
390
		disableInput('outgoing_interface', hide);
391
		disableInput('regdhcpstatic', hide);
392
		disableInput('dnssec', hide);
393
		disableInput('forwarding', hide);
394
		disableInput('regdhcp', hide);
395
		disableInput('regdhcpstatic', hide);
396
		disableInput('txtsupport', hide);
397
		disableInput('btnadvdns', hide);
398
	}
399

    
400
	// Make the 'aditional options' button a plain button, not a submit button
401
	$("#btnadvdns").prop('type','button');
402

    
403
	// Un-hide aditional  controls
404
	$("#btnadvdns").click(function() {
405
		hideInput('custom_options', false);
406

    
407
	});
408

    
409
	// When 'enable' is clicked, diable/enable the following three checkboxes
410
	$('#enable').click(function() {
411
		disableDHCP();
412
	});
413

    
414
	// On initial load
415
	if($('#custom_options').val().length == 0) {
416
		hideInput('custom_options', true);
417
	}
418

    
419
	disableDHCP();
420

    
421
});
422
//]]>
423
</script>
424

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

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

    
494
<nav class="action-buttons">
495
	<a href="services_unbound_host_edit.php" class="btn btn-sm btn-success"><?=gettext('Add')?></a>
496
</nav>
497

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

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

    
540
<nav class="action-buttons">
541
	<a href="services_unbound_domainoverride_edit.php" class="btn btn-sm btn-success"><?=gettext('Add')?></a>
542
</nav>
543
<?php include("foot.inc");
(152-152/234)