Project

General

Profile

Download (15 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
<?php
2 b46bfcf5 Bill Marquette
/* $Id$ */
3 5b237745 Scott Ullrich
/*
4
	services_dnsmasq.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6 f0fe3d30 Scott Ullrich
7 5b237745 Scott Ullrich
	Copyright (C) 2003-2004 Bob Zoller <bob@kludgebox.com> and Manuel Kasper <mk@neon1.net>.
8
	All rights reserved.
9 f0fe3d30 Scott Ullrich
10 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12 f0fe3d30 Scott Ullrich
13 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15 f0fe3d30 Scott Ullrich
16 5b237745 Scott Ullrich
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19 f0fe3d30 Scott Ullrich
20 5b237745 Scott Ullrich
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30
*/
31 70edf50d jim-p
/*
32 1d333258 Scott Ullrich
	pfSense_MODULE:	dnsforwarder
33
*/
34 5b237745 Scott Ullrich
35 6b07c15a Matthew Grooms
##|+PRIV
36
##|*IDENT=page-services-dnsforwarder
37
##|*NAME=Services: DNS Forwarder page
38
##|*DESCR=Allow access to the 'Services: DNS Forwarder' page.
39
##|*MATCH=services_dnsmasq.php*
40
##|-PRIV
41
42 5b237745 Scott Ullrich
require("guiconfig.inc");
43 7a927e67 Scott Ullrich
require_once("functions.inc");
44
require_once("filter.inc");
45
require_once("shaper.inc");
46 5b237745 Scott Ullrich
47 70edf50d jim-p
$pconfig['enable'] = isset($config['dnsmasq']['enable']);
48 5b237745 Scott Ullrich
$pconfig['regdhcp'] = isset($config['dnsmasq']['regdhcp']);
49 6a01ea44 Bill Marquette
$pconfig['regdhcpstatic'] = isset($config['dnsmasq']['regdhcpstatic']);
50 aa994814 Andrew Thompson
$pconfig['dhcpfirst'] = isset($config['dnsmasq']['dhcpfirst']);
51 8f9bffbc Andrew Thompson
$pconfig['custom_options'] = $config['dnsmasq']['custom_options'];
52 5b237745 Scott Ullrich
53 70edf50d jim-p
if (!is_array($config['dnsmasq']['hosts']))
54 5b237745 Scott Ullrich
	$config['dnsmasq']['hosts'] = array();
55 0c2b5df7 Scott Ullrich
56 70edf50d jim-p
if (!is_array($config['dnsmasq']['domainoverrides']))
57
	$config['dnsmasq']['domainoverrides'] = array();
58 0c2b5df7 Scott Ullrich
59 4d6ba181 Scott Ullrich
60 70edf50d jim-p
$a_hosts = &$config['dnsmasq']['hosts'];
61 0c2b5df7 Scott Ullrich
$a_domainOverrides = &$config['dnsmasq']['domainoverrides'];
62 5b237745 Scott Ullrich
63
if ($_POST) {
64
65
	$pconfig = $_POST;
66 8f9bffbc Andrew Thompson
	unset($input_errors);
67 5b237745 Scott Ullrich
68
	$config['dnsmasq']['enable'] = ($_POST['enable']) ? true : false;
69
	$config['dnsmasq']['regdhcp'] = ($_POST['regdhcp']) ? true : false;
70 6a01ea44 Bill Marquette
	$config['dnsmasq']['regdhcpstatic'] = ($_POST['regdhcpstatic']) ? true : false;
71 aa994814 Andrew Thompson
	$config['dnsmasq']['dhcpfirst'] = ($_POST['dhcpfirst']) ? true : false;
72 8f9bffbc Andrew Thompson
	$config['dnsmasq']['custom_options'] = str_replace("\r\n", "\n", $_POST['custom_options']);
73
74
	if ($config['dnsmasq']['custom_options']) {
75
		$args = '';
76
		foreach (preg_split('/\s+/', $config['dnsmasq']['custom_options']) as $c)
77
			$args .= "--$c ";
78
		exec("/usr/local/sbin/dnsmasq --test $args", $output, $rc);
79
		if ($rc != 0)
80
			$input_errors[] = gettext("Invalid custom options");
81
	}
82 5b237745 Scott Ullrich
83 8f9bffbc Andrew Thompson
	if (!$input_errors) {
84
		write_config();
85 f0fe3d30 Scott Ullrich
86 8f9bffbc Andrew Thompson
		$retval = 0;
87
		$retval = services_dnsmasq_configure();
88
		$savemsg = get_std_save_message($retval);
89 5b237745 Scott Ullrich
90 8f9bffbc Andrew Thompson
		// Relaod filter (we might need to sync to CARP hosts)
91
		filter_configure();
92 020d757a Scott Ullrich
93 8f9bffbc Andrew Thompson
		if ($retval == 0)
94
			clear_subsystem_dirty('hosts');
95
	}
96 5b237745 Scott Ullrich
}
97
98
if ($_GET['act'] == "del") {
99 70edf50d jim-p
	if ($_GET['type'] == 'host') {
100
		if ($a_hosts[$_GET['id']]) {
101
			unset($a_hosts[$_GET['id']]);
102
			write_config();
103 a368a026 Ermal Lu?i
			mark_subsystem_dirty('hosts');
104 70edf50d jim-p
			header("Location: services_dnsmasq.php");
105
			exit;
106
		}
107
	}
108
	elseif ($_GET['type'] == 'doverride') {
109
		if ($a_domainOverrides[$_GET['id']]) {
110
			unset($a_domainOverrides[$_GET['id']]);
111
			write_config();
112 a368a026 Ermal Lu?i
			mark_subsystem_dirty('hosts');
113 70edf50d jim-p
			header("Location: services_dnsmasq.php");
114
			exit;
115
		}
116
	}
117 5b237745 Scott Ullrich
}
118 0c2b5df7 Scott Ullrich
119 beb2bc00 Rafael Lucas
$pgtitle = array(gettext("Services"),gettext("DNS forwarder"));
120 b32dd0a6 jim-p
$shortcut_section = "resolver";
121 b63695db Scott Ullrich
include("head.inc");
122 0c2b5df7 Scott Ullrich
123 5b237745 Scott Ullrich
?>
124
125 6a01ea44 Bill Marquette
<script language="JavaScript">
126
<!--
127
function enable_change(enable_over) {
128
	var endis;
129
	endis = !(document.iform.enable.checked || enable_over);
130
	document.iform.regdhcp.disabled = endis;
131
	document.iform.regdhcpstatic.disabled = endis;
132 aa994814 Andrew Thompson
	document.iform.dhcpfirst.disabled = endis;
133 6a01ea44 Bill Marquette
}
134 8f9bffbc Andrew Thompson
function show_advanced_dns() {
135
	document.getElementById("showadvbox").innerHTML='';
136
	aodiv = document.getElementById('showadv');
137
	aodiv.style.display = "block";
138
}
139 6a01ea44 Bill Marquette
//-->
140
</script>
141
142 5b237745 Scott Ullrich
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
143
<?php include("fbegin.inc"); ?>
144 6a01ea44 Bill Marquette
<form action="services_dnsmasq.php" method="post" name="iform" id="iform">
145 8f9bffbc Andrew Thompson
<?php if ($input_errors) print_input_errors($input_errors); ?>
146 5b237745 Scott Ullrich
<?php if ($savemsg) print_info_box($savemsg); ?>
147 a368a026 Ermal Lu?i
<?php if (is_subsystem_dirty('hosts')): ?><p>
148 619c72f9 Carlos Eduardo Ramos
<?php print_info_box_np(gettext("The DNS forwarder configuration has been changed") . ".<br>" . gettext("You must apply the changes in order for them to take effect."));?><br>
149 5b237745 Scott Ullrich
<?php endif; ?>
150 70edf50d jim-p
<table width="100%" border="0" cellpadding="6" cellspacing="0">
151
	<tr>
152 6661dbcf jim-p
		<td colspan="2" valign="top" class="listtopic"><?=gettext("General DNS Forwarder Options");?></td>
153
	</tr>
154
	<tr>
155
		<td width="22%" valign="top" class="vncellreq"><?=gettext("Enable");?></td>
156
		<td width="78%" class="vtable"><p>
157 70edf50d jim-p
			<input name="enable" type="checkbox" id="enable" value="yes" <?php if ($pconfig['enable'] == "yes") echo "checked";?> onClick="enable_change(false)">
158
			<strong><?=gettext("Enable DNS forwarder");?><br>
159
			</strong></p></td>
160 98776e04 jim-p
		</tr>
161 70edf50d jim-p
	<tr>
162 6661dbcf jim-p
		<td width="22%" valign="top" class="vncellreq"><?=gettext("DHCP Registration");?></td>
163
		<td width="78%" class="vtable"><p>
164 70edf50d jim-p
			<input name="regdhcp" type="checkbox" id="regdhcp" value="yes" <?php if ($pconfig['regdhcp'] == "yes") echo "checked";?>>
165
			<strong><?=gettext("Register DHCP leases in DNS forwarder");?><br>
166
			</strong><?php printf(gettext("If this option is set, then machines that specify".
167
			" their hostname when requesting a DHCP lease will be registered".
168
			" in the DNS forwarder, so that their name can be resolved.".
169
			" You should also set the domain in %sSystem:".
170
			" General setup%s to the proper value."),'<a href="system.php">','</a>')?></p>
171
		</td>
172
	</tr>
173
	<tr>
174 6661dbcf jim-p
		<td width="22%" valign="top" class="vncellreq"><?=gettext("Static DHCP");?></td>
175
		<td width="78%" class="vtable"><p>
176 70edf50d jim-p
			<input name="regdhcpstatic" type="checkbox" id="regdhcpstatic" value="yes" <?php if ($pconfig['regdhcpstatic'] == "yes") echo "checked";?>>
177
			<strong><?=gettext("Register DHCP static mappings in DNS forwarder");?><br>
178
			</strong><?php printf(gettext("If this option is set, then DHCP static mappings will ".
179
					"be registered in the DNS forwarder, so that their name can be ".
180
					"resolved. You should also set the domain in %s".
181
					"System: General setup%s to the proper value."),'<a href="system.php">','</a>');?></p>
182
		</td>
183
	</tr>
184 aa994814 Andrew Thompson
	<tr>
185 6661dbcf jim-p
		<td width="22%" valign="top" class="vncellreq"><?=gettext("Prefer DHCP");?></td>
186
		<td width="78%" class="vtable"><p>
187 aa994814 Andrew Thompson
			<input name="dhcpfirst" type="checkbox" id="dhcpfirst" value="yes" <?php if ($pconfig['dhcpfirst'] == "yes") echo "checked";?>>
188
			<strong><?=gettext("Resolve DHCP mappings first");?><br>
189
			</strong><?php printf(gettext("If this option is set, then DHCP mappings will ".
190
					"be resolved before the manual list of names below. This only ".
191 649ea752 Andrew Thompson
					"affects the name given for a reverse lookup (PTR)."));?></p>
192 aa994814 Andrew Thompson
		</td>
193
	</tr>
194 8f9bffbc Andrew Thompson
	<tr>
195 6661dbcf jim-p
		<td width="22%" valign="top" class="vncellreq"><?=gettext("Advanced");?></td>
196
		<td width="78%" class="vtable"><p>
197 8f9bffbc Andrew Thompson
			<div id="showadvbox" <?php if ($pconfig['custom_options']) echo "style='display:none'"; ?>>
198
				<input type="button" onClick="show_advanced_dns()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show advanced option");?></a>
199
			</div>
200
			<div id="showadv" <?php if (empty($pconfig['custom_options'])) echo "style='display:none'"; ?>>
201
				<strong><?=gettext("Advanced");?><br></strong>
202
				<textarea rows="6" cols="78" name="custom_options" id="custom_options"><?=htmlspecialchars($pconfig['custom_options']);?></textarea><br/>
203
				<?=gettext("Enter any additional options you would like to add to the dnsmasq configuration here, separated by a space or newline"); ?><br/>
204
			</div>
205
			</p>
206
		</td>
207
	</tr>
208 70edf50d jim-p
	<tr>
209 6661dbcf jim-p
		<td colspan="2">
210 70edf50d jim-p
			<input name="submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" onclick="enable_change(true)">
211
		</td>
212
	</tr>
213
</table>
214 6661dbcf jim-p
215
<p><span class="vexpl"><span class="red"><strong><?=gettext("Note:");?><br>
216
</strong></span><?php printf(gettext("If the DNS forwarder is enabled, the DHCP".
217
" service (if enabled) will automatically serve the LAN IP".
218
" address as a DNS server to DHCP clients so they will use".
219
" the forwarder. The DNS forwarder will use the DNS servers".
220
" entered in %sSystem: General setup%s".
221
" or those obtained via DHCP or PPP on WAN if the &quot;Allow".
222
" DNS server list to be overridden by DHCP/PPP on WAN&quot;".
223
" is checked. If you don't use that option (or if you use".
224
" a static IP address on WAN), you must manually specify at".
225
" least one DNS server on the %sSystem:".
226
"General setup%s page."),'<a href="system.php">','</a>','<a href="system.php">','</a>');?><br>
227
</span></p>
228
229 70edf50d jim-p
&nbsp;<br>
230 6661dbcf jim-p
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tabcont">
231
<tr>
232
	<td colspan="5" valign="top" class="listtopic"><?=gettext("Host Overrides");?></td>
233
</tr>
234
<tr>
235
	<td><br/>
236
	<?=gettext("Entries in this section override individual results from the forwarders.");?>
237
	<?=gettext("Use these for changing DNS results or for adding custom DNS records.");?>
238
	</td>
239
</tr>
240
</table>
241
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tabcont sortable">
242 70edf50d jim-p
	<thead>
243
	<tr>
244
		<td width="20%" class="listhdrr"><?=gettext("Host");?></td>
245
		<td width="25%" class="listhdrr"><?=gettext("Domain");?></td>
246
		<td width="20%" class="listhdrr"><?=gettext("IP");?></td>
247
		<td width="25%" class="listhdr"><?=gettext("Description");?></td>
248
		<td width="10%" class="list">
249 d415d821 Seth Mos
			<table border="0" cellspacing="0" cellpadding="1">
250 70edf50d jim-p
				<tr>
251
					<td width="17"></td>
252
					<td valign="middle"><a href="services_dnsmasq_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td>
253
				</tr>
254 d415d821 Seth Mos
			</table>
255 70edf50d jim-p
		</td>
256
	</tr>
257
	</thead>
258
	<tbody>
259
	<?php $i = 0; foreach ($a_hosts as $hostent): ?>
260
	<tr>
261
		<td class="listlr" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
262
			<?=strtolower($hostent['host']);?>&nbsp;
263
		</td>
264
		<td class="listr" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
265
			<?=strtolower($hostent['domain']);?>&nbsp;
266
		</td>
267
		<td class="listr" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
268
			<?=$hostent['ip'];?>&nbsp;
269
		</td>
270
		<td class="listbg" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
271
			<?=htmlspecialchars($hostent['descr']);?>&nbsp;
272
		</td>
273
		<td valign="middle" nowrap class="list">
274 d415d821 Seth Mos
			<table border="0" cellspacing="0" cellpadding="1">
275 70edf50d jim-p
				<tr>
276
					<td valign="middle"><a href="services_dnsmasq_edit.php?id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0"></a></td>
277
					<td><a href="services_dnsmasq.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>
278
				</tr>
279 d415d821 Seth Mos
			</table>
280 70edf50d jim-p
	</tr>
281 e37eeb49 jim-p
	<?php if ($hostent['aliases']['item'] && is_array($hostent['aliases']['item'])): ?>
282 5a2a8349 Lorenz Schori
	<?php foreach ($hostent['aliases']['item'] as $alias): ?>
283
	<tr>
284
		<td class="listlr" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
285
			<?=strtolower($alias['host']);?>&nbsp;
286
		</td>
287
		<td class="listr" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
288
			<?=strtolower($alias['domain']);?>&nbsp;
289
		</td>
290
		<td class="listr" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
291
			Alias for <?=$hostent['host'] ? $hostent['host'] . '.' . $hostent['domain'] : $hostent['domain'];?>&nbsp;
292
		</td>
293
		<td class="listbg" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
294
			<?=htmlspecialchars($alias['description']);?>&nbsp;
295
		</td>
296
		<td valign="middle" nowrap class="list">
297
			<a href="services_dnsmasq_edit.php?id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0"></a>
298
		</td>
299
	</tr>
300
	<?php endforeach; ?>
301 e37eeb49 jim-p
	<?php endif; ?>
302 70edf50d jim-p
	<?php $i++; endforeach; ?>
303
	</tbody>
304
	<tfoot>
305
	<tr>
306
		<td class="list" colspan="4"></td>
307
		<td class="list">
308
			<table border="0" cellspacing="0" cellpadding="1">
309
				<tr>
310
					<td width="17"></td>
311
					<td valign="middle"><a href="services_dnsmasq_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td>
312
				</tr>
313
			</table>
314
		</td>
315
	</tr>
316
	</tfoot>
317
</table>
318 6661dbcf jim-p
<br/>
319
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tabcont">
320
<tr>
321
	<td colspan="5" valign="top" class="listtopic"><?=gettext("Domain Overrides");?></td>
322
</tr>
323
<tr>
324 70edf50d jim-p
	<tr>
325 6661dbcf jim-p
		<td><p><?=gettext("Entries in this area override an entire domain by specifying an".
326 70edf50d jim-p
		" authoritative DNS server to be queried for that domain.");?></p></td>
327
	</tr>
328 6661dbcf jim-p
</tr>
329 70edf50d jim-p
</table>
330 6661dbcf jim-p
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tabcont sortable">
331 70edf50d jim-p
	<thead>
332
	<tr>
333
		<td width="35%" class="listhdrr"><?=gettext("Domain");?></td>
334
		<td width="20%" class="listhdrr"><?=gettext("IP");?></td>
335
		<td width="35%" class="listhdr"><?=gettext("Description");?></td>
336
		<td width="10%" class="list">
337
			<table border="0" cellspacing="0" cellpadding="1">
338
				<tr>
339
					<td width="17" heigth="17"></td>
340
					<td><a href="services_dnsmasq_domainoverride_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td>
341
				</tr>
342
			</table>
343
		</td>
344
	</tr>
345
	</thead>
346
	<tbody>
347
	<?php $i = 0; foreach ($a_domainOverrides as $doment): ?>
348
	<tr>
349
		<td class="listlr">
350
			<?=strtolower($doment['domain']);?>&nbsp;
351
		</td>
352
		<td class="listr">
353
			<?=$doment['ip'];?>&nbsp;
354
		</td>
355
		<td class="listbg">
356
			<?=htmlspecialchars($doment['descr']);?>&nbsp;
357
		</td>
358
		<td valign="middle" nowrap class="list"> <a href="services_dnsmasq_domainoverride_edit.php?id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0"></a>
359
			&nbsp;<a href="services_dnsmasq.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>
360
	</tr>
361
	<?php $i++; endforeach; ?>
362
	</tbody>
363
	<tfoot>
364
	<tr>
365
		<td class="list" colspan="3"></td>
366
		<td class="list">
367
		<table border="0" cellspacing="0" cellpadding="1">
368
			<tr>
369
				<td width="17" heigth="17"></td>
370
				<td><a href="services_dnsmasq_domainoverride_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td>
371
			</tr>
372
		</table>
373
		</td>
374
	</tr>
375
	</tfoot>
376
</table>
377
</form>
378 6a01ea44 Bill Marquette
<script language="JavaScript">
379
<!--
380
enable_change(false);
381
//-->
382
</script>
383 5b237745 Scott Ullrich
<?php include("fend.inc"); ?>
384
</body>
385
</html>