Project

General

Profile

Download (40.1 KB) Statistics
| Branch: | Tag: | Revision:
1 99caa67c Seth Mos
<?php
2
/*
3 c5d81585 Renato Botelho
 * services_dhcpv6.php
4 df6cb8fe 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 8f2f85c3 Luiz Otavio O Souza
 * Copyright (c) 2014-2022 Rubicon Communications, LLC (Netgate)
9 c5d81585 Renato Botelho
 * Copyright (c) 2010 Seth Mos <seth.mos@dds.nl>
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 df6cb8fe 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 df6cb8fe Stephen Beaver
 *
20 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
21 df6cb8fe 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 df6cb8fe Stephen Beaver
 */
28 99caa67c Seth Mos
29
##|+PRIV
30
##|*IDENT=page-services-dhcpv6server
31 48157a04 Phil Davis
##|*NAME=Services: DHCPv6 Server
32
##|*DESCR=Allow access to the 'Services: DHCPv6 Server' page.
33 99caa67c Seth Mos
##|*MATCH=services_dhcpv6.php*
34
##|-PRIV
35
36 c81ef6e2 Phil Davis
require_once("guiconfig.inc");
37 472ad9a0 Renato Botelho
require_once("filter.inc");
38 99caa67c Seth Mos
39 8f36f87a jim-p
function dhcpv6_apply_changes($dhcpdv6_enable_changed) {
40 916fa8f9 Viktor G
	global $config, $g;
41
42 8f36f87a jim-p
	$retval = 0;
43
	$retvaldhcp = 0;
44
	$retvaldns = 0;
45
	/* Stop DHCPv6 so we can cleanup leases */
46
	killbypid("{$g['dhcpd_chroot_path']}{$g['varrun_path']}/dhcpdv6.pid");
47
	// dhcp_clean_leases();
48
	/* dnsmasq_configure calls dhcpd_configure */
49
	/* no need to restart dhcpd twice */
50
	if (isset($config['dnsmasq']['enable']) && isset($config['dnsmasq']['regdhcpstatic']))	{
51 44c42356 Phil Davis
		$retvaldns |= services_dnsmasq_configure();
52 8f36f87a jim-p
		if ($retvaldns == 0) {
53
			clear_subsystem_dirty('hosts');
54
			clear_subsystem_dirty('staticmaps');
55
		}
56
	} else if (isset($config['unbound']['enable']) && isset($config['unbound']['regdhcpstatic'])) {
57 44c42356 Phil Davis
		$retvaldns |= services_unbound_configure();
58 8f36f87a jim-p
		if ($retvaldns == 0) {
59
			clear_subsystem_dirty('unbound');
60
			clear_subsystem_dirty('staticmaps');
61
		}
62
	} else {
63 44c42356 Phil Davis
		$retvaldhcp |= services_dhcpd_configure();
64 8f36f87a jim-p
		if ($retvaldhcp == 0) {
65
			clear_subsystem_dirty('staticmaps');
66
		}
67
	}
68 c3fb0119 doktornotor
	/* BIND package - Bug #3710 */
69
	if (!function_exists('is_package_installed')) {
70
		require_once('pkg-utils.inc');
71
	}
72
	if (is_package_installed('pfSense-pkg-bind') && isset($config['installedpackages']['bind']['config'][0]['enable_bind'])) {
73
		$reloadbind = false;
74
		if (is_array($config['installedpackages']['bindzone'])) {
75
			$bindzone = $config['installedpackages']['bindzone']['config'];
76
		} else {
77
			$bindzone = array();
78
		}
79
		for ($x = 0; $x < sizeof($bindzone); $x++) {
80 6cc58ae8 doktornotor
			$zone = $bindzone[$x];
81 c3fb0119 doktornotor
			if ($zone['regdhcpstatic'] == 'on') {
82
				$reloadbind = true;
83
				break;
84
			}
85
		}
86
		if ($reloadbind === true) {
87
			if (file_exists("/usr/local/pkg/bind.inc")) {
88
				require_once("/usr/local/pkg/bind.inc");
89
				bind_sync();
90
			}
91
		}
92
	}
93 8f36f87a jim-p
	if ($dhcpdv6_enable_changed) {
94 44c42356 Phil Davis
		$retvalfc |= filter_configure();
95 8f36f87a jim-p
	}
96
	if ($retvaldhcp == 1 || $retvaldns == 1 || $retvalfc == 1) {
97
		$retval = 1;
98
	}
99 44c42356 Phil Davis
	return $retval;
100 8f36f87a jim-p
}
101
102 8f8682f7 Phil Davis
if (!$g['services_dhcp_server_enable']) {
103 6f3d2063 Renato Botelho
	header("Location: /");
104 99caa67c Seth Mos
	exit;
105
}
106
107 c946d721 Steve Beaver
$if = $_REQUEST['if'];
108 99caa67c Seth Mos
$iflist = get_configured_interface_with_descr();
109 16d9ad13 smos
$iflist = array_merge($iflist, get_configured_pppoe_server_interfaces());
110 99caa67c Seth Mos
111
/* set the starting interface */
112
if (!$if || !isset($iflist[$if])) {
113
	foreach ($iflist as $ifent => $ifname) {
114
		$oc = $config['interfaces'][$ifent];
115 2bf455ca Renato Botelho
		$valid_if_ipaddrv6 = (bool) ($oc['ipaddrv6'] == 'track6' ||
116
		    (is_ipaddrv6($oc['ipaddrv6']) &&
117
		    !is_linklocal($oc['ipaddrv6'])));
118 c80e6a6a Stephen Beaver
119 48602774 Renato Botelho
		if ((!is_array($config['dhcpdv6'][$ifent]) ||
120
		    !isset($config['dhcpdv6'][$ifent]['enable'])) &&
121
		    !$valid_if_ipaddrv6) {
122 99caa67c Seth Mos
			continue;
123 8f8682f7 Phil Davis
		}
124 99caa67c Seth Mos
		$if = $ifent;
125
		break;
126
	}
127
}
128
129 8f8682f7 Phil Davis
if (is_array($config['dhcpdv6'][$if])) {
130 fe838158 smos
	/* DHCPv6 */
131 99caa67c Seth Mos
	if (is_array($config['dhcpdv6'][$if]['range'])) {
132
		$pconfig['range_from'] = $config['dhcpdv6'][$if]['range']['from'];
133
		$pconfig['range_to'] = $config['dhcpdv6'][$if]['range']['to'];
134
	}
135 bfb3e717 Seth Mos
	if (is_array($config['dhcpdv6'][$if]['prefixrange'])) {
136
		$pconfig['prefixrange_from'] = $config['dhcpdv6'][$if]['prefixrange']['from'];
137
		$pconfig['prefixrange_to'] = $config['dhcpdv6'][$if]['prefixrange']['to'];
138
		$pconfig['prefixrange_length'] = $config['dhcpdv6'][$if]['prefixrange']['prefixlength'];
139
	}
140 99caa67c Seth Mos
	$pconfig['deftime'] = $config['dhcpdv6'][$if]['defaultleasetime'];
141
	$pconfig['maxtime'] = $config['dhcpdv6'][$if]['maxleasetime'];
142
	$pconfig['domain'] = $config['dhcpdv6'][$if]['domain'];
143
	$pconfig['domainsearchlist'] = $config['dhcpdv6'][$if]['domainsearchlist'];
144 8f8682f7 Phil Davis
	list($pconfig['wins1'], $pconfig['wins2']) = $config['dhcpdv6'][$if]['winsserver'];
145
	list($pconfig['dns1'], $pconfig['dns2'], $pconfig['dns3'], $pconfig['dns4']) = $config['dhcpdv6'][$if]['dnsserver'];
146 c58e56fb luckman212
	$pconfig['dhcp6c-dns'] = ($config['dhcpdv6'][$if]['dhcp6c-dns'] != 'disabled') ? "enabled" : "disabled";
147 99caa67c Seth Mos
	$pconfig['enable'] = isset($config['dhcpdv6'][$if]['enable']);
148
	$pconfig['ddnsdomain'] = $config['dhcpdv6'][$if]['ddnsdomain'];
149 87019fc4 Andres Petralli
	$pconfig['ddnsdomainprimary'] = $config['dhcpdv6'][$if]['ddnsdomainprimary'];
150 9fbd8f71 Viktor Gurov
	$pconfig['ddnsdomainsecondary'] = $config['dhcpdv6'][$if]['ddnsdomainsecondary'];
151 87019fc4 Andres Petralli
	$pconfig['ddnsdomainkeyname'] = $config['dhcpdv6'][$if]['ddnsdomainkeyname'];
152 534d7d69 Joeri Capens
	$pconfig['ddnsdomainkeyalgorithm'] = $config['dhcpdv6'][$if]['ddnsdomainkeyalgorithm'];
153 87019fc4 Andres Petralli
	$pconfig['ddnsdomainkey'] = $config['dhcpdv6'][$if]['ddnsdomainkey'];
154 99caa67c Seth Mos
	$pconfig['ddnsupdate'] = isset($config['dhcpdv6'][$if]['ddnsupdate']);
155 1a6bda5b Ross Williams
	$pconfig['ddnsforcehostname'] = isset($config['dhcpdv6'][$if]['ddnsforcehostname']);
156 391d63da Renato Botelho
	$pconfig['ddnsreverse'] = isset($config['dhcpdv6'][$if]['ddnsreverse']);
157
	$pconfig['ddnsclientupdates'] = $config['dhcpdv6'][$if]['ddnsclientupdates'];
158 5c52a260 kiokoman
	list($pconfig['ntp1'], $pconfig['ntp2'], $pconfig['ntp3'] ) = $config['dhcpdv6'][$if]['ntpserver'];
159 99caa67c Seth Mos
	$pconfig['tftp'] = $config['dhcpdv6'][$if]['tftp'];
160
	$pconfig['ldap'] = $config['dhcpdv6'][$if]['ldap'];
161
	$pconfig['netboot'] = isset($config['dhcpdv6'][$if]['netboot']);
162 bd942860 Renato Botelho
	$pconfig['bootfile_url'] = $config['dhcpdv6'][$if]['bootfile_url'];
163 99caa67c Seth Mos
	$pconfig['netmask'] = $config['dhcpdv6'][$if]['netmask'];
164
	$pconfig['numberoptions'] = $config['dhcpdv6'][$if]['numberoptions'];
165 138208bf Joecowboy
	$pconfig['dhcpv6leaseinlocaltime'] = $config['dhcpdv6'][$if]['dhcpv6leaseinlocaltime'];
166 8f8682f7 Phil Davis
	if (!is_array($config['dhcpdv6'][$if]['staticmap'])) {
167 99caa67c Seth Mos
		$config['dhcpdv6'][$if]['staticmap'] = array();
168 8f8682f7 Phil Davis
	}
169 c6c398c6 jim-p
	init_config_arr(array('dhcpdv6', $if, 'staticmap'));
170 99caa67c Seth Mos
	$a_maps = &$config['dhcpdv6'][$if]['staticmap'];
171
}
172
173 2bf455ca Renato Botelho
if ($config['interfaces'][$if]['ipaddrv6'] == 'track6') {
174 6c8beed3 Renato Botelho
	$trackifname = $config['interfaces'][$if]['track6-interface'];
175
	$trackcfg = $config['interfaces'][$trackifname];
176 a5776226 Chris Buechler
	$ifcfgsn = "64";
177 2bf455ca Renato Botelho
	$ifcfgip = '::';
178 6c8beed3 Renato Botelho
179
	$str_help_mask = dhcpv6_pd_str_help($ifcfgsn);
180 2bf455ca Renato Botelho
} else {
181
	$ifcfgip = get_interface_ipv6($if);
182
	$ifcfgsn = get_interface_subnetv6($if);
183
}
184 99caa67c Seth Mos
185 cd2c7940 sbeaver
/*	 set the enabled flag which will tell us if DHCP relay is enabled
186
 *	 on any interface. We will use this to disable DHCP server since
187
 *	 the two are not compatible with each other.
188 99caa67c Seth Mos
 */
189
190
$dhcrelay_enabled = false;
191 80c88a68 smos
$dhcrelaycfg = $config['dhcrelay6'];
192 99caa67c Seth Mos
193 9c06758b k-paulius
if (is_array($dhcrelaycfg) && isset($dhcrelaycfg['enable']) && isset($dhcrelaycfg['interface']) && !empty($dhcrelaycfg['interface'])) {
194
	$dhcrelayifs = explode(",", $dhcrelaycfg['interface']);
195
196
	foreach ($dhcrelayifs as $dhcrelayif) {
197
198
		if (isset($iflist[$dhcrelayif]) && (!link_interface_to_bridge($dhcrelayif))) {
199 99caa67c Seth Mos
			$dhcrelay_enabled = true;
200 9c06758b k-paulius
			break;
201 8f8682f7 Phil Davis
		}
202 99caa67c Seth Mos
	}
203
}
204
205 306cbbc8 Phil Davis
if (isset($_POST['apply'])) {
206 44c42356 Phil Davis
	$changes_applied = true;
207
	$retval = dhcpv6_apply_changes(false);
208 306cbbc8 Phil Davis
} elseif (isset($_POST['save'])) {
209 99caa67c Seth Mos
	unset($input_errors);
210
211 472ad9a0 Renato Botelho
	$old_dhcpdv6_enable = ($pconfig['enable'] == true);
212
	$new_dhcpdv6_enable = ($_POST['enable'] ? true : false);
213
	$dhcpdv6_enable_changed = ($old_dhcpdv6_enable != $new_dhcpdv6_enable);
214
215 99caa67c Seth Mos
	$pconfig = $_POST;
216
217
	$numberoptions = array();
218 6c07db48 Phil Davis
	for ($x = 0; $x < 99; $x++) {
219 8f8682f7 Phil Davis
		if (isset($_POST["number{$x}"]) && ctype_digit($_POST["number{$x}"])) {
220 99caa67c Seth Mos
			$numbervalue = array();
221
			$numbervalue['number'] = htmlspecialchars($_POST["number{$x}"]);
222 65cce9d7 Renato Botelho
			$numbervalue['value'] = base64_encode($_POST["value{$x}"]);
223 99caa67c Seth Mos
			$numberoptions['item'][] = $numbervalue;
224
		}
225
	}
226 756da4bd Phil Davis
	// Reload the new pconfig variable that the form uses.
227 99caa67c Seth Mos
	$pconfig['numberoptions'] = $numberoptions;
228
229
	/* input validation */
230 756da4bd Phil Davis
231
	// Note: if DHCPv6 Server is not enabled, then it is OK to adjust other parameters without specifying range from-to.
232 99caa67c Seth Mos
	if ($_POST['enable']) {
233 5c533d72 Viktor G
		if ((empty($_POST['range_from']) || empty($_POST['range_to'])) &&
234
		    ($config['dhcpdv6'][$if]['ramode'] != 'stateless_dhcp')) {
235
			$input_errors[] = gettext("A valid range must be specified for any mode except Stateless DHCP.");
236
		}
237 756da4bd Phil Davis
	}
238 99caa67c Seth Mos
239 756da4bd Phil Davis
	if (($_POST['prefixrange_from'] && !is_ipaddrv6($_POST['prefixrange_from']))) {
240
		$input_errors[] = gettext("A valid prefix range must be specified.");
241
	}
242
	if (($_POST['prefixrange_to'] && !is_ipaddrv6($_POST['prefixrange_to']))) {
243
		$input_errors[] = gettext("A valid prefix range must be specified.");
244
	}
245 bcc2b417 Renato Botelho
246 756da4bd Phil Davis
	if ($_POST['prefixrange_from'] && $_POST['prefixrange_to'] &&
247
		$_POST['prefixrange_length']) {
248
		$netmask = Net_IPv6::getNetmask($_POST['prefixrange_from'],
249
			$_POST['prefixrange_length']);
250 587995fb Phil Davis
		$netmask = text_to_compressed_ip6($netmask);
251 756da4bd Phil Davis
252 587995fb Phil Davis
		if ($netmask != text_to_compressed_ip6(strtolower(
253 756da4bd Phil Davis
			$_POST['prefixrange_from']))) {
254
			$input_errors[] = sprintf(gettext(
255
				"Prefix Delegation From address is not a valid IPv6 Netmask for %s"),
256
				$netmask . '/' . $_POST['prefixrange_length']);
257
		}
258 bcc2b417 Renato Botelho
259 756da4bd Phil Davis
		$netmask = Net_IPv6::getNetmask($_POST['prefixrange_to'],
260
			$_POST['prefixrange_length']);
261 587995fb Phil Davis
		$netmask = text_to_compressed_ip6($netmask);
262 bcc2b417 Renato Botelho
263 587995fb Phil Davis
		if ($netmask != text_to_compressed_ip6(strtolower(
264 756da4bd Phil Davis
			$_POST['prefixrange_to']))) {
265
			$input_errors[] = sprintf(gettext(
266
				"Prefix Delegation To address is not a valid IPv6 Netmask for %s"),
267
				$netmask . '/' . $_POST['prefixrange_length']);
268 bcc2b417 Renato Botelho
		}
269 756da4bd Phil Davis
	}
270 bcc2b417 Renato Botelho
271 756da4bd Phil Davis
	$range_from_to_ok = true;
272
273
	if ($_POST['range_from']) {
274
		if (!is_ipaddrv6($_POST['range_from'])) {
275
			$input_errors[] = gettext("A valid range must be specified.");
276
			$range_from_to_ok = false;
277
		} elseif ($config['interfaces'][$if]['ipaddrv6'] == 'track6' &&
278
			!Net_IPv6::isInNetmask($_POST['range_from'], '::', $ifcfgsn)) {
279
			$input_errors[] = sprintf(gettext(
280 702fa4d0 Phil Davis
				'The prefix (upper %1$s bits) must be zero.  Use the form %2$s'),
281 756da4bd Phil Davis
				$ifcfgsn, $str_help_mask);
282
			$range_from_to_ok = false;
283 8f8682f7 Phil Davis
		}
284 756da4bd Phil Davis
	}
285
	if ($_POST['range_to']) {
286
		if (!is_ipaddrv6($_POST['range_to'])) {
287
			$input_errors[] = gettext("A valid range must be specified.");
288
			$range_from_to_ok = false;
289
		} elseif ($config['interfaces'][$if]['ipaddrv6'] == 'track6' &&
290
			!Net_IPv6::isInNetmask($_POST['range_to'], '::', $ifcfgsn)) {
291
			$input_errors[] = sprintf(gettext(
292 702fa4d0 Phil Davis
				'The prefix (upper %1$s bits) must be zero.  Use the form %2$s'),
293 756da4bd Phil Davis
				$ifcfgsn, $str_help_mask);
294
			$range_from_to_ok = false;
295 8f8682f7 Phil Davis
		}
296 756da4bd Phil Davis
	}
297
	if (($_POST['range_from'] && !$_POST['range_to']) || ($_POST['range_to'] && !$_POST['range_from'])) {
298
		$input_errors[] = gettext("Range From and Range To must both be entered.");
299
	}
300
	if (($_POST['gateway'] && !is_ipaddrv6($_POST['gateway']))) {
301
		$input_errors[] = gettext("A valid IPv6 address must be specified for the gateway.");
302
	}
303
	if (($_POST['dns1'] && !is_ipaddrv6($_POST['dns1'])) ||
304
		($_POST['dns2'] && !is_ipaddrv6($_POST['dns2'])) ||
305
		($_POST['dns3'] && !is_ipaddrv6($_POST['dns3'])) ||
306
		($_POST['dns4'] && !is_ipaddrv6($_POST['dns4']))) {
307
		$input_errors[] = gettext("A valid IPv6 address must be specified for each of the DNS servers.");
308
	}
309 99caa67c Seth Mos
310 756da4bd Phil Davis
	if ($_POST['deftime'] && (!is_numeric($_POST['deftime']) || ($_POST['deftime'] < 60))) {
311
		$input_errors[] = gettext("The default lease time must be at least 60 seconds.");
312
	}
313 635e5b9d Kris Anderson
	if ($_POST['maxtime'] && (!is_numeric($_POST['maxtime']) || ($_POST['maxtime'] < 60) || ($_POST['maxtime'] < $_POST['deftime']))) {
314 ef267412 Kris Anderson
		$input_errors[] = gettext("The maximum lease time must be at least 60 seconds, and the same value or greater than the default lease time.");
315 756da4bd Phil Davis
	}
316 9fbd8f71 Viktor Gurov
	if ($_POST['ddnsupdate']) {
317
		if (!is_domain($_POST['ddnsdomain'])) {
318
			$input_errors[] = gettext("A valid domain name must be specified for the dynamic DNS registration.");
319
		}
320
		if (!is_ipaddr($_POST['ddnsdomainprimary'])) {
321
			$input_errors[] = gettext("A valid primary domain name server IP address must be specified for the dynamic domain name.");
322
		}
323
		if (!empty($_POST['ddnsdomainsecondary']) && !is_ipaddr($_POST['ddnsdomainsecondary'])) {
324
			$input_errors[] = gettext("A valid secondary domain name server IP address must be specified for the dynamic domain name.");
325
		}
326
		if (!$_POST['ddnsdomainkeyname'] || !$_POST['ddnsdomainkeyalgorithm'] || !$_POST['ddnsdomainkey']) {
327
			$input_errors[] = gettext("A valid domain key name, algorithm and secret must be specified.");
328
		}
329 07588052 Viktor G
		if (preg_match('/[^A-Za-z0-9\.\-\_]/', $_POST['ddnsdomainkeyname'])) {
330
			$input_errors[] = gettext("The domain key name may only contain the characters a-z, A-Z, 0-9, '-', '_' and '.'");
331 9fbd8f71 Viktor Gurov
		}
332
		if ($_POST['ddnsdomainkey'] && !base64_decode($_POST['ddnsdomainkey'], true)) {
333
			$input_errors[] = gettext("The domain key secret must be a Base64 encoded value.");
334
		}
335 756da4bd Phil Davis
	}
336
	if ($_POST['domainsearchlist']) {
337 534d7d69 Joeri Capens
		$domain_array = preg_split("/[ ;]+/", $_POST['domainsearchlist']);
338 756da4bd Phil Davis
		foreach ($domain_array as $curdomain) {
339
			if (!is_domain($curdomain)) {
340
				$input_errors[] = gettext("A valid domain search list must be specified.");
341
				break;
342 a3de8b9e Pierre POMES
			}
343
		}
344 756da4bd Phil Davis
	}
345 a3de8b9e Pierre POMES
346 5c52a260 kiokoman
	if (($_POST['ntp1'] && !is_ipaddrv6($_POST['ntp1'])) ||
347
	    ($_POST['ntp2'] && !is_ipaddrv6($_POST['ntp2'])) ||
348
	    ($_POST['ntp3'] && !is_ipaddrv6($_POST['ntp3']))) {
349 756da4bd Phil Davis
		$input_errors[] = gettext("A valid IPv6 address must be specified for the primary/secondary NTP servers.");
350
	}
351
	if (($_POST['domain'] && !is_domain($_POST['domain']))) {
352
		$input_errors[] = gettext("A valid domain name must be specified for the DNS domain.");
353
	}
354
	if ($_POST['tftp'] && !is_ipaddr($_POST['tftp']) && !is_domain($_POST['tftp']) && !is_URL($_POST['tftp'])) {
355
		$input_errors[] = gettext("A valid IPv6 address or hostname must be specified for the TFTP server.");
356
	}
357
	if (($_POST['bootfile_url'] && !is_URL($_POST['bootfile_url']))) {
358
		$input_errors[] = gettext("A valid URL must be specified for the network bootfile.");
359
	}
360 99caa67c Seth Mos
361 756da4bd Phil Davis
	// Disallow a range that includes the virtualip
362
	if ($range_from_to_ok && is_array($config['virtualip']['vip'])) {
363
		foreach ($config['virtualip']['vip'] as $vip) {
364
			if ($vip['interface'] == $if) {
365
				if ($vip['subnetv6'] && is_inrange_v6($vip['subnetv6'], $_POST['range_from'], $_POST['range_to'])) {
366
					$input_errors[] = sprintf(gettext("The subnet range cannot overlap with virtual IPv6 address %s."), $vip['subnetv6']);
367 8f8682f7 Phil Davis
				}
368 99caa67c Seth Mos
			}
369
		}
370 756da4bd Phil Davis
	}
371 99caa67c Seth Mos
372 756da4bd Phil Davis
	$noip = false;
373
	if (is_array($a_maps)) {
374
		foreach ($a_maps as $map) {
375
			if (empty($map['ipaddrv6'])) {
376
				$noip = true;
377 cd2c7940 sbeaver
			}
378
		}
379 756da4bd Phil Davis
	}
380
381
	/* make sure that the DHCP Relay isn't enabled on this interface */
382
	if ($_POST['enable'] && $dhcrelay_enabled) {
383
		$input_errors[] = sprintf(gettext("The DHCP relay on the %s interface must be disabled before enabling the DHCP server."), $iflist[$if]);
384
	}
385
386
	// If nothing is wrong so far, and we have range from and to, then check conditions related to the values of range from and to.
387
	if (!$input_errors && $_POST['range_from'] && $_POST['range_to']) {
388
		/* make sure the range lies within the current subnet */
389
		$subnet_start = gen_subnetv6($ifcfgip, $ifcfgsn);
390
		$subnet_end = gen_subnetv6_max($ifcfgip, $ifcfgsn);
391 99caa67c Seth Mos
392 756da4bd Phil Davis
		if (is_ipaddrv6($ifcfgip)) {
393
			if ((!is_inrange_v6($_POST['range_from'], $subnet_start, $subnet_end)) ||
394
				(!is_inrange_v6($_POST['range_to'], $subnet_start, $subnet_end))) {
395
				$input_errors[] = gettext("The specified range lies outside of the current subnet.");
396 8f8682f7 Phil Davis
			}
397 756da4bd Phil Davis
		}
398
		/* "from" cannot be higher than "to" */
399
		if (inet_pton($_POST['range_from']) > inet_pton($_POST['range_to'])) {
400
			$input_errors[] = gettext("The range is invalid (first element higher than second element).");
401
		}
402 99caa67c Seth Mos
403 756da4bd Phil Davis
		/* Verify static mappings do not overlap:
404
		   - available DHCP range
405
		   - prefix delegation range (FIXME: still need to be completed) */
406
		$dynsubnet_start = inet_pton($_POST['range_from']);
407
		$dynsubnet_end = inet_pton($_POST['range_to']);
408 731de711 Pierre POMES
409 756da4bd Phil Davis
		if (is_array($a_maps)) {
410
			foreach ($a_maps as $map) {
411
				if (empty($map['ipaddrv6'])) {
412
					continue;
413
				}
414
				if ((inet_pton($map['ipaddrv6']) > $dynsubnet_start) &&
415
					(inet_pton($map['ipaddrv6']) < $dynsubnet_end)) {
416
					$input_errors[] = sprintf(gettext("The DHCP range cannot overlap any static DHCP mappings."));
417
					break;
418 99caa67c Seth Mos
				}
419
			}
420
		}
421
	}
422
423
	if (!$input_errors) {
424 5fa2a4a2 Stephen Jones
		if (!is_array($config['dhcpdv6'])) {
425
			$config['dhcpdv6'] = array();
426
		}
427 8f8682f7 Phil Davis
		if (!is_array($config['dhcpdv6'][$if])) {
428 99caa67c Seth Mos
			$config['dhcpdv6'][$if] = array();
429 8f8682f7 Phil Davis
		}
430
		if (!is_array($config['dhcpdv6'][$if]['range'])) {
431 99caa67c Seth Mos
			$config['dhcpdv6'][$if]['range'] = array();
432 8f8682f7 Phil Davis
		}
433
		if (!is_array($config['dhcpdv6'][$if]['prefixrange'])) {
434 bfb3e717 Seth Mos
			$config['dhcpdv6'][$if]['prefixrange'] = array();
435 8f8682f7 Phil Davis
		}
436 99caa67c Seth Mos
437
		$config['dhcpdv6'][$if]['range']['from'] = $_POST['range_from'];
438
		$config['dhcpdv6'][$if]['range']['to'] = $_POST['range_to'];
439 bfb3e717 Seth Mos
		$config['dhcpdv6'][$if]['prefixrange']['from'] = $_POST['prefixrange_from'];
440
		$config['dhcpdv6'][$if]['prefixrange']['to'] = $_POST['prefixrange_to'];
441
		$config['dhcpdv6'][$if]['prefixrange']['prefixlength'] = $_POST['prefixrange_length'];
442 99caa67c Seth Mos
		$config['dhcpdv6'][$if]['defaultleasetime'] = $_POST['deftime'];
443
		$config['dhcpdv6'][$if]['maxleasetime'] = $_POST['maxtime'];
444
		$config['dhcpdv6'][$if]['netmask'] = $_POST['netmask'];
445
446
		unset($config['dhcpdv6'][$if]['winsserver']);
447
448
		unset($config['dhcpdv6'][$if]['dnsserver']);
449 8f8682f7 Phil Davis
		if ($_POST['dns1']) {
450 99caa67c Seth Mos
			$config['dhcpdv6'][$if]['dnsserver'][] = $_POST['dns1'];
451 8f8682f7 Phil Davis
		}
452
		if ($_POST['dns2']) {
453 99caa67c Seth Mos
			$config['dhcpdv6'][$if]['dnsserver'][] = $_POST['dns2'];
454 8f8682f7 Phil Davis
		}
455
		if ($_POST['dns3']) {
456 3d88ea11 Phil Davis
			$config['dhcpdv6'][$if]['dnsserver'][] = $_POST['dns3'];
457 8f8682f7 Phil Davis
		}
458
		if ($_POST['dns4']) {
459 3d88ea11 Phil Davis
			$config['dhcpdv6'][$if]['dnsserver'][] = $_POST['dns4'];
460 8f8682f7 Phil Davis
		}
461 c58e56fb luckman212
		$config['dhcpdv6'][$if]['dhcp6c-dns'] = ($_POST['dhcp6c-dns']) ? "enabled" : "disabled";
462 99caa67c Seth Mos
		$config['dhcpdv6'][$if]['domain'] = $_POST['domain'];
463
		$config['dhcpdv6'][$if]['domainsearchlist'] = $_POST['domainsearchlist'];
464
		$config['dhcpdv6'][$if]['enable'] = ($_POST['enable']) ? true : false;
465
		$config['dhcpdv6'][$if]['ddnsdomain'] = $_POST['ddnsdomain'];
466 87019fc4 Andres Petralli
		$config['dhcpdv6'][$if]['ddnsdomainprimary'] = $_POST['ddnsdomainprimary'];
467 635e5b9d Kris Anderson
		$config['dhcpdv6'][$if]['ddnsdomainsecondary'] = (!empty($_POST['ddnsdomainsecondary'])) ? $_POST['ddnsdomainsecondary'] : '';
468 87019fc4 Andres Petralli
		$config['dhcpdv6'][$if]['ddnsdomainkeyname'] = $_POST['ddnsdomainkeyname'];
469 534d7d69 Joeri Capens
		$config['dhcpdv6'][$if]['ddnsdomainkeyalgorithm'] = $_POST['ddnsdomainkeyalgorithm'];
470 87019fc4 Andres Petralli
		$config['dhcpdv6'][$if]['ddnsdomainkey'] = $_POST['ddnsdomainkey'];
471 99caa67c Seth Mos
		$config['dhcpdv6'][$if]['ddnsupdate'] = ($_POST['ddnsupdate']) ? true : false;
472 1a6bda5b Ross Williams
		$config['dhcpdv6'][$if]['ddnsforcehostname'] = ($_POST['ddnsforcehostname']) ? true : false;
473 391d63da Renato Botelho
		$config['dhcpdv6'][$if]['ddnsreverse'] = ($_POST['ddnsreverse']) ? true : false;
474
		$config['dhcpdv6'][$if]['ddnsclientupdates'] = $_POST['ddnsclientupdates'];
475 99caa67c Seth Mos
476
		unset($config['dhcpdv6'][$if]['ntpserver']);
477 8f8682f7 Phil Davis
		if ($_POST['ntp1']) {
478 99caa67c Seth Mos
			$config['dhcpdv6'][$if]['ntpserver'][] = $_POST['ntp1'];
479 8f8682f7 Phil Davis
		}
480
		if ($_POST['ntp2']) {
481 99caa67c Seth Mos
			$config['dhcpdv6'][$if]['ntpserver'][] = $_POST['ntp2'];
482 8f8682f7 Phil Davis
		}
483 5c52a260 kiokoman
		if ($_POST['ntp3']) {
484
			$config['dhcpdv6'][$if]['ntpserver'][] = $_POST['ntp3'];
485
		}
486 99caa67c Seth Mos
487
		$config['dhcpdv6'][$if]['tftp'] = $_POST['tftp'];
488
		$config['dhcpdv6'][$if]['ldap'] = $_POST['ldap'];
489
		$config['dhcpdv6'][$if]['netboot'] = ($_POST['netboot']) ? true : false;
490 bd942860 Renato Botelho
		$config['dhcpdv6'][$if]['bootfile_url'] = $_POST['bootfile_url'];
491 138208bf Joecowboy
		$config['dhcpdv6'][$if]['dhcpv6leaseinlocaltime'] = $_POST['dhcpv6leaseinlocaltime'];
492 99caa67c Seth Mos
493
		// Handle the custom options rowhelper
494 8f8682f7 Phil Davis
		if (isset($config['dhcpdv6'][$if]['numberoptions']['item'])) {
495 99caa67c Seth Mos
			unset($config['dhcpdv6'][$if]['numberoptions']['item']);
496 8f8682f7 Phil Davis
		}
497 99caa67c Seth Mos
498
		$config['dhcpdv6'][$if]['numberoptions'] = $numberoptions;
499
500 e85ae672 Renato Botelho do Couto
		write_config("DHCPv6 server settings saved");
501 99caa67c Seth Mos
502 44c42356 Phil Davis
		$changes_applied = true;
503
		$retval = dhcpv6_apply_changes($dhcpdv6_enable_changed);
504 99caa67c Seth Mos
	}
505
}
506
507 c946d721 Steve Beaver
if ($_POST['act'] == "del") {
508
	if ($a_maps[$_POST['id']]) {
509
		unset($a_maps[$_POST['id']]);
510 e85ae672 Renato Botelho do Couto
		write_config("DHCPv6 server static map deleted");
511 8f8682f7 Phil Davis
		if (isset($config['dhcpdv6'][$if]['enable'])) {
512 99caa67c Seth Mos
			mark_subsystem_dirty('staticmapsv6');
513 8f8682f7 Phil Davis
			if (isset($config['dnsmasq']['enable']) && isset($config['dnsmasq']['regdhcpstaticv6'])) {
514 99caa67c Seth Mos
				mark_subsystem_dirty('hosts');
515 8f8682f7 Phil Davis
			}
516 99caa67c Seth Mos
		}
517
		header("Location: services_dhcpv6.php?if={$if}");
518
		exit;
519
	}
520
}
521
522 46b7214c k-paulius
$pgtitle = array(gettext("Services"), htmlspecialchars(gettext("DHCPv6 Server & RA")));
523 edcd7535 Phil Davis
$pglinks = array("", "services_dhcpv6.php");
524 253fa019 k-paulius
525 75173246 Chris Buechler
if (!empty($if) && isset($iflist[$if])) {
526 253fa019 k-paulius
	$pgtitle[] = $iflist[$if];
527 edcd7535 Phil Davis
	$pglinks[] = "@self";
528 9c06758b k-paulius
	$pgtitle[] = gettext("DHCPv6 Server");
529 edcd7535 Phil Davis
	$pglinks[] = "@self";
530 253fa019 k-paulius
}
531 b32dd0a6 jim-p
$shortcut_section = "dhcp6";
532 99caa67c Seth Mos
533
include("head.inc");
534
535 6e3488e9 Phil Davis
if ($input_errors) {
536 cd2c7940 sbeaver
	print_input_errors($input_errors);
537 6e3488e9 Phil Davis
}
538 99caa67c Seth Mos
539 44c42356 Phil Davis
if ($changes_applied) {
540
	print_apply_result_box($retval);
541 6e3488e9 Phil Davis
}
542 99caa67c Seth Mos
543 6e3488e9 Phil Davis
if (is_subsystem_dirty('staticmaps')) {
544 5daef710 NOYB
	print_apply_box(gettext('The static mapping configuration has been changed.') . '<br />' . gettext('The changes must be applied for them to take effect.'));
545 6e3488e9 Phil Davis
}
546 99caa67c Seth Mos
547 cd2c7940 sbeaver
/* active tabs */
548
$tab_array = array();
549
$tabscounter = 0;
550
$i = 0;
551 c80e6a6a Stephen Beaver
552 cd2c7940 sbeaver
foreach ($iflist as $ifent => $ifname) {
553
	$oc = $config['interfaces'][$ifent];
554 2bf455ca Renato Botelho
	$valid_if_ipaddrv6 = (bool) ($oc['ipaddrv6'] == 'track6' ||
555
	    (is_ipaddrv6($oc['ipaddrv6']) &&
556
	    !is_linklocal($oc['ipaddrv6'])));
557 c80e6a6a Stephen Beaver
558 8f928dc3 Renato Botelho
	if ((!is_array($config['dhcpdv6'][$ifent]) ||
559 653529c3 Viktor G
	    !isset($config['dhcpdv6'][$ifent]['enable'])) &&
560 8f928dc3 Renato Botelho
	    !$valid_if_ipaddrv6) {
561 cd2c7940 sbeaver
		continue;
562 6e3488e9 Phil Davis
	}
563 cd2c7940 sbeaver
564 6e3488e9 Phil Davis
	if ($ifent == $if) {
565 cd2c7940 sbeaver
		$active = true;
566 6e3488e9 Phil Davis
	} else {
567 cd2c7940 sbeaver
		$active = false;
568 6e3488e9 Phil Davis
	}
569 cd2c7940 sbeaver
570
	$tab_array[] = array($ifname, $active, "services_dhcpv6.php?if={$ifent}");
571
	$tabscounter++;
572
}
573 c80e6a6a Stephen Beaver
574
if ($tabscounter == 0) {
575 cd2c7940 sbeaver
	print_info_box(gettext("The DHCPv6 Server can only be enabled on interfaces configured with a static IPv6 address. This system has none."), 'danger');
576
	include("foot.inc");
577
	exit;
578
}
579 99caa67c Seth Mos
580 9b54ac32 Stephen Beaver
display_top_tabs($tab_array);
581
582 cd2c7940 sbeaver
$tab_array = array();
583
$tab_array[] = array(gettext("DHCPv6 Server"),		 true,	"services_dhcpv6.php?if={$if}");
584
$tab_array[] = array(gettext("Router Advertisements"), false, "services_router_advertisements.php?if={$if}");
585 6e3488e9 Phil Davis
display_top_tabs($tab_array, false, 'nav nav-tabs');
586 99caa67c Seth Mos
587 8f58b51b jim-p
$form = new Form();
588 cd2c7940 sbeaver
589
$section = new Form_Section('DHCPv6 Options');
590
591 756da4bd Phil Davis
if ($dhcrelay_enabled) {
592
	$section->addInput(new Form_Checkbox(
593
		'enable',
594
		'DHCPv6 Server',
595
		gettext("DHCPv6 Relay is currently enabled. DHCPv6 Server canot be enabled while the DHCPv6 Relay is enabled on any interface."),
596
		$pconfig['enable']
597
	))->setAttribute('disabled', true);
598
} else {
599
	$section->addInput(new Form_Checkbox(
600
		'enable',
601
		'DHCPv6 Server',
602
		'Enable DHCPv6 server on interface ' . $iflist[$if],
603
		$pconfig['enable']
604
	));
605
}
606 cd2c7940 sbeaver
607 6e3488e9 Phil Davis
if (is_ipaddrv6($ifcfgip)) {
608 cd2c7940 sbeaver
609 e1953efa Chris Buechler
	if ($ifcfgip == "::") {
610
		$sntext = "Prefix Delegation";
611 29131ce9 Viktor G
		if (get_interface_track6ip($if)) {
612
			$track6ip = get_interface_track6ip($if);
613
			$pdsubnet = gen_subnetv6($track6ip[0], $track6ip[1]);
614
			$sntext .= " ({$pdsubnet}/{$track6ip[1]})";
615
		}
616 e1953efa Chris Buechler
	} else {
617
		$sntext = gen_subnetv6($ifcfgip, $ifcfgsn);
618
	}
619 cd2c7940 sbeaver
	$section->addInput(new Form_StaticText(
620
		'Subnet',
621 e1953efa Chris Buechler
		$sntext
622 cd2c7940 sbeaver
		));
623
624
	$section->addInput(new Form_StaticText(
625
		'Subnet Mask',
626
		$ifcfgsn . ' bits'
627
		));
628
629
	$section->addInput(new Form_StaticText(
630
		'Available Range',
631
		$range_from = gen_subnetv6($ifcfgip, $ifcfgsn) . ' to ' . gen_subnetv6_max($ifcfgip, $ifcfgsn)
632 e1953efa Chris Buechler
		))->setHelp($trackifname ? 'Prefix Delegation subnet will be appended to the beginning of the defined range':'');
633 cd2c7940 sbeaver
}
634
635
$f1 = new Form_Input(
636
	'range_from',
637
	null,
638
	'text',
639
	$pconfig['range_from']
640 218600a2 Renato Botelho
);
641
642
$f1->setHelp('From');
643 cd2c7940 sbeaver
644
$f2 = new Form_Input(
645
	'range_to',
646
	null,
647
	'text',
648
	$pconfig['range_to']
649 218600a2 Renato Botelho
);
650
651
$f2->setHelp('To');
652 cd2c7940 sbeaver
653 24b82516 Phil Davis
$group = new Form_Group('*Range');
654 cd2c7940 sbeaver
655
$group->add($f1);
656
$group->add($f2);
657
658
$section->add($group);
659
660
$f1 = new Form_Input(
661 70f17067 Stephen Beaver
	'prefixrange_from',
662 cd2c7940 sbeaver
	null,
663
	'text',
664 70f17067 Stephen Beaver
	$pconfig['prefixrange_from']
665 218600a2 Renato Botelho
);
666
667
$f1->setHelp('From');
668 cd2c7940 sbeaver
669
$f2 = new Form_Input(
670 70f17067 Stephen Beaver
	'prefixrange_to',
671 cd2c7940 sbeaver
	null,
672
	'text',
673 70f17067 Stephen Beaver
	$pconfig['prefixrange_to']
674 218600a2 Renato Botelho
);
675
676
$f2->setHelp('To');
677 cd2c7940 sbeaver
678
$group = new Form_Group('Prefix Delegation Range');
679
680
$group->add($f1);
681
$group->add($f2);
682
683
$section->add($group);
684
685
$section->addInput(new Form_Select(
686
	'prefixrange_length',
687
	'Prefix Delegation Size',
688
	$pconfig['prefixrange_length'],
689
	array(
690
		'48' => '48',
691
		'52' => '52',
692
		'56' => '56',
693 19d905bc PiBa-NL
		'59' => '59',
694 cd2c7940 sbeaver
		'60' => '60',
695 19d905bc PiBa-NL
		'61' => '61',
696 cd2c7940 sbeaver
		'62' => '62',
697
		'63' => '63',
698
		'64' => '64'
699
		)
700 5daef710 NOYB
))->setHelp('A Prefix range can be defined here for DHCP Prefix Delegation. This allows for assigning networks to subrouters. The start and end of the range must end on boundaries of the prefix delegation size.');
701 cd2c7940 sbeaver
702
$group = new Form_Group('DNS Servers');
703
704 6e3488e9 Phil Davis
for ($i=1;$i<=4; $i++) {
705 cd2c7940 sbeaver
	$group->add(new Form_input(
706
		'dns' . $i,
707
		null,
708
		'text',
709 e32f02a5 Phil Davis
		$pconfig['dns' . $i],
710
		['placeholder' => 'DNS ' . $i]
711
	));
712 cd2c7940 sbeaver
}
713
714 6e3488e9 Phil Davis
$group->setHelp('Leave blank to use the system default DNS servers, this interface\'s IP if DNS forwarder is enabled, or the servers configured on the "General" page.');
715 cd2c7940 sbeaver
$section->add($group);
716 9f6432f0 luckman212
717 e26ad76e luckman212
$section->addInput(new Form_Checkbox(
718 c58e56fb luckman212
	'dhcp6c-dns',
719 e26ad76e luckman212
	null,
720 9f6432f0 luckman212
	'Provide DNS servers to DHCPv6 clients',
721 c58e56fb luckman212
	($pconfig['dhcp6c-dns'] == "enabled")
722 b9f3dfd2 jim-p
))->setHelp('Unchecking this box disables the dhcp6.name-servers option. ' .
723
			'Use with caution, as the resulting behavior may violate RFCs and lead to unintended client behavior.');
724 cd2c7940 sbeaver
725
$section->addInput(new Form_Input(
726
	'domain',
727 cb6c20a9 NewEraCracker
	'Domain name',
728 cd2c7940 sbeaver
	'text',
729 ea6649f7 sbeaver
	$pconfig['domain']
730 5daef710 NOYB
))->setHelp('The default is to use the domain name of this system as the default domain name provided by DHCP. An alternate domain name may be specified here. ');
731 cd2c7940 sbeaver
732
$section->addInput(new Form_Input(
733
	'domainsearchlist',
734
	'Domain search list',
735
	'text',
736 ea6649f7 sbeaver
	$pconfig['domainsearchlist']
737 e4c7d45f NewEraCracker
))->setHelp('The DHCP server can optionally provide a domain search list. Use the semicolon character as separator.');
738 cd2c7940 sbeaver
739
$section->addInput(new Form_Input(
740
	'deftime',
741
	'Default lease time',
742
	'text',
743 ea6649f7 sbeaver
	$pconfig['deftime']
744 3fd41815 Phil Davis
))->setHelp('Lease time in seconds. Used for clients that do not ask for a specific expiration time. %1$s' .
745
			'The default is 7200 seconds.', '<br />');
746 cd2c7940 sbeaver
747
$section->addInput(new Form_Input(
748
	'maxtime',
749
	'Max lease time',
750
	'text',
751 ea6649f7 sbeaver
	$pconfig['maxtime']
752 3fd41815 Phil Davis
))->setHelp('Maximum lease time for clients that ask for a specific expiration time. %1$s' .
753
			'The default is 86400 seconds.', '<br />');
754 cd2c7940 sbeaver
755
$section->addInput(new Form_Checkbox(
756
	'dhcpv6leaseinlocaltime',
757
	'Time Format Change',
758
	'Change DHCPv6 display lease time from UTC to local time',
759
	$pconfig['dhcpv6leaseinlocaltime']
760
))->setHelp('By default DHCPv6 leases are displayed in UTC time. ' .
761
			'By checking this box DHCPv6 lease time will be displayed in local time and set to time zone selected. ' .
762
			'This will be used for all DHCPv6 interfaces lease time.');
763
764 4aa42b06 Phil Davis
$btnadv = new Form_Button(
765
	'btnadvdns',
766
	'Display Advanced',
767 3314e626 jim-p
	null,
768
	'fa-cog'
769 cd2c7940 sbeaver
);
770
771 347c0214 Phil Davis
$btnadv->setAttribute('type','button')->addClass('btn-info btn-sm');
772 cd2c7940 sbeaver
773
$section->addInput(new Form_StaticText(
774
	'Dynamic DNS',
775 4aa42b06 Phil Davis
	$btnadv
776 cd2c7940 sbeaver
));
777
778
$section->addInput(new Form_Checkbox(
779
	'ddnsupdate',
780
	'DHCP Registration',
781
	'Enable registration of DHCP client names in DNS.',
782
	$pconfig['ddnsupdate']
783
));
784
785
$section->addInput(new Form_Input(
786
	'ddnsdomain',
787
	'DDNS Domain',
788
	'text',
789 ea6649f7 sbeaver
	$pconfig['ddnsdomain']
790 e5c4b4fc Joeri Capens
))->setHelp('Enter the dynamic DNS domain which will be used to register client names in the DNS server.');
791 cd2c7940 sbeaver
792 1a6bda5b Ross Williams
$section->addInput(new Form_Checkbox(
793
	'ddnsforcehostname',
794 cfc10a33 Ross Williams
	'DDNS Hostnames',
795 1a6bda5b Ross Williams
	'Force dynamic DNS hostname to be the same as configured hostname for Static Mappings',
796
	$pconfig['ddnsforcehostname']
797 9ca5d4ab Ross Williams
))->setHelp('Default registers host name option supplied by DHCP client.');
798 1a6bda5b Ross Williams
799 cd2c7940 sbeaver
$section->addInput(new Form_IpAddress(
800
	'ddnsdomainprimary',
801 9fbd8f71 Viktor Gurov
	'Primary DDNS address',
802 ff3d11c8 Phil Davis
	$pconfig['ddnsdomainprimary'],
803 9fbd8f71 Viktor Gurov
	'BOTH'
804
))->setHelp('Enter the primary domain name server IP address for the dynamic domain name.');
805
806
$section->addInput(new Form_IpAddress(
807
	'ddnsdomainsecondary',
808
	'Secondary DDNS address',
809
	$pconfig['ddnsdomainsecondary'],
810
	'BOTH'
811
))->setHelp('Enter the secondary domain name server IP address for the dynamic domain name.');
812 cd2c7940 sbeaver
813
$section->addInput(new Form_Input(
814
	'ddnsdomainkeyname',
815
	'DDNS Domain Key name',
816
	'text',
817 ea6649f7 sbeaver
	$pconfig['ddnsdomainkeyname']
818 cd2c7940 sbeaver
))->setHelp('Enter the dynamic DNS domain key name which will be used to register client names in the DNS server.');
819
820 534d7d69 Joeri Capens
$section->addInput(new Form_Select(
821
	'ddnsdomainkeyalgorithm',
822
	'Key algorithm',
823
	$pconfig['ddnsdomainkeyalgorithm'],
824
	array(
825
		'hmac-md5' => 'HMAC-MD5 (legacy default)',
826
		'hmac-sha1' => 'HMAC-SHA1',
827
		'hmac-sha224' => 'HMAC-SHA224',
828
		'hmac-sha256' => 'HMAC-SHA256 (current bind9 default)',
829
		'hmac-sha384' => 'HMAC-SHA384',
830
		'hmac-sha512' => 'HMAC-SHA512 (most secure)',
831
	)
832
));
833
834 cd2c7940 sbeaver
$section->addInput(new Form_Input(
835
	'ddnsdomainkey',
836
	'DDNS Domain Key secret',
837
	'text',
838 ea6649f7 sbeaver
	$pconfig['ddnsdomainkey']
839 9fbd8f71 Viktor Gurov
))->setAttribute('placeholder', 'Base64 encoded string')
840
->setHelp('Enter the dynamic DNS domain key secret which will be used to register client names in the DNS server.');
841 cd2c7940 sbeaver
842 391d63da Renato Botelho
$section->addInput(new Form_Select(
843
	'ddnsclientupdates',
844
	'DDNS Client Updates',
845
	$pconfig['ddnsclientupdates'],
846
	array(
847
	    'allow' => gettext('Allow'),
848
	    'deny' => gettext('Deny'),
849
	    'ignore' => gettext('Ignore'))
850
))->setHelp('How Forward entries are handled when client indicates they wish to update DNS.  ' .
851
	    'Allow prevents DHCP from updating Forward entries, Deny indicates that DHCP will ' .
852
	    'do the updates and the client should not, Ignore specifies that DHCP will do the ' .
853
	    'update and the client can also attempt the update usually using a different domain name.');
854
855
$section->addInput(new Form_Checkbox(
856
	'ddnsreverse',
857
	'DDNS Reverse',
858
	'Add reverse dynamic DNS entries.',
859
	$pconfig['ddnsreverse']
860
));
861
862 4aa42b06 Phil Davis
$btnadv = new Form_Button(
863
	'btnadvntp',
864
	'Display Advanced',
865 3314e626 jim-p
	null,
866
	'fa-cog'
867 cd2c7940 sbeaver
);
868
869 347c0214 Phil Davis
$btnadv->setAttribute('type','button')->addClass('btn-info btn-sm');
870 cd2c7940 sbeaver
871
$section->addInput(new Form_StaticText(
872
	'NTP servers',
873 4aa42b06 Phil Davis
	$btnadv
874 cd2c7940 sbeaver
));
875
876
$group = new Form_Group('NTP Servers');
877
878
$group->add(new Form_Input(
879
	'ntp1',
880
	'NTP Server 1',
881
	'text',
882 ea6649f7 sbeaver
	$pconfig['ntp1'],
883 cd2c7940 sbeaver
	['placeholder' => 'NTP 1']
884
));
885
886
$group->add(new Form_Input(
887
	'ntp2',
888 e32f02a5 Phil Davis
	'NTP Server 2',
889 cd2c7940 sbeaver
	'text',
890 ea6649f7 sbeaver
	$pconfig['ntp2'],
891 cd2c7940 sbeaver
	['placeholder' => 'NTP 2']
892
));
893
894 5c52a260 kiokoman
$group->add(new Form_Input(
895
	'ntp3',
896
	'NTP Server 3',
897
	'text',
898
	$pconfig['ntp3'],
899
	['placeholder' => 'NTP 3']
900
));
901
902 cd2c7940 sbeaver
$group->addClass('ntpclass');
903
904
$section->add($group);
905
906 4aa42b06 Phil Davis
$btnadv = new Form_Button(
907
	'btnadvldap',
908
	'Display Advanced',
909 3314e626 jim-p
	null,
910
	'fa-cog'
911 cd2c7940 sbeaver
);
912
913 347c0214 Phil Davis
$btnadv->setAttribute('type','button')->addClass('btn-info btn-sm');
914 cd2c7940 sbeaver
915
$section->addInput(new Form_StaticText(
916
	'LDAP',
917 4aa42b06 Phil Davis
	$btnadv
918 cd2c7940 sbeaver
));
919
920
$section->addInput(new Form_Input(
921
	'ldap',
922
	'LDAP URI',
923
	'text',
924 ea6649f7 sbeaver
	$pconfig['ldap']
925 cd2c7940 sbeaver
));
926
927 4aa42b06 Phil Davis
$btnadv = new Form_Button(
928
	'btnadvnetboot',
929
	'Display Advanced',
930 3314e626 jim-p
	null,
931
	'fa-cog'
932 cd2c7940 sbeaver
);
933
934 347c0214 Phil Davis
$btnadv->setAttribute('type','button')->addClass('btn-info btn-sm');
935 cd2c7940 sbeaver
936
$section->addInput(new Form_StaticText(
937
	'Network booting',
938 4aa42b06 Phil Davis
	$btnadv
939 cd2c7940 sbeaver
));
940
941
$section->addInput(new Form_Checkbox(
942 e46ea2c6 Stephen Jones
	'netboot',
943 cd2c7940 sbeaver
	'Network booting',
944
	'Enable Network Booting',
945 e46ea2c6 Stephen Jones
	$pconfig['netboot']
946 cd2c7940 sbeaver
));
947
948
$section->addInput(new Form_Input(
949
	'bootfile_url',
950
	'Bootfile URL',
951
	'text',
952 ea6649f7 sbeaver
	$pconfig['bootfile_url']
953 cd2c7940 sbeaver
));
954
955 4aa42b06 Phil Davis
$btnadv = new Form_Button(
956
	'btnadvopts',
957
	'Display Advanced',
958 3314e626 jim-p
	null,
959
	'fa-cog'
960 cd2c7940 sbeaver
);
961
962 347c0214 Phil Davis
$btnadv->setAttribute('type','button')->addClass('btn-info btn-sm');
963 cd2c7940 sbeaver
964
$section->addInput(new Form_StaticText(
965
	'Additional BOOTP/DHCP Options',
966 4aa42b06 Phil Davis
	$btnadv
967 cd2c7940 sbeaver
));
968
969
$form->add($section);
970
971
$title = 'Show Additional BOOTP/DHCP Options';
972
973 b090a0d9 Stephen Beaver
if (!$pconfig['numberoptions']) {
974 0716b616 Stephen Beaver
	$noopts = true;
975 d4cebe1f Steve Beaver
	$pconfig['numberoptions'] = array();
976 b090a0d9 Stephen Beaver
	$pconfig['numberoptions']['item'] = array(0 => array('number' => "", 'value' => ""));
977 0716b616 Stephen Beaver
} else {
978
	$noopts = false;
979 b090a0d9 Stephen Beaver
}
980
981
$counter = 0;
982 a2a60a07 Stephen Jones
if (!is_array($pconfig['numberoptions'])) {
983
	$pconfig['numberoptions'] = array();
984
}
985
if (!is_array($pconfig['numberoptions']['item'])) {
986
	$pconfig['numberoptions']['item'] = array();
987
}
988 b090a0d9 Stephen Beaver
$last = count($pconfig['numberoptions']['item']) - 1;
989
990
foreach ($pconfig['numberoptions']['item'] as $item) {
991
	$group = new Form_Group(null);
992
	$group->addClass('repeatable');
993 0716b616 Stephen Beaver
	$group->addClass('adnloptions');
994 b090a0d9 Stephen Beaver
995
	$group->add(new Form_Input(
996
		'number' . $counter,
997
		null,
998
		'text',
999
		$item['number']
1000
	))->setHelp($counter == $last ? 'Number':null);
1001
1002
	$group->add(new Form_Input(
1003
		'value' . $counter,
1004
		null,
1005
		'text',
1006
		base64_decode($item['value'])
1007
	))->setHelp($counter == $last ? 'Value':null);
1008
1009
	$btn = new Form_Button(
1010
		'deleterow' . $counter,
1011 faab522f Renato Botelho
		'Delete',
1012 cd7ddae6 jim-p
		null,
1013
		'fa-trash'
1014 b090a0d9 Stephen Beaver
	);
1015
1016 cd7ddae6 jim-p
	$btn->addClass('btn-warning');
1017 b090a0d9 Stephen Beaver
	$group->add($btn);
1018
	$section->add($group);
1019
	$counter++;
1020 cd2c7940 sbeaver
}
1021
1022 b090a0d9 Stephen Beaver
1023 cd2c7940 sbeaver
$btnaddopt = new Form_Button(
1024 9eeb91dd Stephen Beaver
	'addrow',
1025 faab522f Renato Botelho
	'Add Option',
1026 cd7ddae6 jim-p
	null,
1027
	'fa-plus'
1028 cd2c7940 sbeaver
);
1029
1030 9eeb91dd Stephen Beaver
$btnaddopt->removeClass('btn-primary')->addClass('btn-success btn-sm');
1031 cd2c7940 sbeaver
1032
$section->addInput($btnaddopt);
1033
1034 ee12dd78 Peter Feichtinger
$form->addGlobal(new Form_Input(
1035 cd2c7940 sbeaver
	'if',
1036
	null,
1037
	'hidden',
1038
	$if
1039
));
1040
1041
print($form);
1042 b090a0d9 Stephen Beaver
1043 f78bbe16 Phil Davis
?>
1044 c95dabdd Stephen Beaver
<div class="infoblock blockopen">
1045 f78bbe16 Phil Davis
<?php
1046 0a8a90f7 Phil Davis
print_info_box(
1047
	sprintf(
1048 e4c7d45f NewEraCracker
		gettext('The DNS servers entered in %1$sSystem: General Setup%3$s (or the %2$sDNS forwarder%3$s if enabled) will be assigned to clients by the DHCP server.'),
1049 0a8a90f7 Phil Davis
		'<a href="system.php">',
1050
		'<a href="services_dnsmasq.php"/>',
1051 9eeb91dd Stephen Beaver
		'</a>') .
1052 0a8a90f7 Phil Davis
	'<br />' .
1053
	sprintf(
1054
		gettext('The DHCP lease table can be viewed on the %1$sStatus: DHCPv6 leases%2$s page.'),
1055
		'<a href="status_dhcpv6_leases.php">',
1056
		'</a>'),
1057
	'info',
1058
	false);
1059 99caa67c Seth Mos
?>
1060 f78bbe16 Phil Davis
</div>
1061 cd2c7940 sbeaver
<div class="panel panel-default">
1062 544af3fe k-paulius
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("DHCPv6 Static Mappings for this Interface");?></h2></div>
1063 cd2c7940 sbeaver
	<div class="panel-body table-responsive">
1064
		<table class="table table-striped table-hover table-condensed">
1065
			<thead>
1066
				<tr>
1067
					<th><?=gettext("DUID")?></th>
1068
					<th><?=gettext("IPv6 address")?></th>
1069
					<th><?=gettext("Hostname")?></th>
1070
					<th><?=gettext("Description")?></th>
1071
					<th><!-- Buttons --></th>
1072
				</tr>
1073
			</thead>
1074
			<tbody>
1075 99caa67c Seth Mos
<?php
1076 6e3488e9 Phil Davis
if (is_array($a_maps)):
1077 99caa67c Seth Mos
	$i = 0;
1078 cd2c7940 sbeaver
	foreach ($a_maps as $mapent):
1079 6e3488e9 Phil Davis
		if ($mapent['duid'] != "" or $mapent['ipaddrv6'] != ""):
1080 99caa67c Seth Mos
?>
1081 cd2c7940 sbeaver
				<tr>
1082 7d0ad4ec Joecowboy
					<td>
1083 cd2c7940 sbeaver
						<?=htmlspecialchars($mapent['duid'])?>
1084 7d0ad4ec Joecowboy
					</td>
1085
					<td>
1086 cd2c7940 sbeaver
						<?=htmlspecialchars($mapent['ipaddrv6'])?>
1087 7d0ad4ec Joecowboy
					</td>
1088
					<td>
1089 cd2c7940 sbeaver
						<?=htmlspecialchars($mapent['hostname'])?>
1090
					</td>
1091
					<td>
1092
						<?=htmlspecialchars($mapent['descr'])?>
1093
					</td>
1094
					<td>
1095 33f0b0d5 Stephen Beaver
						<a class="fa fa-pencil"	title="<?=gettext('Edit static mapping')?>" href="services_dhcpv6_edit.php?if=<?=$if?>&amp;id=<?=$i?>"></a>
1096 c946d721 Steve Beaver
						<a class="fa fa-trash"	title="<?=gettext('Delete static mapping')?>" href="services_dhcpv6.php?if=<?=$if?>&amp;act=del&amp;id=<?=$i?>" usepost></a>
1097 7d0ad4ec Joecowboy
					</td>
1098 99caa67c Seth Mos
				</tr>
1099 cd2c7940 sbeaver
<?php
1100
		endif;
1101
	$i++;
1102
	endforeach;
1103
endif;
1104
?>
1105
			</tbody>
1106 99caa67c Seth Mos
		</table>
1107
	</div>
1108 cd2c7940 sbeaver
</div>
1109
1110 c10cb196 Stephen Beaver
<nav class="action-buttons">
1111 c9679d8c Stephen Beaver
	<a href="services_dhcpv6_edit.php?if=<?=$if?>" class="btn btn-sm btn-success"/>
1112 9d5a20cf heper
		<i class="fa fa-plus icon-embed-btn"></i>
1113 c9679d8c Stephen Beaver
		<?=gettext("Add")?>
1114
	</a>
1115 cd2c7940 sbeaver
</nav>
1116
1117 8fd9052f Colin Fleming
<script type="text/javascript">
1118 ee9530e1 Colin Fleming
//<![CDATA[
1119 6e3488e9 Phil Davis
events.push(function() {
1120 cd2c7940 sbeaver
1121 4aa42b06 Phil Davis
	// Show advanced DNS options ======================================================================================
1122
	var showadvdns = false;
1123
1124
	function show_advdns(ispageload) {
1125
		var text;
1126
		// On page load decide the initial state based on the data.
1127
		if (ispageload) {
1128
<?php
1129
			if (!$pconfig['ddnsupdate'] &&
1130 1a6bda5b Ross Williams
			    !$pconfig['ddnsforcehostname'] &&
1131 4aa42b06 Phil Davis
			    empty($pconfig['ddnsdomain']) &&
1132
			    empty($pconfig['ddnsdomainprimary']) &&
1133 9fbd8f71 Viktor Gurov
			    empty($pconfig['ddnsdomainsecondary']) &&
1134 4aa42b06 Phil Davis
			    empty($pconfig['ddnsdomainkeyname']) &&
1135 7ba6788b jim-p
			    (empty($pconfig['ddnsdomainkeyalgorithm'])  || ($pconfig['ddnsdomainkeyalgorithm'] == "hmac-md5")) &&
1136 4aa42b06 Phil Davis
			    empty($pconfig['ddnsdomainkey']) &&
1137
			    (empty($pconfig['ddnsclientupdates']) || ($pconfig['ddnsclientupdates'] == "allow")) &&
1138
			    !$pconfig['ddnsreverse']) {
1139
				$showadv = false;
1140
			} else {
1141
				$showadv = true;
1142
			}
1143
?>
1144
			showadvdns = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
1145
		} else {
1146
			// It was a click, swap the state.
1147
			showadvdns = !showadvdns;
1148
		}
1149
1150
		hideCheckbox('ddnsupdate', !showadvdns);
1151
		hideInput('ddnsdomain', !showadvdns);
1152 1a6bda5b Ross Williams
		hideCheckbox('ddnsforcehostname', !showadvdns);
1153 4aa42b06 Phil Davis
		hideInput('ddnsdomainprimary', !showadvdns);
1154 9fbd8f71 Viktor Gurov
		hideInput('ddnsdomainsecondary', !showadvdns);
1155 4aa42b06 Phil Davis
		hideInput('ddnsdomainkeyname', !showadvdns);
1156 534d7d69 Joeri Capens
		hideInput('ddnsdomainkeyalgorithm', !showadvdns);
1157 4aa42b06 Phil Davis
		hideInput('ddnsdomainkey', !showadvdns);
1158
		hideInput('ddnsclientupdates', !showadvdns);
1159
		hideCheckbox('ddnsreverse', !showadvdns);
1160
1161
		if (showadvdns) {
1162
			text = "<?=gettext('Hide Advanced');?>";
1163
		} else {
1164
			text = "<?=gettext('Display Advanced');?>";
1165
		}
1166
		$('#btnadvdns').html('<i class="fa fa-cog"></i> ' + text);
1167 cd2c7940 sbeaver
	}
1168
1169 4aa42b06 Phil Davis
	$('#btnadvdns').click(function(event) {
1170
		show_advdns();
1171 cd2c7940 sbeaver
	});
1172
1173 4aa42b06 Phil Davis
	// Show advanced NTP options ======================================================================================
1174
	var showadvntp = false;
1175 cd2c7940 sbeaver
1176 4aa42b06 Phil Davis
	function show_advntp(ispageload) {
1177
		var text;
1178
		// On page load decide the initial state based on the data.
1179
		if (ispageload) {
1180
<?php
1181 5c52a260 kiokoman
			if (empty($pconfig['ntp1']) && empty($pconfig['ntp2']) && empty($pconfig['ntp3'])) {
1182 4aa42b06 Phil Davis
				$showadv = false;
1183
			} else {
1184
				$showadv = true;
1185
			}
1186
?>
1187
			showadvntp = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
1188
		} else {
1189
			// It was a click, swap the state.
1190
			showadvntp = !showadvntp;
1191
		}
1192 cd2c7940 sbeaver
1193 4aa42b06 Phil Davis
		hideInput('ntp1', !showadvntp);
1194
		hideInput('ntp2', !showadvntp);
1195 5c52a260 kiokoman
		hideInput('ntp3', !showadvntp);
1196 cd2c7940 sbeaver
1197 4aa42b06 Phil Davis
		if (showadvntp) {
1198
			text = "<?=gettext('Hide Advanced');?>";
1199
		} else {
1200
			text = "<?=gettext('Display Advanced');?>";
1201
		}
1202
		$('#btnadvntp').html('<i class="fa fa-cog"></i> ' + text);
1203
	}
1204 cd2c7940 sbeaver
1205 4aa42b06 Phil Davis
	$('#btnadvntp').click(function(event) {
1206
		show_advntp();
1207 cd2c7940 sbeaver
	});
1208
1209 4aa42b06 Phil Davis
	// Show advanced LDAP options ======================================================================================
1210
	var showadvldap = false;
1211 cd2c7940 sbeaver
1212 4aa42b06 Phil Davis
	function show_advldap(ispageload) {
1213
		var text;
1214
		// On page load decide the initial state based on the data.
1215
		if (ispageload) {
1216
<?php
1217
			if (empty($pconfig['ldap'])) {
1218
				$showadv = false;
1219
			} else {
1220
				$showadv = true;
1221
			}
1222
?>
1223
			showadvldap = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
1224
		} else {
1225
			// It was a click, swap the state.
1226
			showadvldap = !showadvldap;
1227
		}
1228
1229
		hideInput('ldap', !showadvldap);
1230
1231
		if (showadvldap) {
1232
			text = "<?=gettext('Hide Advanced');?>";
1233
		} else {
1234
			text = "<?=gettext('Display Advanced');?>";
1235
		}
1236
		$('#btnadvldap').html('<i class="fa fa-cog"></i> ' + text);
1237
	}
1238
1239
	$('#btnadvldap').click(function(event) {
1240
		show_advldap();
1241 cd2c7940 sbeaver
	});
1242
1243 4aa42b06 Phil Davis
	// Show advanced Netboot options ======================================================================================
1244
	var showadvnetboot = false;
1245
1246
	function show_advnetboot(ispageload) {
1247
		var text;
1248
		// On page load decide the initial state based on the data.
1249
		if (ispageload) {
1250
<?php
1251 e46ea2c6 Stephen Jones
			if (!$pconfig['netboot'] && empty($pconfig['bootfile_url'])) {
1252 4aa42b06 Phil Davis
				$showadv = false;
1253
			} else {
1254
				$showadv = true;
1255
			}
1256
?>
1257
			showadvnetboot = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
1258
		} else {
1259
			// It was a click, swap the state.
1260
			showadvnetboot = !showadvnetboot;
1261
		}
1262
1263 e46ea2c6 Stephen Jones
		hideCheckbox('netboot', !showadvnetboot);
1264 4aa42b06 Phil Davis
		hideInput('bootfile_url', !showadvnetboot);
1265
1266
		if (showadvnetboot) {
1267
			text = "<?=gettext('Hide Advanced');?>";
1268
		} else {
1269
			text = "<?=gettext('Display Advanced');?>";
1270
		}
1271
		$('#btnadvnetboot').html('<i class="fa fa-cog"></i> ' + text);
1272
	}
1273
1274
	$('#btnadvnetboot').click(function(event) {
1275
		show_advnetboot();
1276 cd2c7940 sbeaver
	});
1277
1278 4aa42b06 Phil Davis
	// Show advanced additional opts options ===========================================================================
1279
	var showadvopts = false;
1280
1281
	function show_advopts(ispageload) {
1282
		var text;
1283
		// On page load decide the initial state based on the data.
1284
		if (ispageload) {
1285
<?php
1286
			if (empty($pconfig['numberoptions']) ||
1287
			    (empty($pconfig['numberoptions']['item'][0]['number']) && (empty($pconfig['numberoptions']['item'][0]['value'])))) {
1288
				$showadv = false;
1289
			} else {
1290
				$showadv = true;
1291
			}
1292
?>
1293
			showadvopts = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
1294
		} else {
1295
			// It was a click, swap the state.
1296
			showadvopts = !showadvopts;
1297
		}
1298
1299
		hideClass('adnloptions', !showadvopts);
1300
		hideInput('addrow', !showadvopts);
1301
1302
		if (showadvopts) {
1303
			text = "<?=gettext('Hide Advanced');?>";
1304
		} else {
1305
			text = "<?=gettext('Display Advanced');?>";
1306
		}
1307
		$('#btnadvopts').html('<i class="fa fa-cog"></i> ' + text);
1308
	}
1309
1310
	$('#btnadvopts').click(function(event) {
1311
		show_advopts();
1312 9eeb91dd Stephen Beaver
		checkLastRow();
1313 cd2c7940 sbeaver
	});
1314
1315
	// On initial load
1316 4aa42b06 Phil Davis
	show_advdns(true);
1317
	show_advntp(true);
1318
	show_advldap(true);
1319
	show_advnetboot(true);
1320
	show_advopts(true);
1321 611cc5ca Renato Botelho
	if ($('#enable').prop('checked')) {
1322
		hideClass('adnloptions', <?php echo json_encode($noopts); ?>);
1323
		hideInput('addrow', <?php echo json_encode($noopts); ?>);
1324
	} else {
1325
		hideClass('adnloptions', true);
1326
		hideInput('addrow', true);
1327
	}
1328 9eeb91dd Stephen Beaver
1329 cd2c7940 sbeaver
});
1330 ee9530e1 Colin Fleming
//]]>
1331 99caa67c Seth Mos
</script>
1332 cd2c7940 sbeaver
1333 2f5dafed heper
<?php include('foot.inc');