Project

General

Profile

Download (56.3 KB) Statistics
| Branch: | Tag: | Revision:
1 e9f147c8 Scott Ullrich
<?php
2 5b237745 Scott Ullrich
/*
3 c5d81585 Renato Botelho
 * services_dhcp.php
4 919d91f9 Phil Davis
 *
5 c5d81585 Renato Botelho
 * part of pfSense (https://www.pfsense.org)
6 4a762cf0 Steve Beaver
 * Copyright (c) 2004-2019 Rubicon Communications, LLC (Netgate)
7 c5d81585 Renato Botelho
 * All rights reserved.
8 b5f6e690 Stephen Beaver
 *
9 c5d81585 Renato Botelho
 * originally based on m0n0wall (http://m0n0.ch/wall)
10
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
11
 * All rights reserved.
12 b5f6e690 Stephen Beaver
 *
13 b12ea3fb Renato Botelho
 * Licensed under the Apache License, Version 2.0 (the "License");
14
 * you may not use this file except in compliance with the License.
15
 * You may obtain a copy of the License at
16 b5f6e690 Stephen Beaver
 *
17 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
18 b5f6e690 Stephen Beaver
 *
19 b12ea3fb Renato Botelho
 * Unless required by applicable law or agreed to in writing, software
20
 * distributed under the License is distributed on an "AS IS" BASIS,
21
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
 * See the License for the specific language governing permissions and
23
 * limitations under the License.
24 b5f6e690 Stephen Beaver
 */
25 5b237745 Scott Ullrich
26 6b07c15a Matthew Grooms
##|+PRIV
27
##|*IDENT=page-services-dhcpserver
28 9599211d jim-p
##|*NAME=Services: DHCP Server
29
##|*DESCR=Allow access to the 'Services: DHCP Server' page.
30 6b07c15a Matthew Grooms
##|*MATCH=services_dhcp.php*
31
##|-PRIV
32
33 c81ef6e2 Phil Davis
require_once("guiconfig.inc");
34 6c124212 Phil Davis
require_once("filter.inc");
35 6303601e heper
require_once('rrd.inc');
36
require_once("shaper.inc");
37 5b237745 Scott Ullrich
38 8f8682f7 Phil Davis
if (!$g['services_dhcp_server_enable']) {
39 6f3d2063 Renato Botelho
	header("Location: /");
40 2ee0410f Scott Ullrich
	exit;
41
}
42
43 c946d721 Steve Beaver
$if = $_REQUEST['if'];
44 934240ef Ermal Luçi
$iflist = get_configured_interface_with_descr();
45 5b237745 Scott Ullrich
46 1c451b06 Scott Ullrich
/* set the starting interface */
47 f19651d1 Ermal
if (!$if || !isset($iflist[$if])) {
48 cde97f1c Phil Davis
	$found_starting_if = false;
49
	// First look for an interface with DHCP already enabled.
50 01fdb2d3 Erik Fonnesbeck
	foreach ($iflist as $ifent => $ifname) {
51 de792e62 jim-p
		$oc = $config['interfaces'][$ifent];
52 403dad2a Renato Botelho
		if (is_array($config['dhcpd'][$ifent]) &&
53
		    isset($config['dhcpd'][$ifent]['enable']) &&
54
		    is_ipaddrv4($oc['ipaddr']) && $oc['subnet'] < 31) {
55 cde97f1c Phil Davis
			$if = $ifent;
56
			$found_starting_if = true;
57
			break;
58 8f8682f7 Phil Davis
		}
59 cde97f1c Phil Davis
	}
60
61 403dad2a Renato Botelho
	/*
62
	 * If there is no DHCP-enabled interface and LAN is a candidate,
63
	 * then choose LAN.
64
	 */
65
	if (!$found_starting_if && isset($iflist['lan']) &&
66
	    is_ipaddrv4($config['interfaces']['lan']['ipaddr']) &&
67
	    $config['interfaces']['lan']['subnet'] < 31) {
68 cde97f1c Phil Davis
		$if = 'lan';
69
		$found_starting_if = true;
70
	}
71 b5f6e690 Stephen Beaver
72 cde97f1c Phil Davis
	// At the last select whatever can be found.
73
	if (!$found_starting_if) {
74
		foreach ($iflist as $ifent => $ifname) {
75
			$oc = $config['interfaces'][$ifent];
76 403dad2a Renato Botelho
77
			/* Not static IPv4 or subnet >= 31 */
78
			if (!is_ipaddrv4($oc['ipaddr']) ||
79
			    empty($oc['subnet']) || $oc['subnet'] < 31) {
80
				continue;
81
			}
82
83
			if (!is_array($config['dhcpd'][$ifent]) ||
84
			    !isset($config['dhcpd'][$ifent]['enable'])) {
85 cde97f1c Phil Davis
				continue;
86
			}
87
88
			$if = $ifent;
89
			break;
90
		}
91 01fdb2d3 Erik Fonnesbeck
	}
92 f19651d1 Ermal
}
93 0a2c6a5b Scott Ullrich
94 c946d721 Steve Beaver
$act = $_REQUEST['act'];
95 cba980f6 jim-p
96 cc6052f0 Renato Botelho
$a_pools = array();
97 cba980f6 jim-p
98 8f8682f7 Phil Davis
if (is_array($config['dhcpd'][$if])) {
99 c946d721 Steve Beaver
	$pool = $_REQUEST['pool'];
100 8f8682f7 Phil Davis
	if (is_numeric($_POST['pool'])) {
101 cba980f6 jim-p
		$pool = $_POST['pool'];
102 8f8682f7 Phil Davis
	}
103 cba980f6 jim-p
104
	// If we have a pool but no interface name, that's not valid. Redirect away.
105
	if (is_numeric($pool) && empty($if)) {
106
		header("Location: services_dhcp.php");
107
		exit;
108 de792e62 jim-p
	}
109 cba980f6 jim-p
110 ea0dd417 jim-p
	init_config_arr(array('dhcpd', $if, 'pool'));
111 cba980f6 jim-p
	$a_pools = &$config['dhcpd'][$if]['pool'];
112
113 8f8682f7 Phil Davis
	if (is_numeric($pool) && $a_pools[$pool]) {
114 cba980f6 jim-p
		$dhcpdconf = &$a_pools[$pool];
115 8f8682f7 Phil Davis
	} elseif ($act == "newpool") {
116 cba980f6 jim-p
		$dhcpdconf = array();
117 8f8682f7 Phil Davis
	} else {
118 cba980f6 jim-p
		$dhcpdconf = &$config['dhcpd'][$if];
119 8f8682f7 Phil Davis
	}
120 e7940d2e Phil Davis
121 ea0dd417 jim-p
	init_config_arr(array('dhcpd', $if, 'staticmap'));
122 e7940d2e Phil Davis
	$a_maps = &$config['dhcpd'][$if]['staticmap'];
123 cba980f6 jim-p
}
124 c946d721 Steve Beaver
125 cba980f6 jim-p
if (is_array($dhcpdconf)) {
126
	// Global Options
127
	if (!is_numeric($pool) && !($act == "newpool")) {
128
		$pconfig['enable'] = isset($dhcpdconf['enable']);
129
		$pconfig['staticarp'] = isset($dhcpdconf['staticarp']);
130
		// No reason to specify this per-pool, per the dhcpd.conf man page it needs to be in every
131 b5f6e690 Stephen Beaver
		//	 pool and should be specified in every pool both nodes share, so we'll treat it as global
132 cba980f6 jim-p
		$pconfig['failover_peerip'] = $dhcpdconf['failover_peerip'];
133 466aae83 Phil Davis
134
		// dhcpleaseinlocaltime is global to all interfaces. So if it is selected on any interface,
135
		// then show it true/checked.
136
		foreach ($config['dhcpd'] as $dhcpdifitem) {
137
			$dhcpleaseinlocaltime = $dhcpdifitem['dhcpleaseinlocaltime'];
138 8f8682f7 Phil Davis
			if ($dhcpleaseinlocaltime) {
139 466aae83 Phil Davis
				break;
140 8f8682f7 Phil Davis
			}
141 466aae83 Phil Davis
		}
142
143
		$pconfig['dhcpleaseinlocaltime'] = $dhcpleaseinlocaltime;
144 ee1fb205 jim-p
	} else {
145
		// Options that exist only in pools
146
		$pconfig['descr'] = $dhcpdconf['descr'];
147 cba980f6 jim-p
	}
148
149
	// Options that can be global or per-pool.
150
	if (is_array($dhcpdconf['range'])) {
151
		$pconfig['range_from'] = $dhcpdconf['range']['from'];
152
		$pconfig['range_to'] = $dhcpdconf['range']['to'];
153
	}
154 b5f6e690 Stephen Beaver
155 cba980f6 jim-p
	$pconfig['deftime'] = $dhcpdconf['defaultleasetime'];
156
	$pconfig['maxtime'] = $dhcpdconf['maxleasetime'];
157
	$pconfig['gateway'] = $dhcpdconf['gateway'];
158
	$pconfig['domain'] = $dhcpdconf['domain'];
159
	$pconfig['domainsearchlist'] = $dhcpdconf['domainsearchlist'];
160 8f8682f7 Phil Davis
	list($pconfig['wins1'], $pconfig['wins2']) = $dhcpdconf['winsserver'];
161
	list($pconfig['dns1'], $pconfig['dns2'], $pconfig['dns3'], $pconfig['dns4']) = $dhcpdconf['dnsserver'];
162 6d53301b Jose Luis Duran
	$pconfig['ignorebootp'] = isset($dhcpdconf['ignorebootp']);
163 cba980f6 jim-p
	$pconfig['denyunknown'] = isset($dhcpdconf['denyunknown']);
164 11ee0c6d Brett Keller
	$pconfig['ignoreclientuids'] = isset($dhcpdconf['ignoreclientuids']);
165 3475eb04 Andrew Pilloud
	$pconfig['nonak'] = isset($dhcpdconf['nonak']);
166 cba980f6 jim-p
	$pconfig['ddnsdomain'] = $dhcpdconf['ddnsdomain'];
167 87019fc4 Andres Petralli
	$pconfig['ddnsdomainprimary'] = $dhcpdconf['ddnsdomainprimary'];
168
	$pconfig['ddnsdomainkeyname'] = $dhcpdconf['ddnsdomainkeyname'];
169 534d7d69 Joeri Capens
	$pconfig['ddnsdomainkeyalgorithm'] = $dhcpdconf['ddnsdomainkeyalgorithm'];
170 87019fc4 Andres Petralli
	$pconfig['ddnsdomainkey'] = $dhcpdconf['ddnsdomainkey'];
171 cba980f6 jim-p
	$pconfig['ddnsupdate'] = isset($dhcpdconf['ddnsupdate']);
172 cf15bcb4 Ross Williams
	$pconfig['ddnsforcehostname'] = isset($dhcpdconf['ddnsforcehostname']);
173 cba980f6 jim-p
	$pconfig['mac_allow'] = $dhcpdconf['mac_allow'];
174
	$pconfig['mac_deny'] = $dhcpdconf['mac_deny'];
175 8f8682f7 Phil Davis
	list($pconfig['ntp1'], $pconfig['ntp2']) = $dhcpdconf['ntpserver'];
176 cba980f6 jim-p
	$pconfig['tftp'] = $dhcpdconf['tftp'];
177
	$pconfig['ldap'] = $dhcpdconf['ldap'];
178
	$pconfig['netboot'] = isset($dhcpdconf['netboot']);
179
	$pconfig['nextserver'] = $dhcpdconf['nextserver'];
180
	$pconfig['filename'] = $dhcpdconf['filename'];
181 7023c602 Charlie Root
	$pconfig['filename32'] = $dhcpdconf['filename32'];
182
	$pconfig['filename64'] = $dhcpdconf['filename64'];
183 cba980f6 jim-p
	$pconfig['rootpath'] = $dhcpdconf['rootpath'];
184
	$pconfig['netmask'] = $dhcpdconf['netmask'];
185
	$pconfig['numberoptions'] = $dhcpdconf['numberoptions'];
186 18d316a5 heper
	$pconfig['statsgraph'] = $dhcpdconf['statsgraph'];
187 67784aa6 Steve Beaver
	$pconfig['ddnsclientupdates'] = $dhcpdconf['ddnsclientupdates'];
188 89019922 Ermal Luçi
}
189 31c59d0d Scott Ullrich
190 51cd7a1e Evgeny Yurchenko
$ifcfgip = $config['interfaces'][$if]['ipaddr'];
191
$ifcfgsn = $config['interfaces'][$if]['subnet'];
192 5b237745 Scott Ullrich
193 b90d635e Renato Botelho
$subnet_start = gen_subnetv4($ifcfgip, $ifcfgsn);
194
$subnet_end = gen_subnetv4_max($ifcfgip, $ifcfgsn);
195
196 1f1a08c8 jim-p
function validate_partial_mac_list($maclist) {
197
	$macs = explode(',', $maclist);
198
199
	// Loop through and look for invalid MACs.
200 8f8682f7 Phil Davis
	foreach ($macs as $mac) {
201
		if (!is_macaddr($mac, true)) {
202 1f1a08c8 jim-p
			return false;
203 8f8682f7 Phil Davis
		}
204
	}
205 b5f6e690 Stephen Beaver
206 1f1a08c8 jim-p
	return true;
207
}
208
209 141d8913 jim-p
if (isset($_POST['save'])) {
210 5b237745 Scott Ullrich
211
	unset($input_errors);
212 b7597d4e Bill Marquette
213 5b237745 Scott Ullrich
	$pconfig = $_POST;
214
215 6d1af0e9 jim-p
	$numberoptions = array();
216 6c07db48 Phil Davis
	for ($x = 0; $x < 99; $x++) {
217 8f8682f7 Phil Davis
		if (isset($_POST["number{$x}"]) && ctype_digit($_POST["number{$x}"])) {
218 60682dd2 Michael Newton
			if ($_POST["number{$x}"] < 1 || $_POST["number{$x}"] > 254) {
219
				$input_errors[] = gettext("The DHCP option must be a number between 1 and 254.");
220
				continue;
221
			}
222 6d1af0e9 jim-p
			$numbervalue = array();
223
			$numbervalue['number'] = htmlspecialchars($_POST["number{$x}"]);
224 678dfd0f Erik Fonnesbeck
			$numbervalue['type'] = htmlspecialchars($_POST["itemtype{$x}"]);
225 65cce9d7 Renato Botelho
			$numbervalue['value'] = base64_encode($_POST["value{$x}"]);
226 6d1af0e9 jim-p
			$numberoptions['item'][] = $numbervalue;
227
		}
228
	}
229 b5f6e690 Stephen Beaver
230 466aae83 Phil Davis
	// Reload the new pconfig variable that the form uses.
231 6d1af0e9 jim-p
	$pconfig['numberoptions'] = $numberoptions;
232
233 5b237745 Scott Ullrich
	/* input validation */
234 48614394 Phil Davis
235
	// Note: if DHCP Server is not enabled, then it is OK to adjust other parameters without specifying range from-to.
236 cba980f6 jim-p
	if ($_POST['enable'] || is_numeric($pool) || $act == "newpool") {
237 5b237745 Scott Ullrich
		$reqdfields = explode(" ", "range_from range_to");
238 8f8682f7 Phil Davis
		$reqdfieldsn = array(gettext("Range begin"), gettext("Range end"));
239 e9f147c8 Scott Ullrich
240 507628d5 Renato Botelho
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
241 48614394 Phil Davis
	}
242 de792e62 jim-p
243 48614394 Phil Davis
	if (($_POST['nonak']) && !empty($_POST['failover_peerip'])) {
244
		$input_errors[] = gettext("Ignore Denied Clients may not be used when a Failover Peer IP is defined.");
245
	}
246 8209517d jim-p
247 48614394 Phil Davis
	if ($_POST['range_from'] && !is_ipaddrv4($_POST['range_from'])) {
248
		$input_errors[] = gettext("A valid IPv4 address must be specified for range from.");
249
	}
250
	if ($_POST['range_to'] && !is_ipaddrv4($_POST['range_to'])) {
251
		$input_errors[] = gettext("A valid IPv4 address must be specified for range to.");
252
	}
253
	if (($_POST['range_from'] && !$_POST['range_to']) || ($_POST['range_to'] && !$_POST['range_from'])) {
254
		$input_errors[] = gettext("Range From and Range To must both be entered.");
255
	}
256
	if (($_POST['gateway'] && $_POST['gateway'] != "none" && !is_ipaddrv4($_POST['gateway']))) {
257
		$input_errors[] = gettext("A valid IP address must be specified for the gateway.");
258
	}
259
	if (($_POST['wins1'] && !is_ipaddrv4($_POST['wins1'])) || ($_POST['wins2'] && !is_ipaddrv4($_POST['wins2']))) {
260
		$input_errors[] = gettext("A valid IP address must be specified for the primary/secondary WINS servers.");
261
	}
262
	$parent_ip = get_interface_ip($_POST['if']);
263
	if (is_ipaddrv4($parent_ip) && $_POST['gateway'] && $_POST['gateway'] != "none") {
264
		$parent_sn = get_interface_subnet($_POST['if']);
265
		if (!ip_in_subnet($_POST['gateway'], gen_subnet($parent_ip, $parent_sn) . "/" . $parent_sn) && !ip_in_interface_alias_subnet($_POST['if'], $_POST['gateway'])) {
266
			$input_errors[] = sprintf(gettext("The gateway address %s does not lie within the chosen interface's subnet."), $_POST['gateway']);
267 45d1024d Scott Ullrich
		}
268 48614394 Phil Davis
	}
269 b5f6e690 Stephen Beaver
270 48614394 Phil Davis
	if (($_POST['dns1'] && !is_ipaddrv4($_POST['dns1'])) || ($_POST['dns2'] && !is_ipaddrv4($_POST['dns2'])) || ($_POST['dns3'] && !is_ipaddrv4($_POST['dns3'])) || ($_POST['dns4'] && !is_ipaddrv4($_POST['dns4']))) {
271
		$input_errors[] = gettext("A valid IP address must be specified for each of the DNS servers.");
272
	}
273
274
	if ($_POST['deftime'] && (!is_numeric($_POST['deftime']) || ($_POST['deftime'] < 60))) {
275
		$input_errors[] = gettext("The default lease time must be at least 60 seconds.");
276
	}
277 26e3ca70 sullrich
278 48614394 Phil Davis
	if (isset($config['captiveportal']) && is_array($config['captiveportal'])) {
279
		$deftime = 7200; // Default value if it's empty
280
		if (is_numeric($_POST['deftime'])) {
281
			$deftime = $_POST['deftime'];
282 8f8682f7 Phil Davis
		}
283 e680b2f9 Renato Botelho
284 48614394 Phil Davis
		foreach ($config['captiveportal'] as $cpZone => $cpdata) {
285
			if (!isset($cpdata['enable'])) {
286
				continue;
287 8f8682f7 Phil Davis
			}
288 48614394 Phil Davis
			if (!isset($cpdata['timeout']) || !is_numeric($cpdata['timeout'])) {
289
				continue;
290
			}
291
			$cp_ifs = explode(',', $cpdata['interface']);
292
			if (!in_array($if, $cp_ifs)) {
293
				continue;
294
			}
295
			if ($cpdata['timeout'] > $deftime) {
296
				$input_errors[] = sprintf(gettext(
297
					'The Captive Portal zone (%1$s) has Hard Timeout parameter set to a value bigger than Default lease time (%2$s).'), $cpZone, $deftime);
298 e680b2f9 Renato Botelho
			}
299
		}
300 48614394 Phil Davis
	}
301 e680b2f9 Renato Botelho
302 48614394 Phil Davis
	if ($_POST['maxtime'] && (!is_numeric($_POST['maxtime']) || ($_POST['maxtime'] < 60) || ($_POST['maxtime'] <= $_POST['deftime']))) {
303
		$input_errors[] = gettext("The maximum lease time must be at least 60 seconds and higher than the default lease time.");
304
	}
305 534d7d69 Joeri Capens
	if ($_POST['ddnsupdate'] && !is_domain($_POST['ddnsdomain'])) {
306 48614394 Phil Davis
		$input_errors[] = gettext("A valid domain name must be specified for the dynamic DNS registration.");
307
	}
308 534d7d69 Joeri Capens
	if ($_POST['ddnsupdate'] && !is_ipaddrv4($_POST['ddnsdomainprimary'])) {
309 48614394 Phil Davis
		$input_errors[] = gettext("A valid primary domain name server IP address must be specified for the dynamic domain name.");
310
	}
311 534d7d69 Joeri Capens
	if ($_POST['ddnsupdate'] && (!$_POST['ddnsdomainkeyname'] || !$_POST['ddnsdomainkeyalgorithm'] || !$_POST['ddnsdomainkey'])) {
312
		$input_errors[] = gettext("A valid domain key name, algorithm and secret must be specified.");
313 48614394 Phil Davis
	}
314
	if ($_POST['domainsearchlist']) {
315
		$domain_array = preg_split("/[ ;]+/", $_POST['domainsearchlist']);
316
		foreach ($domain_array as $curdomain) {
317
			if (!is_domain($curdomain)) {
318
				$input_errors[] = gettext("A valid domain search list must be specified.");
319
				break;
320 42a3cbab Pierre POMES
			}
321
		}
322 48614394 Phil Davis
	}
323 1f1a08c8 jim-p
324 48614394 Phil Davis
	// Validate MACs
325
	if (!empty($_POST['mac_allow']) && !validate_partial_mac_list($_POST['mac_allow'])) {
326
		$input_errors[] = gettext("If a mac allow list is specified, it must contain only valid partial MAC addresses.");
327
	}
328
	if (!empty($_POST['mac_deny']) && !validate_partial_mac_list($_POST['mac_deny'])) {
329
		$input_errors[] = gettext("If a mac deny list is specified, it must contain only valid partial MAC addresses.");
330
	}
331 1f1a08c8 jim-p
332 48614394 Phil Davis
	if (($_POST['ntp1'] && (!is_ipaddrv4($_POST['ntp1']) && !is_hostname($_POST['ntp1']))) || ($_POST['ntp2'] && (!is_ipaddrv4($_POST['ntp2']) && !is_hostname($_POST['ntp2'])))) {
333
		$input_errors[] = gettext("A valid IP address or hostname must be specified for the primary/secondary NTP servers.");
334
	}
335
	if (($_POST['domain'] && !is_domain($_POST['domain']))) {
336
		$input_errors[] = gettext("A valid domain name must be specified for the DNS domain.");
337
	}
338
	if ($_POST['tftp'] && !is_ipaddrv4($_POST['tftp']) && !is_domain($_POST['tftp']) && !filter_var($_POST['tftp'], FILTER_VALIDATE_URL)) {
339
		$input_errors[] = gettext("A valid IP address, hostname or URL must be specified for the TFTP server.");
340
	}
341
	if (($_POST['nextserver'] && !is_ipaddrv4($_POST['nextserver']))) {
342
		$input_errors[] = gettext("A valid IP address must be specified for the network boot server.");
343
	}
344 2c75b451 sullrich
345 48614394 Phil Davis
	if (gen_subnet($ifcfgip, $ifcfgsn) == $_POST['range_from']) {
346
		$input_errors[] = gettext("The network address cannot be used in the starting subnet range.");
347
	}
348
	if (gen_subnet_max($ifcfgip, $ifcfgsn) == $_POST['range_to']) {
349
		$input_errors[] = gettext("The broadcast address cannot be used in the ending subnet range.");
350
	}
351 e9f147c8 Scott Ullrich
352 48614394 Phil Davis
	// Disallow a range that includes the virtualip
353
	if (is_array($config['virtualip']['vip'])) {
354
		foreach ($config['virtualip']['vip'] as $vip) {
355
			if ($vip['interface'] == $if) {
356
				if ($vip['subnet'] && is_inrange_v4($vip['subnet'], $_POST['range_from'], $_POST['range_to'])) {
357
					$input_errors[] = sprintf(gettext("The subnet range cannot overlap with virtual IP address %s."), $vip['subnet']);
358 8f8682f7 Phil Davis
				}
359 7dfa60fa Ermal Lu?i
			}
360 2c75b451 sullrich
		}
361 48614394 Phil Davis
	}
362 2c75b451 sullrich
363 48614394 Phil Davis
	$noip = false;
364
	if (is_array($a_maps)) {
365
		foreach ($a_maps as $map) {
366
			if (empty($map['ipaddr'])) {
367
				$noip = true;
368 8f8682f7 Phil Davis
			}
369
		}
370 48614394 Phil Davis
	}
371 b5f6e690 Stephen Beaver
372 48614394 Phil Davis
	if ($_POST['staticarp'] && $noip) {
373
		$input_errors[] = gettext("Cannot enable static ARP when there are static map entries without IP addresses. Ensure all static maps have IP addresses and try again.");
374
	}
375
376
	if (is_array($pconfig['numberoptions']['item'])) {
377
		foreach ($pconfig['numberoptions']['item'] as $numberoption) {
378
			$numberoption_value = base64_decode($numberoption['value']);
379
			if ($numberoption['type'] == 'text' && strstr($numberoption_value, '"')) {
380
				$input_errors[] = gettext("Text type cannot include quotation marks.");
381
			} else if ($numberoption['type'] == 'string' && !preg_match('/^"[^"]*"$/', $numberoption_value) && !preg_match('/^[0-9a-f]{2}(?:\:[0-9a-f]{2})*$/i', $numberoption_value)) {
382
				$input_errors[] = gettext("String type must be enclosed in quotes like \"this\" or must be a series of octets specified in hexadecimal, separated by colons, like 01:23:45:67:89:ab:cd:ef");
383
			} else if ($numberoption['type'] == 'boolean' && $numberoption_value != 'true' && $numberoption_value != 'false' && $numberoption_value != 'on' && $numberoption_value != 'off') {
384
				$input_errors[] = gettext("Boolean type must be true, false, on, or off.");
385
			} else if ($numberoption['type'] == 'unsigned integer 8' && (!is_numeric($numberoption_value) || $numberoption_value < 0 || $numberoption_value > 255)) {
386
				$input_errors[] = gettext("Unsigned 8-bit integer type must be a number in the range 0 to 255.");
387
			} else if ($numberoption['type'] == 'unsigned integer 16' && (!is_numeric($numberoption_value) || $numberoption_value < 0 || $numberoption_value > 65535)) {
388
				$input_errors[] = gettext("Unsigned 16-bit integer type must be a number in the range 0 to 65535.");
389
			} else if ($numberoption['type'] == 'unsigned integer 32' && (!is_numeric($numberoption_value) || $numberoption_value < 0 || $numberoption_value > 4294967295)) {
390
				$input_errors[] = gettext("Unsigned 32-bit integer type must be a number in the range 0 to 4294967295.");
391
			} else if ($numberoption['type'] == 'signed integer 8' && (!is_numeric($numberoption_value) || $numberoption_value < -128 || $numberoption_value > 127)) {
392
				$input_errors[] = gettext("Signed 8-bit integer type must be a number in the range -128 to 127.");
393
			} else if ($numberoption['type'] == 'signed integer 16' && (!is_numeric($numberoption_value) || $numberoption_value < -32768 || $numberoption_value > 32767)) {
394
				$input_errors[] = gettext("Signed 16-bit integer type must be a number in the range -32768 to 32767.");
395
			} else if ($numberoption['type'] == 'signed integer 32' && (!is_numeric($numberoption_value) || $numberoption_value < -2147483648 || $numberoption_value > 2147483647)) {
396
				$input_errors[] = gettext("Signed 32-bit integer type must be a number in the range -2147483648 to 2147483647.");
397
			} else if ($numberoption['type'] == 'ip-address' && !is_ipaddrv4($numberoption_value) && !is_hostname($numberoption_value)) {
398
				$input_errors[] = gettext("IP address or host type must be an IP address or host name.");
399 678dfd0f Erik Fonnesbeck
			}
400
		}
401 48614394 Phil Davis
	}
402 678dfd0f Erik Fonnesbeck
403 4b980701 Renato Botelho
	if ((!isset($pool) || !is_numeric($pool)) && $act != "newpool") {
404
		/* If enabling DHCP Server, make sure that the DHCP Relay isn't enabled on this interface */
405
		if ($_POST['enable'] && isset($config['dhcrelay']['enable']) &&
406
		    (stristr($config['dhcrelay']['interface'], $if) !== false)) {
407
			$input_errors[] = sprintf(gettext(
408
			    "The DHCP relay on the %s interface must be disabled before enabling the DHCP server."),
409
			    $iflist[$if]);
410 e83c9b73 doktornotor
		}
411 4b980701 Renato Botelho
412
		/* If disabling DHCP Server, make sure that DHCP registration isn't enabled for DNS forwarder/resolver */
413
		if (!$_POST['enable']) {
414 9477c170 jim-p
			/* Find out how many other interfaces have DHCP enabled. */
415
			$dhcp_enabled_count = 0;
416
			foreach ($config['dhcpd'] as $dhif => $dhcps) {
417
				if ($dhif == $if) {
418
					/* Skip this interface, we only want to know how many others are enabled. */
419
					continue;
420
				}
421
				if (isset($dhcps['enable'])) {
422
					$dhcp_enabled_count++;
423
				}
424
			}
425
426 4b980701 Renato Botelho
			if (isset($config['dnsmasq']['enable']) &&
427 9477c170 jim-p
			    ($dhcp_enabled_count == 0) &&
428 4b980701 Renato Botelho
			    (isset($config['dnsmasq']['regdhcp']) ||
429
			    isset($config['dnsmasq']['regdhcpstatic']) ||
430
			    isset($config['dnsmasq']['dhcpfirst']))) {
431
				$input_errors[] = gettext(
432 9477c170 jim-p
				    "DHCP Registration features in the DNS Forwarder are active and require at least one enabled DHCP Server.");
433 4b980701 Renato Botelho
			}
434
			if (isset($config['unbound']['enable']) &&
435 9477c170 jim-p
			    ($dhcp_enabled_count == 0) &&
436 4b980701 Renato Botelho
			    (isset($config['unbound']['regdhcp']) ||
437
			    isset($config['unbound']['regdhcpstatic']))) {
438
				$input_errors[] = gettext(
439 9477c170 jim-p
				    "DHCP Registration features in the DNS Resolver are active and require at least one enabled DHCP Server.");
440 4b980701 Renato Botelho
			}
441 e83c9b73 doktornotor
		}
442
	}
443
444 48614394 Phil Davis
	// 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.
445
	if (!$input_errors && $_POST['range_from'] && $_POST['range_to']) {
446
		/* make sure the range lies within the current subnet */
447
		if (ip_greater_than($_POST['range_from'], $_POST['range_to'])) {
448
			$input_errors[] = gettext("The range is invalid (first element higher than second element).");
449
		}
450
451
		if (!is_inrange_v4($_POST['range_from'], $subnet_start, $subnet_end) ||
452
			!is_inrange_v4($_POST['range_to'], $subnet_start, $subnet_end)) {
453
			$input_errors[] = gettext("The specified range lies outside of the current subnet.");
454
		}
455
456
		if (is_numeric($pool) || ($act == "newpool")) {
457
			if (is_inrange_v4($_POST['range_from'],
458
				$config['dhcpd'][$if]['range']['from'],
459
				$config['dhcpd'][$if]['range']['to']) ||
460
				is_inrange_v4($_POST['range_to'],
461
				$config['dhcpd'][$if]['range']['from'],
462
				$config['dhcpd'][$if]['range']['to'])) {
463
				$input_errors[] = gettext("The specified range must not be within the DHCP range for this interface.");
464 8f8682f7 Phil Davis
			}
465 48614394 Phil Davis
		}
466 e9f147c8 Scott Ullrich
467 48614394 Phil Davis
		foreach ($a_pools as $id => $p) {
468
			if (is_numeric($pool) && ($id == $pool)) {
469
				continue;
470 ec513fa9 stilez
			}
471
472 48614394 Phil Davis
			if (is_inrange_v4($_POST['range_from'],
473
				$p['range']['from'], $p['range']['to']) ||
474
				is_inrange_v4($_POST['range_to'],
475
				$p['range']['from'], $p['range']['to'])) {
476
				$input_errors[] = gettext("The specified range must not be within the range configured on a DHCP pool for this interface.");
477
				break;
478 f657f5e1 Renato Botelho
			}
479 48614394 Phil Davis
		}
480 f657f5e1 Renato Botelho
481 48614394 Phil Davis
		if (is_array($a_maps)) {
482
			foreach ($a_maps as $map) {
483
				if (empty($map['ipaddr'])) {
484 f657f5e1 Renato Botelho
					continue;
485 8f8682f7 Phil Davis
				}
486 48614394 Phil Davis
				if (is_inrange_v4($map['ipaddr'], $_POST['range_from'], $_POST['range_to'])) {
487
					$input_errors[] = sprintf(gettext("The DHCP range cannot overlap any static DHCP mappings."));
488 f657f5e1 Renato Botelho
					break;
489
				}
490
			}
491 5b237745 Scott Ullrich
		}
492
	}
493
494
	if (!$input_errors) {
495 cba980f6 jim-p
		if (!is_numeric($pool)) {
496
			if ($act == "newpool") {
497
				$dhcpdconf = array();
498
			} else {
499 8a228b83 Stephen Jones
				if (!is_array($config['dhcpd'])) {
500
					$config['dhcpd']= array();
501
				}
502 8f8682f7 Phil Davis
				if (!is_array($config['dhcpd'][$if])) {
503 cba980f6 jim-p
					$config['dhcpd'][$if] = array();
504 8f8682f7 Phil Davis
				}
505 cba980f6 jim-p
				$dhcpdconf = $config['dhcpd'][$if];
506
			}
507
		} else {
508
			if (is_array($a_pools[$pool])) {
509
				$dhcpdconf = $a_pools[$pool];
510
			} else {
511
				// Someone specified a pool but it doesn't exist. Punt.
512
				header("Location: services_dhcp.php");
513
				exit;
514
			}
515
		}
516 8a228b83 Stephen Jones
		if (!is_array($dhcpdconf)) {
517
			$dhcpdconf = array();
518
		}
519 8f8682f7 Phil Davis
		if (!is_array($dhcpdconf['range'])) {
520 cba980f6 jim-p
			$dhcpdconf['range'] = array();
521 8f8682f7 Phil Davis
		}
522 cba980f6 jim-p
523 6c124212 Phil Davis
		$dhcpd_enable_changed = false;
524
525 cba980f6 jim-p
		// Global Options
526
		if (!is_numeric($pool) && !($act == "newpool")) {
527 6c124212 Phil Davis
			$old_dhcpd_enable = isset($dhcpdconf['enable']);
528
			$new_dhcpd_enable = ($_POST['enable']) ? true : false;
529
			if ($old_dhcpd_enable != $new_dhcpd_enable) {
530
				/* DHCP has been enabled or disabled. The pf ruleset will need to be rebuilt to allow or disallow DHCP. */
531
				$dhcpd_enable_changed = true;
532
			}
533 b5f6e690 Stephen Beaver
534 6c124212 Phil Davis
			$dhcpdconf['enable'] = $new_dhcpd_enable;
535 cba980f6 jim-p
			$dhcpdconf['staticarp'] = ($_POST['staticarp']) ? true : false;
536
			$previous = $dhcpdconf['failover_peerip'];
537 b5f6e690 Stephen Beaver
			if ($previous != $_POST['failover_peerip']) {
538 cba980f6 jim-p
				mwexec("/bin/rm -rf /var/dhcpd/var/db/*");
539 8f8682f7 Phil Davis
			}
540 b5f6e690 Stephen Beaver
541 cba980f6 jim-p
			$dhcpdconf['failover_peerip'] = $_POST['failover_peerip'];
542 466aae83 Phil Davis
			// dhcpleaseinlocaltime is global to all interfaces. So update the setting on all interfaces.
543
			foreach ($config['dhcpd'] as &$dhcpdifitem) {
544
				$dhcpdifitem['dhcpleaseinlocaltime'] = $_POST['dhcpleaseinlocaltime'];
545
			}
546 ee1fb205 jim-p
		} else {
547
			// Options that exist only in pools
548
			$dhcpdconf['descr'] = $_POST['descr'];
549 cba980f6 jim-p
		}
550
551
		// Options that can be global or per-pool.
552
		$dhcpdconf['range']['from'] = $_POST['range_from'];
553
		$dhcpdconf['range']['to'] = $_POST['range_to'];
554
		$dhcpdconf['defaultleasetime'] = $_POST['deftime'];
555
		$dhcpdconf['maxleasetime'] = $_POST['maxtime'];
556
		$dhcpdconf['netmask'] = $_POST['netmask'];
557
558
		unset($dhcpdconf['winsserver']);
559 8f8682f7 Phil Davis
		if ($_POST['wins1']) {
560 cba980f6 jim-p
			$dhcpdconf['winsserver'][] = $_POST['wins1'];
561 8f8682f7 Phil Davis
		}
562
		if ($_POST['wins2']) {
563 cba980f6 jim-p
			$dhcpdconf['winsserver'][] = $_POST['wins2'];
564 8f8682f7 Phil Davis
		}
565 4cab31d0 Scott Ullrich
566 cba980f6 jim-p
		unset($dhcpdconf['dnsserver']);
567 8f8682f7 Phil Davis
		if ($_POST['dns1']) {
568 cba980f6 jim-p
			$dhcpdconf['dnsserver'][] = $_POST['dns1'];
569 8f8682f7 Phil Davis
		}
570
		if ($_POST['dns2']) {
571 cba980f6 jim-p
			$dhcpdconf['dnsserver'][] = $_POST['dns2'];
572 8f8682f7 Phil Davis
		}
573
		if ($_POST['dns3']) {
574 3b5707db Phil Davis
			$dhcpdconf['dnsserver'][] = $_POST['dns3'];
575 8f8682f7 Phil Davis
		}
576
		if ($_POST['dns4']) {
577 3b5707db Phil Davis
			$dhcpdconf['dnsserver'][] = $_POST['dns4'];
578 8f8682f7 Phil Davis
		}
579 cba980f6 jim-p
580
		$dhcpdconf['gateway'] = $_POST['gateway'];
581
		$dhcpdconf['domain'] = $_POST['domain'];
582
		$dhcpdconf['domainsearchlist'] = $_POST['domainsearchlist'];
583 6d53301b Jose Luis Duran
		$dhcpdconf['ignorebootp'] = ($_POST['ignorebootp']) ? true : false;
584 cba980f6 jim-p
		$dhcpdconf['denyunknown'] = ($_POST['denyunknown']) ? true : false;
585 11ee0c6d Brett Keller
		$dhcpdconf['ignoreclientuids'] = ($_POST['ignoreclientuids']) ? true : false;
586 3475eb04 Andrew Pilloud
		$dhcpdconf['nonak'] = ($_POST['nonak']) ? true : false;
587 cba980f6 jim-p
		$dhcpdconf['ddnsdomain'] = $_POST['ddnsdomain'];
588 87019fc4 Andres Petralli
		$dhcpdconf['ddnsdomainprimary'] = $_POST['ddnsdomainprimary'];
589
		$dhcpdconf['ddnsdomainkeyname'] = $_POST['ddnsdomainkeyname'];
590 534d7d69 Joeri Capens
		$dhcpdconf['ddnsdomainkeyalgorithm'] = $_POST['ddnsdomainkeyalgorithm'];
591 87019fc4 Andres Petralli
		$dhcpdconf['ddnsdomainkey'] = $_POST['ddnsdomainkey'];
592 cba980f6 jim-p
		$dhcpdconf['ddnsupdate'] = ($_POST['ddnsupdate']) ? true : false;
593 cf15bcb4 Ross Williams
		$dhcpdconf['ddnsforcehostname'] = ($_POST['ddnsforcehostname']) ? true : false;
594 cba980f6 jim-p
		$dhcpdconf['mac_allow'] = $_POST['mac_allow'];
595
		$dhcpdconf['mac_deny'] = $_POST['mac_deny'];
596 67784aa6 Steve Beaver
		$dhcpdconf['ddnsclientupdates'] = $_POST['ddnsclientupdates'];
597 cba980f6 jim-p
598
		unset($dhcpdconf['ntpserver']);
599 8f8682f7 Phil Davis
		if ($_POST['ntp1']) {
600 cba980f6 jim-p
			$dhcpdconf['ntpserver'][] = $_POST['ntp1'];
601 8f8682f7 Phil Davis
		}
602
		if ($_POST['ntp2']) {
603 cba980f6 jim-p
			$dhcpdconf['ntpserver'][] = $_POST['ntp2'];
604 8f8682f7 Phil Davis
		}
605 ad171999 Seth Mos
606 cba980f6 jim-p
		$dhcpdconf['tftp'] = $_POST['tftp'];
607
		$dhcpdconf['ldap'] = $_POST['ldap'];
608
		$dhcpdconf['netboot'] = ($_POST['netboot']) ? true : false;
609
		$dhcpdconf['nextserver'] = $_POST['nextserver'];
610
		$dhcpdconf['filename'] = $_POST['filename'];
611 7023c602 Charlie Root
		$dhcpdconf['filename32'] = $_POST['filename32'];
612
		$dhcpdconf['filename64'] = $_POST['filename64'];
613 cba980f6 jim-p
		$dhcpdconf['rootpath'] = $_POST['rootpath'];
614 18d316a5 heper
		unset($dhcpdconf['statsgraph']);
615
		if ($_POST['statsgraph']) {
616
			$dhcpdconf['statsgraph'] = $_POST['statsgraph'];
617 6303601e heper
			enable_rrd_graphing();
618 18d316a5 heper
		}
619 9c748b70 Scott Ullrich
620 d72b4114 Scott Ullrich
		// Handle the custom options rowhelper
621 8f8682f7 Phil Davis
		if (isset($dhcpdconf['numberoptions']['item'])) {
622 cba980f6 jim-p
			unset($dhcpdconf['numberoptions']['item']);
623 8f8682f7 Phil Davis
		}
624 6d1af0e9 jim-p
625 cba980f6 jim-p
		$dhcpdconf['numberoptions'] = $numberoptions;
626
627
		if (is_numeric($pool) && is_array($a_pools[$pool])) {
628
			$a_pools[$pool] = $dhcpdconf;
629
		} elseif ($act == "newpool") {
630
			$a_pools[] = $dhcpdconf;
631
		} else {
632
			$config['dhcpd'][$if] = $dhcpdconf;
633
		}
634 518030b3 Scott Ullrich
635 5b237745 Scott Ullrich
		write_config();
636 565488c9 Renato Botelho
	}
637
}
638 80933129 Bill Marquette
639 141d8913 jim-p
if ((isset($_POST['save']) || isset($_POST['apply'])) && (!$input_errors)) {
640 44c42356 Phil Davis
	$changes_applied = true;
641 565488c9 Renato Botelho
	$retval = 0;
642
	$retvaldhcp = 0;
643
	$retvaldns = 0;
644
	/* dnsmasq_configure calls dhcpd_configure */
645
	/* no need to restart dhcpd twice */
646
	if (isset($config['dnsmasq']['enable']) && isset($config['dnsmasq']['regdhcpstatic']))	{
647 44c42356 Phil Davis
		$retvaldns |= services_dnsmasq_configure();
648 565488c9 Renato Botelho
		if ($retvaldns == 0) {
649
			clear_subsystem_dirty('hosts');
650
			clear_subsystem_dirty('staticmaps');
651 de792e62 jim-p
		}
652 565488c9 Renato Botelho
	} else if (isset($config['unbound']['enable']) && isset($config['unbound']['regdhcpstatic'])) {
653 44c42356 Phil Davis
		$retvaldns |= services_unbound_configure();
654 4230ad16 Phil Davis
		if ($retvaldns == 0) {
655 565488c9 Renato Botelho
			clear_subsystem_dirty('unbound');
656 d3801fdb Renato Botelho
			clear_subsystem_dirty('hosts');
657
			clear_subsystem_dirty('staticmaps');
658 4230ad16 Phil Davis
		}
659 565488c9 Renato Botelho
	} else {
660 44c42356 Phil Davis
		$retvaldhcp |= services_dhcpd_configure();
661 8f8682f7 Phil Davis
		if ($retvaldhcp == 0) {
662 565488c9 Renato Botelho
			clear_subsystem_dirty('staticmaps');
663 8f8682f7 Phil Davis
		}
664 5b237745 Scott Ullrich
	}
665 a207d2c9 doktornotor
	/* BIND package - Bug #3710 */
666
	if (!function_exists('is_package_installed')) {
667
		require_once('pkg-utils.inc');
668
	}
669
	if (is_package_installed('pfSense-pkg-bind') && isset($config['installedpackages']['bind']['config'][0]['enable_bind'])) {
670
		$reloadbind = false;
671
		if (is_array($config['installedpackages']['bindzone'])) {
672
			$bindzone = $config['installedpackages']['bindzone']['config'];
673
		} else {
674
			$bindzone = array();
675
		}
676
		for ($x = 0; $x < sizeof($bindzone); $x++) {
677 e3d5c2e9 doktornotor
			$zone = $bindzone[$x];
678 a207d2c9 doktornotor
			if ($zone['regdhcpstatic'] == 'on') {
679
				$reloadbind = true;
680
				break;
681
			}
682
		}
683
		if ($reloadbind === true) {
684
			if (file_exists("/usr/local/pkg/bind.inc")) {
685
				require_once("/usr/local/pkg/bind.inc");
686
				bind_sync();
687
			}
688
		}
689
	}
690 8f8682f7 Phil Davis
	if ($dhcpd_enable_changed) {
691 44c42356 Phil Davis
		$retvalfc |= filter_configure();
692 8f8682f7 Phil Davis
	}
693 565488c9 Renato Botelho
694 8f8682f7 Phil Davis
	if ($retvaldhcp == 1 || $retvaldns == 1 || $retvalfc == 1) {
695 565488c9 Renato Botelho
		$retval = 1;
696 8f8682f7 Phil Davis
	}
697 5b237745 Scott Ullrich
}
698
699 cba980f6 jim-p
if ($act == "delpool") {
700 c946d721 Steve Beaver
	if ($a_pools[$_POST['id']]) {
701
		unset($a_pools[$_POST['id']]);
702 cba980f6 jim-p
		write_config();
703
		header("Location: services_dhcp.php?if={$if}");
704
		exit;
705
	}
706
}
707
708
if ($act == "del") {
709 c946d721 Steve Beaver
	if (isset($a_maps[$_POST['id']])) {
710 fbb78d6b Phil Davis
		/* Remove static ARP entry, if necessary */
711 c946d721 Steve Beaver
		if (isset($a_maps[$_POST['id']]['arp_table_static_entry'])) {
712
			mwexec("/usr/sbin/arp -d " . escapeshellarg($a_maps[$_POST['id']]['ipaddr']));
713 632e5f50 jim-p
		}
714 c946d721 Steve Beaver
		unset($a_maps[$_POST['id']]);
715 5b237745 Scott Ullrich
		write_config();
716 8f8682f7 Phil Davis
		if (isset($config['dhcpd'][$if]['enable'])) {
717 a368a026 Ermal Lu?i
			mark_subsystem_dirty('staticmaps');
718 8f8682f7 Phil Davis
			if (isset($config['dnsmasq']['enable']) && isset($config['dnsmasq']['regdhcpstatic'])) {
719 a368a026 Ermal Lu?i
				mark_subsystem_dirty('hosts');
720 8f8682f7 Phil Davis
			}
721 6a01ea44 Bill Marquette
		}
722 b5f6e690 Stephen Beaver
723 5b237745 Scott Ullrich
		header("Location: services_dhcp.php?if={$if}");
724
		exit;
725
	}
726
}
727 4df96eff Scott Ullrich
728 3c9befb9 Chris Buechler
// Build an HTML table that can be inserted into a Form_StaticText element
729 b5f6e690 Stephen Beaver
function build_pooltable() {
730 96ab6943 Chris Buechler
	global $a_pools, $if;
731 b5f6e690 Stephen Beaver
732
	$pooltbl =	'<div class="table-responsive">';
733
	$pooltbl .=		'<table class="table table-striped table-hover table-condensed">';
734
	$pooltbl .=			'<thead>';
735
	$pooltbl .=				'<tr>';
736
	$pooltbl .=					'<th>' . gettext("Pool Start") . '</th>';
737
	$pooltbl .=					'<th>' . gettext("Pool End") . '</th>';
738
	$pooltbl .=					'<th>' . gettext("Description") . '</th>';
739 d7d7820e Phil Davis
	$pooltbl .=					'<th>' . gettext("Actions") . '</th>';
740 b5f6e690 Stephen Beaver
	$pooltbl .=				'</tr>';
741
	$pooltbl .=			'</thead>';
742
	$pooltbl .=			'<tbody>';
743
744
	if (is_array($a_pools)) {
745
		$i = 0;
746
		foreach ($a_pools as $poolent) {
747
			if (!empty($poolent['range']['from']) && !empty($poolent['range']['to'])) {
748
				$pooltbl .= '<tr>';
749
				$pooltbl .= '<td ondblclick="document.location=\'services_dhcp.php?if=' . htmlspecialchars($if) . '&pool=' . $i . '\';">' .
750
							htmlspecialchars($poolent['range']['from']) . '</td>';
751
752
				$pooltbl .= '<td ondblclick="document.location=\'services_dhcp.php?if=' . htmlspecialchars($if) . '&pool=' . $i . '\';">' .
753
							htmlspecialchars($poolent['range']['to']) . '</td>';
754
755
				$pooltbl .= '<td ondblclick="document.location=\'services_dhcp.php?if=' . htmlspecialchars($if) . '&pool=' . $i . '\';">' .
756
							htmlspecialchars($poolent['descr']) . '</td>';
757
758 d7d7820e Phil Davis
				$pooltbl .= '<td><a class="fa fa-pencil" title="'. gettext("Edit pool") . '" href="services_dhcp.php?if=' . htmlspecialchars($if) . '&pool=' . $i . '"></a>';
759 b5f6e690 Stephen Beaver
760 c946d721 Steve Beaver
				$pooltbl .= ' <a class="fa fa-trash" title="'. gettext("Delete pool") . '" href="services_dhcp.php?if=' . htmlspecialchars($if) . '&act=delpool&id=' . $i . '" usepost></a></td>';
761 b5f6e690 Stephen Beaver
				$pooltbl .= '</tr>';
762
			}
763
		$i++;
764
		}
765
	}
766
767
	$pooltbl .=			'</tbody>';
768
	$pooltbl .=		'</table>';
769
	$pooltbl .= '</div>';
770
771
	return($pooltbl);
772
}
773
774 bf27317d Phil Davis
$pgtitle = array(gettext("Services"), gettext("DHCP Server"));
775 edcd7535 Phil Davis
$pglinks = array("", "services_dhcp.php");
776 fa94122b k-paulius
777 48614394 Phil Davis
if (!empty($if) && isset($iflist[$if])) {
778 fa94122b k-paulius
	$pgtitle[] = $iflist[$if];
779 edcd7535 Phil Davis
	$pglinks[] = "@self";
780 fa94122b k-paulius
}
781 b32dd0a6 jim-p
$shortcut_section = "dhcp";
782 5224b8e7 jim-p
783 4df96eff Scott Ullrich
include("head.inc");
784
785 6e3488e9 Phil Davis
if ($input_errors) {
786 b5f6e690 Stephen Beaver
	print_input_errors($input_errors);
787 6e3488e9 Phil Davis
}
788 4df96eff Scott Ullrich
789 44c42356 Phil Davis
if ($changes_applied) {
790
	print_apply_result_box($retval);
791 6e3488e9 Phil Davis
}
792 678dfd0f Erik Fonnesbeck
793 6e3488e9 Phil Davis
if (is_subsystem_dirty('staticmaps')) {
794 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."));
795 6e3488e9 Phil Davis
}
796 b5f6e690 Stephen Beaver
797
/* active tabs */
798
$tab_array = array();
799
$tabscounter = 0;
800
$i = 0;
801 b7090449 Phil Davis
$have_small_subnet = false;
802 8a73f407 Stephen Beaver
803 b5f6e690 Stephen Beaver
foreach ($iflist as $ifent => $ifname) {
804
	$oc = $config['interfaces'][$ifent];
805 403dad2a Renato Botelho
806
	/* Not static IPv4 or subnet >= 31 */
807 b7090449 Phil Davis
	if ($oc['subnet'] >= 31) {
808
		$have_small_subnet = true;
809 12e08722 Phil Davis
		$example_name = $ifname;
810
		$example_cidr = $oc['subnet'];
811 b7090449 Phil Davis
		continue;
812
	}
813
	if (!is_ipaddrv4($oc['ipaddr']) || empty($oc['subnet'])) {
814 b5f6e690 Stephen Beaver
		continue;
815 518030b3 Scott Ullrich
	}
816 4e9cd828 Seth Mos
817 b5f6e690 Stephen Beaver
	if ($ifent == $if) {
818
		$active = true;
819
	} else {
820
		$active = false;
821 b1d132f5 Scott Ullrich
	}
822
823 b5f6e690 Stephen Beaver
	$tab_array[] = array($ifname, $active, "services_dhcp.php?if={$ifent}");
824
	$tabscounter++;
825
}
826 ad171999 Seth Mos
827 b5f6e690 Stephen Beaver
if ($tabscounter == 0) {
828 b7090449 Phil Davis
	if ($have_small_subnet) {
829 12e08722 Phil Davis
		$sentence2 = sprintf(gettext('%1$s has a CIDR mask of %2$s, which does not contain enough addresses.'), htmlspecialchars($example_name), htmlspecialchars($example_cidr));
830 b7090449 Phil Davis
	} else {
831 12e08722 Phil Davis
		$sentence2 = gettext("This system has no interfaces configured with a static IPv4 address.");
832 b7090449 Phil Davis
	}
833 12e08722 Phil Davis
	print_info_box(gettext("The DHCP Server requires a static IPv4 subnet large enough to serve addresses to clients.") . " " . $sentence2);
834 b5f6e690 Stephen Beaver
	include("foot.inc");
835
	exit;
836
}
837 1f1a08c8 jim-p
838 b5f6e690 Stephen Beaver
display_top_tabs($tab_array);
839
840 8f58b51b jim-p
$form = new Form();
841 b5f6e690 Stephen Beaver
842
$section = new Form_Section('General Options');
843
844
if (!is_numeric($pool) && !($act == "newpool")) {
845 48614394 Phil Davis
	if (isset($config['dhcrelay']['enable'])) {
846
		$section->addInput(new Form_Checkbox(
847
			'enable',
848
			'Enable',
849
			gettext("DHCP Relay is currently enabled. DHCP Server canot be enabled while the DHCP Relay is enabled on any interface."),
850
			$pconfig['enable']
851
		))->setAttribute('disabled', true);
852
	} else {
853
		$section->addInput(new Form_Checkbox(
854
			'enable',
855
			'Enable',
856
			sprintf(gettext("Enable DHCP server on %s interface"), htmlspecialchars($iflist[$if])),
857
			$pconfig['enable']
858
		));
859
	}
860 b5f6e690 Stephen Beaver
} else {
861 02342d8c k-paulius
	print_info_box(gettext('Editing pool-specific options. To return to the Interface, click its tab above.'), 'info', false);
862 b5f6e690 Stephen Beaver
}
863 6c23757b Martin Fuchs
864 6d53301b Jose Luis Duran
$section->addInput(new Form_Checkbox(
865
	'ignorebootp',
866
	'BOOTP',
867
	'Ignore BOOTP queries',
868
	$pconfig['ignorebootp']
869
));
870
871 b5f6e690 Stephen Beaver
$section->addInput(new Form_Checkbox(
872
	'denyunknown',
873
	'Deny unknown clients',
874
	'Only the clients defined below will get DHCP leases from this server.',
875
	$pconfig['denyunknown']
876
));
877
878 3475eb04 Andrew Pilloud
$section->addInput(new Form_Checkbox(
879
	'nonak',
880
	'Ignore denied clients',
881
	'Denied clients will be ignored rather than rejected.',
882
	$pconfig['nonak']
883 8209517d jim-p
))->setHelp("This option is not compatible with failover and cannot be enabled when a Failover Peer IP address is configured.");
884 3475eb04 Andrew Pilloud
885 11ee0c6d Brett Keller
$section->addInput(new Form_Checkbox(
886
	'ignoreclientuids',
887
	'Ignore client identifiers',
888
	'If a client includes a unique identifier in its DHCP request, that UID will not be recorded in its lease.',
889
	$pconfig['ignoreclientuids']
890
))->setHelp("This option may be useful when a client can dual boot using different client identifiers but the same hardware (MAC) address.  Note that the resulting server behavior violates the official DHCP specification.");
891
892 3475eb04 Andrew Pilloud
893 b5f6e690 Stephen Beaver
if (is_numeric($pool) || ($act == "newpool")) {
894
	$section->addInput(new Form_Input(
895
		'descr',
896
		'Pool Description',
897
		'text',
898
		$pconfig['descr']
899
	));
900
}
901 6c23757b Martin Fuchs
902 b5f6e690 Stephen Beaver
$section->addInput(new Form_StaticText(
903
	'Subnet',
904
	gen_subnet($ifcfgip, $ifcfgsn)
905
));
906 4e9cd828 Seth Mos
907 b5f6e690 Stephen Beaver
$section->addInput(new Form_StaticText(
908
	'Subnet mask',
909
	gen_subnet_mask($ifcfgsn)
910
));
911 5b237745 Scott Ullrich
912 8a73f407 Stephen Beaver
// Compose a string to display the required address ranges
913 b90d635e Renato Botelho
$rangestr = ip_after($subnet_start) . ' - ' . ip_before($subnet_end);
914 b5f6e690 Stephen Beaver
915
if (is_numeric($pool) || ($act == "newpool")) {
916 4bb7c0d1 bruno
	$rangestr .= '<br />' . gettext('In-use DHCP Pool Ranges:');
917 b5f6e690 Stephen Beaver
	if (is_array($config['dhcpd'][$if]['range'])) {
918
		$rangestr .= '<br />' . $config['dhcpd'][$if]['range']['from'] . ' - ' . $config['dhcpd'][$if]['range']['to'];
919 3d7b7757 Chris Buechler
	}
920 b5f6e690 Stephen Beaver
921
	foreach ($a_pools as $p) {
922
		if (is_array($p['range'])) {
923
			$rangestr .= '<br />' . $p['range']['from'] . ' - ' . $p['range']['to'];
924 8f8682f7 Phil Davis
		}
925 934240ef Ermal Luçi
	}
926 b5f6e690 Stephen Beaver
}
927
928
$section->addInput(new Form_StaticText(
929
	'Available range',
930
	$rangestr
931
));
932
933 24b82516 Phil Davis
$group = new Form_Group('*Range');
934 b5f6e690 Stephen Beaver
935
$group->add(new Form_IpAddress(
936
	'range_from',
937
	null,
938 eb01f065 Phil Davis
	$pconfig['range_from'],
939
	'V4'
940 b5f6e690 Stephen Beaver
))->setHelp('From');
941
942
$group->add(new Form_IpAddress(
943
	'range_to',
944
	null,
945 eb01f065 Phil Davis
	$pconfig['range_to'],
946
	'V4'
947 b5f6e690 Stephen Beaver
))->setHelp('To');
948
949
$section->add($group);
950
951
$form->add($section);
952
953
if (!is_numeric($pool) && !($act == "newpool")) {
954 5f88f964 k-paulius
	$section = new Form_Section('Additional Pools');
955 b5f6e690 Stephen Beaver
956
	$btnaddpool = new Form_Button(
957
		'btnaddpool',
958 faab522f Renato Botelho
		'Add pool',
959 37676f4e jim-p
		'services_dhcp.php?if=' . htmlspecialchars($if) . '&act=newpool',
960
		'fa-plus'
961 b5f6e690 Stephen Beaver
	);
962 37676f4e jim-p
	$btnaddpool->addClass('btn-success');
963 b5f6e690 Stephen Beaver
964
	$section->addInput(new Form_StaticText(
965
		'Add',
966
		$btnaddpool
967 e78ecb96 NOYB
	))->setHelp('If additional pools of addresses are needed inside of this subnet outside the above Range, they may be specified here.');
968 b5f6e690 Stephen Beaver
969
	if (is_array($a_pools)) {
970
		$section->addInput(new Form_StaticText(
971
			null,
972
			build_pooltable()
973
		));
974 f0cdf141 Scott Ullrich
	}
975 b5f6e690 Stephen Beaver
976
	$form->add($section);
977
}
978
979
$section = new Form_Section('Servers');
980
981
$section->addInput(new Form_IpAddress(
982
	'wins1',
983
	'WINS servers',
984 eb01f065 Phil Davis
	$pconfig['wins1'],
985
	'V4'
986
))->setAttribute('placeholder', 'WINS Server 1');
987 b5f6e690 Stephen Beaver
988
$section->addInput(new Form_IpAddress(
989
	'wins2',
990
	null,
991 eb01f065 Phil Davis
	$pconfig['wins2'],
992
	'V4'
993
))->setAttribute('placeholder', 'WINS Server 2');
994 b5f6e690 Stephen Beaver
995 6e3488e9 Phil Davis
for ($idx=1; $idx<=4; $idx++) {
996 b5f6e690 Stephen Beaver
	$section->addInput(new Form_IpAddress(
997
		'dns' . $idx,
998
		($idx == 1) ? 'DNS servers':null,
999 eb01f065 Phil Davis
		$pconfig['dns' . $idx],
1000
		'V4'
1001
	))->setAttribute('placeholder', 'DNS Server ' . $idx)->setHelp(($idx == 4) ? 'Leave blank to use the system default DNS servers: this interface\'s IP if DNS Forwarder or Resolver is enabled, otherwise the servers configured on the System / General Setup page.':'');
1002 b5f6e690 Stephen Beaver
}
1003
1004
$form->add($section);
1005
1006 5f88f964 k-paulius
$section = new Form_Section('Other Options');
1007 b5f6e690 Stephen Beaver
1008
$section->addInput(new Form_IpAddress(
1009
	'gateway',
1010
	'Gateway',
1011 eb01f065 Phil Davis
	$pconfig['gateway'],
1012
	'V4'
1013 b5f6e690 Stephen Beaver
))->setPattern('[.a-zA-Z0-9_]+')
1014 e78ecb96 NOYB
  ->setHelp('The default is to use the IP on this interface of the firewall as the gateway. Specify an alternate gateway here if this is not the correct gateway for the network. Type "none" for no gateway assignment.');
1015 b5f6e690 Stephen Beaver
1016
$section->addInput(new Form_Input(
1017
	'domain',
1018
	'Domain name',
1019
	'text',
1020
	$pconfig['domain']
1021 e78ecb96 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.');
1022 b5f6e690 Stephen Beaver
1023
$section->addInput(new Form_Input(
1024
	'domainsearchlist',
1025
	'Domain search list',
1026
	'text',
1027
	$pconfig['domainsearchlist']
1028 e78ecb96 NOYB
))->setHelp('The DHCP server can optionally provide a domain search list. Use the semicolon character as separator.');
1029 b5f6e690 Stephen Beaver
1030
$section->addInput(new Form_Input(
1031
	'deftime',
1032
	'Default lease time',
1033
	'number',
1034
	$pconfig['deftime']
1035 e78ecb96 NOYB
))->setHelp('This is used for clients that do not ask for a specific expiration time. The default is 7200 seconds.');
1036 b5f6e690 Stephen Beaver
1037
$section->addInput(new Form_Input(
1038
	'maxtime',
1039
	'Maximum lease time',
1040
	'number',
1041
	$pconfig['maxtime']
1042 e78ecb96 NOYB
))->setHelp('This is the maximum lease time for clients that ask for a specific expiration time. The default is 86400 seconds.');
1043 b5f6e690 Stephen Beaver
1044
if (!is_numeric($pool) && !($act == "newpool")) {
1045
	$section->addInput(new Form_IpAddress(
1046
		'failover_peerip',
1047
		'Failover peer IP',
1048 eb01f065 Phil Davis
		$pconfig['failover_peerip'],
1049
		'V4'
1050 af8f79b1 Chris Buechler
	))->setHelp('Leave blank to disable. Enter the interface IP address of the other machine. Machines must be using CARP. ' .
1051 4c1284c6 NOYB
				'Interface\'s advskew determines whether the DHCPd process is Primary or Secondary. Ensure one machine\'s advskew &lt; 20 (and the other is &gt; 20).');
1052 b5f6e690 Stephen Beaver
}
1053
1054
if (!is_numeric($pool) && !($act == "newpool")) {
1055
	$section->addInput(new Form_Checkbox(
1056
		'staticarp',
1057
		'Static ARP',
1058
		'Enable Static ARP entries',
1059
		$pconfig['staticarp']
1060 0c8d2784 Chris Buechler
	))->setHelp('This option persists even if DHCP server is disabled. Only the machines listed below will be able to communicate with the firewall on this interface.');
1061 b5f6e690 Stephen Beaver
1062
	$section->addInput(new Form_Checkbox(
1063
		'dhcpleaseinlocaltime',
1064
		'Time format change',
1065
		'Change DHCP display lease time from UTC to local time',
1066
		$pconfig['dhcpleaseinlocaltime']
1067
	))->setHelp('By default DHCP leases are displayed in UTC time.	By checking this box DHCP lease time will be displayed in local time and set to the time zone selected.' .
1068 e78ecb96 NOYB
				' This will be used for all DHCP interfaces lease time.');
1069 18d316a5 heper
	$section->addInput(new Form_Checkbox(
1070
		'statsgraph',
1071 61237194 Chris Buechler
		'Statistics graphs',
1072
		'Enable RRD statistics graphs',
1073 18d316a5 heper
		$pconfig['statsgraph']
1074 61237194 Chris Buechler
	))->setHelp('Enable this to add DHCP leases statistics to the RRD graphs. Disabled by default.');
1075 b5f6e690 Stephen Beaver
}
1076
1077
// DDNS
1078
$btnadv = new Form_Button(
1079
	'btnadvdns',
1080 afe62c2b Phil Davis
	'Display Advanced',
1081 3314e626 jim-p
	null,
1082
	'fa-cog'
1083 b5f6e690 Stephen Beaver
);
1084
1085 347c0214 Phil Davis
$btnadv->setAttribute('type','button')->addClass('btn-info btn-sm');
1086 b5f6e690 Stephen Beaver
1087
$section->addInput(new Form_StaticText(
1088
	'Dynamic DNS',
1089
	$btnadv
1090
));
1091
1092
$section->addInput(new Form_Checkbox(
1093
	'ddnsupdate',
1094
	null,
1095
	'Enable registration of DHCP client names in DNS',
1096
	$pconfig['ddnsupdate']
1097
));
1098
1099
$section->addInput(new Form_Input(
1100
	'ddnsdomain',
1101
	'DDNS Domain',
1102 e8da0bcd Jeremy Porter
	'text',
1103 b5f6e690 Stephen Beaver
	$pconfig['ddnsdomain']
1104 e5c4b4fc Joeri Capens
))->setHelp('Enter the dynamic DNS domain which will be used to register client names in the DNS server.');
1105 b5f6e690 Stephen Beaver
1106 cf15bcb4 Ross Williams
$section->addInput(new Form_Checkbox(
1107
	'ddnsforcehostname',
1108 cfc10a33 Ross Williams
	'DDNS Hostnames',
1109 cf15bcb4 Ross Williams
	'Force dynamic DNS hostname to be the same as configured hostname for Static Mappings',
1110
	$pconfig['ddnsforcehostname']
1111 9ca5d4ab Ross Williams
))->setHelp('Default registers host name option supplied by DHCP client.');
1112 cf15bcb4 Ross Williams
1113 b5f6e690 Stephen Beaver
$section->addInput(new Form_IpAddress(
1114
	'ddnsdomainprimary',
1115
	'Primary DDNS address',
1116 eb01f065 Phil Davis
	$pconfig['ddnsdomainprimary'],
1117
	'V4'
1118 cb6c20a9 NewEraCracker
))->setHelp('Primary domain name server IP address for the dynamic domain name.');
1119 b5f6e690 Stephen Beaver
1120
$section->addInput(new Form_Input(
1121
	'ddnsdomainkeyname',
1122
	'DNS Domain key',
1123
	'text',
1124
	$pconfig['ddnsdomainkeyname']
1125 cb6c20a9 NewEraCracker
))->setHelp('Dynamic DNS domain key name which will be used to register client names in the DNS server.');
1126 b5f6e690 Stephen Beaver
1127 534d7d69 Joeri Capens
$section->addInput(new Form_Select(
1128
	'ddnsdomainkeyalgorithm',
1129
	'Key algorithm',
1130
	$pconfig['ddnsdomainkeyalgorithm'],
1131
	array(
1132
		'hmac-md5' => 'HMAC-MD5 (legacy default)',
1133
		'hmac-sha1' => 'HMAC-SHA1',
1134
		'hmac-sha224' => 'HMAC-SHA224',
1135
		'hmac-sha256' => 'HMAC-SHA256 (current bind9 default)',
1136
		'hmac-sha384' => 'HMAC-SHA384',
1137
		'hmac-sha512' => 'HMAC-SHA512 (most secure)',
1138
	)
1139
));
1140
1141 b5f6e690 Stephen Beaver
$section->addInput(new Form_Input(
1142
	'ddnsdomainkey',
1143
	'DNS Domain key secret',
1144
	'text',
1145
	$pconfig['ddnsdomainkey']
1146 e5c4b4fc Joeri Capens
))->setHelp('Dynamic DNS domain key secret which will be used to register client names in the DNS server.');
1147 b5f6e690 Stephen Beaver
1148 67784aa6 Steve Beaver
$section->addInput(new Form_Select(
1149
	'ddnsclientupdates',
1150
	'DDNS Client Updates',
1151
	$pconfig['ddnsclientupdates'],
1152
	array(
1153
	    'allow' => gettext('Allow'),
1154
	    'deny' => gettext('Deny'),
1155
	    'ignore' => gettext('Ignore'))
1156
))->setHelp('How Forward entries are handled when client indicates they wish to update DNS.  ' .
1157
	    'Allow prevents DHCP from updating Forward entries, Deny indicates that DHCP will ' .
1158
	    'do the updates and the client should not, Ignore specifies that DHCP will do the ' .
1159
	    'update and the client can also attempt the update usually using a different domain name.');
1160
1161 b5f6e690 Stephen Beaver
// Advanced MAC
1162
$btnadv = new Form_Button(
1163
	'btnadvmac',
1164 afe62c2b Phil Davis
	'Display Advanced',
1165 3314e626 jim-p
	null,
1166
	'fa-cog'
1167 b5f6e690 Stephen Beaver
);
1168
1169 347c0214 Phil Davis
$btnadv->setAttribute('type','button')->addClass('btn-info btn-sm');
1170 b5f6e690 Stephen Beaver
1171
$section->addInput(new Form_StaticText(
1172
	'MAC address control',
1173
	$btnadv
1174
));
1175
1176
$section->addInput(new Form_Input(
1177
	'mac_allow',
1178 ef2936e6 Stephen Beaver
	'MAC Allow',
1179 b5f6e690 Stephen Beaver
	'text',
1180
	$pconfig['mac_allow']
1181
))->setHelp('List of partial MAC addresses to allow, comma separated, no spaces, e.g.: 00:00:00,01:E5:FF');
1182
1183
$section->addInput(new Form_Input(
1184
	'mac_deny',
1185 ef2936e6 Stephen Beaver
	'MAC Deny',
1186 b5f6e690 Stephen Beaver
	'text',
1187
	$pconfig['mac_deny']
1188
))->setHelp('List of partial MAC addresses to deny access, comma separated, no spaces, e.g.: 00:00:00,01:E5:FF');
1189
1190
// Advanced NTP
1191
$btnadv = new Form_Button(
1192
	'btnadvntp',
1193 afe62c2b Phil Davis
	'Display Advanced',
1194 3314e626 jim-p
	null,
1195
	'fa-cog'
1196 b5f6e690 Stephen Beaver
);
1197
1198 347c0214 Phil Davis
$btnadv->setAttribute('type','button')->addClass('btn-info btn-sm');
1199 b5f6e690 Stephen Beaver
1200
$section->addInput(new Form_StaticText(
1201 ff3da1e7 Stephen Beaver
	'NTP',
1202 b5f6e690 Stephen Beaver
	$btnadv
1203
));
1204
1205
$section->addInput(new Form_IpAddress(
1206
	'ntp1',
1207 ff3da1e7 Stephen Beaver
	'NTP Server 1',
1208 eb01f065 Phil Davis
	$pconfig['ntp1'],
1209 45541aae Phil Davis
	'HOSTV4'
1210
));
1211 b5f6e690 Stephen Beaver
1212
$section->addInput(new Form_IpAddress(
1213
	'ntp2',
1214 ff3da1e7 Stephen Beaver
	'NTP Server 2',
1215 eb01f065 Phil Davis
	$pconfig['ntp2'],
1216 45541aae Phil Davis
	'HOSTV4'
1217
));
1218 b5f6e690 Stephen Beaver
1219
// Advanced TFTP
1220
$btnadv = new Form_Button(
1221
	'btnadvtftp',
1222 afe62c2b Phil Davis
	'Display Advanced',
1223 3314e626 jim-p
	null,
1224
	'fa-cog'
1225 b5f6e690 Stephen Beaver
);
1226
1227 347c0214 Phil Davis
$btnadv->setAttribute('type','button')->addClass('btn-info btn-sm');
1228 b5f6e690 Stephen Beaver
1229
$section->addInput(new Form_StaticText(
1230 ff3da1e7 Stephen Beaver
	'TFTP',
1231 b5f6e690 Stephen Beaver
	$btnadv
1232
));
1233
1234 c411661a doktornotor
$section->addInput(new Form_Input(
1235 b5f6e690 Stephen Beaver
	'tftp',
1236 ff3da1e7 Stephen Beaver
	'TFTP Server',
1237 9d9736d7 jim-p
	'text',
1238 b5f6e690 Stephen Beaver
	$pconfig['tftp']
1239 c411661a doktornotor
))->setHelp('Leave blank to disable. Enter a valid IP address, hostname or URL for the TFTP server.');
1240 b5f6e690 Stephen Beaver
1241
// Advanced LDAP
1242
$btnadv = new Form_Button(
1243
	'btnadvldap',
1244 afe62c2b Phil Davis
	'Display Advanced',
1245 3314e626 jim-p
	null,
1246
	'fa-cog'
1247 b5f6e690 Stephen Beaver
);
1248
1249 347c0214 Phil Davis
$btnadv->setAttribute('type','button')->addClass('btn-info btn-sm');
1250 b5f6e690 Stephen Beaver
1251
$section->addInput(new Form_StaticText(
1252 ff3da1e7 Stephen Beaver
	'LDAP',
1253 b5f6e690 Stephen Beaver
	$btnadv
1254
));
1255
1256
$section->addInput(new Form_Input(
1257
	'ldap',
1258 ff3da1e7 Stephen Beaver
	'LDAP Server URI',
1259 b5f6e690 Stephen Beaver
	'text',
1260
	$pconfig['ldap']
1261
))->setHelp('Leave blank to disable. Enter a full URI for the LDAP server in the form ldap://ldap.example.com/dc=example,dc=com ');
1262
1263 68de2169 Phil Davis
// Advanced Network Booting options
1264
$btnadv = new Form_Button(
1265
	'btnadvnwkboot',
1266
	'Display Advanced',
1267
	null,
1268
	'fa-cog'
1269
);
1270
1271
$btnadv->setAttribute('type','button')->addClass('btn-info btn-sm');
1272
1273
$section->addInput(new Form_StaticText(
1274
	'Network Booting',
1275
	$btnadv
1276
));
1277
1278
$section->addInput(new Form_Checkbox(
1279
	'netboot',
1280
	'Enable',
1281
	'Enables network booting',
1282
	$pconfig['netboot']
1283
));
1284
1285
$section->addInput(new Form_IpAddress(
1286
	'nextserver',
1287
	'Next Server',
1288 eb01f065 Phil Davis
	$pconfig['nextserver'],
1289
	'V4'
1290 68de2169 Phil Davis
))->setHelp('Enter the IP address of the next server');
1291
1292
$section->addInput(new Form_Input(
1293
	'filename',
1294
	'Default BIOS file name',
1295
	'text',
1296
	$pconfig['filename']
1297
));
1298
1299
$section->addInput(new Form_Input(
1300
	'filename32',
1301
	'UEFI 32 bit file name',
1302
	'text',
1303
	$pconfig['filename32']
1304
));
1305
1306
$section->addInput(new Form_Input(
1307
	'filename64',
1308
	'UEFI 64 bit file name',
1309
	'text',
1310
	$pconfig['filename64']
1311
))->setHelp('Both a filename and a boot server must be configured for this to work! ' .
1312
			'All three filenames and a configured boot server are necessary for UEFI to work! ');
1313
1314
$section->addInput(new Form_Input(
1315
	'rootpath',
1316
	'Root path',
1317
	'text',
1318
	$pconfig['rootpath']
1319
))->setHelp('string-format: iscsi:(servername):(protocol):(port):(LUN):targetname ');
1320
1321 b5f6e690 Stephen Beaver
// Advanced Additional options
1322
$btnadv = new Form_Button(
1323
	'btnadvopts',
1324 afe62c2b Phil Davis
	'Display Advanced',
1325 3314e626 jim-p
	null,
1326
	'fa-cog'
1327 b5f6e690 Stephen Beaver
);
1328
1329 347c0214 Phil Davis
$btnadv->setAttribute('type','button')->addClass('btn-info btn-sm');
1330 b5f6e690 Stephen Beaver
1331
$section->addInput(new Form_StaticText(
1332
	'Additional BOOTP/DHCP Options',
1333
	$btnadv
1334
));
1335
1336 f8088b00 Phil Davis
$form->add($section);
1337
1338 b5f6e690 Stephen Beaver
$section = new Form_Section('Additional BOOTP/DHCP Options');
1339
$section->addClass('adnlopts');
1340
1341
$section->addInput(new Form_StaticText(
1342
	null,
1343 5daef710 NOYB
	'<div class="alert alert-info"> ' . gettext('Enter the DHCP option number and the value for each item to include in the DHCP lease information.') . ' ' .
1344 3fd41815 Phil Davis
	sprintf(gettext('For a list of available options please visit this %1$s URL%2$s.%3$s'), '<a href="http://www.iana.org/assignments/bootp-dhcp-parameters/" target="_blank">', '</a>', '</div>')
1345 b5f6e690 Stephen Beaver
));
1346
1347 6e3488e9 Phil Davis
if (!$pconfig['numberoptions']) {
1348 f156083a Steve Beaver
	$pconfig['numberoptions'] = array();
1349 b5f6e690 Stephen Beaver
	$pconfig['numberoptions']['item']  = array(array('number' => '', 'type' => 'text', 'value' => ''));
1350
}
1351
1352
$customitemtypes = array(
1353
	'text' => gettext('Text'), 'string' => gettext('String'), 'boolean' => gettext('Boolean'),
1354
	'unsigned integer 8' => gettext('Unsigned 8-bit integer'), 'unsigned integer 16' => gettext('Unsigned 16-bit integer'), 'unsigned integer 32' => gettext('Unsigned 32-bit integer'),
1355
	'signed integer 8' => gettext('Signed 8-bit integer'), 'signed integer 16' => gettext('Signed 16-bit integer'), 'signed integer 32' => gettext('Signed 32-bit integer'), 'ip-address' => gettext('IP address or host')
1356
);
1357
1358
$numrows = count($item) -1;
1359
$counter = 0;
1360
1361
$numrows = count($pconfig['numberoptions']['item']) -1;
1362
1363
foreach ($pconfig['numberoptions']['item'] as $item) {
1364
	$number = $item['number'];
1365
	$itemtype = $item['type'];
1366 65cce9d7 Renato Botelho
	$value = base64_decode($item['value']);
1367 b5f6e690 Stephen Beaver
1368
	$group = new Form_Group(($counter == 0) ? 'Option':null);
1369
	$group->addClass('repeatable');
1370
1371
	$group->add(new Form_Input(
1372
		'number' . $counter,
1373
		null,
1374 60682dd2 Michael Newton
		'number',
1375
		$number,
1376
		['min'=>'1', 'max'=>'254']
1377 b5f6e690 Stephen Beaver
	))->setHelp($numrows == $counter ? 'Number':null);
1378
1379
1380
	$group->add(new Form_Select(
1381
		'itemtype' . $counter,
1382
		null,
1383
		$itemtype,
1384
		$customitemtypes
1385 8a73f407 Stephen Beaver
	))->setWidth(3)->setHelp($numrows == $counter ? 'Type':null);
1386 b5f6e690 Stephen Beaver
1387
	$group->add(new Form_Input(
1388
		'value' . $counter,
1389
		null,
1390
		'text',
1391
		$value
1392
	))->setHelp($numrows == $counter ? 'Value':null);
1393
1394
	$group->add(new Form_Button(
1395
		'deleterow' . $counter,
1396 faab522f Renato Botelho
		'Delete',
1397 cd7ddae6 jim-p
		null,
1398
		'fa-trash'
1399
	))->addClass('btn-warning');
1400 b5f6e690 Stephen Beaver
1401
	$section->add($group);
1402
1403
	$counter++;
1404
}
1405
1406
$section->addInput(new Form_Button(
1407
	'addrow',
1408 faab522f Renato Botelho
	'Add',
1409 cd7ddae6 jim-p
	null,
1410
	'fa-plus'
1411
))->addClass('btn-success');
1412 b5f6e690 Stephen Beaver
1413
$form->add($section);
1414
1415
if ($act == "newpool") {
1416
	$form->addGlobal(new Form_Input(
1417
		'act',
1418
		null,
1419
		'hidden',
1420
		'newpool'
1421
	));
1422
}
1423
1424
if (is_numeric($pool)) {
1425
	$form->addGlobal(new Form_Input(
1426
		'pool',
1427
		null,
1428
		'hidden',
1429
		$pool
1430
	));
1431
}
1432
1433
$form->addGlobal(new Form_Input(
1434
	'if',
1435
	null,
1436
	'hidden',
1437
	$if
1438
));
1439
1440
print($form);
1441
1442
// DHCP Static Mappings table
1443
1444
if (!is_numeric($pool) && !($act == "newpool")) {
1445 6e3e95a5 Phil Davis
1446
	// Decide whether display of the Client Id column is needed.
1447
	$got_cid = false;
1448
	if (is_array($a_maps)) {
1449
		foreach ($a_maps as $map) {
1450
			if (!empty($map['cid'])) {
1451
				$got_cid = true;
1452
				break;
1453
			}
1454
		}
1455
	}
1456 de792e62 jim-p
?>
1457 b5f6e690 Stephen Beaver
1458
<div class="panel panel-default">
1459 3d7a8696 k-paulius
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("DHCP Static Mappings for this Interface")?></h2></div>
1460 b5f6e690 Stephen Beaver
	<div class="table-responsive">
1461 55f67b5a Stephen Beaver
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
1462 b5f6e690 Stephen Beaver
				<thead>
1463
					<tr>
1464
						<th><?=gettext("Static ARP")?></th>
1465
						<th><?=gettext("MAC address")?></th>
1466 6e3e95a5 Phil Davis
<?php
1467
	if ($got_cid):
1468
?>
1469
						<th><?=gettext("Client Id")?></th>
1470
<?php
1471
	endif;
1472
?>
1473 b5f6e690 Stephen Beaver
						<th><?=gettext("IP address")?></th>
1474
						<th><?=gettext("Hostname")?></th>
1475
						<th><?=gettext("Description")?></th>
1476
						<th></th>
1477
					</tr>
1478
				</thead>
1479 8f8682f7 Phil Davis
<?php
1480 b5f6e690 Stephen Beaver
	if (is_array($a_maps)) {
1481
		$i = 0;
1482 8f8682f7 Phil Davis
?>
1483 b5f6e690 Stephen Beaver
				<tbody>
1484 8f8682f7 Phil Davis
<?php
1485 b5f6e690 Stephen Beaver
		foreach ($a_maps as $mapent) {
1486 8f8682f7 Phil Davis
?>
1487 b5f6e690 Stephen Beaver
					<tr>
1488 1d932e0c NOYB
						<td class="text-center" ondblclick="document.location='services_dhcp_edit.php?if=<?=htmlspecialchars($if)?>&amp;id=<?=$i?>';">
1489 b5f6e690 Stephen Beaver
							<?php if (isset($mapent['arp_table_static_entry'])): ?>
1490 1b7379f9 Jared Dillard
								<i class="fa fa-check"></i>
1491 b5f6e690 Stephen Beaver
							<?php endif; ?>
1492
						</td>
1493
						<td ondblclick="document.location='services_dhcp_edit.php?if=<?=htmlspecialchars($if)?>&amp;id=<?=$i?>';">
1494
							<?=htmlspecialchars($mapent['mac'])?>
1495
						</td>
1496 6e3e95a5 Phil Davis
<?php
1497
			if ($got_cid):
1498
?>
1499
						<td ondblclick="document.location='services_dhcp_edit.php?if=<?=htmlspecialchars($if)?>&amp;id=<?=$i?>';">
1500
							<?=htmlspecialchars($mapent['cid'])?>
1501
						</td>
1502
<?php
1503
			endif;
1504
?>
1505 b5f6e690 Stephen Beaver
						<td ondblclick="document.location='services_dhcp_edit.php?if=<?=htmlspecialchars($if)?>&amp;id=<?=$i?>';">
1506
							<?=htmlspecialchars($mapent['ipaddr'])?>
1507
						</td>
1508
						<td ondblclick="document.location='services_dhcp_edit.php?if=<?=htmlspecialchars($if)?>&amp;id=<?=$i?>';">
1509
							<?=htmlspecialchars($mapent['hostname'])?>
1510
						</td>
1511
						<td ondblclick="document.location='services_dhcp_edit.php?if=<?=htmlspecialchars($if)?>&amp;id=<?=$i?>';">
1512
							<?=htmlspecialchars($mapent['descr'])?>
1513
						</td>
1514
						<td>
1515 9a6a8329 heper
							<a class="fa fa-pencil"	title="<?=gettext('Edit static mapping')?>"	href="services_dhcp_edit.php?if=<?=htmlspecialchars($if)?>&amp;id=<?=$i?>"></a>
1516 c946d721 Steve Beaver
							<a class="fa fa-trash"	title="<?=gettext('Delete static mapping')?>"	href="services_dhcp.php?if=<?=htmlspecialchars($if)?>&amp;act=del&amp;id=<?=$i?>" usepost></a>
1517 b5f6e690 Stephen Beaver
						</td>
1518
					</tr>
1519 8f8682f7 Phil Davis
<?php
1520 b5f6e690 Stephen Beaver
		$i++;
1521
		}
1522 8f8682f7 Phil Davis
?>
1523 b5f6e690 Stephen Beaver
				</tbody>
1524 8f8682f7 Phil Davis
<?php
1525 b5f6e690 Stephen Beaver
	}
1526 8f8682f7 Phil Davis
?>
1527 82f54a42 Colin Fleming
		</table>
1528 b5f6e690 Stephen Beaver
	</div>
1529
</div>
1530 c9679d8c Stephen Beaver
1531 c10cb196 Stephen Beaver
<nav class="action-buttons">
1532 c9679d8c Stephen Beaver
	<a href="services_dhcp_edit.php?if=<?=htmlspecialchars($if)?>" class="btn btn-sm btn-success">
1533 9d5a20cf heper
		<i class="fa fa-plus icon-embed-btn"></i>
1534 c9679d8c Stephen Beaver
		<?=gettext("Add")?>
1535
	</a>
1536
</nav>
1537 8f8682f7 Phil Davis
<?php
1538 b5f6e690 Stephen Beaver
}
1539 8f8682f7 Phil Davis
?>
1540
1541 8fd9052f Colin Fleming
<script type="text/javascript">
1542 b5f6e690 Stephen Beaver
//<![CDATA[
1543 6e3488e9 Phil Davis
events.push(function() {
1544 b5f6e690 Stephen Beaver
1545
	// Show advanced DNS options ======================================================================================
1546
	var showadvdns = false;
1547
1548 afe62c2b Phil Davis
	function show_advdns(ispageload) {
1549
		var text;
1550
		// On page load decide the initial state based on the data.
1551
		if (ispageload) {
1552 b5f6e690 Stephen Beaver
<?php
1553 67784aa6 Steve Beaver
			if (!$pconfig['ddnsupdate'] &&
1554
				!$pconfig['ddnsforcehostname'] &&
1555
				empty($pconfig['ddnsdomain']) &&
1556
				empty($pconfig['ddnsdomainprimary']) &&
1557
			    empty($pconfig['ddnsdomainkeyname']) &&
1558 3e1b29c7 Michael Alden
			    (empty($pconfig['ddnsdomainkeyalgorithm']) || ($pconfig['ddnsdomainkeyalgorithm'] == "hmac-md5")) &&
1559 67784aa6 Steve Beaver
			    (empty($pconfig['ddnsclientupdates']) || ($pconfig['ddnsclientupdates'] == "allow")) &&
1560
			    empty($pconfig['ddnsdomainkey'])) {
1561 afe62c2b Phil Davis
				$showadv = false;
1562
			} else {
1563
				$showadv = true;
1564
			}
1565
?>
1566
			showadvdns = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
1567 6e3488e9 Phil Davis
		} else {
1568 afe62c2b Phil Davis
			// It was a click, swap the state.
1569
			showadvdns = !showadvdns;
1570 6e3488e9 Phil Davis
		}
1571 afe62c2b Phil Davis
1572
		hideCheckbox('ddnsupdate', !showadvdns);
1573
		hideInput('ddnsdomain', !showadvdns);
1574 cf15bcb4 Ross Williams
		hideCheckbox('ddnsforcehostname', !showadvdns);
1575 afe62c2b Phil Davis
		hideInput('ddnsdomainprimary', !showadvdns);
1576
		hideInput('ddnsdomainkeyname', !showadvdns);
1577 534d7d69 Joeri Capens
		hideInput('ddnsdomainkeyalgorithm', !showadvdns);
1578 afe62c2b Phil Davis
		hideInput('ddnsdomainkey', !showadvdns);
1579 67784aa6 Steve Beaver
		hideInput('ddnsclientupdates', !showadvdns);
1580 afe62c2b Phil Davis
1581
		if (showadvdns) {
1582
			text = "<?=gettext('Hide Advanced');?>";
1583
		} else {
1584
			text = "<?=gettext('Display Advanced');?>";
1585
		}
1586
		$('#btnadvdns').html('<i class="fa fa-cog"></i> ' + text);
1587 b5f6e690 Stephen Beaver
	}
1588
1589
	$('#btnadvdns').click(function(event) {
1590
		show_advdns();
1591
	});
1592
1593 afe62c2b Phil Davis
	// Show advanced MAC options ======================================================================================
1594 b5f6e690 Stephen Beaver
	var showadvmac = false;
1595
1596 afe62c2b Phil Davis
	function show_advmac(ispageload) {
1597
		var text;
1598
		// On page load decide the initial state based on the data.
1599
		if (ispageload) {
1600 8f8682f7 Phil Davis
<?php
1601 afe62c2b Phil Davis
			if (empty($pconfig['mac_allow']) && empty($pconfig['mac_deny'])) {
1602
				$showadv = false;
1603
			} else {
1604
				$showadv = true;
1605
			}
1606
?>
1607
			showadvmac = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
1608 6e3488e9 Phil Davis
		} else {
1609 afe62c2b Phil Davis
			// It was a click, swap the state.
1610
			showadvmac = !showadvmac;
1611 6e3488e9 Phil Davis
		}
1612 b5f6e690 Stephen Beaver
1613 afe62c2b Phil Davis
		hideInput('mac_allow', !showadvmac);
1614
		hideInput('mac_deny', !showadvmac);
1615 b5f6e690 Stephen Beaver
1616 afe62c2b Phil Davis
		if (showadvmac) {
1617
			text = "<?=gettext('Hide Advanced');?>";
1618
		} else {
1619
			text = "<?=gettext('Display Advanced');?>";
1620
		}
1621
		$('#btnadvmac').html('<i class="fa fa-cog"></i> ' + text);
1622 b5f6e690 Stephen Beaver
	}
1623
1624
	$('#btnadvmac').click(function(event) {
1625 afe62c2b Phil Davis
		show_advmac();
1626 b5f6e690 Stephen Beaver
	});
1627
1628 afe62c2b Phil Davis
	// Show advanced NTP options ======================================================================================
1629 b5f6e690 Stephen Beaver
	var showadvntp = false;
1630
1631 afe62c2b Phil Davis
	function show_advntp(ispageload) {
1632
		var text;
1633
		// On page load decide the initial state based on the data.
1634
		if (ispageload) {
1635 8f8682f7 Phil Davis
<?php
1636 afe62c2b Phil Davis
			if (empty($pconfig['ntp1']) && empty($pconfig['ntp2'])) {
1637
				$showadv = false;
1638
			} else {
1639
				$showadv = true;
1640
			}
1641
?>
1642
			showadvntp = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
1643 6e3488e9 Phil Davis
		} else {
1644 afe62c2b Phil Davis
			// It was a click, swap the state.
1645
			showadvntp = !showadvntp;
1646 6e3488e9 Phil Davis
		}
1647 b5f6e690 Stephen Beaver
1648 afe62c2b Phil Davis
		hideInput('ntp1', !showadvntp);
1649
		hideInput('ntp2', !showadvntp);
1650 b5f6e690 Stephen Beaver
1651 afe62c2b Phil Davis
		if (showadvntp) {
1652
			text = "<?=gettext('Hide Advanced');?>";
1653
		} else {
1654
			text = "<?=gettext('Display Advanced');?>";
1655
		}
1656
		$('#btnadvntp').html('<i class="fa fa-cog"></i> ' + text);
1657 b5f6e690 Stephen Beaver
	}
1658
1659
	$('#btnadvntp').click(function(event) {
1660
		show_advntp();
1661
	});
1662
1663 afe62c2b Phil Davis
	// Show advanced TFTP options ======================================================================================
1664
	var showadvtftp = false;
1665 b5f6e690 Stephen Beaver
1666 afe62c2b Phil Davis
	function show_advtftp(ispageload) {
1667
		var text;
1668
		// On page load decide the initial state based on the data.
1669
		if (ispageload) {
1670 8f8682f7 Phil Davis
<?php
1671 afe62c2b Phil Davis
			if (empty($pconfig['tftp'])) {
1672
				$showadv = false;
1673
			} else {
1674
				$showadv = true;
1675
			}
1676
?>
1677
			showadvtftp = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
1678 6e3488e9 Phil Davis
		} else {
1679 afe62c2b Phil Davis
			// It was a click, swap the state.
1680
			showadvtftp = !showadvtftp;
1681 6e3488e9 Phil Davis
		}
1682 b5f6e690 Stephen Beaver
1683 afe62c2b Phil Davis
		hideInput('tftp', !showadvtftp);
1684 b5f6e690 Stephen Beaver
1685 afe62c2b Phil Davis
		if (showadvtftp) {
1686
			text = "<?=gettext('Hide Advanced');?>";
1687
		} else {
1688
			text = "<?=gettext('Display Advanced');?>";
1689
		}
1690
		$('#btnadvtftp').html('<i class="fa fa-cog"></i> ' + text);
1691 b5f6e690 Stephen Beaver
	}
1692
1693
	$('#btnadvtftp').click(function(event) {
1694
		show_advtftp();
1695
	});
1696
1697 afe62c2b Phil Davis
	// Show advanced LDAP options ======================================================================================
1698 b5f6e690 Stephen Beaver
	var showadvldap = false;
1699
1700 afe62c2b Phil Davis
	function show_advldap(ispageload) {
1701
		var text;
1702
		// On page load decide the initial state based on the data.
1703
		if (ispageload) {
1704 8f8682f7 Phil Davis
<?php
1705 afe62c2b Phil Davis
			if (empty($pconfig['ldap'])) {
1706
				$showadv = false;
1707
			} else {
1708
				$showadv = true;
1709
			}
1710
?>
1711
			showadvldap = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
1712 6e3488e9 Phil Davis
		} else {
1713 afe62c2b Phil Davis
			// It was a click, swap the state.
1714
			showadvldap = !showadvldap;
1715 6e3488e9 Phil Davis
		}
1716 b5f6e690 Stephen Beaver
1717 afe62c2b Phil Davis
		hideInput('ldap', !showadvldap);
1718 b5f6e690 Stephen Beaver
1719 afe62c2b Phil Davis
		if (showadvldap) {
1720
			text = "<?=gettext('Hide Advanced');?>";
1721
		} else {
1722
			text = "<?=gettext('Display Advanced');?>";
1723
		}
1724
		$('#btnadvldap').html('<i class="fa fa-cog"></i> ' + text);
1725 b5f6e690 Stephen Beaver
	}
1726
1727
	$('#btnadvldap').click(function(event) {
1728
		show_advldap();
1729
	});
1730
1731 eef93144 Jared Dillard
	// Show advanced additional opts options ===========================================================================
1732 b5f6e690 Stephen Beaver
	var showadvopts = false;
1733
1734 afe62c2b Phil Davis
	function show_advopts(ispageload) {
1735
		var text;
1736
		// On page load decide the initial state based on the data.
1737
		if (ispageload) {
1738 8f8682f7 Phil Davis
<?php
1739 afe62c2b Phil Davis
			if (empty($pconfig['numberoptions']) ||
1740
			    (empty($pconfig['numberoptions']['item'][0]['number']) && (empty($pconfig['numberoptions']['item'][0]['value'])))) {
1741
				$showadv = false;
1742
			} else {
1743
				$showadv = true;
1744
			}
1745
?>
1746
			showadvopts = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
1747 6e3488e9 Phil Davis
		} else {
1748 afe62c2b Phil Davis
			// It was a click, swap the state.
1749
			showadvopts = !showadvopts;
1750 6e3488e9 Phil Davis
		}
1751 b5f6e690 Stephen Beaver
1752 afe62c2b Phil Davis
		hideClass('adnlopts', !showadvopts);
1753 b5f6e690 Stephen Beaver
1754 afe62c2b Phil Davis
		if (showadvopts) {
1755
			text = "<?=gettext('Hide Advanced');?>";
1756
		} else {
1757
			text = "<?=gettext('Display Advanced');?>";
1758
		}
1759
		$('#btnadvopts').html('<i class="fa fa-cog"></i> ' + text);
1760 b5f6e690 Stephen Beaver
	}
1761
1762
	$('#btnadvopts').click(function(event) {
1763
		show_advopts();
1764
	});
1765
1766 68de2169 Phil Davis
	// Show advanced Network Booting options ===========================================================================
1767
	var showadvnwkboot = false;
1768
1769
	function show_advnwkboot(ispageload) {
1770
		var text;
1771
		// On page load decide the initial state based on the data.
1772
		if (ispageload) {
1773
<?php
1774
			if (empty($pconfig['netboot'])) {
1775
				$showadv = false;
1776
			} else {
1777
				$showadv = true;
1778
			}
1779
?>
1780
			showadvnwkboot = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
1781
		} else {
1782
			// It was a click, swap the state.
1783
			showadvnwkboot = !showadvnwkboot;
1784
		}
1785
1786
		hideCheckbox('netboot', !showadvnwkboot);
1787
		hideInput('nextserver', !showadvnwkboot);
1788
		hideInput('filename', !showadvnwkboot);
1789
		hideInput('filename32', !showadvnwkboot);
1790
		hideInput('filename64', !showadvnwkboot);
1791
		hideInput('rootpath', !showadvnwkboot);
1792
1793
		if (showadvnwkboot) {
1794
			text = "<?=gettext('Hide Advanced');?>";
1795
		} else {
1796
			text = "<?=gettext('Display Advanced');?>";
1797
		}
1798
		$('#btnadvnwkboot').html('<i class="fa fa-cog"></i> ' + text);
1799
	}
1800
1801
	$('#btnadvnwkboot').click(function(event) {
1802
		show_advnwkboot();
1803
	});
1804
1805 eef93144 Jared Dillard
	// ---------- On initial page load ------------------------------------------------------------
1806
1807 afe62c2b Phil Davis
	show_advdns(true);
1808
	show_advmac(true);
1809
	show_advntp(true);
1810
	show_advtftp(true);
1811
	show_advldap(true);
1812
	show_advopts(true);
1813 68de2169 Phil Davis
	show_advnwkboot(true);
1814 0bc61baa Stephen Beaver
1815
	// Suppress "Delete row" button if there are fewer than two rows
1816
	checkLastRow();
1817 b5f6e690 Stephen Beaver
});
1818 180db186 Colin Fleming
//]]>
1819 5b237745 Scott Ullrich
</script>
1820 b5f6e690 Stephen Beaver
1821 3c9befb9 Chris Buechler
<?php include("foot.inc");