Project

General

Profile

Download (48.6 KB) Statistics
| Branch: | Tag: | Revision:
1 e9f147c8 Scott Ullrich
<?php
2 5b237745 Scott Ullrich
/*
3
	services_dhcp.php
4
*/
5 b5f6e690 Stephen Beaver
/* ====================================================================
6
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
7 919d91f9 Phil Davis
 *
8 cb41dd63 Renato Botelho
 *	Some or all of this file is based on the m0n0wall project which is
9
 *	Copyright (c)  2004 Manuel Kasper (BSD 2 clause)
10 b5f6e690 Stephen Beaver
 *
11
 *	Redistribution and use in source and binary forms, with or without modification,
12
 *	are permitted provided that the following conditions are met:
13
 *
14
 *	1. Redistributions of source code must retain the above copyright notice,
15
 *		this list of conditions and the following disclaimer.
16
 *
17
 *	2. Redistributions in binary form must reproduce the above copyright
18
 *		notice, this list of conditions and the following disclaimer in
19
 *		the documentation and/or other materials provided with the
20
 *		distribution.
21
 *
22
 *	3. All advertising materials mentioning features or use of this software
23
 *		must display the following acknowledgment:
24
 *		"This product includes software developed by the pfSense Project
25
 *		 for use in the pfSense software distribution. (http://www.pfsense.org/).
26
 *
27
 *	4. The names "pfSense" and "pfSense Project" must not be used to
28
 *		 endorse or promote products derived from this software without
29
 *		 prior written permission. For written permission, please contact
30
 *		 coreteam@pfsense.org.
31
 *
32
 *	5. Products derived from this software may not be called "pfSense"
33
 *		nor may "pfSense" appear in their names without prior written
34
 *		permission of the Electric Sheep Fencing, LLC.
35
 *
36
 *	6. Redistributions of any form whatsoever must retain the following
37
 *		acknowledgment:
38
 *
39
 *	"This product includes software developed by the pfSense Project
40
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
41
 *
42
 *	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
43
 *	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
45
 *	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
46
 *	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47
 *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48
 *	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
49
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
51
 *	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52
 *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
53
 *	OF THE POSSIBILITY OF SUCH DAMAGE.
54
 *
55
 *	====================================================================
56
 *
57
 */
58 5b237745 Scott Ullrich
59 6b07c15a Matthew Grooms
##|+PRIV
60
##|*IDENT=page-services-dhcpserver
61 9599211d jim-p
##|*NAME=Services: DHCP Server
62
##|*DESCR=Allow access to the 'Services: DHCP Server' page.
63 6b07c15a Matthew Grooms
##|*MATCH=services_dhcp.php*
64
##|-PRIV
65
66 b7597d4e Bill Marquette
require("guiconfig.inc");
67 6c124212 Phil Davis
require_once("filter.inc");
68 6303601e heper
require_once('rrd.inc');
69
require_once("shaper.inc");
70 5b237745 Scott Ullrich
71 8f8682f7 Phil Davis
if (!$g['services_dhcp_server_enable']) {
72 6f3d2063 Renato Botelho
	header("Location: /");
73 2ee0410f Scott Ullrich
	exit;
74
}
75
76 5b237745 Scott Ullrich
$if = $_GET['if'];
77 8f8682f7 Phil Davis
if (!empty($_POST['if'])) {
78 5b237745 Scott Ullrich
	$if = $_POST['if'];
79 8f8682f7 Phil Davis
}
80 e9f147c8 Scott Ullrich
81 11bc553c Scott Ullrich
/* if OLSRD is enabled, allow WAN to house DHCP. */
82 8f8682f7 Phil Davis
if ($config['installedpackages']['olsrd']) {
83
	foreach ($config['installedpackages']['olsrd']['config'] as $olsrd) {
84
		if ($olsrd['enable']) {
85
			$is_olsr_enabled = true;
86
			break;
87
		}
88 a3b466b5 Scott Ullrich
	}
89 8f8682f7 Phil Davis
}
90 5b237745 Scott Ullrich
91 934240ef Ermal Luçi
$iflist = get_configured_interface_with_descr();
92 5b237745 Scott Ullrich
93 1c451b06 Scott Ullrich
/* set the starting interface */
94 f19651d1 Ermal
if (!$if || !isset($iflist[$if])) {
95 01fdb2d3 Erik Fonnesbeck
	foreach ($iflist as $ifent => $ifname) {
96 de792e62 jim-p
		$oc = $config['interfaces'][$ifent];
97 e5770bc2 Bill Marquette
		if ((is_array($config['dhcpd'][$ifent]) && !isset($config['dhcpd'][$ifent]['enable']) && (!is_ipaddrv4($oc['ipaddr']))) ||
98 6e3488e9 Phil Davis
		    (!is_array($config['dhcpd'][$ifent]) && (!is_ipaddrv4($oc['ipaddr'])))) {
99 01fdb2d3 Erik Fonnesbeck
			continue;
100 8f8682f7 Phil Davis
		}
101 b5f6e690 Stephen Beaver
102 01fdb2d3 Erik Fonnesbeck
		$if = $ifent;
103
		break;
104
	}
105 f19651d1 Ermal
}
106 0a2c6a5b Scott Ullrich
107 cba980f6 jim-p
$act = $_GET['act'];
108 8f8682f7 Phil Davis
if (!empty($_POST['act'])) {
109 cba980f6 jim-p
	$act = $_POST['act'];
110 8f8682f7 Phil Davis
}
111 cba980f6 jim-p
112 cc6052f0 Renato Botelho
$a_pools = array();
113 cba980f6 jim-p
114 8f8682f7 Phil Davis
if (is_array($config['dhcpd'][$if])) {
115 cba980f6 jim-p
	$pool = $_GET['pool'];
116 8f8682f7 Phil Davis
	if (is_numeric($_POST['pool'])) {
117 cba980f6 jim-p
		$pool = $_POST['pool'];
118 8f8682f7 Phil Davis
	}
119 cba980f6 jim-p
120
	// If we have a pool but no interface name, that's not valid. Redirect away.
121
	if (is_numeric($pool) && empty($if)) {
122
		header("Location: services_dhcp.php");
123
		exit;
124 de792e62 jim-p
	}
125 cba980f6 jim-p
126 8f8682f7 Phil Davis
	if (!is_array($config['dhcpd'][$if]['pool'])) {
127 cba980f6 jim-p
		$config['dhcpd'][$if]['pool'] = array();
128 8f8682f7 Phil Davis
	}
129 b5f6e690 Stephen Beaver
130 cba980f6 jim-p
	$a_pools = &$config['dhcpd'][$if]['pool'];
131
132 8f8682f7 Phil Davis
	if (is_numeric($pool) && $a_pools[$pool]) {
133 cba980f6 jim-p
		$dhcpdconf = &$a_pools[$pool];
134 8f8682f7 Phil Davis
	} elseif ($act == "newpool") {
135 cba980f6 jim-p
		$dhcpdconf = array();
136 8f8682f7 Phil Davis
	} else {
137 cba980f6 jim-p
		$dhcpdconf = &$config['dhcpd'][$if];
138 8f8682f7 Phil Davis
	}
139 e7940d2e Phil Davis
140
	if (!is_array($config['dhcpd'][$if]['staticmap'])) {
141
		$dhcpdconf['staticmap'] = array();
142
	}
143
144
	$a_maps = &$config['dhcpd'][$if]['staticmap'];
145 cba980f6 jim-p
}
146
if (is_array($dhcpdconf)) {
147
	// Global Options
148
	if (!is_numeric($pool) && !($act == "newpool")) {
149
		$pconfig['enable'] = isset($dhcpdconf['enable']);
150
		$pconfig['staticarp'] = isset($dhcpdconf['staticarp']);
151
		// No reason to specify this per-pool, per the dhcpd.conf man page it needs to be in every
152 b5f6e690 Stephen Beaver
		//	 pool and should be specified in every pool both nodes share, so we'll treat it as global
153 cba980f6 jim-p
		$pconfig['failover_peerip'] = $dhcpdconf['failover_peerip'];
154 466aae83 Phil Davis
155
		// dhcpleaseinlocaltime is global to all interfaces. So if it is selected on any interface,
156
		// then show it true/checked.
157
		foreach ($config['dhcpd'] as $dhcpdifitem) {
158
			$dhcpleaseinlocaltime = $dhcpdifitem['dhcpleaseinlocaltime'];
159 8f8682f7 Phil Davis
			if ($dhcpleaseinlocaltime) {
160 466aae83 Phil Davis
				break;
161 8f8682f7 Phil Davis
			}
162 466aae83 Phil Davis
		}
163
164
		$pconfig['dhcpleaseinlocaltime'] = $dhcpleaseinlocaltime;
165 ee1fb205 jim-p
	} else {
166
		// Options that exist only in pools
167
		$pconfig['descr'] = $dhcpdconf['descr'];
168 cba980f6 jim-p
	}
169
170
	// Options that can be global or per-pool.
171
	if (is_array($dhcpdconf['range'])) {
172
		$pconfig['range_from'] = $dhcpdconf['range']['from'];
173
		$pconfig['range_to'] = $dhcpdconf['range']['to'];
174
	}
175 b5f6e690 Stephen Beaver
176 cba980f6 jim-p
	$pconfig['deftime'] = $dhcpdconf['defaultleasetime'];
177
	$pconfig['maxtime'] = $dhcpdconf['maxleasetime'];
178
	$pconfig['gateway'] = $dhcpdconf['gateway'];
179
	$pconfig['domain'] = $dhcpdconf['domain'];
180
	$pconfig['domainsearchlist'] = $dhcpdconf['domainsearchlist'];
181 8f8682f7 Phil Davis
	list($pconfig['wins1'], $pconfig['wins2']) = $dhcpdconf['winsserver'];
182
	list($pconfig['dns1'], $pconfig['dns2'], $pconfig['dns3'], $pconfig['dns4']) = $dhcpdconf['dnsserver'];
183 cba980f6 jim-p
	$pconfig['denyunknown'] = isset($dhcpdconf['denyunknown']);
184
	$pconfig['ddnsdomain'] = $dhcpdconf['ddnsdomain'];
185 87019fc4 Andres Petralli
	$pconfig['ddnsdomainprimary'] = $dhcpdconf['ddnsdomainprimary'];
186
	$pconfig['ddnsdomainkeyname'] = $dhcpdconf['ddnsdomainkeyname'];
187
	$pconfig['ddnsdomainkey'] = $dhcpdconf['ddnsdomainkey'];
188 cba980f6 jim-p
	$pconfig['ddnsupdate'] = isset($dhcpdconf['ddnsupdate']);
189
	$pconfig['mac_allow'] = $dhcpdconf['mac_allow'];
190
	$pconfig['mac_deny'] = $dhcpdconf['mac_deny'];
191 8f8682f7 Phil Davis
	list($pconfig['ntp1'], $pconfig['ntp2']) = $dhcpdconf['ntpserver'];
192 cba980f6 jim-p
	$pconfig['tftp'] = $dhcpdconf['tftp'];
193
	$pconfig['ldap'] = $dhcpdconf['ldap'];
194
	$pconfig['netboot'] = isset($dhcpdconf['netboot']);
195
	$pconfig['nextserver'] = $dhcpdconf['nextserver'];
196
	$pconfig['filename'] = $dhcpdconf['filename'];
197 7023c602 Charlie Root
	$pconfig['filename32'] = $dhcpdconf['filename32'];
198
	$pconfig['filename64'] = $dhcpdconf['filename64'];
199 cba980f6 jim-p
	$pconfig['rootpath'] = $dhcpdconf['rootpath'];
200
	$pconfig['netmask'] = $dhcpdconf['netmask'];
201
	$pconfig['numberoptions'] = $dhcpdconf['numberoptions'];
202 18d316a5 heper
	$pconfig['statsgraph'] = $dhcpdconf['statsgraph'];
203 89019922 Ermal Luçi
}
204 31c59d0d Scott Ullrich
205 51cd7a1e Evgeny Yurchenko
$ifcfgip = $config['interfaces'][$if]['ipaddr'];
206
$ifcfgsn = $config['interfaces'][$if]['subnet'];
207 5b237745 Scott Ullrich
208 1f1a08c8 jim-p
function validate_partial_mac_list($maclist) {
209
	$macs = explode(',', $maclist);
210
211
	// Loop through and look for invalid MACs.
212 8f8682f7 Phil Davis
	foreach ($macs as $mac) {
213
		if (!is_macaddr($mac, true)) {
214 1f1a08c8 jim-p
			return false;
215 8f8682f7 Phil Davis
		}
216
	}
217 b5f6e690 Stephen Beaver
218 1f1a08c8 jim-p
	return true;
219
}
220
221 565488c9 Renato Botelho
if (isset($_POST['submit'])) {
222 5b237745 Scott Ullrich
223
	unset($input_errors);
224 b7597d4e Bill Marquette
225 5b237745 Scott Ullrich
	$pconfig = $_POST;
226
227 6d1af0e9 jim-p
	$numberoptions = array();
228 6c07db48 Phil Davis
	for ($x = 0; $x < 99; $x++) {
229 8f8682f7 Phil Davis
		if (isset($_POST["number{$x}"]) && ctype_digit($_POST["number{$x}"])) {
230 6d1af0e9 jim-p
			$numbervalue = array();
231
			$numbervalue['number'] = htmlspecialchars($_POST["number{$x}"]);
232 678dfd0f Erik Fonnesbeck
			$numbervalue['type'] = htmlspecialchars($_POST["itemtype{$x}"]);
233
			$numbervalue['value'] = str_replace('&quot;', '"', htmlspecialchars($_POST["value{$x}"]));
234 6d1af0e9 jim-p
			$numberoptions['item'][] = $numbervalue;
235
		}
236
	}
237 b5f6e690 Stephen Beaver
238 466aae83 Phil Davis
	// Reload the new pconfig variable that the form uses.
239 6d1af0e9 jim-p
	$pconfig['numberoptions'] = $numberoptions;
240
241 5b237745 Scott Ullrich
	/* input validation */
242 cba980f6 jim-p
	if ($_POST['enable'] || is_numeric($pool) || $act == "newpool") {
243 5b237745 Scott Ullrich
		$reqdfields = explode(" ", "range_from range_to");
244 8f8682f7 Phil Davis
		$reqdfieldsn = array(gettext("Range begin"), gettext("Range end"));
245 e9f147c8 Scott Ullrich
246 507628d5 Renato Botelho
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
247 de792e62 jim-p
248 8f8682f7 Phil Davis
		if (($_POST['range_from'] && !is_ipaddrv4($_POST['range_from']))) {
249 40ad67e0 Rafael Lucas
			$input_errors[] = gettext("A valid range must be specified.");
250 8f8682f7 Phil Davis
		}
251
		if (($_POST['range_to'] && !is_ipaddrv4($_POST['range_to']))) {
252 40ad67e0 Rafael Lucas
			$input_errors[] = gettext("A valid range must be specified.");
253 8f8682f7 Phil Davis
		}
254
		if (($_POST['gateway'] && $_POST['gateway'] != "none" && !is_ipaddrv4($_POST['gateway']))) {
255 40ad67e0 Rafael Lucas
			$input_errors[] = gettext("A valid IP address must be specified for the gateway.");
256 8f8682f7 Phil Davis
		}
257
		if (($_POST['wins1'] && !is_ipaddrv4($_POST['wins1'])) || ($_POST['wins2'] && !is_ipaddrv4($_POST['wins2']))) {
258 40ad67e0 Rafael Lucas
			$input_errors[] = gettext("A valid IP address must be specified for the primary/secondary WINS servers.");
259 8f8682f7 Phil Davis
		}
260 9bc59815 Evgeny Yurchenko
		$parent_ip = get_interface_ip($_POST['if']);
261 1bd021e3 timdufrane
		if (is_ipaddrv4($parent_ip) && $_POST['gateway'] && $_POST['gateway'] != "none") {
262 9bc59815 Evgeny Yurchenko
			$parent_sn = get_interface_subnet($_POST['if']);
263 8f8682f7 Phil Davis
			if (!ip_in_subnet($_POST['gateway'], gen_subnet($parent_ip, $parent_sn) . "/" . $parent_sn) && !ip_in_interface_alias_subnet($_POST['if'], $_POST['gateway'])) {
264 9bc59815 Evgeny Yurchenko
				$input_errors[] = sprintf(gettext("The gateway address %s does not lie within the chosen interface's subnet."), $_POST['gateway']);
265 8f8682f7 Phil Davis
			}
266 45d1024d Scott Ullrich
		}
267 b5f6e690 Stephen Beaver
268 8f8682f7 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']))) {
269 3b5707db Phil Davis
			$input_errors[] = gettext("A valid IP address must be specified for each of the DNS servers.");
270 8f8682f7 Phil Davis
		}
271 26e3ca70 sullrich
272 8f8682f7 Phil Davis
		if ($_POST['deftime'] && (!is_numeric($_POST['deftime']) || ($_POST['deftime'] < 60))) {
273
			$input_errors[] = gettext("The default lease time must be at least 60 seconds.");
274
		}
275 e680b2f9 Renato Botelho
276
		if (isset($config['captiveportal']) && is_array($config['captiveportal'])) {
277
			$deftime = 7200; // Default value if it's empty
278 8f8682f7 Phil Davis
			if (is_numeric($_POST['deftime'])) {
279 e680b2f9 Renato Botelho
				$deftime = $_POST['deftime'];
280 8f8682f7 Phil Davis
			}
281 e680b2f9 Renato Botelho
282
			foreach ($config['captiveportal'] as $cpZone => $cpdata) {
283 8f8682f7 Phil Davis
				if (!isset($cpdata['enable'])) {
284 e680b2f9 Renato Botelho
					continue;
285 8f8682f7 Phil Davis
				}
286
				if (!isset($cpdata['timeout']) || !is_numeric($cpdata['timeout'])) {
287 e680b2f9 Renato Botelho
					continue;
288 8f8682f7 Phil Davis
				}
289 e680b2f9 Renato Botelho
				$cp_ifs = explode(',', $cpdata['interface']);
290 8f8682f7 Phil Davis
				if (!in_array($if, $cp_ifs)) {
291 e680b2f9 Renato Botelho
					continue;
292 8f8682f7 Phil Davis
				}
293
				if ($cpdata['timeout'] > $deftime) {
294 e680b2f9 Renato Botelho
					$input_errors[] = sprintf(gettext(
295
						"The Captive Portal zone '%s' has Hard Timeout parameter set to a value bigger than Default lease time (%s)."), $cpZone, $deftime);
296 8f8682f7 Phil Davis
				}
297 e680b2f9 Renato Botelho
			}
298
		}
299
300 8f8682f7 Phil Davis
		if ($_POST['maxtime'] && (!is_numeric($_POST['maxtime']) || ($_POST['maxtime'] < 60) || ($_POST['maxtime'] <= $_POST['deftime']))) {
301 40ad67e0 Rafael Lucas
			$input_errors[] = gettext("The maximum lease time must be at least 60 seconds and higher than the default lease time.");
302 8f8682f7 Phil Davis
		}
303
		if (($_POST['ddnsdomain'] && !is_domain($_POST['ddnsdomain']))) {
304 40ad67e0 Rafael Lucas
			$input_errors[] = gettext("A valid domain name must be specified for the dynamic DNS registration.");
305 8f8682f7 Phil Davis
		}
306
		if (($_POST['ddnsdomain'] && !is_ipaddrv4($_POST['ddnsdomainprimary']))) {
307 87019fc4 Andres Petralli
			$input_errors[] = gettext("A valid primary domain name server IP address must be specified for the dynamic domain name.");
308 8f8682f7 Phil Davis
		}
309 87019fc4 Andres Petralli
		if (($_POST['ddnsdomainkey'] && !$_POST['ddnsdomainkeyname']) ||
310 6e3488e9 Phil Davis
		    ($_POST['ddnsdomainkeyname'] && !$_POST['ddnsdomainkey'])) {
311 87019fc4 Andres Petralli
			$input_errors[] = gettext("You must specify both a valid domain key and key name.");
312 8f8682f7 Phil Davis
		}
313 42a3cbab Pierre POMES
		if ($_POST['domainsearchlist']) {
314 8f8682f7 Phil Davis
			$domain_array = preg_split("/[ ;]+/", $_POST['domainsearchlist']);
315 42a3cbab Pierre POMES
			foreach ($domain_array as $curdomain) {
316
				if (!is_domain($curdomain)) {
317
					$input_errors[] = gettext("A valid domain search list must be specified.");
318
					break;
319
				}
320
			}
321
		}
322 1f1a08c8 jim-p
323
		// Validate MACs
324 8f8682f7 Phil Davis
		if (!empty($_POST['mac_allow']) && !validate_partial_mac_list($_POST['mac_allow'])) {
325 1f1a08c8 jim-p
			$input_errors[] = gettext("If you specify a mac allow list, it must contain only valid partial MAC addresses.");
326 8f8682f7 Phil Davis
		}
327
		if (!empty($_POST['mac_deny']) && !validate_partial_mac_list($_POST['mac_deny'])) {
328 1f1a08c8 jim-p
			$input_errors[] = gettext("If you specify a mac deny list, it must contain only valid partial MAC addresses.");
329 8f8682f7 Phil Davis
		}
330 1f1a08c8 jim-p
331 8f8682f7 Phil Davis
		if (($_POST['ntp1'] && !is_ipaddrv4($_POST['ntp1'])) || ($_POST['ntp2'] && !is_ipaddrv4($_POST['ntp2']))) {
332 40ad67e0 Rafael Lucas
			$input_errors[] = gettext("A valid IP address must be specified for the primary/secondary NTP servers.");
333 8f8682f7 Phil Davis
		}
334
		if (($_POST['domain'] && !is_domain($_POST['domain']))) {
335 40ad67e0 Rafael Lucas
			$input_errors[] = gettext("A valid domain name must be specified for the DNS domain.");
336 8f8682f7 Phil Davis
		}
337
		if ($_POST['tftp'] && !is_ipaddrv4($_POST['tftp']) && !is_domain($_POST['tftp']) && !is_URL($_POST['tftp'])) {
338 40ad67e0 Rafael Lucas
			$input_errors[] = gettext("A valid IP address or hostname must be specified for the TFTP server.");
339 8f8682f7 Phil Davis
		}
340
		if (($_POST['nextserver'] && !is_ipaddrv4($_POST['nextserver']))) {
341 40ad67e0 Rafael Lucas
			$input_errors[] = gettext("A valid IP address must be specified for the network boot server.");
342 8f8682f7 Phil Davis
		}
343 2c75b451 sullrich
344 8f8682f7 Phil Davis
		if (gen_subnet($ifcfgip, $ifcfgsn) == $_POST['range_from']) {
345 40ad67e0 Rafael Lucas
			$input_errors[] = gettext("You cannot use the network address in the starting subnet range.");
346 8f8682f7 Phil Davis
		}
347
		if (gen_subnet_max($ifcfgip, $ifcfgsn) == $_POST['range_to']) {
348 40ad67e0 Rafael Lucas
			$input_errors[] = gettext("You cannot use the broadcast address in the ending subnet range.");
349 8f8682f7 Phil Davis
		}
350 e9f147c8 Scott Ullrich
351 2c75b451 sullrich
		// Disallow a range that includes the virtualip
352 7dfa60fa Ermal Lu?i
		if (is_array($config['virtualip']['vip'])) {
353 8f8682f7 Phil Davis
			foreach ($config['virtualip']['vip'] as $vip) {
354
				if ($vip['interface'] == $if) {
355
					if ($vip['subnet'] && is_inrange_v4($vip['subnet'], $_POST['range_from'], $_POST['range_to'])) {
356
						$input_errors[] = sprintf(gettext("The subnet range cannot overlap with virtual IP address %s."), $vip['subnet']);
357
					}
358
				}
359 7dfa60fa Ermal Lu?i
			}
360 2c75b451 sullrich
		}
361
362 073a2697 jim-p
		$noip = false;
363 8f8682f7 Phil Davis
		if (is_array($a_maps)) {
364
			foreach ($a_maps as $map) {
365
				if (empty($map['ipaddr'])) {
366 2c7497cb Scott Ullrich
					$noip = true;
367 8f8682f7 Phil Davis
				}
368
			}
369
		}
370 b5f6e690 Stephen Beaver
371 8f8682f7 Phil Davis
		if ($_POST['staticarp'] && $noip) {
372 073a2697 jim-p
			$input_errors[] = "Cannot enable static ARP when you have static map entries without IP addresses. Ensure all static maps have IP addresses and try again.";
373 8f8682f7 Phil Davis
		}
374 073a2697 jim-p
375 8f8682f7 Phil Davis
		if (is_array($pconfig['numberoptions']['item'])) {
376 678dfd0f Erik Fonnesbeck
			foreach ($pconfig['numberoptions']['item'] as $numberoption) {
377 8f8682f7 Phil Davis
				if ($numberoption['type'] == 'text' && strstr($numberoption['value'], '"')) {
378 678dfd0f Erik Fonnesbeck
					$input_errors[] = gettext("Text type cannot include quotation marks.");
379 8f8682f7 Phil Davis
				} else if ($numberoption['type'] == 'string' && !preg_match('/^"[^"]*"$/', $numberoption['value']) && !preg_match('/^[0-9a-f]{2}(?:\:[0-9a-f]{2})*$/i', $numberoption['value'])) {
380 678dfd0f Erik Fonnesbeck
					$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");
381 8f8682f7 Phil Davis
				} else if ($numberoption['type'] == 'boolean' && $numberoption['value'] != 'true' && $numberoption['value'] != 'false' && $numberoption['value'] != 'on' && $numberoption['value'] != 'off') {
382 678dfd0f Erik Fonnesbeck
					$input_errors[] = gettext("Boolean type must be true, false, on, or off.");
383 8f8682f7 Phil Davis
				} else if ($numberoption['type'] == 'unsigned integer 8' && (!is_numeric($numberoption['value']) || $numberoption['value'] < 0 || $numberoption['value'] > 255)) {
384 678dfd0f Erik Fonnesbeck
					$input_errors[] = gettext("Unsigned 8-bit integer type must be a number in the range 0 to 255.");
385 8f8682f7 Phil Davis
				} else if ($numberoption['type'] == 'unsigned integer 16' && (!is_numeric($numberoption['value']) || $numberoption['value'] < 0 || $numberoption['value'] > 65535)) {
386 678dfd0f Erik Fonnesbeck
					$input_errors[] = gettext("Unsigned 16-bit integer type must be a number in the range 0 to 65535.");
387 8f8682f7 Phil Davis
				} else if ($numberoption['type'] == 'unsigned integer 32' && (!is_numeric($numberoption['value']) || $numberoption['value'] < 0 || $numberoption['value'] > 4294967295)) {
388 678dfd0f Erik Fonnesbeck
					$input_errors[] = gettext("Unsigned 32-bit integer type must be a number in the range 0 to 4294967295.");
389 8f8682f7 Phil Davis
				} else if ($numberoption['type'] == 'signed integer 8' && (!is_numeric($numberoption['value']) || $numberoption['value'] < -128 || $numberoption['value'] > 127)) {
390 678dfd0f Erik Fonnesbeck
					$input_errors[] = gettext("Signed 8-bit integer type must be a number in the range -128 to 127.");
391 8f8682f7 Phil Davis
				} else if ($numberoption['type'] == 'signed integer 16' && (!is_numeric($numberoption['value']) || $numberoption['value'] < -32768 || $numberoption['value'] > 32767)) {
392 678dfd0f Erik Fonnesbeck
					$input_errors[] = gettext("Signed 16-bit integer type must be a number in the range -32768 to 32767.");
393 8f8682f7 Phil Davis
				} else if ($numberoption['type'] == 'signed integer 32' && (!is_numeric($numberoption['value']) || $numberoption['value'] < -2147483648 || $numberoption['value'] > 2147483647)) {
394 678dfd0f Erik Fonnesbeck
					$input_errors[] = gettext("Signed 32-bit integer type must be a number in the range -2147483648 to 2147483647.");
395 8f8682f7 Phil Davis
				} else if ($numberoption['type'] == 'ip-address' && !is_ipaddrv4($numberoption['value']) && !is_hostname($numberoption['value'])) {
396 678dfd0f Erik Fonnesbeck
					$input_errors[] = gettext("IP address or host type must be an IP address or host name.");
397 8f8682f7 Phil Davis
				}
398 678dfd0f Erik Fonnesbeck
			}
399
		}
400
401 5b237745 Scott Ullrich
		if (!$input_errors) {
402
			/* make sure the range lies within the current subnet */
403 96033063 Erik Fonnesbeck
			$subnet_start = ip2ulong(long2ip32(ip2long($ifcfgip) & gen_subnet_mask_long($ifcfgsn)));
404
			$subnet_end = ip2ulong(long2ip32(ip2long($ifcfgip) | (~gen_subnet_mask_long($ifcfgsn))));
405 e9f147c8 Scott Ullrich
406 8f8682f7 Phil Davis
			if (ip2ulong($_POST['range_from']) > ip2ulong($_POST['range_to'])) {
407 40ad67e0 Rafael Lucas
				$input_errors[] = gettext("The range is invalid (first element higher than second element).");
408 8f8682f7 Phil Davis
			}
409 e9f147c8 Scott Ullrich
410 ec513fa9 stilez
			if (ip2ulong($_POST['range_from']) < $subnet_start || ip2ulong($_POST['range_to']) > $subnet_end) {
411
				$input_errors[] = gettext("The specified range lies outside of the current subnet.");
412
			}
413
414 f657f5e1 Renato Botelho
			if (is_numeric($pool) || ($act == "newpool")) {
415 e7940d2e Phil Davis
				if (!((ip2ulong($_POST['range_from']) > ip2ulong($config['dhcpd'][$if]['range']['to'])) ||
416
				      (ip2ulong($_POST['range_to']) < ip2ulong($config['dhcpd'][$if]['range']['from'])))) {
417 f657f5e1 Renato Botelho
					$input_errors[] = gettext("The specified range must not be within the DHCP range for this interface.");
418 8f8682f7 Phil Davis
				}
419 f657f5e1 Renato Botelho
			}
420
421
			foreach ($a_pools as $id => $p) {
422 8f8682f7 Phil Davis
				if (is_numeric($pool) && ($id == $pool)) {
423 f657f5e1 Renato Botelho
					continue;
424 8f8682f7 Phil Davis
				}
425 f657f5e1 Renato Botelho
426 e7940d2e Phil Davis
				if (!((ip2ulong($_POST['range_from']) > ip2ulong($p['range']['to'])) ||
427
				      (ip2ulong($_POST['range_to']) < ip2ulong($p['range']['from'])))) {
428 f657f5e1 Renato Botelho
					$input_errors[] = gettext("The specified range must not be within the range configured on a DHCP pool for this interface.");
429
					break;
430
				}
431
			}
432 cba980f6 jim-p
433 5b237745 Scott Ullrich
			/* make sure that the DHCP Relay isn't enabled on this interface */
434 8f8682f7 Phil Davis
			if (isset($config['dhcrelay']['enable']) && (stristr($config['dhcrelay']['interface'], $if) !== false)) {
435
				$input_errors[] = sprintf(gettext("You must disable the DHCP relay on the %s interface before enabling the DHCP server."), $iflist[$if]);
436
			}
437 630d7025 jim-p
438
			$dynsubnet_start = ip2ulong($_POST['range_from']);
439
			$dynsubnet_end = ip2ulong($_POST['range_to']);
440 f02f0675 Erik Fonnesbeck
			if (is_array($a_maps)) {
441
				foreach ($a_maps as $map) {
442 8f8682f7 Phil Davis
					if (empty($map['ipaddr'])) {
443 f02f0675 Erik Fonnesbeck
						continue;
444 8f8682f7 Phil Davis
					}
445 e7940d2e Phil Davis
					if ((ip2ulong($map['ipaddr']) >= $dynsubnet_start) &&
446
					    (ip2ulong($map['ipaddr']) <= $dynsubnet_end)) {
447 f02f0675 Erik Fonnesbeck
						$input_errors[] = sprintf(gettext("The DHCP range cannot overlap any static DHCP mappings."));
448
						break;
449
					}
450 630d7025 jim-p
				}
451
			}
452 5b237745 Scott Ullrich
		}
453
	}
454
455
	if (!$input_errors) {
456 cba980f6 jim-p
		if (!is_numeric($pool)) {
457
			if ($act == "newpool") {
458
				$dhcpdconf = array();
459
			} else {
460 8f8682f7 Phil Davis
				if (!is_array($config['dhcpd'][$if])) {
461 cba980f6 jim-p
					$config['dhcpd'][$if] = array();
462 8f8682f7 Phil Davis
				}
463 cba980f6 jim-p
				$dhcpdconf = $config['dhcpd'][$if];
464
			}
465
		} else {
466
			if (is_array($a_pools[$pool])) {
467
				$dhcpdconf = $a_pools[$pool];
468
			} else {
469
				// Someone specified a pool but it doesn't exist. Punt.
470
				header("Location: services_dhcp.php");
471
				exit;
472
			}
473
		}
474 8f8682f7 Phil Davis
		if (!is_array($dhcpdconf['range'])) {
475 cba980f6 jim-p
			$dhcpdconf['range'] = array();
476 8f8682f7 Phil Davis
		}
477 cba980f6 jim-p
478 6c124212 Phil Davis
		$dhcpd_enable_changed = false;
479
480 cba980f6 jim-p
		// Global Options
481
		if (!is_numeric($pool) && !($act == "newpool")) {
482 6c124212 Phil Davis
			$old_dhcpd_enable = isset($dhcpdconf['enable']);
483
			$new_dhcpd_enable = ($_POST['enable']) ? true : false;
484
			if ($old_dhcpd_enable != $new_dhcpd_enable) {
485
				/* DHCP has been enabled or disabled. The pf ruleset will need to be rebuilt to allow or disallow DHCP. */
486
				$dhcpd_enable_changed = true;
487
			}
488 b5f6e690 Stephen Beaver
489 6c124212 Phil Davis
			$dhcpdconf['enable'] = $new_dhcpd_enable;
490 cba980f6 jim-p
			$dhcpdconf['staticarp'] = ($_POST['staticarp']) ? true : false;
491
			$previous = $dhcpdconf['failover_peerip'];
492 b5f6e690 Stephen Beaver
			if ($previous != $_POST['failover_peerip']) {
493 cba980f6 jim-p
				mwexec("/bin/rm -rf /var/dhcpd/var/db/*");
494 8f8682f7 Phil Davis
			}
495 b5f6e690 Stephen Beaver
496 cba980f6 jim-p
			$dhcpdconf['failover_peerip'] = $_POST['failover_peerip'];
497 466aae83 Phil Davis
			// dhcpleaseinlocaltime is global to all interfaces. So update the setting on all interfaces.
498
			foreach ($config['dhcpd'] as &$dhcpdifitem) {
499
				$dhcpdifitem['dhcpleaseinlocaltime'] = $_POST['dhcpleaseinlocaltime'];
500
			}
501 ee1fb205 jim-p
		} else {
502
			// Options that exist only in pools
503
			$dhcpdconf['descr'] = $_POST['descr'];
504 cba980f6 jim-p
		}
505
506
		// Options that can be global or per-pool.
507
		$dhcpdconf['range']['from'] = $_POST['range_from'];
508
		$dhcpdconf['range']['to'] = $_POST['range_to'];
509
		$dhcpdconf['defaultleasetime'] = $_POST['deftime'];
510
		$dhcpdconf['maxleasetime'] = $_POST['maxtime'];
511
		$dhcpdconf['netmask'] = $_POST['netmask'];
512
513
		unset($dhcpdconf['winsserver']);
514 8f8682f7 Phil Davis
		if ($_POST['wins1']) {
515 cba980f6 jim-p
			$dhcpdconf['winsserver'][] = $_POST['wins1'];
516 8f8682f7 Phil Davis
		}
517
		if ($_POST['wins2']) {
518 cba980f6 jim-p
			$dhcpdconf['winsserver'][] = $_POST['wins2'];
519 8f8682f7 Phil Davis
		}
520 4cab31d0 Scott Ullrich
521 cba980f6 jim-p
		unset($dhcpdconf['dnsserver']);
522 8f8682f7 Phil Davis
		if ($_POST['dns1']) {
523 cba980f6 jim-p
			$dhcpdconf['dnsserver'][] = $_POST['dns1'];
524 8f8682f7 Phil Davis
		}
525
		if ($_POST['dns2']) {
526 cba980f6 jim-p
			$dhcpdconf['dnsserver'][] = $_POST['dns2'];
527 8f8682f7 Phil Davis
		}
528
		if ($_POST['dns3']) {
529 3b5707db Phil Davis
			$dhcpdconf['dnsserver'][] = $_POST['dns3'];
530 8f8682f7 Phil Davis
		}
531
		if ($_POST['dns4']) {
532 3b5707db Phil Davis
			$dhcpdconf['dnsserver'][] = $_POST['dns4'];
533 8f8682f7 Phil Davis
		}
534 cba980f6 jim-p
535
		$dhcpdconf['gateway'] = $_POST['gateway'];
536
		$dhcpdconf['domain'] = $_POST['domain'];
537
		$dhcpdconf['domainsearchlist'] = $_POST['domainsearchlist'];
538
		$dhcpdconf['denyunknown'] = ($_POST['denyunknown']) ? true : false;
539
		$dhcpdconf['ddnsdomain'] = $_POST['ddnsdomain'];
540 87019fc4 Andres Petralli
		$dhcpdconf['ddnsdomainprimary'] = $_POST['ddnsdomainprimary'];
541
		$dhcpdconf['ddnsdomainkeyname'] = $_POST['ddnsdomainkeyname'];
542
		$dhcpdconf['ddnsdomainkey'] = $_POST['ddnsdomainkey'];
543 cba980f6 jim-p
		$dhcpdconf['ddnsupdate'] = ($_POST['ddnsupdate']) ? true : false;
544
		$dhcpdconf['mac_allow'] = $_POST['mac_allow'];
545
		$dhcpdconf['mac_deny'] = $_POST['mac_deny'];
546
547
		unset($dhcpdconf['ntpserver']);
548 8f8682f7 Phil Davis
		if ($_POST['ntp1']) {
549 cba980f6 jim-p
			$dhcpdconf['ntpserver'][] = $_POST['ntp1'];
550 8f8682f7 Phil Davis
		}
551
		if ($_POST['ntp2']) {
552 cba980f6 jim-p
			$dhcpdconf['ntpserver'][] = $_POST['ntp2'];
553 8f8682f7 Phil Davis
		}
554 ad171999 Seth Mos
555 cba980f6 jim-p
		$dhcpdconf['tftp'] = $_POST['tftp'];
556
		$dhcpdconf['ldap'] = $_POST['ldap'];
557
		$dhcpdconf['netboot'] = ($_POST['netboot']) ? true : false;
558
		$dhcpdconf['nextserver'] = $_POST['nextserver'];
559
		$dhcpdconf['filename'] = $_POST['filename'];
560 7023c602 Charlie Root
		$dhcpdconf['filename32'] = $_POST['filename32'];
561
		$dhcpdconf['filename64'] = $_POST['filename64'];
562 cba980f6 jim-p
		$dhcpdconf['rootpath'] = $_POST['rootpath'];
563 18d316a5 heper
		unset($dhcpdconf['statsgraph']);
564
		if ($_POST['statsgraph']) {
565
			$dhcpdconf['statsgraph'] = $_POST['statsgraph'];
566 6303601e heper
			enable_rrd_graphing();
567 18d316a5 heper
		}
568 9c748b70 Scott Ullrich
569 d72b4114 Scott Ullrich
		// Handle the custom options rowhelper
570 8f8682f7 Phil Davis
		if (isset($dhcpdconf['numberoptions']['item'])) {
571 cba980f6 jim-p
			unset($dhcpdconf['numberoptions']['item']);
572 8f8682f7 Phil Davis
		}
573 6d1af0e9 jim-p
574 cba980f6 jim-p
		$dhcpdconf['numberoptions'] = $numberoptions;
575
576
		if (is_numeric($pool) && is_array($a_pools[$pool])) {
577
			$a_pools[$pool] = $dhcpdconf;
578
		} elseif ($act == "newpool") {
579
			$a_pools[] = $dhcpdconf;
580
		} else {
581
			$config['dhcpd'][$if] = $dhcpdconf;
582
		}
583 518030b3 Scott Ullrich
584 5b237745 Scott Ullrich
		write_config();
585 565488c9 Renato Botelho
	}
586
}
587 80933129 Bill Marquette
588 48ac0aa0 Phil Davis
if ((isset($_POST['submit']) || isset($_POST['apply'])) && (!$input_errors)) {
589 565488c9 Renato Botelho
	$retval = 0;
590
	$retvaldhcp = 0;
591
	$retvaldns = 0;
592
	/* dnsmasq_configure calls dhcpd_configure */
593
	/* no need to restart dhcpd twice */
594
	if (isset($config['dnsmasq']['enable']) && isset($config['dnsmasq']['regdhcpstatic']))	{
595
		$retvaldns = services_dnsmasq_configure();
596
		if ($retvaldns == 0) {
597
			clear_subsystem_dirty('hosts');
598
			clear_subsystem_dirty('staticmaps');
599 de792e62 jim-p
		}
600 565488c9 Renato Botelho
	} else if (isset($config['unbound']['enable']) && isset($config['unbound']['regdhcpstatic'])) {
601
		$retvaldns = services_unbound_configure();
602 4230ad16 Phil Davis
		if ($retvaldns == 0) {
603 565488c9 Renato Botelho
			clear_subsystem_dirty('unbound');
604 d3801fdb Renato Botelho
			clear_subsystem_dirty('hosts');
605
			clear_subsystem_dirty('staticmaps');
606 4230ad16 Phil Davis
		}
607 565488c9 Renato Botelho
	} else {
608
		$retvaldhcp = services_dhcpd_configure();
609 8f8682f7 Phil Davis
		if ($retvaldhcp == 0) {
610 565488c9 Renato Botelho
			clear_subsystem_dirty('staticmaps');
611 8f8682f7 Phil Davis
		}
612 5b237745 Scott Ullrich
	}
613 8f8682f7 Phil Davis
	if ($dhcpd_enable_changed) {
614 565488c9 Renato Botelho
		$retvalfc = filter_configure();
615 8f8682f7 Phil Davis
	}
616 565488c9 Renato Botelho
617 8f8682f7 Phil Davis
	if ($retvaldhcp == 1 || $retvaldns == 1 || $retvalfc == 1) {
618 565488c9 Renato Botelho
		$retval = 1;
619 8f8682f7 Phil Davis
	}
620 b5f6e690 Stephen Beaver
621 565488c9 Renato Botelho
	$savemsg = get_std_save_message($retval);
622 5b237745 Scott Ullrich
}
623
624 cba980f6 jim-p
if ($act == "delpool") {
625
	if ($a_pools[$_GET['id']]) {
626
		unset($a_pools[$_GET['id']]);
627
		write_config();
628
		header("Location: services_dhcp.php?if={$if}");
629
		exit;
630
	}
631
}
632
633
if ($act == "del") {
634 5b237745 Scott Ullrich
	if ($a_maps[$_GET['id']]) {
635
		unset($a_maps[$_GET['id']]);
636
		write_config();
637 8f8682f7 Phil Davis
		if (isset($config['dhcpd'][$if]['enable'])) {
638 a368a026 Ermal Lu?i
			mark_subsystem_dirty('staticmaps');
639 8f8682f7 Phil Davis
			if (isset($config['dnsmasq']['enable']) && isset($config['dnsmasq']['regdhcpstatic'])) {
640 a368a026 Ermal Lu?i
				mark_subsystem_dirty('hosts');
641 8f8682f7 Phil Davis
			}
642 6a01ea44 Bill Marquette
		}
643 b5f6e690 Stephen Beaver
644 5b237745 Scott Ullrich
		header("Location: services_dhcp.php?if={$if}");
645
		exit;
646
	}
647
}
648 4df96eff Scott Ullrich
649 3c9befb9 Chris Buechler
// Build an HTML table that can be inserted into a Form_StaticText element
650 b5f6e690 Stephen Beaver
function build_pooltable() {
651
	global $a_pools;
652
653
	$pooltbl =	'<div class="table-responsive">';
654
	$pooltbl .=		'<table class="table table-striped table-hover table-condensed">';
655
	$pooltbl .=			'<thead>';
656
	$pooltbl .=				'<tr>';
657
	$pooltbl .=					'<th>' . gettext("Pool Start") . '</th>';
658
	$pooltbl .=					'<th>' . gettext("Pool End") . '</th>';
659
	$pooltbl .=					'<th>' . gettext("Description") . '</th>';
660
	$pooltbl .=					'<th></th>';
661
	$pooltbl .=				'</tr>';
662
	$pooltbl .=			'</thead>';
663
	$pooltbl .=			'<tbody>';
664
665
	if (is_array($a_pools)) {
666
		$i = 0;
667
		foreach ($a_pools as $poolent) {
668
			if (!empty($poolent['range']['from']) && !empty($poolent['range']['to'])) {
669
				$pooltbl .= '<tr>';
670
				$pooltbl .= '<td ondblclick="document.location=\'services_dhcp.php?if=' . htmlspecialchars($if) . '&pool=' . $i . '\';">' .
671
							htmlspecialchars($poolent['range']['from']) . '</td>';
672
673
				$pooltbl .= '<td ondblclick="document.location=\'services_dhcp.php?if=' . htmlspecialchars($if) . '&pool=' . $i . '\';">' .
674
							htmlspecialchars($poolent['range']['to']) . '</td>';
675
676
				$pooltbl .= '<td ondblclick="document.location=\'services_dhcp.php?if=' . htmlspecialchars($if) . '&pool=' . $i . '\';">' .
677
							htmlspecialchars($poolent['descr']) . '</td>';
678
679
				$pooltbl .= '<td><a class="btn btn-xs btn-info" href="services_dhcp.php?if=' . htmlspecialchars($if) . '&pool=' . $i . '" />' . gettext('Edit') . '</a>';
680
681
				$pooltbl .= '<a class="btn btn-xs btn-danger" href="services_dhcp.php?if=' . htmlspecialchars($if) . '&act=delpool&id=' . $i . '" />' . gettext('Delete') . '</a></td>';
682
				$pooltbl .= '</tr>';
683
			}
684
		$i++;
685
		}
686
	}
687
688
	$pooltbl .=			'</tbody>';
689
	$pooltbl .=		'</table>';
690
	$pooltbl .= '</div>';
691
692
	return($pooltbl);
693
}
694
695 bf27317d Phil Davis
$pgtitle = array(gettext("Services"), gettext("DHCP Server"));
696 b32dd0a6 jim-p
$shortcut_section = "dhcp";
697 5224b8e7 jim-p
698 4df96eff Scott Ullrich
include("head.inc");
699
700 6e3488e9 Phil Davis
if ($input_errors) {
701 b5f6e690 Stephen Beaver
	print_input_errors($input_errors);
702 6e3488e9 Phil Davis
}
703 4df96eff Scott Ullrich
704 6e3488e9 Phil Davis
if ($savemsg) {
705 b5f6e690 Stephen Beaver
	print_info_box($savemsg, 'success');
706 6e3488e9 Phil Davis
}
707 678dfd0f Erik Fonnesbeck
708 b5f6e690 Stephen Beaver
if (isset($config['dhcrelay']['enable'])) {
709
	print_info_box(gettext("DHCP Relay is currently enabled. Cannot enable the DHCP Server service while the DHCP Relay is enabled on any interface."));
710
	include("foot.inc");
711
	exit;
712
}
713 4e9cd828 Seth Mos
714 6e3488e9 Phil Davis
if (is_subsystem_dirty('staticmaps')) {
715 b5f6e690 Stephen Beaver
	print_info_box_np(gettext("The static mapping configuration has been changed") . ".<br />" . gettext("You must apply the changes in order for them to take effect."));
716 6e3488e9 Phil Davis
}
717 b5f6e690 Stephen Beaver
718
/* active tabs */
719
$tab_array = array();
720
$tabscounter = 0;
721
$i = 0;
722 8a73f407 Stephen Beaver
723 b5f6e690 Stephen Beaver
foreach ($iflist as $ifent => $ifname) {
724
	$oc = $config['interfaces'][$ifent];
725
	if ((is_array($config['dhcpd'][$ifent]) && !isset($config['dhcpd'][$ifent]['enable']) && (!is_ipaddrv4($oc['ipaddr']))) ||
726 6e3488e9 Phil Davis
	    (!is_array($config['dhcpd'][$ifent]) && (!is_ipaddrv4($oc['ipaddr'])))) {
727 b5f6e690 Stephen Beaver
		continue;
728 518030b3 Scott Ullrich
	}
729 4e9cd828 Seth Mos
730 b5f6e690 Stephen Beaver
	if ($ifent == $if) {
731
		$active = true;
732
	} else {
733
		$active = false;
734 b1d132f5 Scott Ullrich
	}
735
736 b5f6e690 Stephen Beaver
	$tab_array[] = array($ifname, $active, "services_dhcp.php?if={$ifent}");
737
	$tabscounter++;
738
}
739 ad171999 Seth Mos
740 b5f6e690 Stephen Beaver
if ($tabscounter == 0) {
741
	print_info_box(gettext("The DHCP Server can only be enabled on interfaces configured with a static IPv4 address. This system has none."));
742
	include("foot.inc");
743
	exit;
744
}
745 1f1a08c8 jim-p
746 b5f6e690 Stephen Beaver
display_top_tabs($tab_array);
747
748 5da2095b Stephen Beaver
// This form uses a non-standard submit button name
749 b5f6e690 Stephen Beaver
$form = new Form(new Form_Button(
750
	'submit',
751
	gettext("Save")
752
));
753
754
$section = new Form_Section('General Options');
755
756
if (!is_numeric($pool) && !($act == "newpool")) {
757
	$section->addInput(new Form_Checkbox(
758
		'enable',
759
		'Enable',
760
		sprintf(gettext("Enable DHCP server on %s interface"), htmlspecialchars($iflist[$if])),
761
		$pconfig['enable']
762
	));
763
} else {
764
	$section->addInput(new Form_StaticText(
765
		null,
766 8a73f407 Stephen Beaver
		'<div class="alert alert-info"> Editing Pool-Specific Options. To return to the Interface, click its tab above. </div>'
767 b5f6e690 Stephen Beaver
	));
768
}
769 6c23757b Martin Fuchs
770 b5f6e690 Stephen Beaver
$section->addInput(new Form_Checkbox(
771
	'denyunknown',
772
	'Deny unknown clients',
773
	'Only the clients defined below will get DHCP leases from this server.',
774
	$pconfig['denyunknown']
775
));
776
777
if (is_numeric($pool) || ($act == "newpool")) {
778
	$section->addInput(new Form_Input(
779
		'descr',
780
		'Pool Description',
781
		'text',
782
		$pconfig['descr']
783
	));
784
}
785 6c23757b Martin Fuchs
786 b5f6e690 Stephen Beaver
$section->addInput(new Form_StaticText(
787
	'Subnet',
788
	gen_subnet($ifcfgip, $ifcfgsn)
789
));
790 4e9cd828 Seth Mos
791 b5f6e690 Stephen Beaver
$section->addInput(new Form_StaticText(
792
	'Subnet mask',
793
	gen_subnet_mask($ifcfgsn)
794
));
795 5b237745 Scott Ullrich
796 8a73f407 Stephen Beaver
// Compose a string to display the required address ranges
797 c18ba6bf Phil Davis
$range_from = ip2long(gen_subnetv4($ifcfgip, $ifcfgsn));
798 b5f6e690 Stephen Beaver
$range_from++;
799
800 c18ba6bf Phil Davis
$range_to = ip2long(gen_subnetv4_max($ifcfgip, $ifcfgsn));
801 b5f6e690 Stephen Beaver
$range_to--;
802
803
$rangestr = long2ip32($range_from) . ' - ' . long2ip32($range_to);
804
805
if (is_numeric($pool) || ($act == "newpool")) {
806
	$rangestr .= '<br />' . 'In-use DHCP Pool Ranges:';
807
	if (is_array($config['dhcpd'][$if]['range'])) {
808
		$rangestr .= '<br />' . $config['dhcpd'][$if]['range']['from'] . ' - ' . $config['dhcpd'][$if]['range']['to'];
809 3d7b7757 Chris Buechler
	}
810 b5f6e690 Stephen Beaver
811
	foreach ($a_pools as $p) {
812
		if (is_array($p['range'])) {
813
			$rangestr .= '<br />' . $p['range']['from'] . ' - ' . $p['range']['to'];
814 8f8682f7 Phil Davis
		}
815 934240ef Ermal Luçi
	}
816 b5f6e690 Stephen Beaver
}
817
818
$section->addInput(new Form_StaticText(
819
	'Available range',
820
	$rangestr
821
));
822
823
if ($is_olsr_enabled) {
824
	$section->addInput(new Form_Select(
825
		'netmask',
826
		'Subnet mask',
827
		$pconfig['netmask'],
828
		array_combine(range(32, 1, -1), range(32, 1, -1))
829
	));
830
}
831
832
$group = new Form_Group('Range');
833
834
$group->add(new Form_IpAddress(
835
	'range_from',
836
	null,
837
	$pconfig['range_from']
838
))->setHelp('From');
839
840
$group->add(new Form_IpAddress(
841
	'range_to',
842
	null,
843
	$pconfig['range_to']
844
))->setHelp('To');
845
846
$section->add($group);
847
848
$form->add($section);
849
850
if (!is_numeric($pool) && !($act == "newpool")) {
851
	$section = new Form_Section('Additional pools');
852
853
	$btnaddpool = new Form_Button(
854
		'btnaddpool',
855
		'Add pool',
856
		'services_dhcp.php?if=' . htmlspecialchars($if) . '&act=newpool'
857
	);
858
859
	$section->addInput(new Form_StaticText(
860
		'Add',
861
		$btnaddpool
862
	))->setHelp('If you need additional pools of addresses inside of this subnet outside the above Range, they may be specified here');
863
864
	if (is_array($a_pools)) {
865
		$section->addInput(new Form_StaticText(
866
			null,
867
			build_pooltable()
868
		));
869 f0cdf141 Scott Ullrich
	}
870 b5f6e690 Stephen Beaver
871
	$form->add($section);
872
}
873
874
$section = new Form_Section('Servers');
875
876
$section->addInput(new Form_IpAddress(
877
	'wins1',
878
	'WINS servers',
879
	$pconfig['wins1']
880
))->setPattern('[.a-zA-Z0-9_]+')->setAttribute('placeholder', 'WINS Server 1');
881
882
$section->addInput(new Form_IpAddress(
883
	'wins2',
884
	null,
885
	$pconfig['wins2']
886
))->setPattern('[.a-zA-Z0-9_]+')->setAttribute('placeholder', 'WINS Server 2');
887
888 6e3488e9 Phil Davis
for ($idx=1; $idx<=4; $idx++) {
889 b5f6e690 Stephen Beaver
	$section->addInput(new Form_IpAddress(
890
		'dns' . $idx,
891
		($idx == 1) ? 'DNS servers':null,
892
		$pconfig['dns' . $idx]
893
	))->setPattern('[.a-zA-Z0-9_]+')->setAttribute('placeholder', 'DNS Server ' . $idx)->setHelp(($idx == 4) ? 'Leave blank to use the system default DNS servers, use this interface\'s IP if DNS Forwarder or Resolver is enabled, otherwise use the servers configured on the General page':'');
894
}
895
896
$form->add($section);
897
898
$section = new Form_Section('Other options');
899
900
$section->addInput(new Form_IpAddress(
901
	'gateway',
902
	'Gateway',
903
	$pconfig['gateway']
904
))->setPattern('[.a-zA-Z0-9_]+')
905
  ->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 your network. Type "none" for no gateway assignment');
906
907
$section->addInput(new Form_Input(
908
	'domain',
909
	'Domain name',
910
	'text',
911
	$pconfig['domain']
912
))->setHelp('The default is to use the domain name of this system as the default domain name provided by DHCP. You may specify an alternate domain name here');
913
914
$section->addInput(new Form_Input(
915
	'domainsearchlist',
916
	'Domain search list',
917
	'text',
918
	$pconfig['domainsearchlist']
919
))->setHelp('The DHCP server can optionally provide a domain search list. Use the semicolon character as separator');
920
921
$section->addInput(new Form_Input(
922
	'deftime',
923
	'Default lease time',
924
	'number',
925
	$pconfig['deftime']
926
))->setHelp('This is used for clients that do not ask for a specific expiration time. The default is 7200 seconds');
927
928
$section->addInput(new Form_Input(
929
	'maxtime',
930
	'Maximum lease time',
931
	'number',
932
	$pconfig['maxtime']
933
))->setHelp('This is the maximum lease time for clients that ask for a specific expiration time. The default is 86400 seconds');
934
935
if (!is_numeric($pool) && !($act == "newpool")) {
936
	$section->addInput(new Form_IpAddress(
937
		'failover_peerip',
938
		'Failover peer IP',
939
		$pconfig['failover_peerip']
940
	))->setHelp('Leave blank to disable. Enter the interface IP address of the other machine. Machines must be using CARP.' .
941 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).');
942 b5f6e690 Stephen Beaver
}
943
944
if (!is_numeric($pool) && !($act == "newpool")) {
945
	$section->addInput(new Form_Checkbox(
946
		'staticarp',
947
		'Static ARP',
948
		'Enable Static ARP entries',
949
		$pconfig['staticarp']
950 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.');
951 b5f6e690 Stephen Beaver
952
	$section->addInput(new Form_Checkbox(
953
		'dhcpleaseinlocaltime',
954
		'Time format change',
955
		'Change DHCP display lease time from UTC to local time',
956
		$pconfig['dhcpleaseinlocaltime']
957
	))->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.' .
958
				' This will be used for all DHCP interfaces lease time');
959 18d316a5 heper
	$section->addInput(new Form_Checkbox(
960
		'statsgraph',
961 61237194 Chris Buechler
		'Statistics graphs',
962
		'Enable RRD statistics graphs',
963 18d316a5 heper
		$pconfig['statsgraph']
964 61237194 Chris Buechler
	))->setHelp('Enable this to add DHCP leases statistics to the RRD graphs. Disabled by default.');
965 b5f6e690 Stephen Beaver
}
966
967
// DDNS
968
$btnadv = new Form_Button(
969
	'btnadvdns',
970
	'Advanced'
971
);
972
973
$btnadv->removeClass('btn-primary')->addClass('btn-default btn-sm');
974
975
$section->addInput(new Form_StaticText(
976
	'Dynamic DNS',
977
	$btnadv
978
));
979
980
$section->addInput(new Form_Checkbox(
981
	'ddnsupdate',
982
	null,
983
	'Enable registration of DHCP client names in DNS',
984
	$pconfig['ddnsupdate']
985
));
986
987
$section->addInput(new Form_Input(
988
	'ddnsdomain',
989
	'DDNS Domain',
990 e8da0bcd Jeremy Porter
	'text',
991 b5f6e690 Stephen Beaver
	$pconfig['ddnsdomain']
992
))->setHelp('Leave blank to disable dynamic DNS registration.' . '<br />' .
993
			'Enter the dynamic DNS domain which will be used to register client names in the DNS server.');
994
995
$section->addInput(new Form_IpAddress(
996
	'ddnsdomainprimary',
997
	'Primary DDNS address',
998
	$pconfig['ddnsdomainprimary']
999
))->setHelp('Primary domain name server IP address for the dynamic domain name');
1000
1001
$section->addInput(new Form_Input(
1002
	'ddnsdomainkeyname',
1003
	'DNS Domain key',
1004
	'text',
1005
	$pconfig['ddnsdomainkeyname']
1006
))->setHelp('Dynamic DNS domain key name which will be used to register client names in the DNS server');
1007
1008
$section->addInput(new Form_Input(
1009
	'ddnsdomainkey',
1010
	'DNS Domain key secret',
1011
	'text',
1012
	$pconfig['ddnsdomainkey']
1013
))->setHelp('Dynamic DNS domain key secret which will be used to register client names in the DNS server');
1014
1015
// Advanced MAC
1016
$btnadv = new Form_Button(
1017
	'btnadvmac',
1018
	'Advanced'
1019
);
1020
1021
$btnadv->removeClass('btn-primary')->addClass('btn-default btn-sm');
1022
1023
$section->addInput(new Form_StaticText(
1024
	'MAC address control',
1025
	$btnadv
1026
));
1027
1028
$section->addInput(new Form_Input(
1029
	'mac_allow',
1030
	'Allow',
1031
	'text',
1032
	$pconfig['mac_allow']
1033
))->setHelp('List of partial MAC addresses to allow, comma separated, no spaces, e.g.: 00:00:00,01:E5:FF');
1034
1035
$section->addInput(new Form_Input(
1036
	'mac_deny',
1037
	'Deny',
1038
	'text',
1039
	$pconfig['mac_deny']
1040
))->setHelp('List of partial MAC addresses to deny access, comma separated, no spaces, e.g.: 00:00:00,01:E5:FF');
1041
1042
// Advanced NTP
1043
$btnadv = new Form_Button(
1044
	'btnadvntp',
1045
	'Advanced'
1046
);
1047
1048
$btnadv->removeClass('btn-primary')->addClass('btn-default btn-sm');
1049
1050
$section->addInput(new Form_StaticText(
1051
	'NTP servers',
1052
	$btnadv
1053
));
1054
1055
$section->addInput(new Form_IpAddress(
1056
	'ntp1',
1057 bf27317d Phil Davis
	null,
1058 b5f6e690 Stephen Beaver
	$pconfig['ntp1']
1059 bf27317d Phil Davis
))->setAttribute('placeholder', 'NTP Server 1');
1060 b5f6e690 Stephen Beaver
1061
$section->addInput(new Form_IpAddress(
1062
	'ntp2',
1063 bf27317d Phil Davis
	null,
1064 b5f6e690 Stephen Beaver
	$pconfig['ntp2']
1065 bf27317d Phil Davis
))->setAttribute('placeholder', 'NTP Server 2');
1066 b5f6e690 Stephen Beaver
1067
// Advanced TFTP
1068
$btnadv = new Form_Button(
1069
	'btnadvtftp',
1070
	'Advanced'
1071
);
1072
1073
$btnadv->removeClass('btn-primary')->addClass('btn-default btn-sm');
1074
1075
$section->addInput(new Form_StaticText(
1076
	'TFTP server',
1077
	$btnadv
1078
));
1079
1080
$section->addInput(new Form_IpAddress(
1081
	'tftp',
1082 bf27317d Phil Davis
	null,
1083 b5f6e690 Stephen Beaver
	$pconfig['tftp']
1084
))->setHelp('Leave blank to disable.  Enter a full hostname or IP for the TFTP server')->setPattern('[.a-zA-Z0-9_]+');
1085
1086
// Advanced LDAP
1087
$btnadv = new Form_Button(
1088
	'btnadvldap',
1089
	'Advanced'
1090
);
1091
1092
$btnadv->removeClass('btn-primary')->addClass('btn-default btn-sm');
1093
1094
$section->addInput(new Form_StaticText(
1095
	'LDAP URI',
1096
	$btnadv
1097
));
1098
1099
$section->addInput(new Form_Input(
1100
	'ldap',
1101
	null,
1102
	'text',
1103
	$pconfig['ldap']
1104
))->setHelp('Leave blank to disable. Enter a full URI for the LDAP server in the form ldap://ldap.example.com/dc=example,dc=com ');
1105
1106
// Advanced NETBOOT
1107
$btnadv = new Form_Button(
1108
	'btnadvboot',
1109
	'Advanced'
1110
);
1111
1112
$btnadv->removeClass('btn-primary')->addClass('btn-default btn-sm');
1113
1114
$section->addInput(new Form_StaticText(
1115
	'Network booting',
1116
	$btnadv
1117
));
1118
1119
$section->addInput(new Form_Checkbox(
1120
	'netboot',
1121
	null,
1122
	'Enables network booting',
1123
	$pconfig['netboot']
1124
));
1125
1126
$section->addInput(new Form_IpAddress(
1127
	'nextserver',
1128
	'Next Server',
1129
	$pconfig['nextserver']
1130 8a73f407 Stephen Beaver
))->setHelp('Enter the IP address of the next server');
1131 b5f6e690 Stephen Beaver
1132
$section->addInput(new Form_Input(
1133
	'filename',
1134
	'Default BIOS file name',
1135
	'text',
1136
	$pconfig['filename']
1137
));
1138
1139
$section->addInput(new Form_Input(
1140
	'filename32',
1141
	'UEFI 32 bit file name',
1142
	'text',
1143
	$pconfig['filename32']
1144
));
1145
1146
$section->addInput(new Form_Input(
1147
	'filename64',
1148
	'UEFI 64 bit file name',
1149
	'text',
1150
	$pconfig['filename64']
1151
))->setHelp('You need both a filename and a boot server configured for this to work! ' .
1152
			'You will need all three filenames and a boot server configured for UEFI to work! ');
1153
1154
$section->addInput(new Form_Input(
1155
	'rootpath',
1156
	'Root path',
1157
	'text',
1158
	$pconfig['rootpath']
1159
))->setHelp('string-format: iscsi:(servername):(protocol):(port):(LUN):targetname ');
1160
1161
// Advanced Additional options
1162
$btnadv = new Form_Button(
1163
	'btnadvopts',
1164
	'Advanced'
1165
);
1166
1167
$btnadv->removeClass('btn-primary')->addClass('btn-default btn-sm');
1168
1169
$section->addInput(new Form_StaticText(
1170
	'Additional BOOTP/DHCP Options',
1171
	$btnadv
1172
));
1173
1174
$form->add($section);
1175
1176
$section = new Form_Section('Additional BOOTP/DHCP Options');
1177
$section->addClass('adnlopts');
1178
1179
$section->addInput(new Form_StaticText(
1180
	null,
1181
	'<div class="alert alert-info"> ' . gettext('Enter the DHCP option number and the value for each item you would like to include in the DHCP lease information. ' .
1182
	'For a list of available options please visit this ') . '<a href="http://www.iana.org/assignments/bootp-dhcp-parameters/" target="_blank">' . gettext("URL") . '</a></div>'
1183
));
1184
1185 6e3488e9 Phil Davis
if (!$pconfig['numberoptions']) {
1186 b5f6e690 Stephen Beaver
	$pconfig['numberoptions']['item']  = array(array('number' => '', 'type' => 'text', 'value' => ''));
1187
}
1188
1189
$customitemtypes = array(
1190
	'text' => gettext('Text'), 'string' => gettext('String'), 'boolean' => gettext('Boolean'),
1191
	'unsigned integer 8' => gettext('Unsigned 8-bit integer'), 'unsigned integer 16' => gettext('Unsigned 16-bit integer'), 'unsigned integer 32' => gettext('Unsigned 32-bit integer'),
1192
	'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')
1193
);
1194
1195
$numrows = count($item) -1;
1196
$counter = 0;
1197
1198
$numrows = count($pconfig['numberoptions']['item']) -1;
1199
1200
foreach ($pconfig['numberoptions']['item'] as $item) {
1201
	$number = $item['number'];
1202
	$itemtype = $item['type'];
1203
	$value = $item['value'];
1204
1205
	$group = new Form_Group(($counter == 0) ? 'Option':null);
1206
	$group->addClass('repeatable');
1207
1208
	$group->add(new Form_Input(
1209
		'number' . $counter,
1210
		null,
1211
		'text',
1212
		$number
1213
	))->setHelp($numrows == $counter ? 'Number':null);
1214
1215
1216
	$group->add(new Form_Select(
1217
		'itemtype' . $counter,
1218
		null,
1219
		$itemtype,
1220
		$customitemtypes
1221 8a73f407 Stephen Beaver
	))->setWidth(3)->setHelp($numrows == $counter ? 'Type':null);
1222 b5f6e690 Stephen Beaver
1223
	$group->add(new Form_Input(
1224
		'value' . $counter,
1225
		null,
1226
		'text',
1227
		$value
1228
	))->setHelp($numrows == $counter ? 'Value':null);
1229
1230
	$group->add(new Form_Button(
1231
		'deleterow' . $counter,
1232
		'Delete'
1233
	))->removeClass('btn-primary')->addClass('btn-warning');
1234
1235
	$section->add($group);
1236
1237
	$counter++;
1238
}
1239
1240
$section->addInput(new Form_Button(
1241
	'addrow',
1242
	'Add'
1243
))->removeClass('btn-primary')->addClass('btn-success');
1244
1245
$form->add($section);
1246
1247
if ($act == "newpool") {
1248
	$form->addGlobal(new Form_Input(
1249
		'act',
1250
		null,
1251
		'hidden',
1252
		'newpool'
1253
	));
1254
}
1255
1256
if (is_numeric($pool)) {
1257
	$form->addGlobal(new Form_Input(
1258
		'pool',
1259
		null,
1260
		'hidden',
1261
		$pool
1262
	));
1263
}
1264
1265
$form->addGlobal(new Form_Input(
1266
	'if',
1267
	null,
1268
	'hidden',
1269
	$if
1270
));
1271
1272
print($form);
1273
1274
// DHCP Static Mappings table
1275
1276
if (!is_numeric($pool) && !($act == "newpool")) {
1277 de792e62 jim-p
?>
1278 b5f6e690 Stephen Beaver
1279
<div class="panel panel-default">
1280 7683c990 Chris Buechler
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("DHCP Static Mappings for this interface")?></h2></div>
1281 b5f6e690 Stephen Beaver
	<div class="table-responsive">
1282
			<table class="table table-striped table-hover table-condensed">
1283
				<thead>
1284
					<tr>
1285
						<th><?=gettext("Static ARP")?></th>
1286
						<th><?=gettext("MAC address")?></th>
1287
						<th><?=gettext("IP address")?></th>
1288
						<th><?=gettext("Hostname")?></th>
1289
						<th><?=gettext("Description")?></th>
1290
						<th></th>
1291
					</tr>
1292
				</thead>
1293 8f8682f7 Phil Davis
<?php
1294 b5f6e690 Stephen Beaver
	if (is_array($a_maps)) {
1295
		$i = 0;
1296 8f8682f7 Phil Davis
?>
1297 b5f6e690 Stephen Beaver
				<tbody>
1298 8f8682f7 Phil Davis
<?php
1299 b5f6e690 Stephen Beaver
		foreach ($a_maps as $mapent) {
1300 8f8682f7 Phil Davis
?>
1301 b5f6e690 Stephen Beaver
					<tr>
1302
						<td align="center" ondblclick="document.location='services_dhcp_edit.php?if=<?=htmlspecialchars($if)?>&amp;id=<?=$i?>';">
1303
							<?php if (isset($mapent['arp_table_static_entry'])): ?>
1304 1b7379f9 Jared Dillard
								<i class="fa fa-check"></i>
1305 b5f6e690 Stephen Beaver
							<?php endif; ?>
1306
						</td>
1307
						<td ondblclick="document.location='services_dhcp_edit.php?if=<?=htmlspecialchars($if)?>&amp;id=<?=$i?>';">
1308
							<?=htmlspecialchars($mapent['mac'])?>
1309
						</td>
1310
						<td ondblclick="document.location='services_dhcp_edit.php?if=<?=htmlspecialchars($if)?>&amp;id=<?=$i?>';">
1311
							<?=htmlspecialchars($mapent['ipaddr'])?>
1312
						</td>
1313
						<td ondblclick="document.location='services_dhcp_edit.php?if=<?=htmlspecialchars($if)?>&amp;id=<?=$i?>';">
1314
							<?=htmlspecialchars($mapent['hostname'])?>
1315
						</td>
1316
						<td ondblclick="document.location='services_dhcp_edit.php?if=<?=htmlspecialchars($if)?>&amp;id=<?=$i?>';">
1317
							<?=htmlspecialchars($mapent['descr'])?>
1318
						</td>
1319
						<td>
1320 9a6a8329 heper
							<a class="fa fa-pencil"	title="<?=gettext('Edit static mapping')?>"	href="services_dhcp_edit.php?if=<?=htmlspecialchars($if)?>&amp;id=<?=$i?>"></a>
1321 33f0b0d5 Stephen Beaver
							<a class="fa fa-trash"	title="<?=gettext('Delete static mapping')?>"	href="services_dhcp.php?if=<?=htmlspecialchars($if)?>&amp;act=del&amp;id=<?=$i?>"></a>
1322 b5f6e690 Stephen Beaver
						</td>
1323
					</tr>
1324 8f8682f7 Phil Davis
<?php
1325 b5f6e690 Stephen Beaver
		$i++;
1326
		}
1327 8f8682f7 Phil Davis
?>
1328 b5f6e690 Stephen Beaver
				</tbody>
1329 8f8682f7 Phil Davis
<?php
1330 b5f6e690 Stephen Beaver
	}
1331 8f8682f7 Phil Davis
?>
1332 82f54a42 Colin Fleming
		</table>
1333 b5f6e690 Stephen Beaver
	</div>
1334
</div>
1335 c9679d8c Stephen Beaver
1336 c10cb196 Stephen Beaver
<nav class="action-buttons">
1337 c9679d8c Stephen Beaver
	<a href="services_dhcp_edit.php?if=<?=htmlspecialchars($if)?>" class="btn btn-sm btn-success">
1338 9d5a20cf heper
		<i class="fa fa-plus icon-embed-btn"></i>
1339 c9679d8c Stephen Beaver
		<?=gettext("Add")?>
1340
	</a>
1341
</nav>
1342 8f8682f7 Phil Davis
<?php
1343 b5f6e690 Stephen Beaver
}
1344 8f8682f7 Phil Davis
?>
1345
1346 8fd9052f Colin Fleming
<script type="text/javascript">
1347 b5f6e690 Stephen Beaver
//<![CDATA[
1348 6e3488e9 Phil Davis
events.push(function() {
1349 b5f6e690 Stephen Beaver
1350
	// Show advanced DNS options ======================================================================================
1351
	var showadvdns = false;
1352
1353
	function show_advdns() {
1354
<?php
1355
		if (!$pconfig['ddnsupdate'] && empty($pconfig['ddnsdomain']) && empty($pconfig['ddnsdomainprimary']) &&
1356 6e3488e9 Phil Davis
		    empty($pconfig['ddnsdomainkeyname']) && empty($pconfig['ddnsdomainkey'])) {
1357 b5f6e690 Stephen Beaver
			$hide = false;
1358 6e3488e9 Phil Davis
		} else {
1359 b5f6e690 Stephen Beaver
			$hide = true;
1360 6e3488e9 Phil Davis
		}
1361 8f8682f7 Phil Davis
?>
1362 6e3488e9 Phil Davis
		var hide = <?php if ($hide) {echo 'true';} else {echo 'false';} ?>;
1363 b5f6e690 Stephen Beaver
1364
		hideCheckbox('ddnsupdate', !showadvdns && !hide);
1365
		hideInput('ddnsdomain', !showadvdns && !hide);
1366
		hideInput('ddnsdomainprimary', !showadvdns && !hide);
1367
		hideInput('ddnsdomainkeyname', !showadvdns && !hide);
1368
		hideInput('ddnsdomainkey', !showadvdns && !hide);
1369 8a73f407 Stephen Beaver
		hideInput('btnadvdns', hide);
1370 b5f6e690 Stephen Beaver
		showadvdns = !showadvdns;
1371
	}
1372
1373
	$('#btnadvdns').prop('type', 'button');
1374
1375
	$('#btnadvdns').click(function(event) {
1376
		show_advdns();
1377
	});
1378
1379
 // Show advanced MAC options ======================================================================================
1380
	var showadvmac = false;
1381
1382
	function show_advmac() {
1383 8f8682f7 Phil Davis
<?php
1384 6e3488e9 Phil Davis
		if (empty($pconfig['mac_allow']) && empty($pconfig['mac_deny'])) {
1385 b5f6e690 Stephen Beaver
			$hide = false;
1386 6e3488e9 Phil Davis
		} else {
1387 b5f6e690 Stephen Beaver
			$hide = true;
1388 6e3488e9 Phil Davis
		}
1389 8f8682f7 Phil Davis
?>
1390 6e3488e9 Phil Davis
		var hide = <?php if ($hide) {echo 'true';} else {echo 'false';} ?>;
1391 b5f6e690 Stephen Beaver
1392
		hideInput('mac_allow', !showadvmac && !hide);
1393
		hideInput('mac_deny', !showadvmac && !hide);
1394 8a73f407 Stephen Beaver
		hideInput('btnadvmac', hide);
1395 b5f6e690 Stephen Beaver
1396
		showadvmac = !showadvmac;
1397
	}
1398
1399
	$('#btnadvmac').prop('type', 'button');
1400
1401
	$('#btnadvmac').click(function(event) {
1402
		show_advmac();
1403
	});
1404
1405
  // Show advanced NTP options ======================================================================================
1406
	var showadvntp = false;
1407
1408
	function show_advntp() {
1409 8f8682f7 Phil Davis
<?php
1410 6e3488e9 Phil Davis
		if (empty($pconfig['ntp1']) && empty($pconfig['ntp2'])) {
1411 b5f6e690 Stephen Beaver
			$hide = false;
1412 6e3488e9 Phil Davis
		} else {
1413 b5f6e690 Stephen Beaver
			$hide = true;
1414 6e3488e9 Phil Davis
		}
1415 8f8682f7 Phil Davis
?>
1416 6e3488e9 Phil Davis
		var hide = <?php if ($hide) {echo 'true';} else {echo 'false';} ?>;
1417 b5f6e690 Stephen Beaver
1418
		hideInput('ntp1', !showadvntp && !hide);
1419
		hideInput('ntp2', !showadvntp && !hide);
1420 8a73f407 Stephen Beaver
		hideInput('btnadvntp', hide);
1421 b5f6e690 Stephen Beaver
1422
		showadvntp = !showadvntp;
1423
	}
1424
1425
	$('#btnadvntp').prop('type', 'button');
1426
1427
	$('#btnadvntp').click(function(event) {
1428
		show_advntp();
1429
	});
1430
1431
   // Show advanced TFTP options ======================================================================================
1432
	var showadvtftp = false;
1433
1434
	function show_advtftp() {
1435 8f8682f7 Phil Davis
<?php
1436 6e3488e9 Phil Davis
		if (empty($pconfig['tftp'])) {
1437 b5f6e690 Stephen Beaver
			$hide = false;
1438 6e3488e9 Phil Davis
		} else {
1439 b5f6e690 Stephen Beaver
			$hide = true;
1440 6e3488e9 Phil Davis
		}
1441 8f8682f7 Phil Davis
?>
1442 6e3488e9 Phil Davis
		var hide = <?php if ($hide) {echo 'true';} else {echo 'false';} ?>;
1443 b5f6e690 Stephen Beaver
1444
		hideInput('tftp', !showadvtftp && !hide);
1445 8a73f407 Stephen Beaver
		hideInput('btnadvtftp', hide);
1446 b5f6e690 Stephen Beaver
1447
		showadvtftp = !showadvtftp;
1448
	}
1449
1450
	$('#btnadvtftp').prop('type', 'button');
1451
1452
	$('#btnadvtftp').click(function(event) {
1453
		show_advtftp();
1454
	});
1455
1456
   // Show advanced LDAP options ======================================================================================
1457
	var showadvldap = false;
1458
1459
	function show_advldap() {
1460 8f8682f7 Phil Davis
<?php
1461 6e3488e9 Phil Davis
		if (empty($pconfig['ldap'])) {
1462 b5f6e690 Stephen Beaver
			$hide = false;
1463 6e3488e9 Phil Davis
		} else {
1464 b5f6e690 Stephen Beaver
			$hide = true;
1465 6e3488e9 Phil Davis
		}
1466 8f8682f7 Phil Davis
?>
1467 6e3488e9 Phil Davis
		var hide = <?php if ($hide) {echo 'true';} else {echo 'false';} ?>;
1468 b5f6e690 Stephen Beaver
1469
		hideInput('ldap', !showadvldap && !hide);
1470 8a73f407 Stephen Beaver
		hideInput('btnadvldap', hide);
1471 b5f6e690 Stephen Beaver
1472
		showadvldap = !showadvldap;
1473
	}
1474
1475
	$('#btnadvldap').prop('type', 'button');
1476
1477
	$('#btnadvldap').click(function(event) {
1478
		show_advldap();
1479
	});
1480
1481
   // Show advanced NETBOOT options ===================================================================================
1482
	var showadvboot = false;
1483
1484
	function show_advboot() {
1485 8f8682f7 Phil Davis
<?php
1486 b5f6e690 Stephen Beaver
		if (!$pconfig['netboot'] && empty($pconfig['nextserver']) && empty($pconfig['filename']) && empty($pconfig['filename32']) &&
1487 6e3488e9 Phil Davis
		    empty($pconfig['filename64']) && empty($pconfig['rootpath'])) {
1488 b5f6e690 Stephen Beaver
			$hide = false;
1489 6e3488e9 Phil Davis
		} else {
1490 b5f6e690 Stephen Beaver
			$hide = true;
1491 6e3488e9 Phil Davis
		}
1492 8f8682f7 Phil Davis
?>
1493 6e3488e9 Phil Davis
		var hide = <?php if ($hide) {echo 'true';} else {echo 'false';} ?>;
1494 b5f6e690 Stephen Beaver
1495
		hideCheckbox('netboot', !showadvboot && !hide);
1496
		hideInput('nextserver', !showadvboot && !hide);
1497
		hideInput('filename', !showadvboot && !hide);
1498
		hideInput('filename32', !showadvboot && !hide);
1499
		hideInput('filename64', !showadvboot && !hide);
1500
		hideInput('rootpath', !showadvboot && !hide);
1501 8a73f407 Stephen Beaver
		hideInput('btnadvboot', hide);
1502 b5f6e690 Stephen Beaver
1503
		showadvboot = !showadvboot;
1504
	}
1505
1506
	$('#btnadvboot').prop('type', 'button');
1507
1508
	$('#btnadvboot').click(function(event) {
1509
		show_advboot();
1510
	});
1511
1512 eef93144 Jared Dillard
	// Show advanced additional opts options ===========================================================================
1513 b5f6e690 Stephen Beaver
	var showadvopts = false;
1514
1515
	function show_advopts() {
1516 8f8682f7 Phil Davis
<?php
1517 6e3488e9 Phil Davis
		if (empty($pconfig['numberoptions']) ||
1518
		    (empty($pconfig['numberoptions']['item'][0]['number']) && (empty($pconfig['numberoptions']['item'][0]['value'])))) {
1519 b5f6e690 Stephen Beaver
			$hide = false;
1520 6e3488e9 Phil Davis
		} else {
1521 b5f6e690 Stephen Beaver
			$hide = true;
1522 6e3488e9 Phil Davis
		}
1523 8f8682f7 Phil Davis
?>
1524 6e3488e9 Phil Davis
		var hide = <?php if ($hide) {echo 'true';} else {echo 'false';} ?>;
1525 b5f6e690 Stephen Beaver
1526
		hideClass('adnlopts', !showadvopts && !hide);
1527 8a73f407 Stephen Beaver
		hideInput('btnadvopts', hide);
1528 b5f6e690 Stephen Beaver
1529
		showadvopts = !showadvopts;
1530
	}
1531
1532
	$('#btnadvopts').prop('type', 'button');
1533
1534
	$('#btnadvopts').click(function(event) {
1535
		show_advopts();
1536
	});
1537
1538 eef93144 Jared Dillard
	// ---------- On initial page load ------------------------------------------------------------
1539
1540 b5f6e690 Stephen Beaver
	show_advdns();
1541
	show_advmac();
1542
	show_advntp();
1543
	show_advtftp();
1544
	show_advldap();
1545
	show_advboot();
1546
	show_advopts();
1547 0bc61baa Stephen Beaver
1548
	// Suppress "Delete row" button if there are fewer than two rows
1549
	checkLastRow();
1550 b5f6e690 Stephen Beaver
});
1551 180db186 Colin Fleming
//]]>
1552 5b237745 Scott Ullrich
</script>
1553 b5f6e690 Stephen Beaver
1554 3c9befb9 Chris Buechler
<?php include("foot.inc");