Project

General

Profile

Download (50 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
function is_inrange($test, $start, $end) {
200
	if ( (ip2ulong($test) < ip2ulong($end)) && (ip2ulong($test) > ip2ulong($start)) )
201
		return true;
202
	else
203
		return false;
204
}
205

    
206
function validate_partial_mac_list($maclist) {
207
	$macs = explode(',', $maclist);
208

    
209
	// Loop through and look for invalid MACs.
210
	foreach ($macs as $mac)
211
		if (!is_macaddr($mac, true))
212
			return false;
213
	return true;
214
}
215

    
216
if ($_POST) {
217

    
218
	unset($input_errors);
219

    
220
	$pconfig = $_POST;
221

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

    
235
	/* input validation */
236
	if ($_POST['enable'] || is_numeric($pool) || $act == "newpool") {
237
		$reqdfields = explode(" ", "range_from range_to");
238
		$reqdfieldsn = array(gettext("Range begin"),gettext("Range end"));
239

    
240
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
241

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

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

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

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

    
290
		if(gen_subnet($ifcfgip, $ifcfgsn) == $_POST['range_from'])
291
			$input_errors[] = gettext("You cannot use the network address in the starting subnet range.");
292
		if(gen_subnet_max($ifcfgip, $ifcfgsn) == $_POST['range_to'])
293
			$input_errors[] = gettext("You cannot use the broadcast address in the ending subnet range.");
294

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

    
304
		$noip = false;
305
		if(is_array($a_maps))
306
			foreach ($a_maps as $map)
307
				if (empty($map['ipaddr']))
308
					$noip = true;
309
		if ($_POST['staticarp'] && $noip)
310
			$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.";
311

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

    
337
		if (!$input_errors) {
338
			/* make sure the range lies within the current subnet */
339
			$subnet_start = ip2ulong(long2ip32(ip2long($ifcfgip) & gen_subnet_mask_long($ifcfgsn)));
340
			$subnet_end = ip2ulong(long2ip32(ip2long($ifcfgip) | (~gen_subnet_mask_long($ifcfgsn))));
341

    
342
			if ((ip2ulong($_POST['range_from']) < $subnet_start) || (ip2ulong($_POST['range_from']) > $subnet_end) ||
343
			    (ip2ulong($_POST['range_to']) < $subnet_start) || (ip2ulong($_POST['range_to']) > $subnet_end)) {
344
				$input_errors[] = gettext("The specified range lies outside of the current subnet.");
345
			}
346

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

    
350
			// TODO: Ensure range and pools do not overlap!
351
			// If we're editing the main range, check pools
352
			// If we're editing a pool, locate parent range and other pools.
353

    
354
			/* make sure that the DHCP Relay isn't enabled on this interface */
355
			if (isset($config['dhcrelay']['enable']) && (stristr($config['dhcrelay']['interface'], $if) !== false))
356
				$input_errors[] = sprintf(gettext("You must disable the DHCP relay on the %s interface before enabling the DHCP server."),$iflist[$if]);
357

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

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

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

    
406
		// Options that can be global or per-pool.
407
		$dhcpdconf['range']['from'] = $_POST['range_from'];
408
		$dhcpdconf['range']['to'] = $_POST['range_to'];
409
		$dhcpdconf['defaultleasetime'] = $_POST['deftime'];
410
		$dhcpdconf['maxleasetime'] = $_POST['maxtime'];
411
		$dhcpdconf['netmask'] = $_POST['netmask'];
412

    
413
		unset($dhcpdconf['winsserver']);
414
		if ($_POST['wins1'])
415
			$dhcpdconf['winsserver'][] = $_POST['wins1'];
416
		if ($_POST['wins2'])
417
			$dhcpdconf['winsserver'][] = $_POST['wins2'];
418

    
419
		unset($dhcpdconf['dnsserver']);
420
		if ($_POST['dns1'])
421
			$dhcpdconf['dnsserver'][] = $_POST['dns1'];
422
		if ($_POST['dns2'])
423
			$dhcpdconf['dnsserver'][] = $_POST['dns2'];
424

    
425
		$dhcpdconf['gateway'] = $_POST['gateway'];
426
		$dhcpdconf['domain'] = $_POST['domain'];
427
		$dhcpdconf['domainsearchlist'] = $_POST['domainsearchlist'];
428
		$dhcpdconf['denyunknown'] = ($_POST['denyunknown']) ? true : false;
429
		$dhcpdconf['ddnsdomain'] = $_POST['ddnsdomain'];
430
		$dhcpdconf['ddnsupdate'] = ($_POST['ddnsupdate']) ? true : false;
431
		$dhcpdconf['mac_allow'] = $_POST['mac_allow'];
432
		$dhcpdconf['mac_deny'] = $_POST['mac_deny'];
433

    
434
		unset($dhcpdconf['ntpserver']);
435
		if ($_POST['ntp1'])
436
			$dhcpdconf['ntpserver'][] = $_POST['ntp1'];
437
		if ($_POST['ntp2'])
438
			$dhcpdconf['ntpserver'][] = $_POST['ntp2'];
439

    
440
		$dhcpdconf['tftp'] = $_POST['tftp'];
441
		$dhcpdconf['ldap'] = $_POST['ldap'];
442
		$dhcpdconf['netboot'] = ($_POST['netboot']) ? true : false;
443
		$dhcpdconf['nextserver'] = $_POST['nextserver'];
444
		$dhcpdconf['filename'] = $_POST['filename'];
445
		$dhcpdconf['rootpath'] = $_POST['rootpath'];
446

    
447
		// Handle the custom options rowhelper
448
		if(isset($dhcpdconf['numberoptions']['item']))
449
			unset($dhcpdconf['numberoptions']['item']);
450

    
451
		$dhcpdconf['numberoptions'] = $numberoptions;
452

    
453
		if (is_numeric($pool) && is_array($a_pools[$pool])) {
454
			$a_pools[$pool] = $dhcpdconf;
455
		} elseif ($act == "newpool") {
456
			$a_pools[] = $dhcpdconf;
457
		} else {
458
			$config['dhcpd'][$if] = $dhcpdconf;
459
		}
460

    
461
		write_config();
462

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

    
488
if ($act == "delpool") {
489
	if ($a_pools[$_GET['id']]) {
490
		unset($a_pools[$_GET['id']]);
491
		write_config();
492
		header("Location: services_dhcp.php?if={$if}");
493
		exit;
494
	}
495
}
496

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

    
511
$pgtitle = array(gettext("Services"),gettext("DHCP server"));
512
$shortcut_section = "dhcp";
513

    
514
include("head.inc");
515

    
516
?>
517

    
518
<script type="text/javascript" src="/javascript/row_helper.js">
519
</script>
520

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

    
533
	rowname[0] = "number";
534
	rowtype[0] = "textbox";
535
	rowsize[0] = "10";
536
	rowname[1] = "itemtype";
537
	rowtype[1] = itemtype_field;
538
	rowname[2] = "value";
539
	rowtype[2] = "textbox";
540
	rowsize[2] = "40";
541
</script>
542

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

    
579
	function show_shownumbervalue() {
580
		document.getElementById("shownumbervaluebox").innerHTML='';
581
		aodiv = document.getElementById('shownumbervalue');
582
		aodiv.style.display = "block";
583
	}
584

    
585
	function show_ddns_config() {
586
		document.getElementById("showddnsbox").innerHTML='';
587
		aodiv = document.getElementById('showddns');
588
		aodiv.style.display = "block";
589
	}
590

    
591
	function show_maccontrol_config() {
592
		document.getElementById("showmaccontrolbox").innerHTML='';
593
		aodiv = document.getElementById('showmaccontrol');
594
		aodiv.style.display = "block";
595
	}
596

    
597
	function show_ntp_config() {
598
		document.getElementById("showntpbox").innerHTML='';
599
		aodiv = document.getElementById('showntp');
600
		aodiv.style.display = "block";
601
	}
602

    
603
	function show_tftp_config() {
604
		document.getElementById("showtftpbox").innerHTML='';
605
		aodiv = document.getElementById('showtftp');
606
		aodiv.style.display = "block";
607
	}
608

    
609
	function show_ldap_config() {
610
		document.getElementById("showldapbox").innerHTML='';
611
		aodiv = document.getElementById('showldap');
612
		aodiv.style.display = "block";
613
	}
614

    
615
	function show_netboot_config() {
616
		document.getElementById("shownetbootbox").innerHTML='';
617
		aodiv = document.getElementById('shownetboot');
618
		aodiv.style.display = "block";
619
	}
620
</script>
621

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

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