Project

General

Profile

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

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

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

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

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

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

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

    
43
require("guiconfig.inc");
44

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

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

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

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

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

    
113
$iflist = get_configured_interface_with_descr();
114

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

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

    
131
$a_pools = array();
132

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

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

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

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

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

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

    
203
function validate_partial_mac_list($maclist) {
204
	$macs = explode(',', $maclist);
205

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

    
213
if ($_POST) {
214

    
215
	unset($input_errors);
216

    
217
	$pconfig = $_POST;
218

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

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

    
237
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
238

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

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

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

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

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

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

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

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

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

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

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

    
347
			if (is_numeric($pool) || ($act == "newpool")) {
348
				$rfrom = $config['dhcpd'][$if]['range']['from'];
349
				$rto = $config['dhcpd'][$if]['range']['to'];
350

    
351
				if (is_inrange_v4($_POST['range_from'], $rfrom, $rto) || is_inrange_v4($_POST['range_to'], $rfrom, $rto))
352
					$input_errors[] = gettext("The specified range must not be within the DHCP range for this interface.");
353
			}
354

    
355
			foreach ($a_pools as $id => $p) {
356
				if (is_numeric($pool) && ($id == $pool))
357
					continue;
358

    
359
				if (is_inrange_v4($_POST['range_from'], $p['range']['from'], $p['range']['to']) ||
360
				    is_inrange_v4($_POST['range_to'], $p['range']['from'], $p['range']['to'])) {
361
					$input_errors[] = gettext("The specified range must not be within the range configured on a DHCP pool for this interface.");
362
					break;
363
				}
364
			}
365

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

    
370
			$dynsubnet_start = ip2ulong($_POST['range_from']);
371
			$dynsubnet_end = ip2ulong($_POST['range_to']);
372
			if (is_array($a_maps)) {
373
				foreach ($a_maps as $map) {
374
					if (empty($map['ipaddr']))
375
						continue;
376
					if ((ip2ulong($map['ipaddr']) > $dynsubnet_start) &&
377
						(ip2ulong($map['ipaddr']) < $dynsubnet_end)) {
378
						$input_errors[] = sprintf(gettext("The DHCP range cannot overlap any static DHCP mappings."));
379
						break;
380
					}
381
				}
382
			}
383
		}
384
	}
385

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

    
407
		// Global Options
408
		if (!is_numeric($pool) && !($act == "newpool")) {
409
			$dhcpdconf['enable'] = ($_POST['enable']) ? true : false;
410
			$dhcpdconf['staticarp'] = ($_POST['staticarp']) ? true : false;
411
			$previous = $dhcpdconf['failover_peerip'];
412
			if($previous <> $_POST['failover_peerip'])
413
				mwexec("/bin/rm -rf /var/dhcpd/var/db/*");
414
			$dhcpdconf['failover_peerip'] = $_POST['failover_peerip'];
415
			$dhcpdconf['dhcpleaseinlocaltime'] = $_POST['dhcpleaseinlocaltime'];
416
		} else {
417
			// Options that exist only in pools
418
			$dhcpdconf['descr'] = $_POST['descr'];
419
		}
420

    
421
		// Options that can be global or per-pool.
422
		$dhcpdconf['range']['from'] = $_POST['range_from'];
423
		$dhcpdconf['range']['to'] = $_POST['range_to'];
424
		$dhcpdconf['defaultleasetime'] = $_POST['deftime'];
425
		$dhcpdconf['maxleasetime'] = $_POST['maxtime'];
426
		$dhcpdconf['netmask'] = $_POST['netmask'];
427

    
428
		unset($dhcpdconf['winsserver']);
429
		if ($_POST['wins1'])
430
			$dhcpdconf['winsserver'][] = $_POST['wins1'];
431
		if ($_POST['wins2'])
432
			$dhcpdconf['winsserver'][] = $_POST['wins2'];
433

    
434
		unset($dhcpdconf['dnsserver']);
435
		if ($_POST['dns1'])
436
			$dhcpdconf['dnsserver'][] = $_POST['dns1'];
437
		if ($_POST['dns2'])
438
			$dhcpdconf['dnsserver'][] = $_POST['dns2'];
439

    
440
		$dhcpdconf['gateway'] = $_POST['gateway'];
441
		$dhcpdconf['domain'] = $_POST['domain'];
442
		$dhcpdconf['domainsearchlist'] = $_POST['domainsearchlist'];
443
		$dhcpdconf['denyunknown'] = ($_POST['denyunknown']) ? true : false;
444
		$dhcpdconf['ddnsdomain'] = $_POST['ddnsdomain'];
445
		$dhcpdconf['ddnsupdate'] = ($_POST['ddnsupdate']) ? true : false;
446
		$dhcpdconf['mac_allow'] = $_POST['mac_allow'];
447
		$dhcpdconf['mac_deny'] = $_POST['mac_deny'];
448

    
449
		unset($dhcpdconf['ntpserver']);
450
		if ($_POST['ntp1'])
451
			$dhcpdconf['ntpserver'][] = $_POST['ntp1'];
452
		if ($_POST['ntp2'])
453
			$dhcpdconf['ntpserver'][] = $_POST['ntp2'];
454

    
455
		$dhcpdconf['tftp'] = $_POST['tftp'];
456
		$dhcpdconf['ldap'] = $_POST['ldap'];
457
		$dhcpdconf['netboot'] = ($_POST['netboot']) ? true : false;
458
		$dhcpdconf['nextserver'] = $_POST['nextserver'];
459
		$dhcpdconf['filename'] = $_POST['filename'];
460
		$dhcpdconf['rootpath'] = $_POST['rootpath'];
461

    
462
		// Handle the custom options rowhelper
463
		if(isset($dhcpdconf['numberoptions']['item']))
464
			unset($dhcpdconf['numberoptions']['item']);
465

    
466
		$dhcpdconf['numberoptions'] = $numberoptions;
467

    
468
		if (is_numeric($pool) && is_array($a_pools[$pool])) {
469
			$a_pools[$pool] = $dhcpdconf;
470
		} elseif ($act == "newpool") {
471
			$a_pools[] = $dhcpdconf;
472
		} else {
473
			$config['dhcpd'][$if] = $dhcpdconf;
474
		}
475

    
476
		write_config();
477

    
478
		$retval = 0;
479
		$retvaldhcp = 0;
480
		$retvaldns = 0;
481
		/* Stop DHCP so we can cleanup leases */
482
		killbyname("dhcpd");
483
		dhcp_clean_leases();
484
		/* dnsmasq_configure calls dhcpd_configure */
485
		/* no need to restart dhcpd twice */
486
		if (isset($config['dnsmasq']['regdhcpstatic']))	{
487
			$retvaldns = services_dnsmasq_configure();
488
			if ($retvaldns == 0) {
489
				clear_subsystem_dirty('hosts');
490
				clear_subsystem_dirty('staticmaps');
491
			}
492
		} else {
493
			$retvaldhcp = services_dhcpd_configure();
494
			if ($retvaldhcp == 0)
495
				clear_subsystem_dirty('staticmaps');
496
		}
497
		if($retvaldhcp == 1 || $retvaldns == 1)
498
			$retval = 1;
499
		$savemsg = get_std_save_message($retval);
500
	}
501
}
502

    
503
if ($act == "delpool") {
504
	if ($a_pools[$_GET['id']]) {
505
		unset($a_pools[$_GET['id']]);
506
		write_config();
507
		header("Location: services_dhcp.php?if={$if}");
508
		exit;
509
	}
510
}
511

    
512
if ($act == "del") {
513
	if ($a_maps[$_GET['id']]) {
514
		unset($a_maps[$_GET['id']]);
515
		write_config();
516
		if(isset($config['dhcpd'][$if]['enable'])) {
517
			mark_subsystem_dirty('staticmaps');
518
			if (isset($config['dnsmasq']['regdhcpstatic']))
519
				mark_subsystem_dirty('hosts');
520
		}
521
		header("Location: services_dhcp.php?if={$if}");
522
		exit;
523
	}
524
}
525

    
526
$pgtitle = array(gettext("Services"),gettext("DHCP server"));
527
$shortcut_section = "dhcp";
528

    
529
include("head.inc");
530

    
531
?>
532

    
533
<script type="text/javascript" src="/javascript/row_helper.js">
534
</script>
535

    
536
<script type="text/javascript">
537
	function itemtype_field(fieldname, fieldsize, n) {
538
		return '<select name="' + fieldname + n + '" class="formselect" id="' + fieldname + n + '"><?php
539
			$customitemtypes = array('text' => gettext('Text'), 'string' => gettext('String'), 'boolean' => gettext('Boolean'),
540
				'unsigned integer 8' => gettext('Unsigned 8-bit integer'), 'unsigned integer 16' => gettext('Unsigned 16-bit integer'), 'unsigned integer 32' => gettext('Unsigned 32-bit integer'),
541
				'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'));
542
			foreach ($customitemtypes as $typename => $typedescr) {
543
				echo "<option value=\"{$typename}\">{$typedescr}</option>";
544
			}
545
		?></select>';
546
	}
547

    
548
	rowname[0] = "number";
549
	rowtype[0] = "textbox";
550
	rowsize[0] = "10";
551
	rowname[1] = "itemtype";
552
	rowtype[1] = itemtype_field;
553
	rowname[2] = "value";
554
	rowtype[2] = "textbox";
555
	rowsize[2] = "40";
556
</script>
557

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

    
597
	function show_shownumbervalue() {
598
		document.getElementById("shownumbervaluebox").innerHTML='';
599
		aodiv = document.getElementById('shownumbervalue');
600
		aodiv.style.display = "block";
601
	}
602

    
603
	function show_ddns_config() {
604
		document.getElementById("showddnsbox").innerHTML='';
605
		aodiv = document.getElementById('showddns');
606
		aodiv.style.display = "block";
607
	}
608

    
609
	function show_maccontrol_config() {
610
		document.getElementById("showmaccontrolbox").innerHTML='';
611
		aodiv = document.getElementById('showmaccontrol');
612
		aodiv.style.display = "block";
613
	}
614

    
615
	function show_ntp_config() {
616
		document.getElementById("showntpbox").innerHTML='';
617
		aodiv = document.getElementById('showntp');
618
		aodiv.style.display = "block";
619
	}
620

    
621
	function show_tftp_config() {
622
		document.getElementById("showtftpbox").innerHTML='';
623
		aodiv = document.getElementById('showtftp');
624
		aodiv.style.display = "block";
625
	}
626

    
627
	function show_ldap_config() {
628
		document.getElementById("showldapbox").innerHTML='';
629
		aodiv = document.getElementById('showldap');
630
		aodiv.style.display = "block";
631
	}
632

    
633
	function show_netboot_config() {
634
		document.getElementById("shownetbootbox").innerHTML='';
635
		aodiv = document.getElementById('shownetboot');
636
		aodiv.style.display = "block";
637
	}
638
</script>
639

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

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