Project

General

Profile

Download (51.5 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
	} else {
167
		// Options that exist only in pools
168
		$pconfig['descr'] = $dhcpdconf['descr'];
169
	}
170

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

    
199
$ifcfgip = $config['interfaces'][$if]['ipaddr'];
200
$ifcfgsn = $config['interfaces'][$if]['subnet'];
201

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

    
209
function validate_partial_mac_list($maclist) {
210
	$macs = explode(',', $maclist);
211

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

    
219
if ($_POST) {
220

    
221
	unset($input_errors);
222

    
223
	$pconfig = $_POST;
224

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

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

    
243
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
244

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
467
		write_config();
468

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

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

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

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

    
520
include("head.inc");
521

    
522
?>
523

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

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

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

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

    
588
	function show_shownumbervalue() {
589
		document.getElementById("shownumbervaluebox").innerHTML='';
590
		aodiv = document.getElementById('shownumbervalue');
591
		aodiv.style.display = "block";
592
	}
593

    
594
	function show_ddns_config() {
595
		document.getElementById("showddnsbox").innerHTML='';
596
		aodiv = document.getElementById('showddns');
597
		aodiv.style.display = "block";
598
	}
599

    
600
	function show_maccontrol_config() {
601
		document.getElementById("showmaccontrolbox").innerHTML='';
602
		aodiv = document.getElementById('showmaccontrol');
603
		aodiv.style.display = "block";
604
	}
605

    
606
	function show_ntp_config() {
607
		document.getElementById("showntpbox").innerHTML='';
608
		aodiv = document.getElementById('showntp');
609
		aodiv.style.display = "block";
610
	}
611

    
612
	function show_tftp_config() {
613
		document.getElementById("showtftpbox").innerHTML='';
614
		aodiv = document.getElementById('showtftp');
615
		aodiv.style.display = "block";
616
	}
617

    
618
	function show_ldap_config() {
619
		document.getElementById("showldapbox").innerHTML='';
620
		aodiv = document.getElementById('showldap');
621
		aodiv.style.display = "block";
622
	}
623

    
624
	function show_netboot_config() {
625
		document.getElementById("shownetbootbox").innerHTML='';
626
		aodiv = document.getElementById('shownetboot');
627
		aodiv.style.display = "block";
628
	}
629
</script>
630

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

    
1105
				</td>
1106
			</tr>
1107
			<?php endif; ?>
1108
			<tr>
1109
			<td width="22%" valign="top">&nbsp;</td>
1110
			<td width="78%">
1111
				<?php if ($act == "newpool"): ?>
1112
				<input type="hidden" name="act" value="newpool">
1113
				<?php endif; ?>
1114
				<?php if (is_numeric($pool)): ?>
1115
				<input type="hidden" name="pool" value="<?php echo $pool; ?>">
1116
				<?php endif; ?>
1117
				<input name="if" type="hidden" value="<?=htmlspecialchars($if);?>">
1118
				<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" onclick="enable_change(true)">
1119
			</td>
1120
			</tr>
1121
			<tr>
1122
			<td width="22%" valign="top">&nbsp;</td>
1123
			<td width="78%"> <p><span class="vexpl"><span class="red"><strong><?=gettext("Note:");?><br>
1124
				</strong></span><?=gettext("The DNS servers entered in"); ?> <a href="system.php"><?=gettext("System: " .
1125
				"General setup"); ?></a> <?=gettext("(or the"); ?> <a href="services_dnsmasq.php"><?=gettext("DNS " .
1126
				"forwarder"); ?></a>, <?=gettext("if enabled)"); ?> </span><span class="vexpl"><?=gettext("will " .
1127
				"be assigned to clients by the DHCP server."); ?><br>
1128
				<br>
1129
				<?=gettext("The DHCP lease table can be viewed on the"); ?> <a href="status_dhcp_leases.php"><?=gettext("Status: " .
1130
				"DHCP leases"); ?></a> <?=gettext("page."); ?><br>
1131
				</span></p>
1132
			</td>
1133
			</tr>
1134
		</table>
1135
		<?php if (!is_numeric($pool) && !($act == "newpool")): ?>
1136
		<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
1137
		<tr>
1138
			<td width="7%" class="listhdrr"><?=gettext("Static ARP");?></td>
1139
			<td width="18%" class="listhdrr"><?=gettext("MAC address");?></td>
1140
			<td width="15%" class="listhdrr"><?=gettext("IP address");?></td>
1141
			<td width="20%" class="listhdrr"><?=gettext("Hostname");?></td>
1142
			<td width="30%" class="listhdr"><?=gettext("Description");?></td>
1143
			<td width="10%" class="list">
1144
			<table border="0" cellspacing="0" cellpadding="1">
1145
			<tr>
1146
			<td valign="middle" width="17"></td>
1147
			<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>
1148
			</tr>
1149
			</table>
1150
			</td>
1151
		</tr>
1152
			<?php if(is_array($a_maps)): ?>
1153
			<?php $i = 0; foreach ($a_maps as $mapent): ?>
1154
			<?php if($mapent['mac'] <> "" or $mapent['ipaddr'] <> ""): ?>
1155
		<tr>
1156
		<td align="center" class="listlr" ondblclick="document.location='services_dhcp_edit.php?if=<?=htmlspecialchars($if);?>&id=<?=$i;?>';">
1157
			<?php if (isset($mapent['arp_table_static_entry'])): ?>
1158
				<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_alert.gif" alt="ARP Table Static Entry" width="17" height="17" border="0">
1159
			<?php endif; ?>
1160
		</td>
1161
		<td class="listlr" ondblclick="document.location='services_dhcp_edit.php?if=<?=htmlspecialchars($if);?>&id=<?=$i;?>';">
1162
			<?=htmlspecialchars($mapent['mac']);?>
1163
		</td>
1164
		<td class="listr" ondblclick="document.location='services_dhcp_edit.php?if=<?=htmlspecialchars($if);?>&id=<?=$i;?>';">
1165
			<?=htmlspecialchars($mapent['ipaddr']);?>&nbsp;
1166
		</td>
1167
		<td class="listr" ondblclick="document.location='services_dhcp_edit.php?if=<?=htmlspecialchars($if);?>&id=<?=$i;?>';">
1168
			<?=htmlspecialchars($mapent['hostname']);?>&nbsp;
1169
		</td>
1170
		<td class="listbg" ondblclick="document.location='services_dhcp_edit.php?if=<?=htmlspecialchars($if);?>&id=<?=$i;?>';">
1171
			<?=htmlspecialchars($mapent['descr']);?>&nbsp;
1172
		</td>
1173
		<td valign="middle" nowrap class="list">
1174
			<table border="0" cellspacing="0" cellpadding="1">
1175
			<tr>
1176
			<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>
1177
			<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>
1178
			</tr>
1179
			</table>
1180
		</td>
1181
		</tr>
1182
		<?php endif; ?>
1183
		<?php $i++; endforeach; ?>
1184
		<?php endif; ?>
1185
		<tr>
1186
		<td class="list" colspan="5"></td>
1187
		<td class="list">
1188
			<table border="0" cellspacing="0" cellpadding="1">
1189
			<tr>
1190
			<td valign="middle" width="17"></td>
1191
			<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>
1192
			</tr>
1193
			</table>
1194
		</td>
1195
		</tr>
1196
		</table>
1197
		<?php endif; ?>
1198
	</div>
1199
</td>
1200
</tr>
1201
</table>
1202
</form>
1203
<script language="JavaScript">
1204
<!--
1205
enable_change(false);
1206
//-->
1207
</script>
1208
<?php include("fend.inc"); ?>
1209
</body>
1210
</html>
(148-148/249)