Project

General

Profile

Download (10.6 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
<?php
2
/*
3 c5d81585 Renato Botelho
 * services_dnsmasq.php
4 191cb31d Stephen Beaver
 *
5 c5d81585 Renato Botelho
 * part of pfSense (https://www.pfsense.org)
6 38809d47 Renato Botelho do Couto
 * Copyright (c) 2004-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8 8f585441 Luiz Souza
 * Copyright (c) 2014-2021 Rubicon Communications, LLC (Netgate)
9 c5d81585 Renato Botelho
 * Copyright (c) 2003-2004 Bob Zoller <bob@kludgebox.com>
10
 * All rights reserved.
11 191cb31d Stephen Beaver
 *
12 c5d81585 Renato Botelho
 * originally based on m0n0wall (http://m0n0.ch/wall)
13
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
14
 * All rights reserved.
15 191cb31d Stephen Beaver
 *
16 b12ea3fb Renato Botelho
 * Licensed under the Apache License, Version 2.0 (the "License");
17
 * you may not use this file except in compliance with the License.
18
 * You may obtain a copy of the License at
19 191cb31d Stephen Beaver
 *
20 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
21 191cb31d Stephen Beaver
 *
22 b12ea3fb Renato Botelho
 * Unless required by applicable law or agreed to in writing, software
23
 * distributed under the License is distributed on an "AS IS" BASIS,
24
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25
 * See the License for the specific language governing permissions and
26
 * limitations under the License.
27 191cb31d Stephen Beaver
 */
28 5b237745 Scott Ullrich
29 6b07c15a Matthew Grooms
##|+PRIV
30
##|*IDENT=page-services-dnsforwarder
31 5230f468 jim-p
##|*NAME=Services: DNS Forwarder
32 6b07c15a Matthew Grooms
##|*DESCR=Allow access to the 'Services: DNS Forwarder' page.
33
##|*MATCH=services_dnsmasq.php*
34
##|-PRIV
35
36 c81ef6e2 Phil Davis
require_once("guiconfig.inc");
37 8e033f72 Steve Beaver
require_once("services_dnsmasq.inc");
38 5b237745 Scott Ullrich
39 8e033f72 Steve Beaver
$retval = 0;
40 5b237745 Scott Ullrich
41 8e033f72 Steve Beaver
$rv = getDNSMasqConfig();
42
$pconfig = $rv['config'];
43
$a_hosts = $rv['hosts'];
44
$a_domainOverrides = $rv['domainoverrides'];
45
$iflist = $rv['iflist'];
46 6e3488e9 Phil Davis
47 13541a81 Steve Beaver
if ($_POST['apply']) {
48 8e033f72 Steve Beaver
	$retval = applyDNSMasqConfig();
49
} else if ($_POST['save']) {
50
	$rv = saveDNSMasqConfig($_POST);
51
	$pconfig = $rv['pconfig'];
52
	$input_errors = $rv['input_errors'];
53 cac2103a Steve Beaver
	$iflist = $rv['iflist'];
54 8e033f72 Steve Beaver
} else if ($_POST['act'] == "del") {
55
	deleteDNSMasqEntry($_POST);
56 e6363160 sbeaver
}
57
58 9f5aa90f Phil Davis
$pgtitle = array(gettext("Services"), gettext("DNS Forwarder"));
59 db88a3a2 Phil Davis
$shortcut_section = "forwarder";
60 b63695db Scott Ullrich
include("head.inc");
61 0c2b5df7 Scott Ullrich
62 6e3488e9 Phil Davis
if ($input_errors) {
63 e6363160 sbeaver
	print_input_errors($input_errors);
64 6e3488e9 Phil Davis
}
65 5b237745 Scott Ullrich
66 44c42356 Phil Davis
if ($_POST['apply']) {
67
	print_apply_result_box($retval);
68 6e3488e9 Phil Davis
}
69 e6363160 sbeaver
70 6e3488e9 Phil Davis
if (is_subsystem_dirty('hosts')) {
71 c9a66c65 NOYB
	print_apply_box(gettext("The DNS forwarder configuration has been changed.") . "<br />" . gettext("The changes must be applied for them to take effect."));
72 6e3488e9 Phil Davis
}
73 e6363160 sbeaver
74 fae9a73c sbeaver
$form = new Form();
75 e6363160 sbeaver
76
$section = new Form_Section('General DNS Forwarder Options');
77
78
$section->addInput(new Form_Checkbox(
79
	'enable',
80
	'Enable',
81
	'Enable DNS forwarder',
82
	$pconfig['enable']
83 08d1762e Sjon Hortensius
))->toggles('.toggle-dhcp', 'disable');
84 e6363160 sbeaver
85
$section->addInput(new Form_Checkbox(
86
	'regdhcp',
87
	'DHCP Registration',
88
	'Register DHCP leases in DNS forwarder',
89
	$pconfig['regdhcp']
90 d2a2f018 Steve Beaver
))->setHelp('If this option is set machines that specify'.
91 702fa4d0 Phil Davis
			' their hostname when requesting a DHCP lease will be registered'.
92
			' in the DNS forwarder, so that their name can be resolved.'.
93
			' The domain in %1$sSystem: General Setup%2$s should also'.
94 3fd41815 Phil Davis
			' be set to the proper value.', '<a href="system.php">', '</a>')
95 08d1762e Sjon Hortensius
	->addClass('toggle-dhcp');
96 e6363160 sbeaver
97
$section->addInput(new Form_Checkbox(
98
	'regdhcpstatic',
99
	'Static DHCP',
100
	'Register DHCP static mappings in DNS forwarder',
101
	$pconfig['regdhcpstatic']
102 ecf4b407 Isaac McDonald
))->setHelp('If this option is set, IPv4 DHCP static mappings will '.
103 e7d76457 Isaac McDonald
					'be registered in the DNS forwarder so that their name can be '.
104 702fa4d0 Phil Davis
					'resolved. The domain in %1$sSystem: General Setup%2$s should also '.
105 3fd41815 Phil Davis
					'be set to the proper value.', '<a href="system.php">', '</a>')
106 08d1762e Sjon Hortensius
	->addClass('toggle-dhcp');
107 e6363160 sbeaver
108
$section->addInput(new Form_Checkbox(
109
	'dhcpfirst',
110
	'Prefer DHCP',
111
	'Resolve DHCP mappings first',
112
	$pconfig['dhcpfirst']
113 d2a2f018 Steve Beaver
))->setHelp("If this option is set DHCP mappings will ".
114 aa994814 Andrew Thompson
					"be resolved before the manual list of names below. This only ".
115 d2a2f018 Steve Beaver
					"affects the name given for a reverse lookup (PTR).")
116 08d1762e Sjon Hortensius
	->addClass('toggle-dhcp');
117 e6363160 sbeaver
118 08d1762e Sjon Hortensius
$group = new Form_Group('DNS Query Forwarding');
119
120
$group->add(new Form_Checkbox(
121 e6363160 sbeaver
	'strict_order',
122
	'DNS Query Forwarding',
123
	'Query DNS servers sequentially',
124
	$pconfig['strict_order']
125 3fd41815 Phil Davis
))->setHelp('If this option is set %1$s DNS Forwarder (dnsmasq) will '.
126
					'query the DNS servers sequentially in the order specified (%2$sSystem - General Setup - DNS Servers%3$s), '.
127 c67c74dd Steve Beaver
					'rather than all at once in parallel. ', $g['product_label'], '<i>', '</i>');
128 e6363160 sbeaver
129 08d1762e Sjon Hortensius
$group->add(new Form_Checkbox(
130 e6363160 sbeaver
	'domain_needed',
131
	null,
132
	'Require domain',
133
	$pconfig['domain_needed']
134 d2a2f018 Steve Beaver
))->setHelp("If this option is set %s DNS Forwarder (dnsmasq) will ".
135 e6363160 sbeaver
					"not forward A or AAAA queries for plain names, without dots or domain parts, to upstream name servers.	 ".
136 c67c74dd Steve Beaver
					"If the name is not known from /etc/hosts or DHCP then a \"not found\" answer is returned. ", $g['product_label']);
137 e6363160 sbeaver
138 08d1762e Sjon Hortensius
$group->add(new Form_Checkbox(
139 e6363160 sbeaver
	'no_private_reverse',
140
	null,
141
	'Do not forward private reverse lookups',
142
	$pconfig['no_private_reverse']
143 d2a2f018 Steve Beaver
))->setHelp("If this option is set %s DNS Forwarder (dnsmasq) will ".
144 7bdd28fb Phil Davis
					"not forward reverse DNS lookups (PTR) for private addresses (RFC 1918) to upstream name servers.  ".
145
					"Any entries in the Domain Overrides section forwarding private \"n.n.n.in-addr.arpa\" names to a specific server are still forwarded. ".
146 c67c74dd Steve Beaver
					"If the IP to name is not known from /etc/hosts, DHCP or a specific domain override then a \"not found\" answer is immediately returned. ", $g['product_label']);
147 e6363160 sbeaver
148 08d1762e Sjon Hortensius
$section->add($group);
149
150 e6363160 sbeaver
$section->addInput(new Form_Input(
151
	'port',
152
	'Listen Port',
153 08d1762e Sjon Hortensius
	'number',
154
	$pconfig['port'],
155
	['placeholder' => '53']
156 e6363160 sbeaver
))->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.');
157
158
$section->addInput(new Form_Select(
159
	'interface',
160 24b82516 Phil Davis
	'*Interfaces',
161 e6363160 sbeaver
	$iflist['selected'],
162
	$iflist['options'],
163
	true
164 c3ff46e1 Steve Beaver
))->setHelp('Interface IPs used by the DNS Forwarder for responding to queries from clients. If an interface has both IPv4 and IPv6 IPs, ' . 
165
			'both are used. Queries to other interface IPs not selected above are discarded. ' .
166 e6363160 sbeaver
			'The default behavior is to respond to queries on every available IPv4 and IPv6 address.');
167
168
$section->addInput(new Form_Checkbox(
169
	'strictbind',
170 08d1762e Sjon Hortensius
	'Strict binding',
171 e6363160 sbeaver
	'Strict interface binding',
172
	$pconfig['strictbind']
173 fae9a73c sbeaver
))->setHelp('If this option is set, the DNS forwarder will only bind to the interfaces containing the IP addresses selected above, ' .
174 3fd41815 Phil Davis
					'rather than binding to all interfaces and discarding queries to other addresses.%1$s' .
175
					'This option does NOT work with IPv6. If set, dnsmasq will not bind to IPv6 addresses.', '<br /><br />');
176 e6363160 sbeaver
177 33ed4d60 Stephen Beaver
$section->addInput(new Form_Textarea(
178 e6363160 sbeaver
	'custom_options',
179
	'Custom options',
180
	$pconfig['custom_options']
181 e78ecb96 NOYB
))->setHelp('Enter any additional options to add to the dnsmasq configuration here, separated by a space or newline.')
182 b6b7ab7d Stephen Beaver
  ->addClass('advanced');
183 e6363160 sbeaver
184
$form->add($section);
185
print($form);
186 98f28b4e k-paulius
187 b6b7ab7d Stephen Beaver
?>
188 e6363160 sbeaver
<div class="panel panel-default">
189 c9679d8c Stephen Beaver
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("Host Overrides")?></h2></div>
190 e6363160 sbeaver
	<div class="panel-body table-responsive">
191 1c10ce97 PiBa-NL
		<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap table-rowdblclickedit" data-sortable>
192 e6363160 sbeaver
			<thead>
193 70edf50d jim-p
				<tr>
194 e6363160 sbeaver
					<th><?=gettext("Host")?></th>
195
					<th><?=gettext("Domain")?></th>
196
					<th><?=gettext("IP")?></th>
197
					<th><?=gettext("Description")?></th>
198 21d973b2 Phil Davis
					<th><?=gettext("Actions")?></th>
199 70edf50d jim-p
				</tr>
200 e6363160 sbeaver
			</thead>
201
			<tbody>
202
<?php
203 08d1762e Sjon Hortensius
foreach ($a_hosts as $i => $hostent):
204 e6363160 sbeaver
?>
205
				<tr>
206
					<td>
207 a15714cc NOYB
						<?=$hostent['host']?>
208 e6363160 sbeaver
					</td>
209
					<td>
210 a15714cc NOYB
						<?=$hostent['domain']?>
211 e6363160 sbeaver
					</td>
212
					<td>
213 08d1762e Sjon Hortensius
						<?=$hostent['ip']?>
214 e6363160 sbeaver
					</td>
215
					<td>
216
						<?=htmlspecialchars($hostent['descr'])?>
217
					</td>
218
					<td>
219 589634a9 Steve Beaver
						<a class="fa fa-pencil"	title="<?=gettext('Edit host override')?>" 	href="services_dnsmasq_edit.php?id=<?=$hostent['idx']?>"></a>
220 13541a81 Steve Beaver
						<a class="fa fa-trash"	title="<?=gettext('Delete host override')?>"	href="services_dnsmasq.php?type=host&amp;act=del&amp;id=<?=$hostent['idx']?>" usepost></a>
221 e6363160 sbeaver
					</td>
222
				</tr>
223
224
<?php
225
	if ($hostent['aliases']['item'] && is_array($hostent['aliases']['item'])):
226 231197bb Phil Davis
		foreach ($hostent['aliases']['item'] as $alias):
227 e6363160 sbeaver
?>
228 7bd5b320 Colin Fleming
				<tr>
229 e6363160 sbeaver
					<td>
230 a15714cc NOYB
						<?=$alias['host']?>
231 e6363160 sbeaver
					</td>
232
					<td>
233 a15714cc NOYB
						<?=$alias['domain']?>
234 e6363160 sbeaver
					</td>
235
					<td>
236 4bb7c0d1 bruno
						<?=gettext("Alias for ");?><?=$hostent['host'] ? $hostent['host'] . '.' . $hostent['domain'] : $hostent['domain']?>
237 e6363160 sbeaver
					</td>
238
					<td>
239 39609bf9 Stephen Beaver
						<i class="fa fa-angle-double-right text-info"></i>
240 e6363160 sbeaver
						<?=htmlspecialchars($alias['description'])?>
241
					</td>
242
					<td>
243 c84a6977 heper
						<a class="fa fa-pencil"	title="<?=gettext('Edit host override')?>" 	href="services_dnsmasq_edit.php?id=<?=$i?>"></a>
244 e6363160 sbeaver
					</td>
245 7bd5b320 Colin Fleming
				</tr>
246 e6363160 sbeaver
<?php
247
		endforeach;
248
	endif;
249
endforeach;
250
?>
251
			</tbody>
252
		</table>
253
	</div>
254
</div>
255
256 c10cb196 Stephen Beaver
<nav class="action-buttons">
257 c9679d8c Stephen Beaver
	<a href="services_dnsmasq_edit.php" class="btn btn-sm btn-success btn-sm">
258 9d5a20cf heper
		<i class="fa fa-plus icon-embed-btn"></i>
259 c9679d8c Stephen Beaver
		<?=gettext('Add')?>
260
	</a>
261 e6363160 sbeaver
</nav>
262
263
<div class="panel panel-default">
264 c9679d8c Stephen Beaver
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("Domain Overrides")?></h2></div>
265 e6363160 sbeaver
	<div class="panel-body table-responsive">
266 1c10ce97 PiBa-NL
		<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap table-rowdblclickedit" data-sortable>
267 e6363160 sbeaver
			<thead>
268 70edf50d jim-p
				<tr>
269 e6363160 sbeaver
					<th><?=gettext("Domain")?></th>
270
					<th><?=gettext("IP")?></th>
271
					<th><?=gettext("Description")?></th>
272 21d973b2 Phil Davis
					<th><?=gettext("Actions")?></th>
273 70edf50d jim-p
				</tr>
274 e6363160 sbeaver
			</thead>
275
276
			<tbody>
277
<?php
278 08d1762e Sjon Hortensius
foreach ($a_domainOverrides as $i => $doment):
279 e6363160 sbeaver
?>
280 70edf50d jim-p
				<tr>
281 e6363160 sbeaver
					<td>
282 a15714cc NOYB
						<?=$doment['domain']?>
283 e6363160 sbeaver
					</td>
284
					<td>
285 08d1762e Sjon Hortensius
						<?=$doment['ip']?>
286 e6363160 sbeaver
					</td>
287
					<td>
288 08d1762e Sjon Hortensius
						<?=htmlspecialchars($doment['descr'])?>
289 e6363160 sbeaver
					</td>
290
					<td>
291 589634a9 Steve Beaver
						<a class="fa fa-pencil"	title="<?=gettext('Edit domain override')?>" href="services_dnsmasq_domainoverride_edit.php?id=<?=$doment['idx']?>"></a>
292 13541a81 Steve Beaver
						<a class="fa fa-trash"	title="<?=gettext('Delete domain override')?>" href="services_dnsmasq.php?act=del&amp;type=doverride&amp;id=<?=$doment['idx']?>" usepost></a>
293 e6363160 sbeaver
					</td>
294 70edf50d jim-p
				</tr>
295 e6363160 sbeaver
<?php
296
endforeach;
297
?>
298
			</tbody>
299 7bd5b320 Colin Fleming
		</table>
300 e6363160 sbeaver
	</div>
301
</div>
302
303 c10cb196 Stephen Beaver
<nav class="action-buttons">
304 c9679d8c Stephen Beaver
	<a href="services_dnsmasq_domainoverride_edit.php" class="btn btn-sm btn-success btn-sm">
305 9d5a20cf heper
		<i class="fa fa-plus icon-embed-btn"></i>
306 c9679d8c Stephen Beaver
		<?=gettext('Add')?>
307
	</a>
308 e6363160 sbeaver
</nav>
309 bd3b483a Phil Davis
<div class="infoblock">
310
<?php
311
print_info_box(
312
	'<p>' .
313
	gettext('If the DNS forwarder is enabled, the DHCP service (if enabled) will automatically' .
314
		    ' serve the LAN IP address as a DNS server to DHCP clients so they will use the forwarder.') . '</p><p>' .
315
	sprintf(gettext('The DNS forwarder will use the DNS servers entered in %1$sSystem > General Setup%2$s or' .
316
				    ' those obtained via DHCP or PPP on WAN if &quot;Allow DNS server list to be overridden by DHCP/PPP on WAN&quot; is checked.' .
317
				    ' If that option is not used (or if a static IP address is used on WAN),' .
318
				    ' at least one DNS server must be manually specified on the %1$sSystem > General Setup%2$s page.'),
319
			'<a href="system.php">',
320
			'</a>') .
321
	'</p>',
322
	'info',
323
	false
324
);
325
?>
326
</div>
327 e6363160 sbeaver
328 c53fc00e Phil Davis
<?php
329 c84a6977 heper
include("foot.inc");