Project

General

Profile

Download (50.1 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	services_dhcp.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6

    
7
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
	All rights reserved.
9

    
10
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12

    
13
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15

    
16
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19

    
20
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30
*/
31
/*
32
	pfSense_BUILDER_BINARIES:	/bin/rm
33
	pfSense_MODULE:	interfaces
34
*/
35

    
36
##|+PRIV
37
##|*IDENT=page-services-dhcpserver
38
##|*NAME=Services: DHCP server page
39
##|*DESCR=Allow access to the 'Services: DHCP server' page.
40
##|*MATCH=services_dhcp.php*
41
##|-PRIV
42

    
43
require("guiconfig.inc");
44

    
45
if(!$g['services_dhcp_server_enable']) {
46
	Header("Location: /");
47
	exit;
48
}
49

    
50
/* This function will remove entries from dhcpd.leases that would otherwise
51
 * overlap with static DHCP reservations. If we don't clean these out,
52
 * then DHCP will print a warning in the logs about a duplicate lease
53
 */
54
function dhcp_clean_leases() {
55
	global $g, $config;
56
	$leasesfile = "{$g['dhcpd_chroot_path']}/var/db/dhcpd.leases";
57
	if (!file_exists($leasesfile))
58
		return;
59
	/* Build list of static MACs */
60
	$staticmacs = array();
61
	foreach($config['interfaces'] as $ifname => $ifarr)
62
		if (is_array($config['dhcpd'][$ifname]['staticmap']))
63
			foreach($config['dhcpd'][$ifname]['staticmap'] as $static)
64
				$staticmacs[] = $static['mac'];
65
	/* Read existing leases */
66
	$leases_contents = explode("\n", file_get_contents($leasesfile));
67
	$newleases_contents = array();
68
	$i=0;
69
	while ($i < count($leases_contents)) {
70
		/* Find a lease definition */
71
		if (substr($leases_contents[$i], 0, 6) == "lease ") {
72
			$templease = array();
73
			$thismac = "";
74
			/* Read to the end of the lease declaration */
75
			do {
76
				if (substr($leases_contents[$i], 0, 20) == "  hardware ethernet ")
77
					$thismac = substr($leases_contents[$i], 20, 17);
78
				$templease[] = $leases_contents[$i];
79
				$i++;
80
			} while ($leases_contents[$i-1] != "}");
81
			/* Check for a matching MAC address and if not present, keep it. */
82
			if (! in_array($thismac, $staticmacs))
83
				$newleases_contents = array_merge($newleases_contents, $templease);
84
		} else {
85
			/* It's a line we want to keep, copy it over. */
86
			$newleases_contents[] = $leases_contents[$i];
87
			$i++;
88
		}
89
	}
90
	/* Write out the new leases file */
91
	$fd = fopen($leasesfile, 'w');
92
	fwrite($fd, implode("\n", $newleases_contents));
93
	fclose($fd);
94
}
95

    
96
$if = $_GET['if'];
97
if (!empty($_POST['if']))
98
	$if = $_POST['if'];
99

    
100
/* if OLSRD is enabled, allow WAN to house DHCP. */
101
if($config['installedpackages']['olsrd']) {
102
	foreach($config['installedpackages']['olsrd']['config'] as $olsrd) {
103
			if($olsrd['enable']) {
104
				$is_olsr_enabled = true;
105
				break;
106
			}
107
	}
108
}
109

    
110
if (!$_GET['if'])
111
	$savemsg = "<b>" . gettext("The DHCP Server can only be enabled on interfaces configured with static IP addresses") . ".<p>" . gettext("Only interfaces configured with a static IP will be shown") . ".</p></b>";
112

    
113
$iflist = get_configured_interface_with_descr();
114

    
115
/* set the starting interface */
116
if (!$if || !isset($iflist[$if])) {
117
	foreach ($iflist as $ifent => $ifname) {
118
		$oc = $config['interfaces'][$ifent];
119
		if ((is_array($config['dhcpd'][$ifent]) && !isset($config['dhcpd'][$ifent]['enable']) && (!is_ipaddrv4($oc['ipaddr']))) ||
120
			(!is_array($config['dhcpd'][$ifent]) && (!is_ipaddrv4($oc['ipaddr']))))
121
			continue;
122
		$if = $ifent;
123
		break;
124
	}
125
}
126

    
127
$act = $_GET['act'];
128
if (!empty($_POST['act']))
129
	$act = $_POST['act'];
130

    
131

    
132
if (is_array($config['dhcpd'][$if])){
133
	$pool = $_GET['pool'];
134
	if (is_numeric($_POST['pool']))
135
		$pool = $_POST['pool'];
136

    
137
	// If we have a pool but no interface name, that's not valid. Redirect away.
138
	if (is_numeric($pool) && empty($if)) {
139
		header("Location: services_dhcp.php");
140
		exit;
141
	}
142

    
143
	if (!is_array($config['dhcpd'][$if]['pool']))
144
		$config['dhcpd'][$if]['pool'] = array();
145
	$a_pools = &$config['dhcpd'][$if]['pool'];
146

    
147
	if (is_numeric($pool) && $a_pools[$pool])
148
		$dhcpdconf = &$a_pools[$pool];
149
	elseif ($act == "newpool")
150
		$dhcpdconf = array();
151
	else
152
		$dhcpdconf = &$config['dhcpd'][$if];
153
}
154
if (is_array($dhcpdconf)) {
155
	// Global Options
156
	if (!is_numeric($pool) && !($act == "newpool")) {
157
		$pconfig['enable'] = isset($dhcpdconf['enable']);
158
		$pconfig['staticarp'] = isset($dhcpdconf['staticarp']);
159
		// No reason to specify this per-pool, per the dhcpd.conf man page it needs to be in every
160
		//   pool and should be specified in every pool both nodes share, so we'll treat it as global
161
		$pconfig['failover_peerip'] = $dhcpdconf['failover_peerip'];
162
		$pconfig['dhcpleaseinlocaltime'] = $dhcpdconf['dhcpleaseinlocaltime'];
163
		if (!is_array($dhcpdconf['staticmap']))
164
			$dhcpdconf['staticmap'] = array();
165
		$a_maps = &$dhcpdconf['staticmap'];
166
	}
167

    
168
	// Options that can be global or per-pool.
169
	if (is_array($dhcpdconf['range'])) {
170
		$pconfig['range_from'] = $dhcpdconf['range']['from'];
171
		$pconfig['range_to'] = $dhcpdconf['range']['to'];
172
	}
173
	$pconfig['deftime'] = $dhcpdconf['defaultleasetime'];
174
	$pconfig['maxtime'] = $dhcpdconf['maxleasetime'];
175
	$pconfig['gateway'] = $dhcpdconf['gateway'];
176
	$pconfig['domain'] = $dhcpdconf['domain'];
177
	$pconfig['domainsearchlist'] = $dhcpdconf['domainsearchlist'];
178
	list($pconfig['wins1'],$pconfig['wins2']) = $dhcpdconf['winsserver'];
179
	list($pconfig['dns1'],$pconfig['dns2']) = $dhcpdconf['dnsserver'];
180
	$pconfig['denyunknown'] = isset($dhcpdconf['denyunknown']);
181
	$pconfig['ddnsdomain'] = $dhcpdconf['ddnsdomain'];
182
	$pconfig['ddnsupdate'] = isset($dhcpdconf['ddnsupdate']);
183
	$pconfig['mac_allow'] = $dhcpdconf['mac_allow'];
184
	$pconfig['mac_deny'] = $dhcpdconf['mac_deny'];
185
	list($pconfig['ntp1'],$pconfig['ntp2']) = $dhcpdconf['ntpserver'];
186
	$pconfig['tftp'] = $dhcpdconf['tftp'];
187
	$pconfig['ldap'] = $dhcpdconf['ldap'];
188
	$pconfig['netboot'] = isset($dhcpdconf['netboot']);
189
	$pconfig['nextserver'] = $dhcpdconf['nextserver'];
190
	$pconfig['filename'] = $dhcpdconf['filename'];
191
	$pconfig['rootpath'] = $dhcpdconf['rootpath'];
192
	$pconfig['netmask'] = $dhcpdconf['netmask'];
193
	$pconfig['numberoptions'] = $dhcpdconf['numberoptions'];
194
}
195

    
196
$ifcfgip = $config['interfaces'][$if]['ipaddr'];
197
$ifcfgsn = $config['interfaces'][$if]['subnet'];
198

    
199
/*   set the enabled flag which will tell us if DHCP relay is enabled
200
 *   on any interface. We will use this to disable DHCP server since
201
 *   the two are not compatible with each other.
202
 */
203

    
204
function is_inrange($test, $start, $end) {
205
	if ( (ip2ulong($test) < ip2ulong($end)) && (ip2ulong($test) > ip2ulong($start)) )
206
		return true;
207
	else
208
		return false;
209
}
210

    
211
function validate_partial_mac_list($maclist) {
212
	$macs = explode(',', $maclist);
213

    
214
	// Loop through and look for invalid MACs.
215
	foreach ($macs as $mac)
216
		if (!is_macaddr($mac, true))
217
			return false;
218
	return true;
219
}
220

    
221
if ($_POST) {
222

    
223
	unset($input_errors);
224

    
225
	$pconfig = $_POST;
226

    
227
	$numberoptions = array();
228
	for($x=0; $x<99; $x++) {
229
		if(isset($_POST["number{$x}"]) && ctype_digit($_POST["number{$x}"])) {
230
			$numbervalue = array();
231
			$numbervalue['number'] = htmlspecialchars($_POST["number{$x}"]);
232
			$numbervalue['type'] = htmlspecialchars($_POST["itemtype{$x}"]);
233
			$numbervalue['value'] = str_replace('&quot;', '"', htmlspecialchars($_POST["value{$x}"]));
234
			$numberoptions['item'][] = $numbervalue;
235
		}
236
	}
237
	// Reload the new pconfig variable that the forum uses.
238
	$pconfig['numberoptions'] = $numberoptions;
239

    
240
	/* input validation */
241
	if ($_POST['enable'] || is_numeric($pool) || $act == "newpool") {
242
		$reqdfields = explode(" ", "range_from range_to");
243
		$reqdfieldsn = array(gettext("Range begin"),gettext("Range end"));
244

    
245
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
246

    
247
		if (($_POST['range_from'] && !is_ipaddrv4($_POST['range_from'])))
248
			$input_errors[] = gettext("A valid range must be specified.");
249
		if (($_POST['range_to'] && !is_ipaddrv4($_POST['range_to'])))
250
			$input_errors[] = gettext("A valid range must be specified.");
251
		if (($_POST['gateway'] && !is_ipaddrv4($_POST['gateway'])))
252
			$input_errors[] = gettext("A valid IP address must be specified for the gateway.");
253
		if (($_POST['wins1'] && !is_ipaddrv4($_POST['wins1'])) || ($_POST['wins2'] && !is_ipaddrv4($_POST['wins2'])))
254
			$input_errors[] = gettext("A valid IP address must be specified for the primary/secondary WINS servers.");
255
		$parent_ip = get_interface_ip($_POST['if']);
256
		if (is_ipaddrv4($parent_ip) && $_POST['gateway']) {
257
			$parent_sn = get_interface_subnet($_POST['if']);
258
			if(!ip_in_subnet($_POST['gateway'], gen_subnet($parent_ip, $parent_sn) . "/" . $parent_sn) && !ip_in_interface_alias_subnet($_POST['if'], $_POST['gateway'])) 
259
				$input_errors[] = sprintf(gettext("The gateway address %s does not lie within the chosen interface's subnet."), $_POST['gateway']);
260
		}
261
		if (($_POST['dns1'] && !is_ipaddrv4($_POST['dns1'])) || ($_POST['dns2'] && !is_ipaddrv4($_POST['dns2'])))
262
			$input_errors[] = gettext("A valid IP address must be specified for the primary/secondary DNS servers.");
263

    
264
		if ($_POST['deftime'] && (!is_numeric($_POST['deftime']) || ($_POST['deftime'] < 60)))
265
			$input_errors[] = gettext("The default lease time must be at least 60 seconds.");
266
		if ($_POST['maxtime'] && (!is_numeric($_POST['maxtime']) || ($_POST['maxtime'] < 60) || ($_POST['maxtime'] <= $_POST['deftime'])))
267
			$input_errors[] = gettext("The maximum lease time must be at least 60 seconds and higher than the default lease time.");
268
		if (($_POST['ddnsdomain'] && !is_domain($_POST['ddnsdomain'])))
269
			$input_errors[] = gettext("A valid domain name must be specified for the dynamic DNS registration.");
270
		if ($_POST['domainsearchlist']) {
271
			$domain_array=preg_split("/[ ;]+/",$_POST['domainsearchlist']);
272
			foreach ($domain_array as $curdomain) {
273
				if (!is_domain($curdomain)) {
274
					$input_errors[] = gettext("A valid domain search list must be specified.");
275
					break;
276
				}
277
			}
278
		}
279

    
280
		// Validate MACs
281
		if (!empty($_POST['mac_allow']) && !validate_partial_mac_list($_POST['mac_allow']))
282
			$input_errors[] = gettext("If you specify a mac allow list, it must contain only valid partial MAC addresses.");
283
		if (!empty($_POST['mac_deny']) && !validate_partial_mac_list($_POST['mac_deny']))
284
			$input_errors[] = gettext("If you specify a mac deny list, it must contain only valid partial MAC addresses.");
285

    
286
		if (($_POST['ntp1'] && !is_ipaddrv4($_POST['ntp1'])) || ($_POST['ntp2'] && !is_ipaddrv4($_POST['ntp2'])))
287
			$input_errors[] = gettext("A valid IP address must be specified for the primary/secondary NTP servers.");
288
		if (($_POST['domain'] && !is_domain($_POST['domain'])))
289
			$input_errors[] = gettext("A valid domain name must be specified for the DNS domain.");
290
		if ($_POST['tftp'] && !is_ipaddrv4($_POST['tftp']) && !is_domain($_POST['tftp']) && !is_URL($_POST['tftp']))
291
			$input_errors[] = gettext("A valid IP address or hostname must be specified for the TFTP server.");
292
		if (($_POST['nextserver'] && !is_ipaddrv4($_POST['nextserver'])))
293
			$input_errors[] = gettext("A valid IP address must be specified for the network boot server.");
294

    
295
		if(gen_subnet($ifcfgip, $ifcfgsn) == $_POST['range_from'])
296
			$input_errors[] = gettext("You cannot use the network address in the starting subnet range.");
297
		if(gen_subnet_max($ifcfgip, $ifcfgsn) == $_POST['range_to'])
298
			$input_errors[] = gettext("You cannot use the broadcast address in the ending subnet range.");
299

    
300
		// Disallow a range that includes the virtualip
301
		if (is_array($config['virtualip']['vip'])) {
302
			foreach($config['virtualip']['vip'] as $vip) {
303
				if($vip['interface'] == $if)
304
					if($vip['subnet'] && is_inrange($vip['subnet'], $_POST['range_from'], $_POST['range_to']))
305
						$input_errors[] = sprintf(gettext("The subnet range cannot overlap with virtual IP address %s."),$vip['subnet']);
306
			}
307
		}
308

    
309
		$noip = false;
310
		if(is_array($a_maps))
311
			foreach ($a_maps as $map)
312
				if (empty($map['ipaddr']))
313
					$noip = true;
314
		if ($_POST['staticarp'] && $noip)
315
			$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.";
316

    
317
		if(is_array($pconfig['numberoptions']['item'])) {
318
			foreach ($pconfig['numberoptions']['item'] as $numberoption) {
319
				if ( $numberoption['type'] == 'text' && strstr($numberoption['value'], '"') )
320
					$input_errors[] = gettext("Text type cannot include quotation marks.");
321
				else if ( $numberoption['type'] == 'string' && !preg_match('/^"[^"]*"$/', $numberoption['value']) && !preg_match('/^[0-9a-f]{2}(?:\:[0-9a-f]{2})*$/i', $numberoption['value']) )
322
					$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");
323
				else if ( $numberoption['type'] == 'boolean' && $numberoption['value'] != 'true' && $numberoption['value'] != 'false' && $numberoption['value'] != 'on' && $numberoption['value'] != 'off' )
324
					$input_errors[] = gettext("Boolean type must be true, false, on, or off.");
325
				else if ( $numberoption['type'] == 'unsigned integer 8' && (!is_numeric($numberoption['value']) || $numberoption['value'] < 0 || $numberoption['value'] > 255) )
326
					$input_errors[] = gettext("Unsigned 8-bit integer type must be a number in the range 0 to 255.");
327
				else if ( $numberoption['type'] == 'unsigned integer 16' && (!is_numeric($numberoption['value']) || $numberoption['value'] < 0 || $numberoption['value'] > 65535) )
328
					$input_errors[] = gettext("Unsigned 16-bit integer type must be a number in the range 0 to 65535.");
329
				else if ( $numberoption['type'] == 'unsigned integer 32' && (!is_numeric($numberoption['value']) || $numberoption['value'] < 0 || $numberoption['value'] > 4294967295) )
330
					$input_errors[] = gettext("Unsigned 32-bit integer type must be a number in the range 0 to 4294967295.");
331
				else if ( $numberoption['type'] == 'signed integer 8' && (!is_numeric($numberoption['value']) || $numberoption['value'] < -128 || $numberoption['value'] > 127) )
332
					$input_errors[] = gettext("Signed 8-bit integer type must be a number in the range -128 to 127.");
333
				else if ( $numberoption['type'] == 'signed integer 16' && (!is_numeric($numberoption['value']) || $numberoption['value'] < -32768 || $numberoption['value'] > 32767) )
334
					$input_errors[] = gettext("Signed 16-bit integer type must be a number in the range -32768 to 32767.");
335
				else if ( $numberoption['type'] == 'signed integer 32' && (!is_numeric($numberoption['value']) || $numberoption['value'] < -2147483648 || $numberoption['value'] > 2147483647) )
336
					$input_errors[] = gettext("Signed 32-bit integer type must be a number in the range -2147483648 to 2147483647.");
337
				else if ( $numberoption['type'] == 'ip-address' && !is_ipaddrv4($numberoption['value']) && !is_hostname($numberoption['value']) )
338
					$input_errors[] = gettext("IP address or host type must be an IP address or host name.");
339
			}
340
		}
341

    
342
		if (!$input_errors) {
343
			/* make sure the range lies within the current subnet */
344
			$subnet_start = ip2ulong(long2ip32(ip2long($ifcfgip) & gen_subnet_mask_long($ifcfgsn)));
345
			$subnet_end = ip2ulong(long2ip32(ip2long($ifcfgip) | (~gen_subnet_mask_long($ifcfgsn))));
346

    
347
			if ((ip2ulong($_POST['range_from']) < $subnet_start) || (ip2ulong($_POST['range_from']) > $subnet_end) ||
348
			    (ip2ulong($_POST['range_to']) < $subnet_start) || (ip2ulong($_POST['range_to']) > $subnet_end)) {
349
				$input_errors[] = gettext("The specified range lies outside of the current subnet.");
350
			}
351

    
352
			if (ip2ulong($_POST['range_from']) > ip2ulong($_POST['range_to']))
353
				$input_errors[] = gettext("The range is invalid (first element higher than second element).");
354

    
355
			// TODO: Ensure range and pools do not overlap!
356
			// If we're editing the main range, check pools
357
			// If we're editing a pool, locate parent range and other pools.
358

    
359
			/* make sure that the DHCP Relay isn't enabled on this interface */
360
			if (isset($config['dhcrelay'][$if]['enable']))
361
				$input_errors[] = sprintf(gettext("You must disable the DHCP relay on the %s interface before enabling the DHCP server."),$iflist[$if]);
362

    
363
			$dynsubnet_start = ip2ulong($_POST['range_from']);
364
			$dynsubnet_end = ip2ulong($_POST['range_to']);
365
			if (is_array($a_maps)) {
366
				foreach ($a_maps as $map) {
367
					if (empty($map['ipaddr']))
368
						continue;
369
					if ((ip2ulong($map['ipaddr']) > $dynsubnet_start) &&
370
						(ip2ulong($map['ipaddr']) < $dynsubnet_end)) {
371
						$input_errors[] = sprintf(gettext("The DHCP range cannot overlap any static DHCP mappings."));
372
						break;
373
					}
374
				}
375
			}
376
		}
377
	}
378

    
379
	if (!$input_errors) {
380
		if (!is_numeric($pool)) {
381
			if ($act == "newpool") {
382
				$dhcpdconf = array();
383
			} else {
384
				if (!is_array($config['dhcpd'][$if]))
385
					$config['dhcpd'][$if] = array();
386
				$dhcpdconf = $config['dhcpd'][$if];
387
			}
388
		} else {
389
			if (is_array($a_pools[$pool])) {
390
				$dhcpdconf = $a_pools[$pool];
391
			} else {
392
				// Someone specified a pool but it doesn't exist. Punt.
393
				header("Location: services_dhcp.php");
394
				exit;
395
			}
396
		}
397
		if (!is_array($dhcpdconf['range']))
398
			$dhcpdconf['range'] = array();
399

    
400
		// Global Options
401
		if (!is_numeric($pool) && !($act == "newpool")) {
402
			$dhcpdconf['enable'] = ($_POST['enable']) ? true : false;
403
			$dhcpdconf['staticarp'] = ($_POST['staticarp']) ? true : false;
404
			$previous = $dhcpdconf['failover_peerip'];
405
			if($previous <> $_POST['failover_peerip'])
406
				mwexec("/bin/rm -rf /var/dhcpd/var/db/*");
407
			$dhcpdconf['failover_peerip'] = $_POST['failover_peerip'];
408
			$dhcpdconf['dhcpleaseinlocaltime'] = $_POST['dhcpleaseinlocaltime'];
409
		}
410

    
411
		// Options that can be global or per-pool.
412
		$dhcpdconf['range']['from'] = $_POST['range_from'];
413
		$dhcpdconf['range']['to'] = $_POST['range_to'];
414
		$dhcpdconf['defaultleasetime'] = $_POST['deftime'];
415
		$dhcpdconf['maxleasetime'] = $_POST['maxtime'];
416
		$dhcpdconf['netmask'] = $_POST['netmask'];
417

    
418
		unset($dhcpdconf['winsserver']);
419
		if ($_POST['wins1'])
420
			$dhcpdconf['winsserver'][] = $_POST['wins1'];
421
		if ($_POST['wins2'])
422
			$dhcpdconf['winsserver'][] = $_POST['wins2'];
423

    
424
		unset($dhcpdconf['dnsserver']);
425
		if ($_POST['dns1'])
426
			$dhcpdconf['dnsserver'][] = $_POST['dns1'];
427
		if ($_POST['dns2'])
428
			$dhcpdconf['dnsserver'][] = $_POST['dns2'];
429

    
430
		$dhcpdconf['gateway'] = $_POST['gateway'];
431
		$dhcpdconf['domain'] = $_POST['domain'];
432
		$dhcpdconf['domainsearchlist'] = $_POST['domainsearchlist'];
433
		$dhcpdconf['denyunknown'] = ($_POST['denyunknown']) ? true : false;
434
		$dhcpdconf['ddnsdomain'] = $_POST['ddnsdomain'];
435
		$dhcpdconf['ddnsupdate'] = ($_POST['ddnsupdate']) ? true : false;
436
		$dhcpdconf['mac_allow'] = $_POST['mac_allow'];
437
		$dhcpdconf['mac_deny'] = $_POST['mac_deny'];
438

    
439
		unset($dhcpdconf['ntpserver']);
440
		if ($_POST['ntp1'])
441
			$dhcpdconf['ntpserver'][] = $_POST['ntp1'];
442
		if ($_POST['ntp2'])
443
			$dhcpdconf['ntpserver'][] = $_POST['ntp2'];
444

    
445
		$dhcpdconf['tftp'] = $_POST['tftp'];
446
		$dhcpdconf['ldap'] = $_POST['ldap'];
447
		$dhcpdconf['netboot'] = ($_POST['netboot']) ? true : false;
448
		$dhcpdconf['nextserver'] = $_POST['nextserver'];
449
		$dhcpdconf['filename'] = $_POST['filename'];
450
		$dhcpdconf['rootpath'] = $_POST['rootpath'];
451

    
452
		// Handle the custom options rowhelper
453
		if(isset($dhcpdconf['numberoptions']['item']))
454
			unset($dhcpdconf['numberoptions']['item']);
455

    
456
		$dhcpdconf['numberoptions'] = $numberoptions;
457

    
458
		if (is_numeric($pool) && is_array($a_pools[$pool])) {
459
			$a_pools[$pool] = $dhcpdconf;
460
		} elseif ($act == "newpool") {
461
			$a_pools[] = $dhcpdconf;
462
		} else {
463
			$config['dhcpd'][$if] = $dhcpdconf;
464
		}
465

    
466
		write_config();
467

    
468
		$retval = 0;
469
		$retvaldhcp = 0;
470
		$retvaldns = 0;
471
		/* Stop DHCP so we can cleanup leases */
472
		killbyname("dhcpd");
473
		dhcp_clean_leases();
474
		/* dnsmasq_configure calls dhcpd_configure */
475
		/* no need to restart dhcpd twice */
476
		if (isset($config['dnsmasq']['regdhcpstatic']))	{
477
			$retvaldns = services_dnsmasq_configure();
478
			if ($retvaldns == 0) {
479
				clear_subsystem_dirty('hosts');
480
				clear_subsystem_dirty('staticmaps');
481
			}
482
		} else {
483
			$retvaldhcp = services_dhcpd_configure();
484
			if ($retvaldhcp == 0)
485
				clear_subsystem_dirty('staticmaps');
486
		}
487
		if($retvaldhcp == 1 || $retvaldns == 1)
488
			$retval = 1;
489
		$savemsg = get_std_save_message($retval);
490
	}
491
}
492

    
493
if ($act == "delpool") {
494
	if ($a_pools[$_GET['id']]) {
495
		unset($a_pools[$_GET['id']]);
496
		write_config();
497
		header("Location: services_dhcp.php?if={$if}");
498
		exit;
499
	}
500
}
501

    
502
if ($act == "del") {
503
	if ($a_maps[$_GET['id']]) {
504
		unset($a_maps[$_GET['id']]);
505
		write_config();
506
		if(isset($config['dhcpd'][$if]['enable'])) {
507
			mark_subsystem_dirty('staticmaps');
508
			if (isset($config['dnsmasq']['regdhcpstatic']))
509
				mark_subsystem_dirty('hosts');
510
		}
511
		header("Location: services_dhcp.php?if={$if}");
512
		exit;
513
	}
514
}
515

    
516
$pgtitle = array(gettext("Services"),gettext("DHCP server"));
517
$shortcut_section = "dhcp";
518

    
519
include("head.inc");
520

    
521
?>
522

    
523
<script type="text/javascript" src="/javascript/row_helper.js">
524
</script>
525

    
526
<script type="text/javascript">
527
	function itemtype_field(fieldname, fieldsize, n) {
528
		return '<select name="' + fieldname + n + '" class="formselect" id="' + fieldname + n + '"><?php
529
			$customitemtypes = array('text' => gettext('Text'), 'string' => gettext('String'), 'boolean' => gettext('Boolean'),
530
				'unsigned integer 8' => gettext('Unsigned 8-bit integer'), 'unsigned integer 16' => gettext('Unsigned 16-bit integer'), 'unsigned integer 32' => gettext('Unsigned 32-bit integer'),
531
				'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'));
532
			foreach ($customitemtypes as $typename => $typedescr) {
533
				echo "<option value=\"{$typename}\">{$typedescr}</option>";
534
			}
535
		?></select>';
536
	}
537

    
538
	rowname[0] = "number";
539
	rowtype[0] = "textbox";
540
	rowsize[0] = "10";
541
	rowname[1] = "itemtype";
542
	rowtype[1] = itemtype_field;
543
	rowname[2] = "value";
544
	rowtype[2] = "textbox";
545
	rowsize[2] = "40";
546
</script>
547

    
548
<script type="text/javascript" language="JavaScript">
549
	function enable_change(enable_over) {
550
		var endis;
551
		<?php if (is_numeric($pool) || ($act == "newpool")): ?>
552
			enable_over = true;
553
		<?php endif; ?>
554
		endis = !(document.iform.enable.checked || enable_over);
555
		document.iform.range_from.disabled = endis;
556
		document.iform.range_to.disabled = endis;
557
		document.iform.wins1.disabled = endis;
558
		document.iform.wins2.disabled = endis;
559
		document.iform.dns1.disabled = endis;
560
		document.iform.dns2.disabled = endis;
561
		document.iform.deftime.disabled = endis;
562
		document.iform.maxtime.disabled = endis;
563
		document.iform.gateway.disabled = endis;
564
		document.iform.failover_peerip.disabled = endis;
565
		document.iform.domain.disabled = endis;
566
		document.iform.domainsearchlist.disabled = endis;
567
		document.iform.staticarp.disabled = endis;
568
		document.iform.dhcpleaseinlocaltime.disabled = endis;
569
		document.iform.ddnsdomain.disabled = endis;
570
		document.iform.ddnsupdate.disabled = endis;
571
		document.iform.mac_allow.disabled = endis;
572
		document.iform.mac_deny.disabled = endis;
573
		document.iform.ntp1.disabled = endis;
574
		document.iform.ntp2.disabled = endis;
575
		document.iform.tftp.disabled = endis;
576
		document.iform.ldap.disabled = endis;
577
		document.iform.netboot.disabled = endis;
578
		document.iform.nextserver.disabled = endis;
579
		document.iform.filename.disabled = endis;
580
		document.iform.rootpath.disabled = endis;
581
		document.iform.denyunknown.disabled = endis;
582
	}
583

    
584
	function show_shownumbervalue() {
585
		document.getElementById("shownumbervaluebox").innerHTML='';
586
		aodiv = document.getElementById('shownumbervalue');
587
		aodiv.style.display = "block";
588
	}
589

    
590
	function show_ddns_config() {
591
		document.getElementById("showddnsbox").innerHTML='';
592
		aodiv = document.getElementById('showddns');
593
		aodiv.style.display = "block";
594
	}
595

    
596
	function show_maccontrol_config() {
597
		document.getElementById("showmaccontrolbox").innerHTML='';
598
		aodiv = document.getElementById('showmaccontrol');
599
		aodiv.style.display = "block";
600
	}
601

    
602
	function show_ntp_config() {
603
		document.getElementById("showntpbox").innerHTML='';
604
		aodiv = document.getElementById('showntp');
605
		aodiv.style.display = "block";
606
	}
607

    
608
	function show_tftp_config() {
609
		document.getElementById("showtftpbox").innerHTML='';
610
		aodiv = document.getElementById('showtftp');
611
		aodiv.style.display = "block";
612
	}
613

    
614
	function show_ldap_config() {
615
		document.getElementById("showldapbox").innerHTML='';
616
		aodiv = document.getElementById('showldap');
617
		aodiv.style.display = "block";
618
	}
619

    
620
	function show_netboot_config() {
621
		document.getElementById("shownetbootbox").innerHTML='';
622
		aodiv = document.getElementById('shownetboot');
623
		aodiv.style.display = "block";
624
	}
625
</script>
626

    
627
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
628
<?php include("fbegin.inc"); ?>
629
<form action="services_dhcp.php" method="post" name="iform" id="iform">
630
<?php if ($input_errors) print_input_errors($input_errors); ?>
631
<?php if ($savemsg) print_info_box($savemsg); ?>
632
<?php
633
	if ($config['dhcrelay']['enable']) {
634
		echo gettext("DHCP Relay is currently enabled. Cannot enable the DHCP Server service while the DHCP Relay is enabled on any interface.");
635
		include("fend.inc");
636
		echo "</body>";
637
		echo "</html>";
638
		exit;
639
	}
640
?>
641
<?php if (is_subsystem_dirty('staticmaps')): ?><p>
642
<?php 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."));?><br>
643
<?php endif; ?>
644
<table width="100%" border="0" cellpadding="0" cellspacing="0">
645
<tr><td>
646
<?php
647
	/* active tabs */
648
	$tab_array = array();
649
	$tabscounter = 0;
650
	$i = 0;
651
	foreach ($iflist as $ifent => $ifname) {
652
		$oc = $config['interfaces'][$ifent];
653
		if ((is_array($config['dhcpd'][$ifent]) && !isset($config['dhcpd'][$ifent]['enable']) && (!is_ipaddrv4($oc['ipaddr']))) ||
654
			(!is_array($config['dhcpd'][$ifent]) && (!is_ipaddrv4($oc['ipaddr']))))
655
			continue;
656
		if ($ifent == $if)
657
			$active = true;
658
		else
659
			$active = false;
660
		$tab_array[] = array($ifname, $active, "services_dhcp.php?if={$ifent}");
661
		$tabscounter++;
662
	}
663
	if ($tabscounter == 0) {
664
		echo "</td></tr></table></form>";
665
		include("fend.inc");
666
		echo "</body>";
667
		echo "</html>";
668
		exit;
669
	}
670
	display_top_tabs($tab_array);
671
?>
672
</td></tr>
673
<tr>
674
<td>
675
	<div id="mainarea">
676
		<table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
677
			<?php if (!is_numeric($pool) && !($act == "newpool")): ?>
678
			<tr>
679
			<td width="22%" valign="top" class="vtable">&nbsp;</td>
680
			<td width="78%" class="vtable">
681
				<input name="enable" type="checkbox" value="yes" <?php if ($pconfig['enable']) echo "checked"; ?> onClick="enable_change(false)">
682
			<strong><?php printf(gettext("Enable DHCP server on " .
683
			"%s " .
684
			"interface"),htmlspecialchars($iflist[$if]));?></strong></td>
685
			</tr>
686
			<?php else: ?>
687
			<tr>
688
				<td colspan="2" class="listtopic"><?php echo gettext("Editing Pool-Specific Options. To return to the Interface, click its tab above."); ?></td>
689
			</tr>
690
			<?php endif; ?>
691
			<tr>
692
			<td width="22%" valign="top" class="vtable">&nbsp;</td>
693
			<td width="78%" class="vtable">
694
				<input name="denyunknown" id="denyunknown" type="checkbox" value="yes" <?php if ($pconfig['denyunknown']) echo "checked"; ?>>
695
				<strong><?=gettext("Deny unknown clients");?></strong><br>
696
				<?=gettext("If this is checked, only the clients defined below will get DHCP leases from this server. ");?></td>
697
			</tr>
698
			<tr>
699
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Subnet");?></td>
700
			<td width="78%" class="vtable">
701
				<?=gen_subnet($ifcfgip, $ifcfgsn);?>
702
			</td>
703
			</tr>
704
			<tr>
705
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Subnet mask");?></td>
706
			<td width="78%" class="vtable">
707
				<?=gen_subnet_mask($ifcfgsn);?>
708
			</td>
709
			</tr>
710
			<tr>
711
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Available range");?></td>
712
			<td width="78%" class="vtable">
713
			<?php
714
				$range_from = ip2long(long2ip32(ip2long($ifcfgip) & gen_subnet_mask_long($ifcfgsn)));
715
				$range_from++;
716
				echo long2ip32($range_from);
717
			?>
718
			-
719
			<?php
720
				$range_to = ip2long(long2ip32(ip2long($ifcfgip) | (~gen_subnet_mask_long($ifcfgsn))));
721
				$range_to--;
722
				echo long2ip32($range_to);
723
			?>
724
			<?php if (is_numeric($pool) || ($act == "newpool")): ?>
725
				<br/>In-use DHCP Pool Ranges:
726
				<?php if (is_array($config['dhcpd'][$if]['range'])): ?>
727
					<br/><?php echo $config['dhcpd'][$if]['range']['from']; ?>-<?php echo $config['dhcpd'][$if]['range']['to']; ?>
728
				<?php endif; ?>
729
				<?php foreach ($a_pools as $p): ?>
730
					<?php if (is_array($p['range'])): ?>
731
					<br/><?php echo $p['range']['from']; ?>-<?php echo $p['range']['to']; ?>
732
					<?php endif; ?>
733
				<?php endforeach; ?>
734
			<?php endif; ?>
735
			</td>
736
			</tr>
737
			<?php if($is_olsr_enabled): ?>
738
			<tr>
739
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Subnet Mask");?></td>
740
			<td width="78%" class="vtable">
741
				<select name="netmask" class="formselect" id="netmask">
742
				<?php
743
				for ($i = 32; $i > 0; $i--) {
744
					if($i <> 31) {
745
						echo "<option value=\"{$i}\" ";
746
						if ($i == $pconfig['netmask']) echo "selected";
747
						echo ">" . $i . "</option>";
748
					}
749
				}
750
				?>
751
				</select>
752
			</td>
753
			</tr>
754
			<?php endif; ?>
755
			<tr>
756
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Range");?></td>
757
			<td width="78%" class="vtable">
758
				<input name="range_from" type="text" class="formfld unknown" id="range_from" size="20" value="<?=htmlspecialchars($pconfig['range_from']);?>">
759
				&nbsp;<?=gettext("to"); ?>&nbsp; <input name="range_to" type="text" class="formfld unknown" id="range_to" size="20" value="<?=htmlspecialchars($pconfig['range_to']);?>">
760
			</td>
761
			</tr>
762
			<?php if (!is_numeric($pool) && !($act == "newpool")): ?>
763
			<tr>
764
			<td width="22%" valign="top" class="vncell"><?=gettext("Additional Pools");?></td>
765
			<td width="78%" class="vtable">
766
				<?php echo gettext("If you need additional pools of addresses inside of this subnet outside the above Range, they may be specified here."); ?>
767
				<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
768
				<tr>
769
					<td width="45%" class="listhdrr"><?=gettext("Pool Start");?></td>
770
					<td width="45%" class="listhdrr"><?=gettext("Pool End");?></td>
771
					<td width="10%" class="list">
772
					<table border="0" cellspacing="0" cellpadding="1">
773
					<tr>
774
					<td valign="middle" width="17"></td>
775
					<td valign="middle"><a href="services_dhcp.php?if=<?=htmlspecialchars($if);?>&act=newpool"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td>
776
					</tr>
777
					</table>
778
					</td>
779
				</tr>
780
					<?php if(is_array($a_pools)): ?>
781
					<?php $i = 0; foreach ($a_pools as $poolent): ?>
782
					<?php if(!empty($poolent['range']['from']) && !empty($poolent['range']['to'])): ?>
783
				<tr>
784
				<td class="listlr" ondblclick="document.location='services_dhcp.php?if=<?=htmlspecialchars($if);?>&pool=<?=$i;?>';">
785
					<?=htmlspecialchars($poolent['range']['from']);?>
786
				</td>
787
				<td class="listr" ondblclick="document.location='services_dhcp.php?if=<?=htmlspecialchars($if);?>&pool=<?=$i;?>';">
788
					<?=htmlspecialchars($poolent['range']['to']);?>&nbsp;
789
				</td>
790
				<td valign="middle" nowrap class="list">
791
					<table border="0" cellspacing="0" cellpadding="1">
792
					<tr>
793
					<td valign="middle"><a href="services_dhcp.php?if=<?=htmlspecialchars($if);?>&pool=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0"></a></td>
794
					<td valign="middle"><a href="services_dhcp.php?if=<?=htmlspecialchars($if);?>&act=delpool&id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this pool?");?>')"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0"></a></td>
795
					</tr>
796
					</table>
797
				</td>
798
				</tr>
799
				<?php endif; ?>
800
				<?php $i++; endforeach; ?>
801
				<?php endif; ?>
802
				<tr>
803
				<td class="list" colspan="2"></td>
804
				<td class="list">
805
					<table border="0" cellspacing="0" cellpadding="1">
806
					<tr>
807
					<td valign="middle" width="17"></td>
808
					<td valign="middle"><a href="services_dhcp.php?if=<?=htmlspecialchars($if);?>&act=newpool"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td>
809
					</tr>
810
					</table>
811
				</td>
812
				</tr>
813
				</table>
814
			</td>
815
			</tr>
816
			<?php endif; ?>
817
			<tr>
818
			<td width="22%" valign="top" class="vncell"><?=gettext("WINS servers");?></td>
819
			<td width="78%" class="vtable">
820
				<input name="wins1" type="text" class="formfld unknown" id="wins1" size="20" value="<?=htmlspecialchars($pconfig['wins1']);?>"><br>
821
				<input name="wins2" type="text" class="formfld unknown" id="wins2" size="20" value="<?=htmlspecialchars($pconfig['wins2']);?>">
822
			</td>
823
			</tr>
824
			<tr>
825
			<td width="22%" valign="top" class="vncell"><?=gettext("DNS servers");?></td>
826
			<td width="78%" class="vtable">
827
				<input name="dns1" type="text" class="formfld unknown" id="dns1" size="20" value="<?=htmlspecialchars($pconfig['dns1']);?>"><br>
828
				<input name="dns2" type="text" class="formfld unknown" id="dns2" size="20" value="<?=htmlspecialchars($pconfig['dns2']);?>"><br>
829
				<?=gettext("NOTE: leave blank to use the system default DNS servers - this interface's IP if DNS forwarder is enabled, otherwise the servers configured on the General page.");?>
830
			</td>
831
			</tr>
832
			<tr>
833
			<td width="22%" valign="top" class="vncell"><?=gettext("Gateway");?></td>
834
			<td width="78%" class="vtable">
835
				<input name="gateway" type="text" class="formfld host" id="gateway" size="20" value="<?=htmlspecialchars($pconfig['gateway']);?>"><br>
836
			 	 <?=gettext("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.");?>
837
			</td>
838
			</tr>
839
			<tr>
840
			<td width="22%" valign="top" class="vncell"><?=gettext("Domain name");?></td>
841
			<td width="78%" class="vtable">
842
				<input name="domain" type="text" class="formfld unknown" id="domain" size="20" value="<?=htmlspecialchars($pconfig['domain']);?>"><br>
843
				 <?=gettext("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.");?>
844
			 </td>
845
			</tr>
846
			<tr>
847
			<td width="22%" valign="top" class="vncell"><?=gettext("Domain search list");?></td>
848
			<td width="78%" class="vtable">
849
				<input name="domainsearchlist" type="text" class="formfld unknown" id="domainsearchlist" size="20" value="<?=htmlspecialchars($pconfig['domainsearchlist']);?>"><br>
850
				<?=gettext("The DHCP server can optionally provide a domain search list. Use the semicolon character as seperator ");?>
851
			</td>
852
			</tr>
853
			<tr>
854
			<td width="22%" valign="top" class="vncell"><?=gettext("Default lease time");?></td>
855
			<td width="78%" class="vtable">
856
				<input name="deftime" type="text" class="formfld unknown" id="deftime" size="10" value="<?=htmlspecialchars($pconfig['deftime']);?>">
857
				<?=gettext("seconds");?><br>
858
				<?=gettext("This is used for clients that do not ask for a specific " .
859
				"expiration time."); ?><br>
860
				<?=gettext("The default is 7200 seconds.");?>
861
			</td>
862
			</tr>
863
			<tr>
864
			<td width="22%" valign="top" class="vncell"><?=gettext("Maximum lease time");?></td>
865
			<td width="78%" class="vtable">
866
				<input name="maxtime" type="text" class="formfld unknown" id="maxtime" size="10" value="<?=htmlspecialchars($pconfig['maxtime']);?>">
867
				<?=gettext("seconds");?><br>
868
				<?=gettext("This is the maximum lease time for clients that ask".
869
				" for a specific expiration time."); ?><br>
870
				<?=gettext("The default is 86400 seconds.");?>
871
			</td>
872
			</tr>
873
			<?php if (!is_numeric($pool) && !($act == "newpool")): ?>
874
			<tr>
875
			<td width="22%" valign="top" class="vncell"><?=gettext("Failover peer IP:");?></td>
876
			<td width="78%" class="vtable">
877
				<input name="failover_peerip" type="text" class="formfld host" id="failover_peerip" size="20" value="<?=htmlspecialchars($pconfig['failover_peerip']);?>"><br>
878
				<?=gettext("Leave blank to disable.  Enter the interface IP address of the other machine.  Machines must be using CARP.");?>
879
			</td>
880
			</tr>
881
			<?php endif; ?>
882
			<?php if (!is_numeric($pool) && !($act == "newpool")): ?>
883
			<tr>
884
			<td width="22%" valign="top" class="vncell"><?=gettext("Static ARP");?></td>
885
			<td width="78%" class="vtable">
886
				<table>
887
					<tr>
888
					<td>
889
						<input valign="middle" type="checkbox" value="yes" name="staticarp" id="staticarp" <?php if($pconfig['staticarp']) echo " checked"; ?>>&nbsp;
890
					</td>
891
					<td><b><?=gettext("Enable Static ARP entries");?></b></td>
892
					</tr>
893
					<tr>
894
					<td>&nbsp;</td>
895
					<td>
896
						<span class="red"><strong><?=gettext("Note:");?></strong></span> <?=gettext("Only the machines listed below will be able to communicate with the firewall on this NIC.");?>
897
					</td>
898
					</tr>
899
				</table>
900
			</td>
901
			</tr>
902
			<?php endif; ?>
903
			<?php if (!is_numeric($pool) && !($act == "newpool")): ?>
904
			<tr>
905
				<td width="22%" valign="top" class="vncell"><?=gettext("Time format change"); ?></td>
906
				<td width="78%" class="vtable">
907
				<table>
908
					<tr>
909
					<td>
910
						<input name="dhcpleaseinlocaltime" type="checkbox" id="dhcpleaseinlocaltime" value="yes" <?php if ($pconfig['dhcpleaseinlocaltime']) echo "checked"; ?>>
911
					</td>
912
					<td>
913
						<strong>
914
							<?=gettext("Change DHCP display lease time from UTC to local time."); ?>
915
						</strong>
916
					</td>
917
					</tr>
918
					<tr>
919
					<td>&nbsp;</td>
920
					<td>
921
						<span class="red"><strong><?=gettext("Note:");?></strong></span> <?=gettext("By default DHCP leases are displayed in UTC time.  By checking this 
922
						box DHCP lease time will be displayed in local time and set to time zone selected.  This will be used for all DHCP interfaces lease time."); ?>
923
					
924
					</td>
925
					</tr>
926
				</table>
927
				</td>
928
			</tr>
929
			<?php endif; ?>
930
			<tr>
931
			<td width="22%" valign="top" class="vncell"><?=gettext("Dynamic DNS");?></td>
932
			<td width="78%" class="vtable">
933
				<div id="showddnsbox">
934
					<input type="button" onClick="show_ddns_config()" value="<?=gettext("Advanced");?>"></input> - <?=gettext("Show Dynamic DNS");?></a>
935
				</div>
936
				<div id="showddns" style="display:none">
937
					<input valign="middle" type="checkbox" value="yes" name="ddnsupdate" id="ddnsupdate" <?php if($pconfig['ddnsupdate']) echo " checked"; ?>>&nbsp;
938
					<b><?=gettext("Enable registration of DHCP client names in DNS.");?></b><br />
939
					<p>
940
					<input name="ddnsdomain" type="text" class="formfld unknown" id="ddnsdomain" size="20" value="<?=htmlspecialchars($pconfig['ddnsdomain']);?>"><br />
941
					<?=gettext("Note: Leave blank to disable dynamic DNS registration.");?><br />
942
					<?=gettext("Enter the dynamic DNS domain which will be used to register client names in the DNS server.");?>
943
				</div>
944
			</td>
945
			</tr>
946
			<tr>
947
			<td width="22%" valign="top" class="vncell"><?=gettext("MAC Address Control");?></td>
948
			<td width="78%" class="vtable">
949
				<div id="showmaccontrolbox">
950
					<input type="button" onClick="show_maccontrol_config()" value="<?=gettext("Advanced");?>"></input> - <?=gettext("Show MAC Address Control");?></a>
951
				</div>
952
				<div id="showmaccontrol" style="display:none">
953
					<input name="mac_allow" type="text" class="formfld unknown" id="mac_allow" size="20" value="<?=htmlspecialchars($pconfig['mac_allow']);?>"><br />
954
					<?=gettext("Enter a list of partial MAC addresses to allow, comma separated, no spaces, such as ");?>00:00:00,01:E5:FF
955
					<input name="mac_deny" type="text" class="formfld unknown" id="mac_deny" size="20" value="<?=htmlspecialchars($pconfig['mac_deny']);?>"><br />
956
					<?=gettext("Enter a list of partial MAC addresses to deny access, comma separated, no spaces, such as ");?>00:00:00,01:E5:FF
957
				</div>
958
			</td>
959
			</tr>
960
			<tr>
961
			<td width="22%" valign="top" class="vncell"><?=gettext("NTP servers");?></td>
962
			<td width="78%" class="vtable">
963
				<div id="showntpbox">
964
					<input type="button" onClick="show_ntp_config()" value="<?=gettext("Advanced");?>"></input> - <?=gettext("Show NTP configuration");?></a>
965
				</div>
966
				<div id="showntp" style="display:none">
967
					<input name="ntp1" type="text" class="formfld unknown" id="ntp1" size="20" value="<?=htmlspecialchars($pconfig['ntp1']);?>"><br>
968
					<input name="ntp2" type="text" class="formfld unknown" id="ntp2" size="20" value="<?=htmlspecialchars($pconfig['ntp2']);?>">
969
				</div>
970
			</td>
971
			</tr>
972
			<tr>
973
			<td width="22%" valign="top" class="vncell"><?=gettext("TFTP server");?></td>
974
			<td width="78%" class="vtable">
975
			<div id="showtftpbox">
976
				<input type="button" onClick="show_tftp_config()" value="<?=gettext("Advanced");?>"></input> - <?=gettext("Show TFTP configuration");?></a>
977
			</div>
978
			<div id="showtftp" style="display:none">
979
				<input name="tftp" type="text" class="formfld unknown" id="tftp" size="50" value="<?=htmlspecialchars($pconfig['tftp']);?>"><br>
980
				<?=gettext("Leave blank to disable.  Enter a full hostname or IP for the TFTP server.");?>
981
			</div>
982
			</td>
983
			</tr>
984
			<tr>
985
			<td width="22%" valign="top" class="vncell"><?=gettext("LDAP URI");?></td>
986
			<td width="78%" class="vtable">
987
				<div id="showldapbox">
988
					<input type="button" onClick="show_ldap_config()" value="<?=gettext("Advanced");?>"></input> - <?=gettext("Show LDAP configuration");?></a>
989
				</div>
990
				<div id="showldap" style="display:none">
991
					<input name="ldap" type="text" class="formfld unknown" id="ldap" size="80" value="<?=htmlspecialchars($pconfig['ldap']);?>"><br>
992
					<?=gettext("Leave blank to disable.  Enter a full URI for the LDAP server in the form ldap://ldap.example.com/dc=example,dc=com");?>
993
				</div>
994
			</td>
995
			</tr>
996
			<tr>
997
			<td width="22%" valign="top" class="vncell"><?=gettext("Enable network booting");?></td>
998
			<td width="78%" class="vtable">
999
				<div id="shownetbootbox">
1000
					<input type="button" onClick="show_netboot_config()" value="<?=gettext("Advanced");?>"></input> - <?=gettext("Show Network booting");?></a>
1001
				</div>
1002
				<div id="shownetboot" style="display:none">
1003
					<input valign="middle" type="checkbox" value="yes" name="netboot" id="netboot" <?php if($pconfig['netboot']) echo " checked"; ?>>&nbsp;
1004
					<b><?=gettext("Enables network booting.");?></b>
1005
					<p>
1006
					<?=gettext("Enter the IP of the"); ?> <b><?=gettext("next-server"); ?></b>
1007
					<input name="nextserver" type="text" class="formfld unknown" id="nextserver" size="20" value="<?=htmlspecialchars($pconfig['nextserver']);?>">
1008
					<?=gettext("and the filename");?>
1009
					<input name="filename" type="text" class="formfld unknown" id="filename" size="20" value="<?=htmlspecialchars($pconfig['filename']);?>"><br>
1010
					<?=gettext("Note: You need both a filename and a boot server configured for this to work!");?>
1011
					<p>
1012
					<?=gettext("Enter the"); ?> <b><?=gettext("root-path"); ?></b>-<?=gettext("string");?>
1013
					<input name="rootpath" type="text" class="formfld unknown" id="rootpath" size="90" value="<?=htmlspecialchars($pconfig['rootpath']);?>"><br>
1014
					<?=gettext("Note: string-format: iscsi:(servername):(protocol):(port):(LUN):targetname");?>
1015
				</div>
1016
			</td>
1017
			</tr>
1018
			<?php if (!is_numeric($pool) && !($act == "newpool")): ?>
1019
			<tr>
1020
			<td width="22%" valign="top" class="vncell"><?=gettext("Additional BOOTP/DHCP Options");?></td>
1021
			<td width="78%" class="vtable">
1022
				<div id="shownumbervaluebox">
1023
					<input type="button" onClick="show_shownumbervalue()" value="<?=gettext("Advanced");?>"></input> - <?=gettext("Show Additional BOOTP/DHCP Options");?></a>
1024
				</div>
1025
				<div id="shownumbervalue" style="display:none">
1026
				<table id="maintable">
1027
				<tbody>
1028
				<tr>
1029
				<td colspan="3">
1030
					<div style="padding:5px; margin-top: 16px; margin-bottom: 16px; border:1px dashed #000066; background-color: #ffffff; color: #000000; font-size: 8pt;" id="itemhelp">
1031
					<?=gettext("Enter the DHCP option number and the value for each item you would like to include in the DHCP lease information.  For a list of available options please visit this"); ?> <a href="http://www.iana.org/assignments/bootp-dhcp-parameters/" target="_new"><?=gettext("URL"); ?></a>
1032
					</div>
1033
				</td>
1034
				</tr>
1035
				<tr>
1036
				<td><div id="onecolumn"><?=gettext("Number");?></div></td>
1037
				<td><div id="twocolumn"><?=gettext("Type");?></div></td>
1038
				<td><div id="threecolumn"><?=gettext("Value");?></div></td>
1039
				</tr>
1040
				<?php $counter = 0; ?>
1041
				<?php
1042
					if($pconfig['numberoptions'])
1043
						foreach($pconfig['numberoptions']['item'] as $item):
1044
				?>
1045
					<?php
1046
						$number = $item['number'];
1047
						$itemtype = $item['type'];
1048
						$value = $item['value'];
1049
					?>
1050
				<tr>
1051
				<td>
1052
					<input autocomplete="off" name="number<?php echo $counter; ?>" type="text" class="formfld unknown" id="number<?php echo $counter; ?>" size="10" value="<?=htmlspecialchars($number);?>" />
1053
				</td>
1054
				<td>
1055
					<select name="itemtype<?php echo $counter; ?>" class="formselect" id="itemtype<?php echo $counter; ?>">
1056
					<?php
1057
					foreach ($customitemtypes as $typename => $typedescr) {
1058
						echo "<option value=\"{$typename}\" ";
1059
						if ($itemtype == $typename) echo "selected";
1060
						echo ">" . $typedescr . "</option>";
1061
					}
1062
					?>
1063
					</select>
1064
				</td>
1065
				<td>
1066
					<input autocomplete="off" name="value<?php echo $counter; ?>" type="text" class="formfld unknown" id="value<?php echo $counter; ?>" size="40" value="<?=htmlspecialchars($value);?>" />
1067
				</td>
1068
				<td>
1069
					<a onclick="removeRow(this); return false;" href="#"><img border="0" src="/themes/<?echo $g['theme'];?>/images/icons/icon_x.gif" /></a>
1070
				</td>
1071
				</tr>
1072
				<?php $counter++; ?>
1073
				<?php endforeach; ?>
1074
				</tbody>
1075
				<tfoot>
1076
				</tfoot>
1077
				</table>
1078
				<a onclick="javascript:addRowTo('maintable', 'formfldalias'); return false;" href="#">
1079
					<img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="<?=gettext("add another entry");?>" />
1080
				</a>
1081
				<script type="text/javascript">
1082
					field_counter_js = 3;
1083
					rows = 1;
1084
					totalrows = <?php echo $counter; ?>;
1085
					loaded = <?php echo $counter; ?>;
1086
				</script>
1087
				</div>
1088

    
1089
				</td>
1090
			</tr>
1091
			<?php endif; ?>
1092
			<tr>
1093
			<td width="22%" valign="top">&nbsp;</td>
1094
			<td width="78%">
1095
				<?php if ($act == "newpool"): ?>
1096
				<input type="hidden" name="act" value="newpool">
1097
				<?php endif; ?>
1098
				<?php if (is_numeric($pool)): ?>
1099
				<input type="hidden" name="pool" value="<?php echo $pool; ?>">
1100
				<?php endif; ?>
1101
				<input name="if" type="hidden" value="<?=htmlspecialchars($if);?>">
1102
				<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" onclick="enable_change(true)">
1103
			</td>
1104
			</tr>
1105
			<tr>
1106
			<td width="22%" valign="top">&nbsp;</td>
1107
			<td width="78%"> <p><span class="vexpl"><span class="red"><strong><?=gettext("Note:");?><br>
1108
				</strong></span><?=gettext("The DNS servers entered in"); ?> <a href="system.php"><?=gettext("System: " .
1109
				"General setup"); ?></a> <?=gettext("(or the"); ?> <a href="services_dnsmasq.php"><?=gettext("DNS " .
1110
				"forwarder"); ?></a>, <?=gettext("if enabled)"); ?> </span><span class="vexpl"><?=gettext("will " .
1111
				"be assigned to clients by the DHCP server."); ?><br>
1112
				<br>
1113
				<?=gettext("The DHCP lease table can be viewed on the"); ?> <a href="status_dhcp_leases.php"><?=gettext("Status: " .
1114
				"DHCP leases"); ?></a> <?=gettext("page."); ?><br>
1115
				</span></p>
1116
			</td>
1117
			</tr>
1118
		</table>
1119
		<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
1120
		<tr>
1121
			<td width="25%" class="listhdrr"><?=gettext("MAC address");?></td>
1122
			<td width="15%" class="listhdrr"><?=gettext("IP address");?></td>
1123
			<td width="20%" class="listhdrr"><?=gettext("Hostname");?></td>
1124
			<td width="30%" class="listhdr"><?=gettext("Description");?></td>
1125
			<td width="10%" class="list">
1126
			<table border="0" cellspacing="0" cellpadding="1">
1127
			<tr>
1128
			<td valign="middle" width="17"></td>
1129
			<td valign="middle"><a href="services_dhcp_edit.php?if=<?=htmlspecialchars($if);?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td>
1130
			</tr>
1131
			</table>
1132
			</td>
1133
		</tr>
1134
			<?php if(is_array($a_maps)): ?>
1135
			<?php $i = 0; foreach ($a_maps as $mapent): ?>
1136
			<?php if($mapent['mac'] <> "" or $mapent['ipaddr'] <> ""): ?>
1137
		<tr>
1138
		<td class="listlr" ondblclick="document.location='services_dhcp_edit.php?if=<?=htmlspecialchars($if);?>&id=<?=$i;?>';">
1139
			<?=htmlspecialchars($mapent['mac']);?>
1140
		</td>
1141
		<td class="listr" ondblclick="document.location='services_dhcp_edit.php?if=<?=htmlspecialchars($if);?>&id=<?=$i;?>';">
1142
			<?=htmlspecialchars($mapent['ipaddr']);?>&nbsp;
1143
		</td>
1144
		<td class="listr" ondblclick="document.location='services_dhcp_edit.php?if=<?=htmlspecialchars($if);?>&id=<?=$i;?>';">
1145
			<?=htmlspecialchars($mapent['hostname']);?>&nbsp;
1146
		</td>
1147
		<td class="listbg" ondblclick="document.location='services_dhcp_edit.php?if=<?=htmlspecialchars($if);?>&id=<?=$i;?>';">
1148
			<?=htmlspecialchars($mapent['descr']);?>&nbsp;
1149
		</td>
1150
		<td valign="middle" nowrap class="list">
1151
			<table border="0" cellspacing="0" cellpadding="1">
1152
			<tr>
1153
			<td valign="middle"><a href="services_dhcp_edit.php?if=<?=htmlspecialchars($if);?>&id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0"></a></td>
1154
			<td valign="middle"><a href="services_dhcp.php?if=<?=htmlspecialchars($if);?>&act=del&id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this mapping?");?>')"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0"></a></td>
1155
			</tr>
1156
			</table>
1157
		</td>
1158
		</tr>
1159
		<?php endif; ?>
1160
		<?php $i++; endforeach; ?>
1161
		<?php endif; ?>
1162
		<tr>
1163
		<td class="list" colspan="4"></td>
1164
		<td class="list">
1165
			<table border="0" cellspacing="0" cellpadding="1">
1166
			<tr>
1167
			<td valign="middle" width="17"></td>
1168
			<td valign="middle"><a href="services_dhcp_edit.php?if=<?=htmlspecialchars($if);?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td>
1169
			</tr>
1170
			</table>
1171
		</td>
1172
		</tr>
1173
		</table>
1174
	</div>
1175
</td>
1176
</tr>
1177
</table>
1178
</form>
1179
<script language="JavaScript">
1180
<!--
1181
enable_change(false);
1182
//-->
1183
</script>
1184
<?php include("fend.inc"); ?>
1185
</body>
1186
</html>
(148-148/249)