Project

General

Profile

Download (13.1 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 f7c7eecb Andrew Thompson
$pconfig['dhcpfirst'] = isset($config['dnsmasq']['dhcpfirst']);
51 487830da 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 487830da 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 f7c7eecb Andrew Thompson
	$config['dnsmasq']['dhcpfirst'] = ($_POST['dhcpfirst']) ? true : false;
72 487830da 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 487830da Andrew Thompson
	if (!$input_errors) {
84
		write_config();
85 f0fe3d30 Scott Ullrich
86 487830da Andrew Thompson
		$retval = 0;
87
		$retval = services_dnsmasq_configure();
88
		$savemsg = get_std_save_message($retval);
89 5b237745 Scott Ullrich
90 487830da Andrew Thompson
		// Relaod filter (we might need to sync to CARP hosts)
91
		filter_configure();
92 020d757a Scott Ullrich
93 487830da 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 b63695db Scott Ullrich
include("head.inc");
121 0c2b5df7 Scott Ullrich
122 5b237745 Scott Ullrich
?>
123
124 6a01ea44 Bill Marquette
<script language="JavaScript">
125
<!--
126
function enable_change(enable_over) {
127
	var endis;
128
	endis = !(document.iform.enable.checked || enable_over);
129
	document.iform.regdhcp.disabled = endis;
130
	document.iform.regdhcpstatic.disabled = endis;
131 f7c7eecb Andrew Thompson
	document.iform.dhcpfirst.disabled = endis;
132 6a01ea44 Bill Marquette
}
133 487830da Andrew Thompson
function show_advanced_dns() {
134
	document.getElementById("showadvbox").innerHTML='';
135
	aodiv = document.getElementById('showadv');
136
	aodiv.style.display = "block";
137
}
138 6a01ea44 Bill Marquette
//-->
139
</script>
140
141 5b237745 Scott Ullrich
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
142
<?php include("fbegin.inc"); ?>
143 6a01ea44 Bill Marquette
<form action="services_dnsmasq.php" method="post" name="iform" id="iform">
144 487830da Andrew Thompson
<?php if ($input_errors) print_input_errors($input_errors); ?>
145 5b237745 Scott Ullrich
<?php if ($savemsg) print_info_box($savemsg); ?>
146 a368a026 Ermal Lu?i
<?php if (is_subsystem_dirty('hosts')): ?><p>
147 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>
148 5b237745 Scott Ullrich
<?php endif; ?>
149 70edf50d jim-p
<table width="100%" border="0" cellpadding="6" cellspacing="0">
150
	<tr>
151
		<td class="vtable"><p>
152
			<input name="enable" type="checkbox" id="enable" value="yes" <?php if ($pconfig['enable'] == "yes") echo "checked";?> onClick="enable_change(false)">
153
			<strong><?=gettext("Enable DNS forwarder");?><br>
154
			</strong></p></td>
155 98776e04 jim-p
		</tr>
156 70edf50d jim-p
	<tr>
157
		<td class="vtable"><p>
158
			<input name="regdhcp" type="checkbox" id="regdhcp" value="yes" <?php if ($pconfig['regdhcp'] == "yes") echo "checked";?>>
159
			<strong><?=gettext("Register DHCP leases in DNS forwarder");?><br>
160
			</strong><?php printf(gettext("If this option is set, then machines that specify".
161
			" their hostname when requesting a DHCP lease will be registered".
162
			" in the DNS forwarder, so that their name can be resolved.".
163
			" You should also set the domain in %sSystem:".
164
			" General setup%s to the proper value."),'<a href="system.php">','</a>')?></p>
165
		</td>
166
	</tr>
167
	<tr>
168
		<td class="vtable"><p>
169
			<input name="regdhcpstatic" type="checkbox" id="regdhcpstatic" value="yes" <?php if ($pconfig['regdhcpstatic'] == "yes") echo "checked";?>>
170
			<strong><?=gettext("Register DHCP static mappings in DNS forwarder");?><br>
171
			</strong><?php printf(gettext("If this option is set, then DHCP static mappings will ".
172
					"be registered in the DNS forwarder, so that their name can be ".
173
					"resolved. You should also set the domain in %s".
174
					"System: General setup%s to the proper value."),'<a href="system.php">','</a>');?></p>
175
		</td>
176
	</tr>
177 f7c7eecb Andrew Thompson
	<tr>
178
		<td class="vtable"><p>
179
			<input name="dhcpfirst" type="checkbox" id="dhcpfirst" value="yes" <?php if ($pconfig['dhcpfirst'] == "yes") echo "checked";?>>
180
			<strong><?=gettext("Resolve DHCP mappings first");?><br>
181
			</strong><?php printf(gettext("If this option is set, then DHCP mappings will ".
182
					"be resolved before the manual list of names below. This only ".
183 0a213420 Andrew Thompson
					"affects the name given for a reverse lookup (PTR)."));?></p>
184 f7c7eecb Andrew Thompson
		</td>
185
	</tr>
186 487830da Andrew Thompson
	<tr>
187
		<td class="vtable"><p>
188
			<div id="showadvbox" <?php if ($pconfig['custom_options']) echo "style='display:none'"; ?>>
189
				<input type="button" onClick="show_advanced_dns()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show advanced option");?></a>
190
			</div>
191
			<div id="showadv" <?php if (empty($pconfig['custom_options'])) echo "style='display:none'"; ?>>
192
				<strong><?=gettext("Advanced");?><br></strong>
193
				<textarea rows="6" cols="78" name="custom_options" id="custom_options"><?=htmlspecialchars($pconfig['custom_options']);?></textarea><br/>
194
				<?=gettext("Enter any additional options you would like to add to the dnsmasq configuration here, separated by a space or newline"); ?><br/>
195
			</div>
196
			</p>
197
		</td>
198
	</tr>
199 70edf50d jim-p
	<tr>
200
		<td>
201
			<input name="submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" onclick="enable_change(true)">
202
		</td>
203
	</tr>
204
	<tr>
205
		<td>
206
			<p><span class="vexpl"><span class="red"><strong><?=gettext("Note:");?><br>
207
			</strong></span><?php printf(gettext("If the DNS forwarder is enabled, the DHCP".
208
			" service (if enabled) will automatically serve the LAN IP".
209
			" address as a DNS server to DHCP clients so they will use".
210
			" the forwarder. The DNS forwarder will use the DNS servers".
211
			" entered in %sSystem: General setup%s".
212
			" or those obtained via DHCP or PPP on WAN if the &quot;Allow".
213
			" DNS server list to be overridden by DHCP/PPP on WAN&quot;".
214
			" is checked. If you don't use that option (or if you use".
215
			" a static IP address on WAN), you must manually specify at".
216
			" least one DNS server on the %sSystem:".
217
			"General setup%s page."),'<a href="system.php">','</a>','<a href="system.php">','</a>');?><br>
218
			<br>
219
			<?=gettext("You may enter records that override the results from the".
220
			" forwarders below.");?></span></p>
221
		</td>
222
	</tr>
223
</table>
224
&nbsp;<br>
225 79633b6c Evgeny Yurchenko
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="sortable">
226 70edf50d jim-p
	<thead>
227
	<tr>
228
		<td width="20%" class="listhdrr"><?=gettext("Host");?></td>
229
		<td width="25%" class="listhdrr"><?=gettext("Domain");?></td>
230
		<td width="20%" class="listhdrr"><?=gettext("IP");?></td>
231
		<td width="25%" class="listhdr"><?=gettext("Description");?></td>
232
		<td width="10%" class="list">
233 d415d821 Seth Mos
			<table border="0" cellspacing="0" cellpadding="1">
234 70edf50d jim-p
				<tr>
235
					<td width="17"></td>
236
					<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>
237
				</tr>
238 d415d821 Seth Mos
			</table>
239 70edf50d jim-p
		</td>
240
	</tr>
241
	</thead>
242
	<tbody>
243
	<?php $i = 0; foreach ($a_hosts as $hostent): ?>
244
	<tr>
245
		<td class="listlr" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
246
			<?=strtolower($hostent['host']);?>&nbsp;
247
		</td>
248
		<td class="listr" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
249
			<?=strtolower($hostent['domain']);?>&nbsp;
250
		</td>
251
		<td class="listr" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
252
			<?=$hostent['ip'];?>&nbsp;
253
		</td>
254
		<td class="listbg" ondblclick="document.location='services_dnsmasq_edit.php?id=<?=$i;?>';">
255
			<?=htmlspecialchars($hostent['descr']);?>&nbsp;
256
		</td>
257
		<td valign="middle" nowrap class="list">
258 d415d821 Seth Mos
			<table border="0" cellspacing="0" cellpadding="1">
259 70edf50d jim-p
				<tr>
260
					<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>
261
					<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>
262
				</tr>
263 d415d821 Seth Mos
			</table>
264 70edf50d jim-p
	</tr>
265
	<?php $i++; endforeach; ?>
266
	</tbody>
267
	<tfoot>
268
	<tr>
269
		<td class="list" colspan="4"></td>
270
		<td class="list">
271
			<table border="0" cellspacing="0" cellpadding="1">
272
				<tr>
273
					<td width="17"></td>
274
					<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>
275
				</tr>
276
			</table>
277
		</td>
278
	</tr>
279
	</tfoot>
280
</table>
281
<!-- update to enable domain overrides -->
282
<table width="100%" border="0" cellpadding="6" cellspacing="0">
283
	<tr><td>&nbsp;</td></tr>
284
	<tr>
285
		<td><p><?=gettext("Below you can override an entire domain by specifying an".
286
		" authoritative DNS server to be queried for that domain.");?></p></td>
287
	</tr>
288
</table>
289
&nbsp;<br>
290 79633b6c Evgeny Yurchenko
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="sortable">
291 70edf50d jim-p
	<thead>
292
	<tr>
293
		<td width="35%" class="listhdrr"><?=gettext("Domain");?></td>
294
		<td width="20%" class="listhdrr"><?=gettext("IP");?></td>
295
		<td width="35%" class="listhdr"><?=gettext("Description");?></td>
296
		<td width="10%" class="list">
297
			<table border="0" cellspacing="0" cellpadding="1">
298
				<tr>
299
					<td width="17" heigth="17"></td>
300
					<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>
301
				</tr>
302
			</table>
303
		</td>
304
	</tr>
305
	</thead>
306
	<tbody>
307
	<?php $i = 0; foreach ($a_domainOverrides as $doment): ?>
308
	<tr>
309
		<td class="listlr">
310
			<?=strtolower($doment['domain']);?>&nbsp;
311
		</td>
312
		<td class="listr">
313
			<?=$doment['ip'];?>&nbsp;
314
		</td>
315
		<td class="listbg">
316
			<?=htmlspecialchars($doment['descr']);?>&nbsp;
317
		</td>
318
		<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>
319
			&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>
320
	</tr>
321
	<?php $i++; endforeach; ?>
322
	</tbody>
323
	<tfoot>
324
	<tr>
325
		<td class="list" colspan="3"></td>
326
		<td class="list">
327
		<table border="0" cellspacing="0" cellpadding="1">
328
			<tr>
329
				<td width="17" heigth="17"></td>
330
				<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>
331
			</tr>
332
		</table>
333
		</td>
334
	</tr>
335
	</tfoot>
336
</table>
337
</form>
338 6a01ea44 Bill Marquette
<script language="JavaScript">
339
<!--
340
enable_change(false);
341
//-->
342
</script>
343 5b237745 Scott Ullrich
<?php include("fend.inc"); ?>
344
</body>
345
</html>