Project

General

Profile

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

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

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

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

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

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

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

    
43
require("guiconfig.inc");
44

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

    
50
/*  Fix failover DHCP problem
51
 *  http://article.gmane.org/gmane.comp.security.firewalls.pfsense.support/18749
52
 */
53
ini_set("memory_limit","64M");
54

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

    
101
$if = $_GET['if'];
102
if ($_POST['if'])
103
	$if = $_POST['if'];
104

    
105
/* if OLSRD is enabled, allow WAN to house DHCP. */
106
if($config['installedpackages']['olsrd']) {
107
	foreach($config['installedpackages']['olsrd']['config'] as $olsrd) {
108
			if($olsrd['enable']) {
109
				$is_olsr_enabled = true;
110
				break;
111
			}
112
	}
113
}
114

    
115
if (!$_GET['if'])
116
	$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>";
117

    
118
$iflist = get_configured_interface_with_descr();
119

    
120
/* set the starting interface */
121
if (!$if || !isset($iflist[$if])) {
122
	foreach ($iflist as $ifent => $ifname) {
123
		$oc = $config['interfaces'][$ifent];
124
		if ((is_array($config['dhcpd'][$ifent]) && !isset($config['dhcpd'][$ifent]['enable']) && (!is_ipaddr($oc['ipaddr']))) ||
125
			(!is_array($config['dhcpd'][$ifent]) && (!is_ipaddr($oc['ipaddr']))))
126
			continue;
127
		$if = $ifent;
128
		break;
129
	}
130
}
131

    
132
if (is_array($config['dhcpd'][$if])){
133
	if (is_array($config['dhcpd'][$if]['range'])) {
134
		$pconfig['range_from'] = $config['dhcpd'][$if]['range']['from'];
135
		$pconfig['range_to'] = $config['dhcpd'][$if]['range']['to'];
136
	}
137
	$pconfig['deftime'] = $config['dhcpd'][$if]['defaultleasetime'];
138
	$pconfig['maxtime'] = $config['dhcpd'][$if]['maxleasetime'];
139
	$pconfig['gateway'] = $config['dhcpd'][$if]['gateway'];
140
	$pconfig['domain'] = $config['dhcpd'][$if]['domain'];
141
	$pconfig['domainsearchlist'] = $config['dhcpd'][$if]['domainsearchlist'];
142
	list($pconfig['wins1'],$pconfig['wins2']) = $config['dhcpd'][$if]['winsserver'];
143
	list($pconfig['dns1'],$pconfig['dns2']) = $config['dhcpd'][$if]['dnsserver'];
144
	$pconfig['enable'] = isset($config['dhcpd'][$if]['enable']);
145
	$pconfig['denyunknown'] = isset($config['dhcpd'][$if]['denyunknown']);
146
	$pconfig['staticarp'] = isset($config['dhcpd'][$if]['staticarp']);
147
	$pconfig['ddnsdomain'] = $config['dhcpd'][$if]['ddnsdomain'];
148
	$pconfig['ddnsupdate'] = isset($config['dhcpd'][$if]['ddnsupdate']);
149
	list($pconfig['ntp1'],$pconfig['ntp2']) = $config['dhcpd'][$if]['ntpserver'];
150
	$pconfig['tftp'] = $config['dhcpd'][$if]['tftp'];
151
	$pconfig['ldap'] = $config['dhcpd'][$if]['ldap'];
152
	$pconfig['netboot'] = isset($config['dhcpd'][$if]['netboot']);
153
	$pconfig['nextserver'] = $config['dhcpd'][$if]['next-server'];
154
	$pconfig['filename'] = $config['dhcpd'][$if]['filename'];
155
	$pconfig['rootpath'] = $config['dhcpd'][$if]['rootpath'];
156
	$pconfig['failover_peerip'] = $config['dhcpd'][$if]['failover_peerip'];
157
	$pconfig['netmask'] = $config['dhcpd'][$if]['netmask'];
158
	$pconfig['numberoptions'] = $config['dhcpd'][$if]['numberoptions'];
159
	if (!is_array($config['dhcpd'][$if]['staticmap']))
160
		$config['dhcpd'][$if]['staticmap'] = array();
161
	$a_maps = &$config['dhcpd'][$if]['staticmap'];
162
}
163

    
164
$ifcfgip = get_interface_ip($if);
165
$ifcfgsn = get_interface_subnet($if);
166

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

    
172
$dhcrelay_enabled = false;
173
$dhcrelaycfg = $config['dhcrelay'];
174

    
175
if(is_array($dhcrelaycfg)) {
176
	foreach ($dhcrelaycfg as $dhcrelayif => $dhcrelayifconf) {
177
		if (isset($dhcrelayifconf['enable']) && isset($iflist[$dhcrelayif]) &&
178
			(!link_interface_to_bridge($dhcrelayif)))
179
			$dhcrelay_enabled = true;
180
	}
181
}
182

    
183
function is_inrange($test, $start, $end) {
184
	if ( (ip2ulong($test) < ip2ulong($end)) && (ip2ulong($test) > ip2ulong($start)) )
185
		return true;
186
	else
187
		return false;
188
}
189

    
190
if ($_POST) {
191

    
192
	unset($input_errors);
193

    
194
	$pconfig = $_POST;
195

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

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

    
213
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
214

    
215
		if (($_POST['range_from'] && !is_ipaddr($_POST['range_from'])))
216
			$input_errors[] = gettext("A valid range must be specified.");
217
		if (($_POST['range_to'] && !is_ipaddr($_POST['range_to'])))
218
			$input_errors[] = gettext("A valid range must be specified.");
219
		if (($_POST['gateway'] && !is_ipaddr($_POST['gateway'])))
220
			$input_errors[] = gettext("A valid IP address must be specified for the gateway.");
221
		if (($_POST['wins1'] && !is_ipaddr($_POST['wins1'])) || ($_POST['wins2'] && !is_ipaddr($_POST['wins2'])))
222
			$input_errors[] = gettext("A valid IP address must be specified for the primary/secondary WINS servers.");
223
		if (($_POST['dns1'] && !is_ipaddr($_POST['dns1'])) || ($_POST['dns2'] && !is_ipaddr($_POST['dns2'])))
224
			$input_errors[] = gettext("A valid IP address must be specified for the primary/secondary DNS servers.");
225

    
226
		if ($_POST['deftime'] && (!is_numeric($_POST['deftime']) || ($_POST['deftime'] < 60)))
227
			$input_errors[] = gettext("The default lease time must be at least 60 seconds.");
228
		if ($_POST['maxtime'] && (!is_numeric($_POST['maxtime']) || ($_POST['maxtime'] < 60) || ($_POST['maxtime'] <= $_POST['deftime'])))
229
			$input_errors[] = gettext("The maximum lease time must be at least 60 seconds and higher than the default lease time.");
230
		if (($_POST['ddnsdomain'] && !is_domain($_POST['ddnsdomain'])))
231
			$input_errors[] = gettext("A valid domain name must be specified for the dynamic DNS registration.");
232
		if (($_POST['ntp1'] && !is_ipaddr($_POST['ntp1'])) || ($_POST['ntp2'] && !is_ipaddr($_POST['ntp2'])))
233
			$input_errors[] = gettext("A valid IP address must be specified for the primary/secondary NTP servers.");
234
		if (($_POST['domain'] && !is_domain($_POST['domain'])))
235
			$input_errors[] = gettext("A valid domain name must be specified for the DNS domain.");
236
		if (($_POST['tftp'] && (!is_ipaddr($_POST['tftp']) && !is_domain($_POST['tftp']))))
237
			$input_errors[] = gettext("A valid IP address or hostname must be specified for the TFTP server.");
238
		if (($_POST['nextserver'] && !is_ipaddr($_POST['nextserver'])))
239
			$input_errors[] = gettext("A valid IP address must be specified for the network boot server.");
240

    
241
		if(gen_subnet($ifcfgip, $ifcfgsn) == $_POST['range_from'])
242
			$input_errors[] = gettext("You cannot use the network address in the starting subnet range.");
243
		if(gen_subnet_max($ifcfgip, $ifcfgsn) == $_POST['range_to'])
244
			$input_errors[] = gettext("You cannot use the broadcast address in the ending subnet range.");
245

    
246
		// Disallow a range that includes the virtualip
247
		if (is_array($config['virtualip']['vip'])) {
248
			foreach($config['virtualip']['vip'] as $vip) {
249
				if($vip['interface'] == $if)
250
					if($vip['subnet'] && is_inrange($vip['subnet'], $_POST['range_from'], $_POST['range_to']))
251
						$input_errors[] = printf(gettext("The subnet range cannot overlap with virtual IP address %s."),$vip['subnet']);
252
			}
253
		}
254

    
255
		$noip = false;
256
		foreach ($a_maps as $map)
257
			if (empty($map['ipaddr']))
258
				$noip = true;
259
		if ($_POST['staticarp'] && $noip)
260
			$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.";
261

    
262
		if (!$input_errors) {
263
			/* make sure the range lies within the current subnet */
264
			$subnet_start = ip2ulong(long2ip32(ip2long($ifcfgip) & gen_subnet_mask_long($ifcfgsn)));
265
			$subnet_end = ip2ulong(long2ip32(ip2long($ifcfgip) | (~gen_subnet_mask_long($ifcfgsn))));
266

    
267
			if ((ip2ulong($_POST['range_from']) < $subnet_start) || (ip2ulong($_POST['range_from']) > $subnet_end) ||
268
			    (ip2ulong($_POST['range_to']) < $subnet_start) || (ip2ulong($_POST['range_to']) > $subnet_end)) {
269
				$input_errors[] = gettext("The specified range lies outside of the current subnet.");
270
			}
271

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

    
275
			/* make sure that the DHCP Relay isn't enabled on this interface */
276
			if (isset($config['dhcrelay'][$if]['enable']))
277
				$input_errors[] = printf(gettext("You must disable the DHCP relay on the %s interface before enabling the DHCP server."),$iflist[$if]);
278
		}
279
	}
280

    
281
	if (!$input_errors) {
282
		if (!is_array($config['dhcpd'][$if]))
283
			$config['dhcpd'][$if] = array();
284
		if (!is_array($config['dhcpd'][$if]['range']))
285
			$config['dhcpd'][$if]['range'] = array();
286

    
287
		$config['dhcpd'][$if]['range']['from'] = $_POST['range_from'];
288
		$config['dhcpd'][$if]['range']['to'] = $_POST['range_to'];
289
		$config['dhcpd'][$if]['defaultleasetime'] = $_POST['deftime'];
290
		$config['dhcpd'][$if]['maxleasetime'] = $_POST['maxtime'];
291
		$config['dhcpd'][$if]['netmask'] = $_POST['netmask'];
292
		$previous = $config['dhcpd'][$if]['failover_peerip'];
293
		if($previous <> $_POST['failover_peerip'])
294
			mwexec("/bin/rm -rf /var/dhcpd/var/db/*");
295

    
296
		$config['dhcpd'][$if]['failover_peerip'] = $_POST['failover_peerip'];
297

    
298
		unset($config['dhcpd'][$if]['winsserver']);
299
		if ($_POST['wins1'])
300
			$config['dhcpd'][$if]['winsserver'][] = $_POST['wins1'];
301
		if ($_POST['wins2'])
302
			$config['dhcpd'][$if]['winsserver'][] = $_POST['wins2'];
303

    
304
		unset($config['dhcpd'][$if]['dnsserver']);
305
		if ($_POST['dns1'])
306
			$config['dhcpd'][$if]['dnsserver'][] = $_POST['dns1'];
307
		if ($_POST['dns2'])
308
			$config['dhcpd'][$if]['dnsserver'][] = $_POST['dns2'];
309

    
310
		$config['dhcpd'][$if]['gateway'] = $_POST['gateway'];
311
		$config['dhcpd'][$if]['domain'] = $_POST['domain'];
312
		$config['dhcpd'][$if]['domainsearchlist'] = $_POST['domainsearchlist'];
313
		$config['dhcpd'][$if]['denyunknown'] = ($_POST['denyunknown']) ? true : false;
314
		$config['dhcpd'][$if]['enable'] = ($_POST['enable']) ? true : false;
315
		$config['dhcpd'][$if]['staticarp'] = ($_POST['staticarp']) ? true : false;
316
		$config['dhcpd'][$if]['ddnsdomain'] = $_POST['ddnsdomain'];
317
		$config['dhcpd'][$if]['ddnsupdate'] = ($_POST['ddnsupdate']) ? true : false;
318

    
319
		unset($config['dhcpd'][$if]['ntpserver']);
320
		if ($_POST['ntp1'])
321
			$config['dhcpd'][$if]['ntpserver'][] = $_POST['ntp1'];
322
		if ($_POST['ntp2'])
323
			$config['dhcpd'][$if]['ntpserver'][] = $_POST['ntp2'];
324

    
325
		$config['dhcpd'][$if]['tftp'] = $_POST['tftp'];
326
		$config['dhcpd'][$if]['ldap'] = $_POST['ldap'];
327
		$config['dhcpd'][$if]['netboot'] = ($_POST['netboot']) ? true : false;
328
		$config['dhcpd'][$if]['next-server'] = $_POST['nextserver'];
329
		$config['dhcpd'][$if]['filename'] = $_POST['filename'];
330
		$config['dhcpd'][$if]['rootpath'] = $_POST['rootpath'];
331

    
332
		// Handle the custom options rowhelper
333
		if(isset($config['dhcpd'][$if]['numberoptions']['item']))
334
			unset($config['dhcpd'][$if]['numberoptions']['item']);
335

    
336
		$config['dhcpd'][$if]['numberoptions'] = $numberoptions;
337

    
338
		write_config();
339

    
340
		$retval = 0;
341
		$retvaldhcp = 0;
342
		$retvaldns = 0;
343
		/* Stop DHCP so we can cleanup leases */
344
		killbyname("dhcpd");
345
		dhcp_clean_leases();
346
		/* dnsmasq_configure calls dhcpd_configure */
347
		/* no need to restart dhcpd twice */
348
		if (isset($config['dnsmasq']['regdhcpstatic']))	{
349
			$retvaldns = services_dnsmasq_configure();
350
			if ($retvaldns == 0) {
351
				clear_subsystem_dirty('hosts');
352
				clear_subsystem_dirty('staticmaps');
353
			}
354
		} else {
355
			$retvaldhcp = services_dhcpd_configure();
356
			if ($retvaldhcp == 0)
357
				clear_subsystem_dirty('staticmaps');
358
		}
359
		if($retvaldhcp == 1 || $retvaldns == 1)
360
			$retval = 1;
361
		$savemsg = get_std_save_message($retval);
362
	}
363
}
364

    
365
if ($_GET['act'] == "del") {
366
	if ($a_maps[$_GET['id']]) {
367
		unset($a_maps[$_GET['id']]);
368
		write_config();
369
		if(isset($config['dhcpd'][$if]['enable'])) {
370
			mark_subsystem_dirty('staticmaps');
371
			if (isset($config['dnsmasq']['regdhcpstatic']))
372
				mark_subsystem_dirty('hosts');
373
		}
374
		header("Location: services_dhcp.php?if={$if}");
375
		exit;
376
	}
377
}
378

    
379
$pgtitle = array(gettext("Services"),gettext("DHCP server"));
380
$statusurl = "status_dhcp_leases.php";
381
$logurl = "diag_logs_dhcp.php";
382

    
383
include("head.inc");
384

    
385
?>
386

    
387
<script type="text/javascript" src="/javascript/row_helper.js">
388
</script>
389

    
390
<script type="text/javascript">
391
	rowname[0] = "number";
392
	rowtype[0] = "textbox";
393
	rowsize[0] = "10";
394
	rowname[1] = "value";
395
	rowtype[1] = "textbox";
396
	rowsize[1] = "55";
397
</script>
398

    
399
<script type="text/javascript" language="JavaScript">
400
	function enable_change(enable_over) {
401
		var endis;
402
		endis = !(document.iform.enable.checked || enable_over);
403
		document.iform.range_from.disabled = endis;
404
		document.iform.range_to.disabled = endis;
405
		document.iform.wins1.disabled = endis;
406
		document.iform.wins2.disabled = endis;
407
		document.iform.dns1.disabled = endis;
408
		document.iform.dns2.disabled = endis;
409
		document.iform.deftime.disabled = endis;
410
		document.iform.maxtime.disabled = endis;
411
		document.iform.gateway.disabled = endis;
412
		document.iform.failover_peerip.disabled = endis;
413
		document.iform.domain.disabled = endis;
414
		document.iform.domainsearchlist.disabled = endis;
415
		document.iform.staticarp.disabled = endis;
416
		document.iform.ddnsdomain.disabled = endis;
417
		document.iform.ddnsupdate.disabled = endis;
418
		document.iform.ntp1.disabled = endis;
419
		document.iform.ntp2.disabled = endis;
420
		document.iform.tftp.disabled = endis;
421
		document.iform.ldap.disabled = endis;
422
		document.iform.netboot.disabled = endis;
423
		document.iform.nextserver.disabled = endis;
424
		document.iform.filename.disabled = endis;
425
		document.iform.rootpath.disabled = endis;
426
		document.iform.denyunknown.disabled = endis;
427
	}
428

    
429
	function show_shownumbervalue() {
430
		document.getElementById("shownumbervaluebox").innerHTML='';
431
		aodiv = document.getElementById('shownumbervalue');
432
		aodiv.style.display = "block";
433
	}
434

    
435
	function show_ddns_config() {
436
		document.getElementById("showddnsbox").innerHTML='';
437
		aodiv = document.getElementById('showddns');
438
		aodiv.style.display = "block";
439
	}
440

    
441
	function show_ntp_config() {
442
		document.getElementById("showntpbox").innerHTML='';
443
		aodiv = document.getElementById('showntp');
444
		aodiv.style.display = "block";
445
	}
446

    
447
	function show_tftp_config() {
448
		document.getElementById("showtftpbox").innerHTML='';
449
		aodiv = document.getElementById('showtftp');
450
		aodiv.style.display = "block";
451
	}
452

    
453
	function show_ldap_config() {
454
		document.getElementById("showldapbox").innerHTML='';
455
		aodiv = document.getElementById('showldap');
456
		aodiv.style.display = "block";
457
	}
458

    
459
	function show_netboot_config() {
460
		document.getElementById("shownetbootbox").innerHTML='';
461
		aodiv = document.getElementById('shownetboot');
462
		aodiv.style.display = "block";
463
	}
464
</script>
465

    
466
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
467
<?php include("fbegin.inc"); ?>
468
<form action="services_dhcp.php" method="post" name="iform" id="iform">
469
<?php if ($input_errors) print_input_errors($input_errors); ?>
470
<?php if ($savemsg) print_info_box($savemsg); ?>
471
<?php
472
	if ($dhcrelay_enabled) {
473
		echo gettext("DHCP Relay is currently enabled. Cannot enable the DHCP Server service while the DHCP Relay is enabled on any interface.");
474
		include("fend.inc");
475
		echo "</body>";
476
		echo "</html>";
477
		exit;
478
	}
479
?>
480
<?php if (is_subsystem_dirty('staticmaps')): ?><p>
481
<?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>
482
<?php endif; ?>
483
<table width="100%" border="0" cellpadding="0" cellspacing="0">
484
<tr><td>
485
<?php
486
	/* active tabs */
487
	$tab_array = array();
488
	$tabscounter = 0;
489
	$i = 0;
490
	foreach ($iflist as $ifent => $ifname) {
491
		$oc = $config['interfaces'][$ifent];
492
		if ((is_array($config['dhcpd'][$ifent]) && !isset($config['dhcpd'][$ifent]['enable']) && (!is_ipaddr($oc['ipaddr']))) ||
493
			(!is_array($config['dhcpd'][$ifent]) && (!is_ipaddr($oc['ipaddr']))))
494
			continue;
495
		if ($ifent == $if)
496
			$active = true;
497
		else
498
			$active = false;
499
		$tab_array[] = array($ifname, $active, "services_dhcp.php?if={$ifent}");
500
		$tabscounter++;
501
	}
502
	if ($tabscounter == 0) {
503
		echo "</td></tr></table></form>";
504
		include("fend.inc");
505
		echo "</body>";
506
		echo "</html>";
507
		exit;
508
	}
509
	display_top_tabs($tab_array);
510
?>
511
</td></tr>
512
<tr>
513
<td>
514
	<div id="mainarea">
515
		<table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
516
			<tr>
517
			<td width="22%" valign="top" class="vtable">&nbsp;</td>
518
			<td width="78%" class="vtable">
519
				<input name="enable" type="checkbox" value="yes" <?php if ($pconfig['enable']) echo "checked"; ?> onClick="enable_change(false)">
520
			<strong><?php printf(gettext("Enable DHCP server on " .
521
			"%s " .
522
			"interface"),htmlspecialchars($iflist[$if]));?></strong></td>
523
			</tr>
524
			<tr>
525
			<td width="22%" valign="top" class="vtable">&nbsp;</td>
526
			<td width="78%" class="vtable">
527
				<input name="denyunknown" id="denyunknown" type="checkbox" value="yes" <?php if ($pconfig['denyunknown']) echo "checked"; ?>>
528
				<strong><?=gettext("Deny unknown clients");?></strong><br>
529
				<?=gettext("If this is checked, only the clients defined below will get DHCP leases from this server. ");?></td>
530
			</tr>
531
			<tr>
532
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Subnet");?></td>
533
			<td width="78%" class="vtable">
534
				<?=gen_subnet($ifcfgip, $ifcfgsn);?>
535
			</td>
536
			</tr>
537
			<tr>
538
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Subnet mask");?></td>
539
			<td width="78%" class="vtable">
540
				<?=gen_subnet_mask($ifcfgsn);?>
541
			</td>
542
			</tr>
543
			<tr>
544
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Available range");?></td>
545
			<td width="78%" class="vtable">
546
			<?php
547
				$range_from = ip2long(long2ip32(ip2long($ifcfgip) & gen_subnet_mask_long($ifcfgsn)));
548
				$range_from++;
549
				echo long2ip32($range_from);
550
			?>
551
			-
552
			<?php
553
				$range_to = ip2long(long2ip32(ip2long($ifcfgip) | (~gen_subnet_mask_long($ifcfgsn))));
554
				$range_to--;
555
				echo long2ip32($range_to);
556
			?>
557
			</td>
558
			</tr>
559
			<?php if($is_olsr_enabled): ?>
560
			<tr>
561
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Subnet Mask");?></td>
562
			<td width="78%" class="vtable">
563
				<select name="netmask" class="formselect" id="netmask">
564
				<?php
565
				for ($i = 32; $i > 0; $i--) {
566
					if($i <> 31) {
567
						echo "<option value=\"{$i}\" ";
568
						if ($i == $pconfig['netmask']) echo "selected";
569
						echo ">" . $i . "</option>";
570
					}
571
				}
572
				?>
573
				</select>
574
			</td>
575
			</tr>
576
			<?php endif; ?>
577
			<tr>
578
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Range");?></td>
579
			<td width="78%" class="vtable">
580
				<input name="range_from" type="text" class="formfld unknown" id="range_from" size="20" value="<?=htmlspecialchars($pconfig['range_from']);?>">
581
				&nbsp;<?=gettext("to"); ?>&nbsp; <input name="range_to" type="text" class="formfld unknown" id="range_to" size="20" value="<?=htmlspecialchars($pconfig['range_to']);?>">
582
			</td>
583
			</tr>
584
			<tr>
585
			<td width="22%" valign="top" class="vncell"><?=gettext("WINS servers");?></td>
586
			<td width="78%" class="vtable">
587
				<input name="wins1" type="text" class="formfld unknown" id="wins1" size="20" value="<?=htmlspecialchars($pconfig['wins1']);?>"><br>
588
				<input name="wins2" type="text" class="formfld unknown" id="wins2" size="20" value="<?=htmlspecialchars($pconfig['wins2']);?>">
589
			</td>
590
			</tr>
591
			<tr>
592
			<td width="22%" valign="top" class="vncell"><?=gettext("DNS servers");?></td>
593
			<td width="78%" class="vtable">
594
				<input name="dns1" type="text" class="formfld unknown" id="dns1" size="20" value="<?=htmlspecialchars($pconfig['dns1']);?>"><br>
595
				<input name="dns2" type="text" class="formfld unknown" id="dns2" size="20" value="<?=htmlspecialchars($pconfig['dns2']);?>"><br>
596
				<?=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.");?>
597
			</td>
598
			</tr>
599
			<tr>
600
			<td width="22%" valign="top" class="vncell"><?=gettext("Gateway");?></td>
601
			<td width="78%" class="vtable">
602
				<input name="gateway" type="text" class="formfld host" id="gateway" size="20" value="<?=htmlspecialchars($pconfig['gateway']);?>"><br>
603
			 	 <?=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.");?>
604
			</td>
605
			</tr>
606
			<tr>
607
			<td width="22%" valign="top" class="vncell"><?=gettext("Domain name");?></td>
608
			<td width="78%" class="vtable">
609
				<input name="domain" type="text" class="formfld unknown" id="domain" size="20" value="<?=htmlspecialchars($pconfig['domain']);?>"><br>
610
				 <?=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.");?>
611
			 </td>
612
			</tr>
613
			<tr>
614
			<td width="22%" valign="top" class="vncell"><?=gettext("Domain search list");?></td>
615
			<td width="78%" class="vtable">
616
				<input name="domainsearchlist" type="text" class="formfld unknown" id="domainsearchlist" size="20" value="<?=htmlspecialchars($pconfig['domainsearchlist']);?>"><br>
617
				<?=gettext("The DHCP server can optionally provide a domain search list.");?>
618
			</td>
619
			</tr>
620
			<tr>
621
			<td width="22%" valign="top" class="vncell"><?=gettext("Default lease time");?></td>
622
			<td width="78%" class="vtable">
623
				<input name="deftime" type="text" class="formfld unknown" id="deftime" size="10" value="<?=htmlspecialchars($pconfig['deftime']);?>">
624
				<?=gettext("seconds");?><br>
625
				<?=gettext("This is used for clients that do not ask for a specific " .
626
				"expiration time"); ?>.<br>
627
				<?=gettext("The default is 7200 seconds");?>.
628
			</td>
629
			</tr>
630
			<tr>
631
			<td width="22%" valign="top" class="vncell"><?=gettext("Maximum lease time");?></td>
632
			<td width="78%" class="vtable">
633
				<input name="maxtime" type="text" class="formfld unknown" id="maxtime" size="10" value="<?=htmlspecialchars($pconfig['maxtime']);?>">
634
				<?=gettext("seconds");?><br>
635
				<?=gettext("This is the maximum lease time for clients that ask".
636
				" for a specific expiration time"); ?>.<br>
637
				<?=gettext("The default is 86400 seconds");?>.
638
			</td>
639
			</tr>
640
			<tr>
641
			<td width="22%" valign="top" class="vncell"><?=gettext("Failover peer IP");?>:</td>
642
			<td width="78%" class="vtable">
643
				<input name="failover_peerip" type="text" class="formfld host" id="failover_peerip" size="20" value="<?=htmlspecialchars($pconfig['failover_peerip']);?>"><br>
644
				<?=gettext("Leave blank to disable.  Enter the interface IP address of the other machine.  Machines must be using CARP.");?>
645
			</td>
646
			</tr>
647
			<tr>
648
			<td width="22%" valign="top" class="vncell"><?=gettext("Static ARP");?></td>
649
			<td width="78%" class="vtable">
650
				<table>
651
					<tr>
652
					<td>
653
						<input valign="middle" type="checkbox" value="yes" name="staticarp" id="staticarp" <?php if($pconfig['staticarp']) echo " checked"; ?>>&nbsp;
654
					</td>
655
					<td><b><?=gettext("Enable Static ARP entries");?></b></td>
656
					</tr>
657
					<tr>
658
					<td>&nbsp;</td>
659
					<td>
660
						<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.");?>
661
					</td>
662
					</tr>
663
				</table>
664
			</td>
665
			</tr>
666
			<tr>
667
			<td width="22%" valign="top" class="vncell"><?=gettext("Dynamic DNS");?></td>
668
			<td width="78%" class="vtable">
669
				<div id="showddnsbox">
670
					<input type="button" onClick="show_ddns_config()" value="<?=gettext("Advanced");?>"></input> - <?=gettext("Show Dynamic DNS");?></a>
671
				</div>
672
				<div id="showddns" style="display:none">
673
					<input valign="middle" type="checkbox" value="yes" name="ddnsupdate" id="ddnsupdate" <?php if($pconfig['ddnsupdate']) echo " checked"; ?>>&nbsp;
674
					<b><?=gettext("Enable registration of DHCP client names in DNS.");?></b><br />
675
					<p>
676
					<input name="ddnsdomain" type="text" class="formfld unknown" id="ddnsdomain" size="20" value="<?=htmlspecialchars($pconfig['ddnsdomain']);?>"><br />
677
					<?=gettext("Note: Leave blank to disable dynamic DNS registration");?>.<br />
678
					<?=gettext("Enter the dynamic DNS domain which will be used to register client names in the DNS server");?>.
679
				</div>
680
			</td>
681
			</tr>
682
			<tr>
683
			<td width="22%" valign="top" class="vncell"><?=gettext("NTP servers");?></td>
684
			<td width="78%" class="vtable">
685
				<div id="showntpbox">
686
					<input type="button" onClick="show_ntp_config()" value="<?=gettext("Advanced");?>"></input> - <?=gettext("Show NTP configuration");?></a>
687
				</div>
688
				<div id="showntp" style="display:none">
689
					<input name="ntp1" type="text" class="formfld unknown" id="ntp1" size="20" value="<?=htmlspecialchars($pconfig['ntp1']);?>"><br>
690
					<input name="ntp2" type="text" class="formfld unknown" id="ntp2" size="20" value="<?=htmlspecialchars($pconfig['ntp2']);?>">
691
				</div>
692
			</td>
693
			</tr>
694
			<tr>
695
			<td width="22%" valign="top" class="vncell"><?=gettext("TFTP server");?></td>
696
			<td width="78%" class="vtable">
697
			<div id="showtftpbox">
698
				<input type="button" onClick="show_tftp_config()" value="<?=gettext("Advanced");?>"></input> - <?=gettext("Show TFTP configuration");?></a>
699
			</div>
700
			<div id="showtftp" style="display:none">
701
				<input name="tftp" type="text" class="formfld unknown" id="tftp" size="50" value="<?=htmlspecialchars($pconfig['tftp']);?>"><br>
702
				<?=gettext("Leave blank to disable.  Enter a full hostname or IP for the TFTP server.");?>
703
			</div>
704
			</td>
705
			</tr>
706
			<tr>
707
			<td width="22%" valign="top" class="vncell"><?=gettext("LDAP URI");?></td>
708
			<td width="78%" class="vtable">
709
				<div id="showldapbox">
710
					<input type="button" onClick="show_ldap_config()" value="<?=gettext("Advanced");?>"></input> - <?=gettext("Show LDAP configuration");?></a>
711
				</div>
712
				<div id="showldap" style="display:none">
713
					<input name="ldap" type="text" class="formfld unknown" id="ldap" size="80" value="<?=htmlspecialchars($pconfig['ldap']);?>"><br>
714
					<?=gettext("Leave blank to disable.  Enter a full URI for the LDAP server in the form ldap://ldap.example.com/dc=example,dc=com");?>
715
				</div>
716
			</td>
717
			</tr>
718
			<tr>
719
			<td width="22%" valign="top" class="vncell"><?=gettext("Enable network booting");?></td>
720
			<td width="78%" class="vtable">
721
				<div id="shownetbootbox">
722
					<input type="button" onClick="show_netboot_config()" value="<?=gettext("Advanced");?>"></input> - <?=gettext("Show Network booting");?></a>
723
				</div>
724
				<div id="shownetboot" style="display:none">
725
					<input valign="middle" type="checkbox" value="yes" name="netboot" id="netboot" <?php if($pconfig['netboot']) echo " checked"; ?>>&nbsp;
726
					<b><?=gettext("Enables network booting.");?></b>
727
					<p>
728
					<?=gettext("Enter the IP of the"); ?> <b><?=gettext("next-server"); ?></b>
729
					<input name="nextserver" type="text" class="formfld unknown" id="nextserver" size="20" value="<?=htmlspecialchars($pconfig['nextserver']);?>">
730
					<?=gettext("and the filename");?>
731
					<input name="filename" type="text" class="formfld unknown" id="filename" size="20" value="<?=htmlspecialchars($pconfig['filename']);?>"><br>
732
					<?=gettext("Note: You need both a filename and a boot server configured for this to work!");?>
733
					<p>
734
					<?=gettext("Enter the"); ?> <b><?=gettext("root-path"); ?></b>-<?=gettext("string");?>
735
					<input name="rootpath" type="text" class="formfld unknown" id="rootpath" size="90" value="<?=htmlspecialchars($pconfig['rootpath']);?>"><br>
736
					<?=gettext("Note: string-format: iscsi:(servername):(protocol):(port):(LUN):targetname");?>
737
				</div>
738
			</td>
739
			</tr>
740
			<tr>
741
			<td width="22%" valign="top" class="vncell"><?=gettext("Additional BOOTP/DHCP Options");?></td>
742
			<td width="78%" class="vtable">
743
				<div id="shownumbervaluebox">
744
					<input type="button" onClick="show_shownumbervalue()" value="<?=gettext("Advanced");?>"></input> - <?=gettext("Show Additional BOOTP/DHCP Options");?></a>
745
				</div>
746
				<div id="shownumbervalue" style="display:none">
747
				<table id="maintable">
748
				<tbody>
749
				<tr>
750
				<td colspan="3">
751
					<div style="padding:5px; margin-top: 16px; margin-bottom: 16px; border:1px dashed #000066; background-color: #ffffff; color: #000000; font-size: 8pt;" id="itemhelp">
752
					<?=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>
753
					</div>
754
				</td>
755
				</tr>
756
				<tr>
757
				<td><div id="onecolumn"><?=gettext("Number");?></div></td>
758
				<td><div id="twocolumn"><?=gettext("Value");?></div></td>
759
				</tr>
760
				<?php $counter = 0; ?>
761
				<?php
762
					if($pconfig['numberoptions'])
763
						foreach($pconfig['numberoptions']['item'] as $item):
764
				?>
765
					<?php
766
						$number = $item['number'];
767
						$value = $item['value'];
768
					?>
769
				<tr>
770
				<td>
771
					<input autocomplete="off" name="number<?php echo $counter; ?>" type="text" class="formfld" id="number<?php echo $counter; ?>" size="10" value="<?=htmlspecialchars($number);?>" />
772
				</td>
773
				<td>
774
					<input autocomplete="off" name="value<?php echo $counter; ?>" type="text" class="formfld" id="value<?php echo $counter; ?>" size="55" value="<?=htmlspecialchars($value);?>" />
775
				</td>
776
				<td>
777
					<input type="image" src="/themes/<?echo $g['theme'];?>/images/icons/icon_x.gif" onclick="removeRow(this); return false;" value="<?=gettext("Delete");?>" />
778
				</td>
779
				</tr>
780
				<?php $counter++; ?>
781
				<?php endforeach; ?>
782
				</tbody>
783
				<tfoot>
784
				</tfoot>
785
				</table>
786
				<a onclick="javascript:addRowTo('maintable', 'formfldalias'); return false;" href="#">
787
					<img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="<?=gettext("add another entry");?>" />
788
				</a>
789
				<script type="text/javascript">
790
					field_counter_js = 2;
791
					rows = 1;
792
					totalrows = <?php echo $counter; ?>;
793
					loaded = <?php echo $counter; ?>;
794
				</script>
795
				</div>
796

    
797
				</td>
798
			</tr>
799
			<tr>
800
			<td width="22%" valign="top">&nbsp;</td>
801
			<td width="78%">
802
				<input name="if" type="hidden" value="<?=$if;?>">
803
				<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" onclick="enable_change(true)">
804
			</td>
805
			</tr>
806
			<tr>
807
			<td width="22%" valign="top">&nbsp;</td>
808
			<td width="78%"> <p><span class="vexpl"><span class="red"><strong><?=gettext("Note");?>:<br>
809
				</strong></span><?=gettext("The DNS servers entered in"); ?> <a href="system.php"><?=gettext("System: " .
810
				"General setup"); ?></a> <?=gettext("(or the"); ?> <a href="services_dnsmasq.php"><?=gettext("DNS " .
811
				"forwarder"); ?></a>, <?=gettext("if enabled)"); ?> </span><span class="vexpl"><?=gettext("will " .
812
				"be assigned to clients by the DHCP server"); ?>.<br>
813
				<br>
814
				<?=gettext("The DHCP lease table can be viewed on the"); ?> <a href="status_dhcp_leases.php"><?=gettext("Status: " .
815
				"DHCP leases"); ?></a> <?=gettext("page"); ?>.<br>
816
				</span></p>
817
			</td>
818
			</tr>
819
		</table>
820
		<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
821
		<tr>
822
			<td width="25%" class="listhdrr"><?=gettext("MAC address");?></td>
823
			<td width="15%" class="listhdrr"><?=gettext("IP address");?></td>
824
			<td width="20%" class="listhdrr"><?=gettext("Hostname");?></td>
825
			<td width="30%" class="listhdr"><?=gettext("Description");?></td>
826
			<td width="10%" class="list">
827
			<table border="0" cellspacing="0" cellpadding="1">
828
			<tr>
829
			<td valign="middle" width="17"></td>
830
			<td valign="middle"><a href="services_dhcp_edit.php?if=<?=$if;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td>
831
			</tr>
832
			</table>
833
			</td>
834
		</tr>
835
			<?php if(is_array($a_maps)): ?>
836
			<?php $i = 0; foreach ($a_maps as $mapent): ?>
837
			<?php if($mapent['mac'] <> "" or $mapent['ipaddr'] <> ""): ?>
838
		<tr>
839
		<td class="listlr" ondblclick="document.location='services_dhcp_edit.php?if=<?=$if;?>&id=<?=$i;?>';">
840
			<?=htmlspecialchars($mapent['mac']);?>
841
		</td>
842
		<td class="listr" ondblclick="document.location='services_dhcp_edit.php?if=<?=$if;?>&id=<?=$i;?>';">
843
			<?=htmlspecialchars($mapent['ipaddr']);?>&nbsp;
844
		</td>
845
		<td class="listr" ondblclick="document.location='services_dhcp_edit.php?if=<?=$if;?>&id=<?=$i;?>';">
846
			<?=htmlspecialchars($mapent['hostname']);?>&nbsp;
847
		</td>
848
		<td class="listbg" ondblclick="document.location='services_dhcp_edit.php?if=<?=$if;?>&id=<?=$i;?>';">
849
			<?=htmlspecialchars($mapent['descr']);?>&nbsp;
850
		</td>
851
		<td valign="middle" nowrap class="list">
852
			<table border="0" cellspacing="0" cellpadding="1">
853
			<tr>
854
			<td valign="middle"><a href="services_dhcp_edit.php?if=<?=$if;?>&id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0"></a></td>
855
			<td valign="middle"><a href="services_dhcp.php?if=<?=$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>
856
			</tr>
857
			</table>
858
		</td>
859
		</tr>
860
		<?php endif; ?>
861
		<?php $i++; endforeach; ?>
862
		<?php endif; ?>
863
		<tr>
864
		<td class="list" colspan="4"></td>
865
		<td class="list">
866
			<table border="0" cellspacing="0" cellpadding="1">
867
			<tr>
868
			<td valign="middle" width="17"></td>
869
			<td valign="middle"><a href="services_dhcp_edit.php?if=<?=$if;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td>
870
			</tr>
871
			</table>
872
		</td>
873
		</tr>
874
		</table>
875
	</div>
876
</td>
877
</tr>
878
</table>
879
</form>
880
<script language="JavaScript">
881
<!--
882
enable_change(false);
883
//-->
884
</script>
885
<?php include("fend.inc"); ?>
886
</body>
887
</html>
(134-134/222)