Project

General

Profile

Download (16.3 KB) Statistics
| Branch: | Tag: | Revision:
1 14b1279d Warren Baker
<?php
2
/* $Id$ */
3
/*
4
	services_unbound.php
5
	part of the pfSense project (http://www.pfsense.com)
6
	Copyright (C) 2011	Warren Baker (warren@pfsense.org)
7
	All rights reserved.
8
9
	Copyright (C) 2003-2004 Bob Zoller <bob@kludgebox.com> and Manuel Kasper <mk@neon1.net>.
10
	All rights reserved.
11
    
12
	Redistribution and use in source and binary forms, with or without
13
    modification, are permitted provided that the following conditions are met:
14
15
    1. Redistributions of source code must retain the above copyright notice,
16
       this list of conditions and the following disclaimer.
17
18
    2. Redistributions in binary form must reproduce the above copyright
19
       notice, this list of conditions and the following disclaimer in the
20
       documentation and/or other materials provided with the distribution.
21
22
    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
23
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24
    AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
    AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26
    OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
    POSSIBILITY OF SUCH DAMAGE.
32
*/
33
/*
34
	pfSense_MODULE:	dnscache
35
*/
36
37
##|+PRIV
38
##|*IDENT=page-services-unbound
39 2bb29c16 Warren Baker
##|*NAME=Services: DNS Resolver page
40
##|*DESCR=Allow access to the 'Services: DNS Resolver' page.
41 14b1279d Warren Baker
##|*MATCH=services_unbound.php*
42
##|-PRIV
43
44
require_once("guiconfig.inc");
45
require_once("unbound.inc");
46
47
$pconfig['enable'] = isset($config['unbound']['enable']);
48 ac2cfab2 Warren Baker
$pconfig['active_interface'] = $config['unbound']['active_interface'];
49
$pconfig['outgoing_interface'] = $config['unbound']['outgoing_interface'];
50 8314e2a3 Warren Baker
$pconfig['dnssec'] = isset($config['unbound']['dnssec']);
51 14b1279d Warren Baker
$pconfig['dnssec'] = isset($config['unbound']['dnssec']);
52
$pconfig['forwarding'] = isset($config['unbound']['forwarding']);
53
$pconfig['regdhcp'] = isset($config['unbound']['regdhcp']);
54
$pconfig['regdhcpstatic'] = isset($config['unbound']['regdhcpstatic']);
55
$pconfig['dhcpfirst'] = isset($config['unbound']['dhcpfirst']);
56
57 8314e2a3 Warren Baker
if(!is_array($config['unbound']))
58
	$config['unbound'] = array();
59
$a_unboundcfg =& $config['unbound'];
60
61 14b1279d Warren Baker
if (!is_array($config['unbound']['hosts']))
62
	$config['unbound']['hosts'] = array();
63 8314e2a3 Warren Baker
$a_hosts =& $config['unbound']['hosts'];
64 14b1279d Warren Baker
65
if (!is_array($config['unbound']['domainoverrides']))
66
	$config['unbound']['domainoverrides'] = array();
67
$a_domainOverrides = &$config['unbound']['domainoverrides'];
68
69
if ($_POST) {
70
71
	unset($input_errors);
72
73 8314e2a3 Warren Baker
	if($_POST['enable'] == "yes" && isset($config['dnsmasq']['enable']))
74 4ed3cc97 Warren Baker
		$input_errors[] = "The system dns-forwarder is still active. Disable it before enabling the DNS Resolver.";
75
76 ac2cfab2 Warren Baker
	if(empty($_POST['active_interface']))
77
		$input_errors[] = "A single network interface needs to be selected for the DNS Resolver to bind to.";
78
79 14b1279d Warren Baker
	if (!$input_errors) {
80 8314e2a3 Warren Baker
		$a_unboundcfg['enable'] = ($_POST['enable']) ? true : false;
81
		$a_unboundcfg['dnssec'] = ($_POST['dnssec']) ? true : false;
82
		$a_unboundcfg['forwarding'] = ($_POST['forwarding']) ? true : false;
83
		$a_unboundcfg['regdhcp'] = ($_POST['regdhcp']) ? true : false;
84
		$a_unboundcfg['regdhcpstatic'] = ($_POST['regdhcpstatic']) ? true : false;
85
		$a_unboundcfg['dhcpfirst'] = ($_POST['dhcpfirst']) ? true : false;
86 ac2cfab2 Warren Baker
		if (is_array($_POST['active_interface']))
87
			$a_unboundcfg['active_interface'] = implode(",", $_POST['active_interface']);
88
		else
89
			$a_unboundcfg['active_interface'] = $_POST['active_interface'];
90
		if (is_array($_POST['outgoing_interface']))
91
			$a_unboundcfg['outgoing_interface'] = implode(",", $_POST['outgoing_interface']);
92
		else
93
			$a_unboundcfg['outgoing_interface'] = $_POST['outgoing_interface'];
94
95 2bb29c16 Warren Baker
		write_config("DNS Resolver configured.");
96 14b1279d Warren Baker
		$retval = 0;
97
		$retval = services_unbound_configure();
98
		$savemsg = get_std_save_message($retval);
99
	}
100
}
101
102 2bb29c16 Warren Baker
$pgtitle = array(gettext("Services"),gettext("DNS Resolver"));
103 14b1279d Warren Baker
include_once("head.inc");
104
105
?>
106
107
<script language="JavaScript">
108
<!--
109
function enable_change(enable_over) {
110
	var endis;
111
	endis = !(document.iform.enable.checked || enable_over);
112
	document.iform.active_interface.disabled = endis;
113 f196aba3 Warren Baker
	document.iform.outgoing_interface.disabled = endis;
114 14b1279d Warren Baker
	document.iform.dnssec.disabled = endis;
115
	document.iform.forwarding.disabled = endis;
116
	document.iform.regdhcp.disabled = endis;
117
	document.iform.regdhcpstatic.disabled = endis;
118
	document.iform.dhcpfirst.disabled = endis;
119
}
120
//-->
121
</script>
122
	
123
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
124
<?php include("fbegin.inc"); ?>
125
<form action="services_unbound.php" method="post" name="iform" id="iform">
126
<?php if ($input_errors) print_input_errors($input_errors); ?>
127
<?php if ($savemsg) print_info_box($savemsg); ?>
128
<?php if (is_subsystem_dirty('hosts')): ?><p>
129 2bb29c16 Warren Baker
<?php print_info_box_np(gettext("The configuration for the DNS Resolver, has been changed") . ".<br>" . gettext("You must apply the changes in order for them to take effect."));?><br>
130 14b1279d Warren Baker
<?php endif; ?>
131
<table width="100%" border="0" cellpadding="0" cellspacing="0">
132
	<tr>
133
		<td class="tabnavtbl">
134
			<?php
135
				$tab_array = array();
136
				$tab_array[] = array(gettext("General settings"), true, "services_unbound.php");
137
				$tab_array[] = array(gettext("Advanced settings"), false, "services_unbound_advanced.php");
138 2bb29c16 Warren Baker
				$tab_array[] = array(gettext("Access Lists"), false, "/services_unbound_acls.php");
139 14b1279d Warren Baker
				display_top_tabs($tab_array, true);
140
			?>
141
		</td>
142
	</tr>
143
	<tr>
144 2bb29c16 Warren Baker
		<td class="tabcont">
145
		<table width="100%" border="0" cellpadding="6" cellspacing="0">
146
			<tr>
147
				<td colspan="2" valign="top" class="listtopic"><?=gettext("General DNS Resolver Options");?></td>
148
			</tr>
149
			<tr>
150
				<td width="22%" valign="top" class="vncellreq"><?=gettext("Enable");?></td>
151
				<td width="78%" class="vtable"><p>
152 8314e2a3 Warren Baker
					<input name="enable" type="checkbox" id="enable" value="yes" <?php if ($pconfig['enable'] === true) echo "checked";?> onClick="enable_change(false)">
153 2bb29c16 Warren Baker
					<strong><?=gettext("Enable DNS Resolver");?><br>
154
					</strong></p></td>
155
			</tr>
156
			<tr>
157
				<td width="22%" valign="top" class="vncellreq"><?=gettext("Network interfaces");?></td>
158
				<td width="78%" class="vtable">
159
					<select name="active_interface[]" id="active_interface" multiple="true" size="3">
160
					<?php $iflist = get_configured_interface_with_descr();
161
						$active_iface = explode(",", $pconfig['active_interface']);
162
						$iflist['localhost'] = "Localhost";
163
						foreach ($iflist as $iface => $ifdescr) {
164
							echo "<option value='{$iface}' ";
165
							if (in_array($iface, $active_iface))
166
								echo "selected";
167
							echo ">{$ifdescr}</option>\n";
168
						}
169
					?>
170
					</select>
171
					<br/><span class="vexpl">
172
							<?=gettext("The DNS Resolver Server will listen on the selected interfaces. To add an interface click inside the interface box and select the interface from the drop down.");?> <br/>
173
						</span>
174
				</td>
175
			</tr>
176 f196aba3 Warren Baker
			<tr>
177
				<td width="22%" valign="top" class="vncellreq"><?=gettext("Outgoing interfaces");?></td>
178
				<td width="78%" class="vtable">
179
					<select name="outgoing_interface[]" id="outgoing_interface" multiple="true" size="3">
180
					<?php $iflist = get_configured_interface_with_descr();
181 ac2cfab2 Warren Baker
						$outgoing_iface = explode(",", $pconfig['outgoing_interface']);
182 f196aba3 Warren Baker
						$iflist['localhost'] = "Localhost";
183
						foreach ($iflist as $iface => $ifdescr) {
184
							echo "<option value='{$iface}' ";
185 ac2cfab2 Warren Baker
							if (in_array($iface, $outgoing_iface))
186 f196aba3 Warren Baker
								echo "selected";
187
							echo ">{$ifdescr}</option>\n";
188
						}
189
					?>
190
					</select>
191
					<br/><span class="vexpl">
192
							<?=gettext("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.");?> <br/>
193
						</span>
194
				</td>
195
			</tr>
196 2bb29c16 Warren Baker
			<tr>
197
				<td width="22%" valign="top" class="vncellreq"><?=gettext("DNSSEC");?></td>
198
				<td width="78%" class="vtable"><p>
199 8314e2a3 Warren Baker
					<input name="dnssec" type="checkbox" id="dnssec" value="yes" <?php if ($pconfig['dnssec'] === true) echo "checked";?>/>
200 2bb29c16 Warren Baker
					<strong><?=gettext("Enable DNSSEC Support");?><br>
201
					</strong></p></td>
202
			</tr>
203
			<tr>
204
				<td width="22%" valign="top" class="vncellreq"><?=gettext("Forwarding");?></td>
205
				<td width="78%" class="vtable"><p>
206 8314e2a3 Warren Baker
					<input name="forwarding" type="checkbox" id="forwarding" value="yes" <?php if ($pconfig['forwarding'] === true) echo "checked";?>/>
207 2bb29c16 Warren Baker
					<strong><?=gettext("Enable Forwarding Mode");?><br>
208
					</strong></p></td>
209
			</tr>
210
			<tr>
211
				<td width="22%" valign="top" class="vncellreq"><?=gettext("DHCP Registration");?></td>
212
				<td width="78%" class="vtable"><p>
213 8314e2a3 Warren Baker
					<input name="regdhcp" type="checkbox" id="regdhcp" value="yes" <?php if ($pconfig['regdhcp'] === true) echo "checked";?>>
214 2bb29c16 Warren Baker
					<strong><?=gettext("Register DHCP leases in the DNS Resolver");?><br>
215
					</strong><?php printf(gettext("If this option is set, then machines that specify".
216
					" their hostname when requesting a DHCP lease will be registered".
217
					" in the DNS Resolver, so that their name can be resolved.".
218
					" You should also set the domain in %sSystem:".
219
					" General setup%s to the proper value."),'<a href="system.php">','</a>')?></p>
220
				</td>
221
			</tr>
222
			<tr>
223
				<td width="22%" valign="top" class="vncellreq"><?=gettext("Static DHCP");?></td>
224
				<td width="78%" class="vtable"><p>
225 8314e2a3 Warren Baker
					<input name="regdhcpstatic" type="checkbox" id="regdhcpstatic" value="yes" <?php if ($pconfig['regdhcpstatic'] === true) echo "checked";?>>
226 2bb29c16 Warren Baker
					<strong><?=gettext("Register DHCP static mappings in the DNS Resolver");?><br>
227
					</strong><?php printf(gettext("If this option is set, then DHCP static mappings will ".
228
							"be registered in the DNS Resolver, so that their name can be ".
229
							"resolved. You should also set the domain in %s".
230
							"System: General setup%s to the proper value."),'<a href="system.php">','</a>');?></p>
231
				</td>
232
			</tr>
233
			<tr>
234
				<td width="22%" valign="top" class="vncellreq"><?=gettext("Prefer DHCP");?></td>
235
				<td width="78%" class="vtable"><p>
236 8314e2a3 Warren Baker
					<input name="dhcpfirst" type="checkbox" id="dhcpfirst" value="yes" <?php if ($pconfig['dhcpfirst'] === true) echo "checked";?>>
237 2bb29c16 Warren Baker
					<strong><?=gettext("Resolve DHCP mappings first");?><br>
238
					</strong><?php printf(gettext("If this option is set, then DHCP mappings will ".
239
							"be resolved before the manual list of names below. This only ".
240
							"affects the name given for a reverse lookup (PTR)."));?></p>
241
				</td>
242
			</tr>	
243
			<tr>
244
				<td colspan="2">
245
					<input name="submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" onclick="enable_change(true)"/>
246
				</td>
247
			</tr>
248
		</table>
249 14b1279d Warren Baker
		</td>
250
	</tr>
251
</table>
252
253
<p><span class="vexpl"><span class="red"><strong><?=gettext("Note:");?><br>
254 2bb29c16 Warren Baker
</strong></span><?php printf(gettext("If the DNS Resolver is enabled, the DHCP".
255 14b1279d Warren Baker
" service (if enabled) will automatically serve the LAN IP".
256
" address as a DNS server to DHCP clients so they will use".
257 2bb29c16 Warren Baker
" the DNS Resolver. If Forwarding, is enabled, the DNS Resolver will use the DNS servers".
258 14b1279d Warren Baker
" entered in %sSystem: General setup%s".
259
" or those obtained via DHCP or PPP on WAN if the &quot;Allow".
260
" DNS server list to be overridden by DHCP/PPP on WAN&quot;".
261
" is checked."),'<a href="system.php">','</a>');?><br>
262
</span></p>
263
264
&nbsp;<br>
265
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tabcont">
266
<tr>
267
	<td colspan="5" valign="top" class="listtopic"><?=gettext("Host Overrides");?></td>
268
</tr>
269
<tr>
270
	<td><br/>
271
	<?=gettext("Entries in this section override individual results from the forwarders.");?>
272
	<?=gettext("Use these for changing DNS results or for adding custom DNS records.");?>
273
	</td>
274
</tr>
275
</table>
276
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tabcont sortable">
277
	<thead>
278
	<tr>
279
		<td width="20%" class="listhdrr"><?=gettext("Host");?></td>
280
		<td width="25%" class="listhdrr"><?=gettext("Domain");?></td>
281
		<td width="20%" class="listhdrr"><?=gettext("IP");?></td>
282
		<td width="25%" class="listhdr"><?=gettext("Description");?></td>
283
		<td width="10%" class="list">
284
			<table border="0" cellspacing="0" cellpadding="1">
285
				<tr>
286
					<td width="17"></td>
287
					<td valign="middle"><a href="services_unbound_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td>
288
				</tr>
289
			</table>
290
		</td>
291
	</tr>
292
	</thead>
293
	<tbody>
294
	<?php $i = 0; foreach ($a_hosts as $hostent): ?>
295
	<tr>
296
		<td class="listlr" ondblclick="document.location='services_unbound_edit.php?id=<?=$i;?>';">
297
			<?=strtolower($hostent['host']);?>&nbsp;
298
		</td>
299
		<td class="listr" ondblclick="document.location='services_unbound_edit.php?id=<?=$i;?>';">
300
			<?=strtolower($hostent['domain']);?>&nbsp;
301
		</td>
302
		<td class="listr" ondblclick="document.location='services_unbound_edit.php?id=<?=$i;?>';">
303
			<?=$hostent['ip'];?>&nbsp;
304
		</td>
305
		<td class="listbg" ondblclick="document.location='services_unbound_edit.php?id=<?=$i;?>';">
306
			<?=htmlspecialchars($hostent['descr']);?>&nbsp;
307
		</td>
308
		<td valign="middle" nowrap class="list">
309
			<table border="0" cellspacing="0" cellpadding="1">
310
				<tr>
311
					<td valign="middle"><a href="services_unbound_edit.php?id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0"></a></td>
312
					<td><a href="services_unbound.php?type=host&act=del&id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this host?");?>')"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0"></a></td>
313
				</tr>
314
			</table>
315
	</tr>
316
	<?php $i++; endforeach; ?>
317
	</tbody>
318
	<tfoot>
319
	<tr>
320
		<td class="list" colspan="4"></td>
321
		<td class="list">
322
			<table border="0" cellspacing="0" cellpadding="1">
323
				<tr>
324
					<td width="17"></td>
325
					<td valign="middle"><a href="services_unbound_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td>
326
				</tr>
327
			</table>
328
		</td>
329
	</tr>
330
	</tfoot>
331
</table>
332
<br/>
333
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tabcont">
334
<tr>
335
	<td colspan="5" valign="top" class="listtopic"><?=gettext("Domain Overrides");?></td>
336
</tr>
337
<tr>
338
	<tr>
339
		<td><p><?=gettext("Entries in this area override an entire domain by specifying an".
340
		" authoritative DNS server to be queried for that domain.");?></p></td>
341
	</tr>
342
</tr>
343
</table>
344
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tabcont sortable">
345
	<thead>
346
	<tr>
347
		<td width="35%" class="listhdrr"><?=gettext("Domain");?></td>
348
		<td width="20%" class="listhdrr"><?=gettext("IP");?></td>
349
		<td width="35%" class="listhdr"><?=gettext("Description");?></td>
350
		<td width="10%" class="list">
351
			<table border="0" cellspacing="0" cellpadding="1">
352
				<tr>
353
					<td width="17" heigth="17"></td>
354
					<td><a href="services_unbound_domainoverride_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td>
355
				</tr>
356
			</table>
357
		</td>
358
	</tr>
359
	</thead>
360
	<tbody>
361
	<?php $i = 0; foreach ($a_domainOverrides as $doment): ?>
362
	<tr>
363
		<td class="listlr">
364
			<?=strtolower($doment['domain']);?>&nbsp;
365
		</td>
366
		<td class="listr">
367
			<?=$doment['ip'];?>&nbsp;
368
		</td>
369
		<td class="listbg">
370
			<?=htmlspecialchars($doment['descr']);?>&nbsp;
371
		</td>
372
		<td valign="middle" nowrap class="list"> <a href="services_unbound_domainoverride_edit.php?id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0"></a>
373
			&nbsp;<a href="services_unbound.php?act=del&type=doverride&id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this domain override?");?>')"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0"></a></td>
374
	</tr>
375
	<?php $i++; endforeach; ?>
376
	</tbody>
377
	<tfoot>
378
	<tr>
379
		<td class="list" colspan="3"></td>
380
		<td class="list">
381
		<table border="0" cellspacing="0" cellpadding="1">
382
			<tr>
383
				<td width="17" heigth="17"></td>
384
				<td><a href="services_unbound_domainoverride_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td>
385
			</tr>
386
		</table>
387
		</td>
388
	</tr>
389
	</tfoot>
390
</table>
391
</form>
392
<script language="JavaScript">
393
<!--
394
enable_change(false);
395
//-->
396
</script>
397
<?php include("fend.inc"); ?>
398
</body>
399
</html>