Project

General

Profile

Download (10.6 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * services_dnsmasq.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8
 * Copyright (c) 2014-2021 Rubicon Communications, LLC (Netgate)
9
 * Copyright (c) 2003-2004 Bob Zoller <bob@kludgebox.com>
10
 * All rights reserved.
11
 *
12
 * originally based on m0n0wall (http://m0n0.ch/wall)
13
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
14
 * All rights reserved.
15
 *
16
 * 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
 *
20
 * http://www.apache.org/licenses/LICENSE-2.0
21
 *
22
 * 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
 */
28

    
29
##|+PRIV
30
##|*IDENT=page-services-dnsforwarder
31
##|*NAME=Services: DNS Forwarder
32
##|*DESCR=Allow access to the 'Services: DNS Forwarder' page.
33
##|*MATCH=services_dnsmasq.php*
34
##|-PRIV
35

    
36
require_once("guiconfig.inc");
37
require_once("services_dnsmasq.inc");
38

    
39
$retval = 0;
40

    
41
$rv = getDNSMasqConfig();
42
$pconfig = $rv['config'];
43
$a_hosts = $rv['hosts'];
44
$a_domainOverrides = $rv['domainoverrides'];
45
$iflist = $rv['iflist'];
46

    
47
if ($_POST['apply']) {
48
	$retval = applyDNSMasqConfig();
49
} else if ($_POST['save']) {
50
	$rv = saveDNSMasqConfig($_POST);
51
	$pconfig = $rv['pconfig'];
52
	$input_errors = $rv['input_errors'];
53
	$iflist = $rv['iflist'];
54
} else if ($_POST['act'] == "del") {
55
	deleteDNSMasqEntry($_POST);
56
}
57

    
58
$pgtitle = array(gettext("Services"), gettext("DNS Forwarder"));
59
$shortcut_section = "forwarder";
60
include("head.inc");
61

    
62
if ($input_errors) {
63
	print_input_errors($input_errors);
64
}
65

    
66
if ($_POST['apply']) {
67
	print_apply_result_box($retval);
68
}
69

    
70
if (is_subsystem_dirty('hosts')) {
71
	print_apply_box(gettext("The DNS forwarder configuration has been changed.") . "<br />" . gettext("The changes must be applied for them to take effect."));
72
}
73

    
74
$form = new Form();
75

    
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
))->toggles('.toggle-dhcp', 'disable');
84

    
85
$section->addInput(new Form_Checkbox(
86
	'regdhcp',
87
	'DHCP Registration',
88
	'Register DHCP leases in DNS forwarder',
89
	$pconfig['regdhcp']
90
))->setHelp('If this option is set machines that specify'.
91
			' 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
			' be set to the proper value.', '<a href="system.php">', '</a>')
95
	->addClass('toggle-dhcp');
96

    
97
$section->addInput(new Form_Checkbox(
98
	'regdhcpstatic',
99
	'Static DHCP',
100
	'Register DHCP static mappings in DNS forwarder',
101
	$pconfig['regdhcpstatic']
102
))->setHelp('If this option is set, IPv4 DHCP static mappings will '.
103
					'be registered in the DNS forwarder so that their name can be '.
104
					'resolved. The domain in %1$sSystem: General Setup%2$s should also '.
105
					'be set to the proper value.', '<a href="system.php">', '</a>')
106
	->addClass('toggle-dhcp');
107

    
108
$section->addInput(new Form_Checkbox(
109
	'dhcpfirst',
110
	'Prefer DHCP',
111
	'Resolve DHCP mappings first',
112
	$pconfig['dhcpfirst']
113
))->setHelp("If this option is set DHCP mappings will ".
114
					"be resolved before the manual list of names below. This only ".
115
					"affects the name given for a reverse lookup (PTR).")
116
	->addClass('toggle-dhcp');
117

    
118
$group = new Form_Group('DNS Query Forwarding');
119

    
120
$group->add(new Form_Checkbox(
121
	'strict_order',
122
	'DNS Query Forwarding',
123
	'Query DNS servers sequentially',
124
	$pconfig['strict_order']
125
))->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
					'rather than all at once in parallel. ', $g['product_label'], '<i>', '</i>');
128

    
129
$group->add(new Form_Checkbox(
130
	'domain_needed',
131
	null,
132
	'Require domain',
133
	$pconfig['domain_needed']
134
))->setHelp("If this option is set %s DNS Forwarder (dnsmasq) will ".
135
					"not forward A or AAAA queries for plain names, without dots or domain parts, to upstream name servers.	 ".
136
					"If the name is not known from /etc/hosts or DHCP then a \"not found\" answer is returned. ", $g['product_label']);
137

    
138
$group->add(new Form_Checkbox(
139
	'no_private_reverse',
140
	null,
141
	'Do not forward private reverse lookups',
142
	$pconfig['no_private_reverse']
143
))->setHelp("If this option is set %s DNS Forwarder (dnsmasq) will ".
144
					"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
					"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

    
148
$section->add($group);
149

    
150
$section->addInput(new Form_Input(
151
	'port',
152
	'Listen Port',
153
	'number',
154
	$pconfig['port'],
155
	['placeholder' => '53']
156
))->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
	'*Interfaces',
161
	$iflist['selected'],
162
	$iflist['options'],
163
	true
164
))->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
			'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
	'Strict binding',
171
	'Strict interface binding',
172
	$pconfig['strictbind']
173
))->setHelp('If this option is set, the DNS forwarder will only bind to the interfaces containing the IP addresses selected above, ' .
174
					'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

    
177
$section->addInput(new Form_Textarea(
178
	'custom_options',
179
	'Custom options',
180
	$pconfig['custom_options']
181
))->setHelp('Enter any additional options to add to the dnsmasq configuration here, separated by a space or newline.')
182
  ->addClass('advanced');
183

    
184
$form->add($section);
185
print($form);
186

    
187
?>
188
<div class="panel panel-default">
189
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("Host Overrides")?></h2></div>
190
	<div class="panel-body table-responsive">
191
		<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap table-rowdblclickedit" data-sortable>
192
			<thead>
193
				<tr>
194
					<th><?=gettext("Host")?></th>
195
					<th><?=gettext("Domain")?></th>
196
					<th><?=gettext("IP")?></th>
197
					<th><?=gettext("Description")?></th>
198
					<th><?=gettext("Actions")?></th>
199
				</tr>
200
			</thead>
201
			<tbody>
202
<?php
203
foreach ($a_hosts as $i => $hostent):
204
?>
205
				<tr>
206
					<td>
207
						<?=$hostent['host']?>
208
					</td>
209
					<td>
210
						<?=$hostent['domain']?>
211
					</td>
212
					<td>
213
						<?=$hostent['ip']?>
214
					</td>
215
					<td>
216
						<?=htmlspecialchars($hostent['descr'])?>
217
					</td>
218
					<td>
219
						<a class="fa fa-pencil"	title="<?=gettext('Edit host override')?>" 	href="services_dnsmasq_edit.php?id=<?=$hostent['idx']?>"></a>
220
						<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
					</td>
222
				</tr>
223

    
224
<?php
225
	if ($hostent['aliases']['item'] && is_array($hostent['aliases']['item'])):
226
		foreach ($hostent['aliases']['item'] as $alias):
227
?>
228
				<tr>
229
					<td>
230
						<?=$alias['host']?>
231
					</td>
232
					<td>
233
						<?=$alias['domain']?>
234
					</td>
235
					<td>
236
						<?=gettext("Alias for ");?><?=$hostent['host'] ? $hostent['host'] . '.' . $hostent['domain'] : $hostent['domain']?>
237
					</td>
238
					<td>
239
						<i class="fa fa-angle-double-right text-info"></i>
240
						<?=htmlspecialchars($alias['description'])?>
241
					</td>
242
					<td>
243
						<a class="fa fa-pencil"	title="<?=gettext('Edit host override')?>" 	href="services_dnsmasq_edit.php?id=<?=$i?>"></a>
244
					</td>
245
				</tr>
246
<?php
247
		endforeach;
248
	endif;
249
endforeach;
250
?>
251
			</tbody>
252
		</table>
253
	</div>
254
</div>
255

    
256
<nav class="action-buttons">
257
	<a href="services_dnsmasq_edit.php" class="btn btn-sm btn-success btn-sm">
258
		<i class="fa fa-plus icon-embed-btn"></i>
259
		<?=gettext('Add')?>
260
	</a>
261
</nav>
262

    
263
<div class="panel panel-default">
264
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("Domain Overrides")?></h2></div>
265
	<div class="panel-body table-responsive">
266
		<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap table-rowdblclickedit" data-sortable>
267
			<thead>
268
				<tr>
269
					<th><?=gettext("Domain")?></th>
270
					<th><?=gettext("IP")?></th>
271
					<th><?=gettext("Description")?></th>
272
					<th><?=gettext("Actions")?></th>
273
				</tr>
274
			</thead>
275

    
276
			<tbody>
277
<?php
278
foreach ($a_domainOverrides as $i => $doment):
279
?>
280
				<tr>
281
					<td>
282
						<?=$doment['domain']?>
283
					</td>
284
					<td>
285
						<?=$doment['ip']?>
286
					</td>
287
					<td>
288
						<?=htmlspecialchars($doment['descr'])?>
289
					</td>
290
					<td>
291
						<a class="fa fa-pencil"	title="<?=gettext('Edit domain override')?>" href="services_dnsmasq_domainoverride_edit.php?id=<?=$doment['idx']?>"></a>
292
						<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
					</td>
294
				</tr>
295
<?php
296
endforeach;
297
?>
298
			</tbody>
299
		</table>
300
	</div>
301
</div>
302

    
303
<nav class="action-buttons">
304
	<a href="services_dnsmasq_domainoverride_edit.php" class="btn btn-sm btn-success btn-sm">
305
		<i class="fa fa-plus icon-embed-btn"></i>
306
		<?=gettext('Add')?>
307
	</a>
308
</nav>
309
<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

    
328
<?php
329
include("foot.inc");
(124-124/227)