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

    
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 validate_partial_mac_list($maclist) {
203
	$macs = explode(',', $maclist);
204

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

    
212
if ($_POST) {
213

    
214
	unset($input_errors);
215

    
216
	$pconfig = $_POST;
217

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
475
		write_config();
476

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

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

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

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

    
528
include("head.inc");
529

    
530
?>
531

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

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

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

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

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

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

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

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

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

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

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

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

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