Project

General

Profile

Download (43.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 ($_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
if (is_array($config['dhcpd'][$if])){
128
	if (is_array($config['dhcpd'][$if]['range'])) {
129
		$pconfig['range_from'] = $config['dhcpd'][$if]['range']['from'];
130
		$pconfig['range_to'] = $config['dhcpd'][$if]['range']['to'];
131
	}
132
	$pconfig['deftime'] = $config['dhcpd'][$if]['defaultleasetime'];
133
	$pconfig['maxtime'] = $config['dhcpd'][$if]['maxleasetime'];
134
	$pconfig['gateway'] = $config['dhcpd'][$if]['gateway'];
135
	$pconfig['domain'] = $config['dhcpd'][$if]['domain'];
136
	$pconfig['domainsearchlist'] = $config['dhcpd'][$if]['domainsearchlist'];
137
	list($pconfig['wins1'],$pconfig['wins2']) = $config['dhcpd'][$if]['winsserver'];
138
	list($pconfig['dns1'],$pconfig['dns2']) = $config['dhcpd'][$if]['dnsserver'];
139
	$pconfig['enable'] = isset($config['dhcpd'][$if]['enable']);
140
	$pconfig['denyunknown'] = isset($config['dhcpd'][$if]['denyunknown']);
141
	$pconfig['staticarp'] = isset($config['dhcpd'][$if]['staticarp']);
142
	$pconfig['ddnsdomain'] = $config['dhcpd'][$if]['ddnsdomain'];
143
	$pconfig['ddnsupdate'] = isset($config['dhcpd'][$if]['ddnsupdate']);
144
	list($pconfig['ntp1'],$pconfig['ntp2']) = $config['dhcpd'][$if]['ntpserver'];
145
	$pconfig['tftp'] = $config['dhcpd'][$if]['tftp'];
146
	$pconfig['ldap'] = $config['dhcpd'][$if]['ldap'];
147
	$pconfig['netboot'] = isset($config['dhcpd'][$if]['netboot']);
148
	$pconfig['nextserver'] = $config['dhcpd'][$if]['nextserver'];
149
	$pconfig['filename'] = $config['dhcpd'][$if]['filename'];
150
	$pconfig['rootpath'] = $config['dhcpd'][$if]['rootpath'];
151
	$pconfig['failover_peerip'] = $config['dhcpd'][$if]['failover_peerip'];
152
	$pconfig['netmask'] = $config['dhcpd'][$if]['netmask'];
153
	$pconfig['numberoptions'] = $config['dhcpd'][$if]['numberoptions'];
154
	$pconfig['dhcpleaseinlocaltime'] = $config['dhcpd'][$if]['dhcpleaseinlocaltime'];
155
	if (!is_array($config['dhcpd'][$if]['staticmap']))
156
		$config['dhcpd'][$if]['staticmap'] = array();
157
	$a_maps = &$config['dhcpd'][$if]['staticmap'];
158
}
159

    
160
$ifcfgip = $config['interfaces'][$if]['ipaddr'];
161
$ifcfgsn = $config['interfaces'][$if]['subnet'];
162

    
163
/*   set the enabled flag which will tell us if DHCP relay is enabled
164
 *   on any interface. We will use this to disable DHCP server since
165
 *   the two are not compatible with each other.
166
 */
167

    
168
$dhcrelay_enabled = false;
169
$dhcrelaycfg = $config['dhcrelay'];
170

    
171
if(is_array($dhcrelaycfg)) {
172
	foreach ($dhcrelaycfg as $dhcrelayif => $dhcrelayifconf) {
173
		if (isset($dhcrelayifconf['enable']) && isset($iflist[$dhcrelayif]) &&
174
			(!link_interface_to_bridge($dhcrelayif)))
175
			$dhcrelay_enabled = true;
176
	}
177
}
178

    
179
function is_inrange($test, $start, $end) {
180
	if ( (ip2ulong($test) < ip2ulong($end)) && (ip2ulong($test) > ip2ulong($start)) )
181
		return true;
182
	else
183
		return false;
184
}
185

    
186
if ($_POST) {
187

    
188
	unset($input_errors);
189

    
190
	$pconfig = $_POST;
191

    
192
	$numberoptions = array();
193
	for($x=0; $x<99; $x++) {
194
		if(isset($_POST["number{$x}"]) && ctype_digit($_POST["number{$x}"])) {
195
			$numbervalue = array();
196
			$numbervalue['number'] = htmlspecialchars($_POST["number{$x}"]);
197
			$numbervalue['type'] = htmlspecialchars($_POST["itemtype{$x}"]);
198
			$numbervalue['value'] = str_replace('&quot;', '"', htmlspecialchars($_POST["value{$x}"]));
199
			$numberoptions['item'][] = $numbervalue;
200
		}
201
	}
202
	// Reload the new pconfig variable that the forum uses.
203
	$pconfig['numberoptions'] = $numberoptions;
204

    
205
	/* input validation */
206
	if ($_POST['enable']) {
207
		$reqdfields = explode(" ", "range_from range_to");
208
		$reqdfieldsn = array(gettext("Range begin"),gettext("Range end"));
209

    
210
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
211

    
212
		if (($_POST['range_from'] && !is_ipaddrv4($_POST['range_from'])))
213
			$input_errors[] = gettext("A valid range must be specified.");
214
		if (($_POST['range_to'] && !is_ipaddrv4($_POST['range_to'])))
215
			$input_errors[] = gettext("A valid range must be specified.");
216
		if (($_POST['gateway'] && !is_ipaddrv4($_POST['gateway'])))
217
			$input_errors[] = gettext("A valid IP address must be specified for the gateway.");
218
		if (($_POST['wins1'] && !is_ipaddrv4($_POST['wins1'])) || ($_POST['wins2'] && !is_ipaddrv4($_POST['wins2'])))
219
			$input_errors[] = gettext("A valid IP address must be specified for the primary/secondary WINS servers.");
220
		$parent_ip = get_interface_ip($_POST['if']);
221
		if (is_ipaddrv4($parent_ip) && $_POST['gateway']) {
222
			$parent_sn = get_interface_subnet($_POST['if']);
223
			if(!ip_in_subnet($_POST['gateway'], gen_subnet($parent_ip, $parent_sn) . "/" . $parent_sn) && !ip_in_interface_alias_subnet($_POST['if'], $_POST['gateway'])) 
224
				$input_errors[] = sprintf(gettext("The gateway address %s does not lie within the chosen interface's subnet."), $_POST['gateway']);
225
		}
226
		if (($_POST['dns1'] && !is_ipaddrv4($_POST['dns1'])) || ($_POST['dns2'] && !is_ipaddrv4($_POST['dns2'])))
227
			$input_errors[] = gettext("A valid IP address must be specified for the primary/secondary DNS servers.");
228

    
229
		if ($_POST['deftime'] && (!is_numeric($_POST['deftime']) || ($_POST['deftime'] < 60)))
230
			$input_errors[] = gettext("The default lease time must be at least 60 seconds.");
231
		if ($_POST['maxtime'] && (!is_numeric($_POST['maxtime']) || ($_POST['maxtime'] < 60) || ($_POST['maxtime'] <= $_POST['deftime'])))
232
			$input_errors[] = gettext("The maximum lease time must be at least 60 seconds and higher than the default lease time.");
233
		if (($_POST['ddnsdomain'] && !is_domain($_POST['ddnsdomain'])))
234
			$input_errors[] = gettext("A valid domain name must be specified for the dynamic DNS registration.");
235
		if ($_POST['domainsearchlist']) {
236
			$domain_array=preg_split("/[ ;]+/",$_POST['domainsearchlist']);
237
			foreach ($domain_array as $curdomain) {
238
				if (!is_domain($curdomain)) {
239
					$input_errors[] = gettext("A valid domain search list must be specified.");
240
					break;
241
				}
242
			}
243
		}
244
			
245
		if (($_POST['ntp1'] && !is_ipaddrv4($_POST['ntp1'])) || ($_POST['ntp2'] && !is_ipaddrv4($_POST['ntp2'])))
246
			$input_errors[] = gettext("A valid IP address must be specified for the primary/secondary NTP servers.");
247
		if (($_POST['domain'] && !is_domain($_POST['domain'])))
248
			$input_errors[] = gettext("A valid domain name must be specified for the DNS domain.");
249
		if ($_POST['tftp'] && !is_ipaddrv4($_POST['tftp']) && !is_domain($_POST['tftp']) && !is_URL($_POST['tftp']))
250
			$input_errors[] = gettext("A valid IP address or hostname must be specified for the TFTP server.");
251
		if (($_POST['nextserver'] && !is_ipaddrv4($_POST['nextserver'])))
252
			$input_errors[] = gettext("A valid IP address must be specified for the network boot server.");
253

    
254
		if(gen_subnet($ifcfgip, $ifcfgsn) == $_POST['range_from'])
255
			$input_errors[] = gettext("You cannot use the network address in the starting subnet range.");
256
		if(gen_subnet_max($ifcfgip, $ifcfgsn) == $_POST['range_to'])
257
			$input_errors[] = gettext("You cannot use the broadcast address in the ending subnet range.");
258

    
259
		// Disallow a range that includes the virtualip
260
		if (is_array($config['virtualip']['vip'])) {
261
			foreach($config['virtualip']['vip'] as $vip) {
262
				if($vip['interface'] == $if)
263
					if($vip['subnet'] && is_inrange($vip['subnet'], $_POST['range_from'], $_POST['range_to']))
264
						$input_errors[] = sprintf(gettext("The subnet range cannot overlap with virtual IP address %s."),$vip['subnet']);
265
			}
266
		}
267

    
268
		$noip = false;
269
		if(is_array($a_maps))
270
			foreach ($a_maps as $map)
271
				if (empty($map['ipaddr']))
272
					$noip = true;
273
		if ($_POST['staticarp'] && $noip)
274
			$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.";
275

    
276
		if(is_array($pconfig['numberoptions']['item'])) {
277
			foreach ($pconfig['numberoptions']['item'] as $numberoption) {
278
				if ( $numberoption['type'] == 'text' && strstr($numberoption['value'], '"') )
279
					$input_errors[] = gettext("Text type cannot include quotation marks.");
280
				else if ( $numberoption['type'] == 'string' && !preg_match('/^"[^"]*"$/', $numberoption['value']) && !preg_match('/^[0-9a-f]{2}(?:\:[0-9a-f]{2})*$/i', $numberoption['value']) )
281
					$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");
282
				else if ( $numberoption['type'] == 'boolean' && $numberoption['value'] != 'true' && $numberoption['value'] != 'false' && $numberoption['value'] != 'on' && $numberoption['value'] != 'off' )
283
					$input_errors[] = gettext("Boolean type must be true, false, on, or off.");
284
				else if ( $numberoption['type'] == 'unsigned integer 8' && (!is_numeric($numberoption['value']) || $numberoption['value'] < 0 || $numberoption['value'] > 255) )
285
					$input_errors[] = gettext("Unsigned 8-bit integer type must be a number in the range 0 to 255.");
286
				else if ( $numberoption['type'] == 'unsigned integer 16' && (!is_numeric($numberoption['value']) || $numberoption['value'] < 0 || $numberoption['value'] > 65535) )
287
					$input_errors[] = gettext("Unsigned 16-bit integer type must be a number in the range 0 to 65535.");
288
				else if ( $numberoption['type'] == 'unsigned integer 32' && (!is_numeric($numberoption['value']) || $numberoption['value'] < 0 || $numberoption['value'] > 4294967295) )
289
					$input_errors[] = gettext("Unsigned 32-bit integer type must be a number in the range 0 to 4294967295.");
290
				else if ( $numberoption['type'] == 'signed integer 8' && (!is_numeric($numberoption['value']) || $numberoption['value'] < -128 || $numberoption['value'] > 127) )
291
					$input_errors[] = gettext("Signed 8-bit integer type must be a number in the range -128 to 127.");
292
				else if ( $numberoption['type'] == 'signed integer 16' && (!is_numeric($numberoption['value']) || $numberoption['value'] < -32768 || $numberoption['value'] > 32767) )
293
					$input_errors[] = gettext("Signed 16-bit integer type must be a number in the range -32768 to 32767.");
294
				else if ( $numberoption['type'] == 'signed integer 32' && (!is_numeric($numberoption['value']) || $numberoption['value'] < -2147483648 || $numberoption['value'] > 2147483647) )
295
					$input_errors[] = gettext("Signed 32-bit integer type must be a number in the range -2147483648 to 2147483647.");
296
				else if ( $numberoption['type'] == 'ip-address' && !is_ipaddrv4($numberoption['value']) && !is_hostname($numberoption['value']) )
297
					$input_errors[] = gettext("IP address or host type must be an IP address or host name.");
298
			}
299
		}
300

    
301
		if (!$input_errors) {
302
			/* make sure the range lies within the current subnet */
303
			$subnet_start = ip2ulong(long2ip32(ip2long($ifcfgip) & gen_subnet_mask_long($ifcfgsn)));
304
			$subnet_end = ip2ulong(long2ip32(ip2long($ifcfgip) | (~gen_subnet_mask_long($ifcfgsn))));
305

    
306
			if ((ip2ulong($_POST['range_from']) < $subnet_start) || (ip2ulong($_POST['range_from']) > $subnet_end) ||
307
			    (ip2ulong($_POST['range_to']) < $subnet_start) || (ip2ulong($_POST['range_to']) > $subnet_end)) {
308
				$input_errors[] = gettext("The specified range lies outside of the current subnet.");
309
			}
310

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

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

    
318
			$dynsubnet_start = ip2ulong($_POST['range_from']);
319
			$dynsubnet_end = ip2ulong($_POST['range_to']);
320
			if (is_array($a_maps)) {
321
				foreach ($a_maps as $map) {
322
					if (empty($map['ipaddr']))
323
						continue;
324
					if ((ip2ulong($map['ipaddr']) > $dynsubnet_start) &&
325
						(ip2ulong($map['ipaddr']) < $dynsubnet_end)) {
326
						$input_errors[] = sprintf(gettext("The DHCP range cannot overlap any static DHCP mappings."));
327
						break;
328
					}
329
				}
330
			}
331
		}
332
	}
333

    
334
	if (!$input_errors) {
335
		if (!is_array($config['dhcpd'][$if]))
336
			$config['dhcpd'][$if] = array();
337
		if (!is_array($config['dhcpd'][$if]['range']))
338
			$config['dhcpd'][$if]['range'] = array();
339

    
340
		$config['dhcpd'][$if]['range']['from'] = $_POST['range_from'];
341
		$config['dhcpd'][$if]['range']['to'] = $_POST['range_to'];
342
		$config['dhcpd'][$if]['defaultleasetime'] = $_POST['deftime'];
343
		$config['dhcpd'][$if]['maxleasetime'] = $_POST['maxtime'];
344
		$config['dhcpd'][$if]['netmask'] = $_POST['netmask'];
345
		$previous = $config['dhcpd'][$if]['failover_peerip'];
346
		if($previous <> $_POST['failover_peerip'])
347
			mwexec("/bin/rm -rf /var/dhcpd/var/db/*");
348

    
349
		$config['dhcpd'][$if]['failover_peerip'] = $_POST['failover_peerip'];
350

    
351
		unset($config['dhcpd'][$if]['winsserver']);
352
		if ($_POST['wins1'])
353
			$config['dhcpd'][$if]['winsserver'][] = $_POST['wins1'];
354
		if ($_POST['wins2'])
355
			$config['dhcpd'][$if]['winsserver'][] = $_POST['wins2'];
356

    
357
		unset($config['dhcpd'][$if]['dnsserver']);
358
		if ($_POST['dns1'])
359
			$config['dhcpd'][$if]['dnsserver'][] = $_POST['dns1'];
360
		if ($_POST['dns2'])
361
			$config['dhcpd'][$if]['dnsserver'][] = $_POST['dns2'];
362

    
363
		$config['dhcpd'][$if]['gateway'] = $_POST['gateway'];
364
		$config['dhcpd'][$if]['domain'] = $_POST['domain'];
365
		$config['dhcpd'][$if]['domainsearchlist'] = $_POST['domainsearchlist'];
366
		$config['dhcpd'][$if]['denyunknown'] = ($_POST['denyunknown']) ? true : false;
367
		$config['dhcpd'][$if]['enable'] = ($_POST['enable']) ? true : false;
368
		$config['dhcpd'][$if]['staticarp'] = ($_POST['staticarp']) ? true : false;
369
		$config['dhcpd'][$if]['ddnsdomain'] = $_POST['ddnsdomain'];
370
		$config['dhcpd'][$if]['ddnsupdate'] = ($_POST['ddnsupdate']) ? true : false;
371

    
372
		unset($config['dhcpd'][$if]['ntpserver']);
373
		if ($_POST['ntp1'])
374
			$config['dhcpd'][$if]['ntpserver'][] = $_POST['ntp1'];
375
		if ($_POST['ntp2'])
376
			$config['dhcpd'][$if]['ntpserver'][] = $_POST['ntp2'];
377

    
378
		$config['dhcpd'][$if]['tftp'] = $_POST['tftp'];
379
		$config['dhcpd'][$if]['ldap'] = $_POST['ldap'];
380
		$config['dhcpd'][$if]['netboot'] = ($_POST['netboot']) ? true : false;
381
		$config['dhcpd'][$if]['nextserver'] = $_POST['nextserver'];
382
		$config['dhcpd'][$if]['filename'] = $_POST['filename'];
383
		$config['dhcpd'][$if]['rootpath'] = $_POST['rootpath'];
384
		$config['dhcpd'][$if]['dhcpleaseinlocaltime'] = $_POST['dhcpleaseinlocaltime'];
385

    
386
		// Handle the custom options rowhelper
387
		if(isset($config['dhcpd'][$if]['numberoptions']['item']))
388
			unset($config['dhcpd'][$if]['numberoptions']['item']);
389

    
390
		$config['dhcpd'][$if]['numberoptions'] = $numberoptions;
391

    
392
		write_config();
393

    
394
		$retval = 0;
395
		$retvaldhcp = 0;
396
		$retvaldns = 0;
397
		/* Stop DHCP so we can cleanup leases */
398
		killbyname("dhcpd");
399
		dhcp_clean_leases();
400
		/* dnsmasq_configure calls dhcpd_configure */
401
		/* no need to restart dhcpd twice */
402
		if (isset($config['dnsmasq']['regdhcpstatic']))	{
403
			$retvaldns = services_dnsmasq_configure();
404
			if ($retvaldns == 0) {
405
				clear_subsystem_dirty('hosts');
406
				clear_subsystem_dirty('staticmaps');
407
			}
408
		} else {
409
			$retvaldhcp = services_dhcpd_configure();
410
			if ($retvaldhcp == 0)
411
				clear_subsystem_dirty('staticmaps');
412
		}
413
		if($retvaldhcp == 1 || $retvaldns == 1)
414
			$retval = 1;
415
		$savemsg = get_std_save_message($retval);
416
	}
417
}
418

    
419
if ($_GET['act'] == "del") {
420
	if ($a_maps[$_GET['id']]) {
421
		unset($a_maps[$_GET['id']]);
422
		write_config();
423
		if(isset($config['dhcpd'][$if]['enable'])) {
424
			mark_subsystem_dirty('staticmaps');
425
			if (isset($config['dnsmasq']['regdhcpstatic']))
426
				mark_subsystem_dirty('hosts');
427
		}
428
		header("Location: services_dhcp.php?if={$if}");
429
		exit;
430
	}
431
}
432

    
433
$pgtitle = array(gettext("Services"),gettext("DHCP server"));
434
$statusurl = "status_dhcp_leases.php";
435
$logurl = "diag_logs_dhcp.php";
436

    
437
include("head.inc");
438

    
439
?>
440

    
441
<script type="text/javascript" src="/javascript/row_helper.js">
442
</script>
443

    
444
<script type="text/javascript">
445
	function itemtype_field(fieldname, fieldsize, n) {
446
		return '<select name="' + fieldname + n + '" class="formselect" id="' + fieldname + n + '"><?php
447
			$customitemtypes = array('text' => gettext('Text'), 'string' => gettext('String'), 'boolean' => gettext('Boolean'),
448
				'unsigned integer 8' => gettext('Unsigned 8-bit integer'), 'unsigned integer 16' => gettext('Unsigned 16-bit integer'), 'unsigned integer 32' => gettext('Unsigned 32-bit integer'),
449
				'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'));
450
			foreach ($customitemtypes as $typename => $typedescr) {
451
				echo "<option value=\"{$typename}\">{$typedescr}</option>";
452
			}
453
		?></select>';
454
	}
455

    
456
	rowname[0] = "number";
457
	rowtype[0] = "textbox";
458
	rowsize[0] = "10";
459
	rowname[1] = "itemtype";
460
	rowtype[1] = itemtype_field;
461
	rowname[2] = "value";
462
	rowtype[2] = "textbox";
463
	rowsize[2] = "40";
464
</script>
465

    
466
<script type="text/javascript" language="JavaScript">
467
	function enable_change(enable_over) {
468
		var endis;
469
		endis = !(document.iform.enable.checked || enable_over);
470
		document.iform.range_from.disabled = endis;
471
		document.iform.range_to.disabled = endis;
472
		document.iform.wins1.disabled = endis;
473
		document.iform.wins2.disabled = endis;
474
		document.iform.dns1.disabled = endis;
475
		document.iform.dns2.disabled = endis;
476
		document.iform.deftime.disabled = endis;
477
		document.iform.maxtime.disabled = endis;
478
		document.iform.gateway.disabled = endis;
479
		document.iform.failover_peerip.disabled = endis;
480
		document.iform.domain.disabled = endis;
481
		document.iform.domainsearchlist.disabled = endis;
482
		document.iform.staticarp.disabled = endis;
483
		document.iform.dhcpleaseinlocaltime.disabled = endis;
484
		document.iform.ddnsdomain.disabled = endis;
485
		document.iform.ddnsupdate.disabled = endis;
486
		document.iform.ntp1.disabled = endis;
487
		document.iform.ntp2.disabled = endis;
488
		document.iform.tftp.disabled = endis;
489
		document.iform.ldap.disabled = endis;
490
		document.iform.netboot.disabled = endis;
491
		document.iform.nextserver.disabled = endis;
492
		document.iform.filename.disabled = endis;
493
		document.iform.rootpath.disabled = endis;
494
		document.iform.denyunknown.disabled = endis;
495
	}
496

    
497
	function show_shownumbervalue() {
498
		document.getElementById("shownumbervaluebox").innerHTML='';
499
		aodiv = document.getElementById('shownumbervalue');
500
		aodiv.style.display = "block";
501
	}
502

    
503
	function show_ddns_config() {
504
		document.getElementById("showddnsbox").innerHTML='';
505
		aodiv = document.getElementById('showddns');
506
		aodiv.style.display = "block";
507
	}
508

    
509
	function show_ntp_config() {
510
		document.getElementById("showntpbox").innerHTML='';
511
		aodiv = document.getElementById('showntp');
512
		aodiv.style.display = "block";
513
	}
514

    
515
	function show_tftp_config() {
516
		document.getElementById("showtftpbox").innerHTML='';
517
		aodiv = document.getElementById('showtftp');
518
		aodiv.style.display = "block";
519
	}
520

    
521
	function show_ldap_config() {
522
		document.getElementById("showldapbox").innerHTML='';
523
		aodiv = document.getElementById('showldap');
524
		aodiv.style.display = "block";
525
	}
526

    
527
	function show_netboot_config() {
528
		document.getElementById("shownetbootbox").innerHTML='';
529
		aodiv = document.getElementById('shownetboot');
530
		aodiv.style.display = "block";
531
	}
532
</script>
533

    
534
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
535
<?php include("fbegin.inc"); ?>
536
<form action="services_dhcp.php" method="post" name="iform" id="iform">
537
<?php if ($input_errors) print_input_errors($input_errors); ?>
538
<?php if ($savemsg) print_info_box($savemsg); ?>
539
<?php
540
	if ($dhcrelay_enabled) {
541
		echo gettext("DHCP Relay is currently enabled. Cannot enable the DHCP Server service while the DHCP Relay is enabled on any interface.");
542
		include("fend.inc");
543
		echo "</body>";
544
		echo "</html>";
545
		exit;
546
	}
547
?>
548
<?php if (is_subsystem_dirty('staticmaps')): ?><p>
549
<?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>
550
<?php endif; ?>
551
<table width="100%" border="0" cellpadding="0" cellspacing="0">
552
<tr><td>
553
<?php
554
	/* active tabs */
555
	$tab_array = array();
556
	$tabscounter = 0;
557
	$i = 0;
558
	foreach ($iflist as $ifent => $ifname) {
559
		$oc = $config['interfaces'][$ifent];
560
		if ((is_array($config['dhcpd'][$ifent]) && !isset($config['dhcpd'][$ifent]['enable']) && (!is_ipaddrv4($oc['ipaddr']))) ||
561
			(!is_array($config['dhcpd'][$ifent]) && (!is_ipaddrv4($oc['ipaddr']))))
562
			continue;
563
		if ($ifent == $if)
564
			$active = true;
565
		else
566
			$active = false;
567
		$tab_array[] = array($ifname, $active, "services_dhcp.php?if={$ifent}");
568
		$tabscounter++;
569
	}
570
	if ($tabscounter == 0) {
571
		echo "</td></tr></table></form>";
572
		include("fend.inc");
573
		echo "</body>";
574
		echo "</html>";
575
		exit;
576
	}
577
	display_top_tabs($tab_array);
578
?>
579
</td></tr>
580
<tr>
581
<td>
582
	<div id="mainarea">
583
		<table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
584
			<tr>
585
			<td width="22%" valign="top" class="vtable">&nbsp;</td>
586
			<td width="78%" class="vtable">
587
				<input name="enable" type="checkbox" value="yes" <?php if ($pconfig['enable']) echo "checked"; ?> onClick="enable_change(false)">
588
			<strong><?php printf(gettext("Enable DHCP server on " .
589
			"%s " .
590
			"interface"),htmlspecialchars($iflist[$if]));?></strong></td>
591
			</tr>
592
			<tr>
593
			<td width="22%" valign="top" class="vtable">&nbsp;</td>
594
			<td width="78%" class="vtable">
595
				<input name="denyunknown" id="denyunknown" type="checkbox" value="yes" <?php if ($pconfig['denyunknown']) echo "checked"; ?>>
596
				<strong><?=gettext("Deny unknown clients");?></strong><br>
597
				<?=gettext("If this is checked, only the clients defined below will get DHCP leases from this server. ");?></td>
598
			</tr>
599
			<tr>
600
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Subnet");?></td>
601
			<td width="78%" class="vtable">
602
				<?=gen_subnet($ifcfgip, $ifcfgsn);?>
603
			</td>
604
			</tr>
605
			<tr>
606
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Subnet mask");?></td>
607
			<td width="78%" class="vtable">
608
				<?=gen_subnet_mask($ifcfgsn);?>
609
			</td>
610
			</tr>
611
			<tr>
612
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Available range");?></td>
613
			<td width="78%" class="vtable">
614
			<?php
615
				$range_from = ip2long(long2ip32(ip2long($ifcfgip) & gen_subnet_mask_long($ifcfgsn)));
616
				$range_from++;
617
				echo long2ip32($range_from);
618
			?>
619
			-
620
			<?php
621
				$range_to = ip2long(long2ip32(ip2long($ifcfgip) | (~gen_subnet_mask_long($ifcfgsn))));
622
				$range_to--;
623
				echo long2ip32($range_to);
624
			?>
625
			</td>
626
			</tr>
627
			<?php if($is_olsr_enabled): ?>
628
			<tr>
629
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Subnet Mask");?></td>
630
			<td width="78%" class="vtable">
631
				<select name="netmask" class="formselect" id="netmask">
632
				<?php
633
				for ($i = 32; $i > 0; $i--) {
634
					if($i <> 31) {
635
						echo "<option value=\"{$i}\" ";
636
						if ($i == $pconfig['netmask']) echo "selected";
637
						echo ">" . $i . "</option>";
638
					}
639
				}
640
				?>
641
				</select>
642
			</td>
643
			</tr>
644
			<?php endif; ?>
645
			<tr>
646
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Range");?></td>
647
			<td width="78%" class="vtable">
648
				<input name="range_from" type="text" class="formfld unknown" id="range_from" size="20" value="<?=htmlspecialchars($pconfig['range_from']);?>">
649
				&nbsp;<?=gettext("to"); ?>&nbsp; <input name="range_to" type="text" class="formfld unknown" id="range_to" size="20" value="<?=htmlspecialchars($pconfig['range_to']);?>">
650
			</td>
651
			</tr>
652
			<tr>
653
			<td width="22%" valign="top" class="vncell"><?=gettext("WINS servers");?></td>
654
			<td width="78%" class="vtable">
655
				<input name="wins1" type="text" class="formfld unknown" id="wins1" size="20" value="<?=htmlspecialchars($pconfig['wins1']);?>"><br>
656
				<input name="wins2" type="text" class="formfld unknown" id="wins2" size="20" value="<?=htmlspecialchars($pconfig['wins2']);?>">
657
			</td>
658
			</tr>
659
			<tr>
660
			<td width="22%" valign="top" class="vncell"><?=gettext("DNS servers");?></td>
661
			<td width="78%" class="vtable">
662
				<input name="dns1" type="text" class="formfld unknown" id="dns1" size="20" value="<?=htmlspecialchars($pconfig['dns1']);?>"><br>
663
				<input name="dns2" type="text" class="formfld unknown" id="dns2" size="20" value="<?=htmlspecialchars($pconfig['dns2']);?>"><br>
664
				<?=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.");?>
665
			</td>
666
			</tr>
667
			<tr>
668
			<td width="22%" valign="top" class="vncell"><?=gettext("Gateway");?></td>
669
			<td width="78%" class="vtable">
670
				<input name="gateway" type="text" class="formfld host" id="gateway" size="20" value="<?=htmlspecialchars($pconfig['gateway']);?>"><br>
671
			 	 <?=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.");?>
672
			</td>
673
			</tr>
674
			<tr>
675
			<td width="22%" valign="top" class="vncell"><?=gettext("Domain name");?></td>
676
			<td width="78%" class="vtable">
677
				<input name="domain" type="text" class="formfld unknown" id="domain" size="20" value="<?=htmlspecialchars($pconfig['domain']);?>"><br>
678
				 <?=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.");?>
679
			 </td>
680
			</tr>
681
			<tr>
682
			<td width="22%" valign="top" class="vncell"><?=gettext("Domain search list");?></td>
683
			<td width="78%" class="vtable">
684
				<input name="domainsearchlist" type="text" class="formfld unknown" id="domainsearchlist" size="20" value="<?=htmlspecialchars($pconfig['domainsearchlist']);?>"><br>
685
				<?=gettext("The DHCP server can optionally provide a domain search list. Use the semicolon character as seperator ");?>
686
			</td>
687
			</tr>
688
			<tr>
689
			<td width="22%" valign="top" class="vncell"><?=gettext("Default lease time");?></td>
690
			<td width="78%" class="vtable">
691
				<input name="deftime" type="text" class="formfld unknown" id="deftime" size="10" value="<?=htmlspecialchars($pconfig['deftime']);?>">
692
				<?=gettext("seconds");?><br>
693
				<?=gettext("This is used for clients that do not ask for a specific " .
694
				"expiration time."); ?><br>
695
				<?=gettext("The default is 7200 seconds.");?>
696
			</td>
697
			</tr>
698
			<tr>
699
			<td width="22%" valign="top" class="vncell"><?=gettext("Maximum lease time");?></td>
700
			<td width="78%" class="vtable">
701
				<input name="maxtime" type="text" class="formfld unknown" id="maxtime" size="10" value="<?=htmlspecialchars($pconfig['maxtime']);?>">
702
				<?=gettext("seconds");?><br>
703
				<?=gettext("This is the maximum lease time for clients that ask".
704
				" for a specific expiration time."); ?><br>
705
				<?=gettext("The default is 86400 seconds.");?>
706
			</td>
707
			</tr>
708
			<tr>
709
			<td width="22%" valign="top" class="vncell"><?=gettext("Failover peer IP:");?></td>
710
			<td width="78%" class="vtable">
711
				<input name="failover_peerip" type="text" class="formfld host" id="failover_peerip" size="20" value="<?=htmlspecialchars($pconfig['failover_peerip']);?>"><br>
712
				<?=gettext("Leave blank to disable.  Enter the interface IP address of the other machine.  Machines must be using CARP.");?>
713
			</td>
714
			</tr>
715
			<tr>
716
			<td width="22%" valign="top" class="vncell"><?=gettext("Static ARP");?></td>
717
			<td width="78%" class="vtable">
718
				<table>
719
					<tr>
720
					<td>
721
						<input valign="middle" type="checkbox" value="yes" name="staticarp" id="staticarp" <?php if($pconfig['staticarp']) echo " checked"; ?>>&nbsp;
722
					</td>
723
					<td><b><?=gettext("Enable Static ARP entries");?></b></td>
724
					</tr>
725
					<tr>
726
					<td>&nbsp;</td>
727
					<td>
728
						<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.");?>
729
					</td>
730
					</tr>
731
				</table>
732
			</td>
733
			</tr>
734
			<tr>
735
				<td width="22%" valign="top" class="vncell"><?=gettext("Time format change"); ?></td>
736
				<td width="78%" class="vtable">
737
				<table>
738
					<tr>
739
					<td>
740
						<input name="dhcpleaseinlocaltime" type="checkbox" id="dhcpleaseinlocaltime" value="yes" <?php if ($pconfig['dhcpleaseinlocaltime']) echo "checked"; ?>>
741
					</td>
742
					<td>
743
						<strong>
744
							<?=gettext("Change DHCP display lease time from UTC to local time."); ?>
745
						</strong>
746
					</td>
747
					</tr>
748
					<tr>
749
					<td>&nbsp;</td>
750
					<td>
751
						<span class="red"><strong><?=gettext("Note:");?></strong></span> <?=gettext("By default DHCP leases are displayed in UTC time.  By checking this 
752
						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."); ?>
753
					
754
					</td>
755
					</tr>
756
				</table>
757
				</td>
758
			</tr>
759
			<tr>
760
			<td width="22%" valign="top" class="vncell"><?=gettext("Dynamic DNS");?></td>
761
			<td width="78%" class="vtable">
762
				<div id="showddnsbox">
763
					<input type="button" onClick="show_ddns_config()" value="<?=gettext("Advanced");?>"></input> - <?=gettext("Show Dynamic DNS");?></a>
764
				</div>
765
				<div id="showddns" style="display:none">
766
					<input valign="middle" type="checkbox" value="yes" name="ddnsupdate" id="ddnsupdate" <?php if($pconfig['ddnsupdate']) echo " checked"; ?>>&nbsp;
767
					<b><?=gettext("Enable registration of DHCP client names in DNS.");?></b><br />
768
					<p>
769
					<input name="ddnsdomain" type="text" class="formfld unknown" id="ddnsdomain" size="20" value="<?=htmlspecialchars($pconfig['ddnsdomain']);?>"><br />
770
					<?=gettext("Note: Leave blank to disable dynamic DNS registration.");?><br />
771
					<?=gettext("Enter the dynamic DNS domain which will be used to register client names in the DNS server.");?>
772
				</div>
773
			</td>
774
			</tr>
775
			<tr>
776
			<td width="22%" valign="top" class="vncell"><?=gettext("NTP servers");?></td>
777
			<td width="78%" class="vtable">
778
				<div id="showntpbox">
779
					<input type="button" onClick="show_ntp_config()" value="<?=gettext("Advanced");?>"></input> - <?=gettext("Show NTP configuration");?></a>
780
				</div>
781
				<div id="showntp" style="display:none">
782
					<input name="ntp1" type="text" class="formfld unknown" id="ntp1" size="20" value="<?=htmlspecialchars($pconfig['ntp1']);?>"><br>
783
					<input name="ntp2" type="text" class="formfld unknown" id="ntp2" size="20" value="<?=htmlspecialchars($pconfig['ntp2']);?>">
784
				</div>
785
			</td>
786
			</tr>
787
			<tr>
788
			<td width="22%" valign="top" class="vncell"><?=gettext("TFTP server");?></td>
789
			<td width="78%" class="vtable">
790
			<div id="showtftpbox">
791
				<input type="button" onClick="show_tftp_config()" value="<?=gettext("Advanced");?>"></input> - <?=gettext("Show TFTP configuration");?></a>
792
			</div>
793
			<div id="showtftp" style="display:none">
794
				<input name="tftp" type="text" class="formfld unknown" id="tftp" size="50" value="<?=htmlspecialchars($pconfig['tftp']);?>"><br>
795
				<?=gettext("Leave blank to disable.  Enter a full hostname or IP for the TFTP server.");?>
796
			</div>
797
			</td>
798
			</tr>
799
			<tr>
800
			<td width="22%" valign="top" class="vncell"><?=gettext("LDAP URI");?></td>
801
			<td width="78%" class="vtable">
802
				<div id="showldapbox">
803
					<input type="button" onClick="show_ldap_config()" value="<?=gettext("Advanced");?>"></input> - <?=gettext("Show LDAP configuration");?></a>
804
				</div>
805
				<div id="showldap" style="display:none">
806
					<input name="ldap" type="text" class="formfld unknown" id="ldap" size="80" value="<?=htmlspecialchars($pconfig['ldap']);?>"><br>
807
					<?=gettext("Leave blank to disable.  Enter a full URI for the LDAP server in the form ldap://ldap.example.com/dc=example,dc=com");?>
808
				</div>
809
			</td>
810
			</tr>
811
			<tr>
812
			<td width="22%" valign="top" class="vncell"><?=gettext("Enable network booting");?></td>
813
			<td width="78%" class="vtable">
814
				<div id="shownetbootbox">
815
					<input type="button" onClick="show_netboot_config()" value="<?=gettext("Advanced");?>"></input> - <?=gettext("Show Network booting");?></a>
816
				</div>
817
				<div id="shownetboot" style="display:none">
818
					<input valign="middle" type="checkbox" value="yes" name="netboot" id="netboot" <?php if($pconfig['netboot']) echo " checked"; ?>>&nbsp;
819
					<b><?=gettext("Enables network booting.");?></b>
820
					<p>
821
					<?=gettext("Enter the IP of the"); ?> <b><?=gettext("next-server"); ?></b>
822
					<input name="nextserver" type="text" class="formfld unknown" id="nextserver" size="20" value="<?=htmlspecialchars($pconfig['nextserver']);?>">
823
					<?=gettext("and the filename");?>
824
					<input name="filename" type="text" class="formfld unknown" id="filename" size="20" value="<?=htmlspecialchars($pconfig['filename']);?>"><br>
825
					<?=gettext("Note: You need both a filename and a boot server configured for this to work!");?>
826
					<p>
827
					<?=gettext("Enter the"); ?> <b><?=gettext("root-path"); ?></b>-<?=gettext("string");?>
828
					<input name="rootpath" type="text" class="formfld unknown" id="rootpath" size="90" value="<?=htmlspecialchars($pconfig['rootpath']);?>"><br>
829
					<?=gettext("Note: string-format: iscsi:(servername):(protocol):(port):(LUN):targetname");?>
830
				</div>
831
			</td>
832
			</tr>
833
			<tr>
834
			<td width="22%" valign="top" class="vncell"><?=gettext("Additional BOOTP/DHCP Options");?></td>
835
			<td width="78%" class="vtable">
836
				<div id="shownumbervaluebox">
837
					<input type="button" onClick="show_shownumbervalue()" value="<?=gettext("Advanced");?>"></input> - <?=gettext("Show Additional BOOTP/DHCP Options");?></a>
838
				</div>
839
				<div id="shownumbervalue" style="display:none">
840
				<table id="maintable">
841
				<tbody>
842
				<tr>
843
				<td colspan="3">
844
					<div style="padding:5px; margin-top: 16px; margin-bottom: 16px; border:1px dashed #000066; background-color: #ffffff; color: #000000; font-size: 8pt;" id="itemhelp">
845
					<?=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>
846
					</div>
847
				</td>
848
				</tr>
849
				<tr>
850
				<td><div id="onecolumn"><?=gettext("Number");?></div></td>
851
				<td><div id="twocolumn"><?=gettext("Type");?></div></td>
852
				<td><div id="threecolumn"><?=gettext("Value");?></div></td>
853
				</tr>
854
				<?php $counter = 0; ?>
855
				<?php
856
					if($pconfig['numberoptions'])
857
						foreach($pconfig['numberoptions']['item'] as $item):
858
				?>
859
					<?php
860
						$number = $item['number'];
861
						$itemtype = $item['type'];
862
						$value = $item['value'];
863
					?>
864
				<tr>
865
				<td>
866
					<input autocomplete="off" name="number<?php echo $counter; ?>" type="text" class="formfld unknown" id="number<?php echo $counter; ?>" size="10" value="<?=htmlspecialchars($number);?>" />
867
				</td>
868
				<td>
869
					<select name="itemtype<?php echo $counter; ?>" class="formselect" id="itemtype<?php echo $counter; ?>">
870
					<?php
871
					foreach ($customitemtypes as $typename => $typedescr) {
872
						echo "<option value=\"{$typename}\" ";
873
						if ($itemtype == $typename) echo "selected";
874
						echo ">" . $typedescr . "</option>";
875
					}
876
					?>
877
					</select>
878
				</td>
879
				<td>
880
					<input autocomplete="off" name="value<?php echo $counter; ?>" type="text" class="formfld unknown" id="value<?php echo $counter; ?>" size="40" value="<?=htmlspecialchars($value);?>" />
881
				</td>
882
				<td>
883
					<a onclick="removeRow(this); return false;" href="#"><img border="0" src="/themes/<?echo $g['theme'];?>/images/icons/icon_x.gif" /></a>
884
				</td>
885
				</tr>
886
				<?php $counter++; ?>
887
				<?php endforeach; ?>
888
				</tbody>
889
				<tfoot>
890
				</tfoot>
891
				</table>
892
				<a onclick="javascript:addRowTo('maintable', 'formfldalias'); return false;" href="#">
893
					<img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="<?=gettext("add another entry");?>" />
894
				</a>
895
				<script type="text/javascript">
896
					field_counter_js = 3;
897
					rows = 1;
898
					totalrows = <?php echo $counter; ?>;
899
					loaded = <?php echo $counter; ?>;
900
				</script>
901
				</div>
902

    
903
				</td>
904
			</tr>
905
			<tr>
906
			<td width="22%" valign="top">&nbsp;</td>
907
			<td width="78%">
908
				<input name="if" type="hidden" value="<?=htmlspecialchars($if);?>">
909
				<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" onclick="enable_change(true)">
910
			</td>
911
			</tr>
912
			<tr>
913
			<td width="22%" valign="top">&nbsp;</td>
914
			<td width="78%"> <p><span class="vexpl"><span class="red"><strong><?=gettext("Note:");?><br>
915
				</strong></span><?=gettext("The DNS servers entered in"); ?> <a href="system.php"><?=gettext("System: " .
916
				"General setup"); ?></a> <?=gettext("(or the"); ?> <a href="services_dnsmasq.php"><?=gettext("DNS " .
917
				"forwarder"); ?></a>, <?=gettext("if enabled)"); ?> </span><span class="vexpl"><?=gettext("will " .
918
				"be assigned to clients by the DHCP server."); ?><br>
919
				<br>
920
				<?=gettext("The DHCP lease table can be viewed on the"); ?> <a href="status_dhcp_leases.php"><?=gettext("Status: " .
921
				"DHCP leases"); ?></a> <?=gettext("page."); ?><br>
922
				</span></p>
923
			</td>
924
			</tr>
925
		</table>
926
		<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
927
		<tr>
928
			<td width="25%" class="listhdrr"><?=gettext("MAC address");?></td>
929
			<td width="15%" class="listhdrr"><?=gettext("IP address");?></td>
930
			<td width="20%" class="listhdrr"><?=gettext("Hostname");?></td>
931
			<td width="30%" class="listhdr"><?=gettext("Description");?></td>
932
			<td width="10%" class="list">
933
			<table border="0" cellspacing="0" cellpadding="1">
934
			<tr>
935
			<td valign="middle" width="17"></td>
936
			<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>
937
			</tr>
938
			</table>
939
			</td>
940
		</tr>
941
			<?php if(is_array($a_maps)): ?>
942
			<?php $i = 0; foreach ($a_maps as $mapent): ?>
943
			<?php if($mapent['mac'] <> "" or $mapent['ipaddr'] <> ""): ?>
944
		<tr>
945
		<td class="listlr" ondblclick="document.location='services_dhcp_edit.php?if=<?=htmlspecialchars($if);?>&id=<?=$i;?>';">
946
			<?=htmlspecialchars($mapent['mac']);?>
947
		</td>
948
		<td class="listr" ondblclick="document.location='services_dhcp_edit.php?if=<?=htmlspecialchars($if);?>&id=<?=$i;?>';">
949
			<?=htmlspecialchars($mapent['ipaddr']);?>&nbsp;
950
		</td>
951
		<td class="listr" ondblclick="document.location='services_dhcp_edit.php?if=<?=htmlspecialchars($if);?>&id=<?=$i;?>';">
952
			<?=htmlspecialchars($mapent['hostname']);?>&nbsp;
953
		</td>
954
		<td class="listbg" ondblclick="document.location='services_dhcp_edit.php?if=<?=htmlspecialchars($if);?>&id=<?=$i;?>';">
955
			<?=htmlspecialchars($mapent['descr']);?>&nbsp;
956
		</td>
957
		<td valign="middle" nowrap class="list">
958
			<table border="0" cellspacing="0" cellpadding="1">
959
			<tr>
960
			<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>
961
			<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>
962
			</tr>
963
			</table>
964
		</td>
965
		</tr>
966
		<?php endif; ?>
967
		<?php $i++; endforeach; ?>
968
		<?php endif; ?>
969
		<tr>
970
		<td class="list" colspan="4"></td>
971
		<td class="list">
972
			<table border="0" cellspacing="0" cellpadding="1">
973
			<tr>
974
			<td valign="middle" width="17"></td>
975
			<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>
976
			</tr>
977
			</table>
978
		</td>
979
		</tr>
980
		</table>
981
	</div>
982
</td>
983
</tr>
984
</table>
985
</form>
986
<script language="JavaScript">
987
<!--
988
enable_change(false);
989
//-->
990
</script>
991
<?php include("fend.inc"); ?>
992
</body>
993
</html>
(148-148/245)