Project

General

Profile

Download (37.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>The DHCP Server can only be enabled on interfaces configured with static IP addresses.<p> 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 ( (ip2long($test) < ip2long($end)) && (ip2long($test) > ip2long($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
	/* input validation */
197
	if ($_POST['enable']) {
198
		$reqdfields = explode(" ", "range_from range_to");
199
		$reqdfieldsn = explode(",", "Range begin,Range end");
200

    
201
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
202
		
203
		if (($_POST['range_from'] && !is_ipaddr($_POST['range_from']))) 
204
			$input_errors[] = "A valid range must be specified.";
205
		if (($_POST['range_to'] && !is_ipaddr($_POST['range_to']))) 
206
			$input_errors[] = "A valid range must be specified.";
207
		if (($_POST['gateway'] && !is_ipaddr($_POST['gateway']))) 
208
			$input_errors[] = "A valid IP address must be specified for the gateway.";
209
		if (($_POST['wins1'] && !is_ipaddr($_POST['wins1'])) || ($_POST['wins2'] && !is_ipaddr($_POST['wins2']))) 
210
			$input_errors[] = "A valid IP address must be specified for the primary/secondary WINS servers.";
211
		if (($_POST['dns1'] && !is_ipaddr($_POST['dns1'])) || ($_POST['dns2'] && !is_ipaddr($_POST['dns2']))) 
212
			$input_errors[] = "A valid IP address must be specified for the primary/secondary DNS servers.";
213

    
214
		if ($_POST['deftime'] && (!is_numeric($_POST['deftime']) || ($_POST['deftime'] < 60))) 
215
			$input_errors[] = "The default lease time must be at least 60 seconds.";
216
		if ($_POST['maxtime'] && (!is_numeric($_POST['maxtime']) || ($_POST['maxtime'] < 60) || ($_POST['maxtime'] <= $_POST['deftime']))) 
217
			$input_errors[] = "The maximum lease time must be at least 60 seconds and higher than the default lease time.";
218
		if (($_POST['ddnsdomain'] && !is_domain($_POST['ddnsdomain']))) 
219
			$input_errors[] = "A valid domain name must be specified for the dynamic DNS registration.";
220
		if (($_POST['ntp1'] && !is_ipaddr($_POST['ntp1'])) || ($_POST['ntp2'] && !is_ipaddr($_POST['ntp2']))) 
221
			$input_errors[] = "A valid IP address must be specified for the primary/secondary NTP servers.";
222
		if (($_POST['domain'] && !is_domain($_POST['domain'])))
223
			$input_errors[] = "A valid domain name must be specified for the DNS domain.";
224
		if (($_POST['tftp'] && (!is_ipaddr($_POST['tftp']) && !is_domain($_POST['tftp']))))
225
			$input_errors[] = "A valid IP address or hostname must be specified for the TFTP server.";
226
		if (($_POST['nextserver'] && !is_ipaddr($_POST['nextserver']))) 
227
			$input_errors[] = "A valid IP address must be specified for the network boot server.";
228

    
229
		if(gen_subnet($ifcfgip, $ifcfgsn) == $_POST['range_from'])
230
			$input_errors[] = "You cannot use the network address in the starting subnet range.";
231
		if(gen_subnet_max($ifcfgip, $ifcfgsn) == $_POST['range_to'])
232
			$input_errors[] = "You cannot use the broadcast address in the ending subnet range.";
233

    
234
		// Disallow a range that includes the virtualip
235
		if (is_array($config['virtualip']['vip'])) {
236
			foreach($config['virtualip']['vip'] as $vip) {
237
				if($vip['interface'] == $if) 
238
					if($vip['subnet'] && is_inrange($vip['subnet'], $_POST['range_from'], $_POST['range_to'])) 
239
						$input_errors[] = "The subnet range cannot overlap with virtual IP address {$vip['subnet']}.";
240
			}
241
		}
242

    
243
		if (!$input_errors) {
244
			/* make sure the range lies within the current subnet */
245
			$subnet_start = (ip2long($ifcfgip) & gen_subnet_mask_long($ifcfgsn));
246
			$subnet_end = (ip2long($ifcfgip) | (~gen_subnet_mask_long($ifcfgsn)));
247

    
248
			if ((ip2long($_POST['range_from']) < $subnet_start) || (ip2long($_POST['range_from']) > $subnet_end) ||
249
			    (ip2long($_POST['range_to']) < $subnet_start) || (ip2long($_POST['range_to']) > $subnet_end)) {
250
				$input_errors[] = "The specified range lies outside of the current subnet.";
251
			}
252

    
253
			if (ip2long($_POST['range_from']) > ip2long($_POST['range_to']))
254
				$input_errors[] = "The range is invalid (first element higher than second element).";
255

    
256
			/* make sure that the DHCP Relay isn't enabled on this interface */
257
			if (isset($config['dhcrelay'][$if]['enable']))
258
				$input_errors[] = "You must disable the DHCP relay on the {$iflist[$if]} interface before enabling the DHCP server.";
259
		}
260
	}
261

    
262
	if (!$input_errors) {
263
		if (!is_array($config['dhcpd'][$if]))
264
			$config['dhcpd'][$if] = array();
265
		if (!is_array($config['dhcpd'][$if]['range']))
266
			$config['dhcpd'][$if]['range'] = array();
267

    
268
		$config['dhcpd'][$if]['range']['from'] = $_POST['range_from'];
269
		$config['dhcpd'][$if]['range']['to'] = $_POST['range_to'];
270
		$config['dhcpd'][$if]['defaultleasetime'] = $_POST['deftime'];
271
		$config['dhcpd'][$if]['maxleasetime'] = $_POST['maxtime'];
272
		$config['dhcpd'][$if]['netmask'] = $_POST['netmask'];
273
		$previous = $config['dhcpd'][$if]['failover_peerip'];
274
		if($previous <> $_POST['failover_peerip']) 
275
			mwexec("/bin/rm -rf /var/dhcpd/var/db/*");
276

    
277
		$config['dhcpd'][$if]['failover_peerip'] = $_POST['failover_peerip'];
278

    
279
		unset($config['dhcpd'][$if]['winsserver']);
280
		if ($_POST['wins1'])
281
			$config['dhcpd'][$if]['winsserver'][] = $_POST['wins1'];
282
		if ($_POST['wins2'])
283
			$config['dhcpd'][$if]['winsserver'][] = $_POST['wins2'];
284

    
285
		unset($config['dhcpd'][$if]['dnsserver']);
286
		if ($_POST['dns1'])
287
			$config['dhcpd'][$if]['dnsserver'][] = $_POST['dns1'];
288
		if ($_POST['dns2'])
289
			$config['dhcpd'][$if]['dnsserver'][] = $_POST['dns2'];
290

    
291
		$config['dhcpd'][$if]['gateway'] = $_POST['gateway'];
292
		$config['dhcpd'][$if]['domain'] = $_POST['domain'];
293
		$config['dhcpd'][$if]['domainsearchlist'] = $_POST['domainsearchlist'];
294
		$config['dhcpd'][$if]['denyunknown'] = ($_POST['denyunknown']) ? true : false;
295
		$config['dhcpd'][$if]['enable'] = ($_POST['enable']) ? true : false;
296
		$config['dhcpd'][$if]['staticarp'] = ($_POST['staticarp']) ? true : false;
297
		$config['dhcpd'][$if]['ddnsdomain'] = $_POST['ddnsdomain'];
298
		$config['dhcpd'][$if]['ddnsupdate'] = ($_POST['ddnsupdate']) ? true : false;
299

    
300
		unset($config['dhcpd'][$if]['ntpserver']);
301
		if ($_POST['ntp1'])
302
			$config['dhcpd'][$if]['ntpserver'][] = $_POST['ntp1'];
303
		if ($_POST['ntp2'])
304
			$config['dhcpd'][$if]['ntpserver'][] = $_POST['ntp2'];
305

    
306
		$config['dhcpd'][$if]['tftp'] = $_POST['tftp'];
307
		$config['dhcpd'][$if]['ldap'] = $_POST['ldap'];
308
		$config['dhcpd'][$if]['netboot'] = ($_POST['netboot']) ? true : false;
309
		$config['dhcpd'][$if]['next-server'] = $_POST['nextserver'];
310
		$config['dhcpd'][$if]['filename'] = $_POST['filename'];
311
		$config['dhcpd'][$if]['rootpath'] = $_POST['rootpath'];
312

    
313
		// Handle the custom options rowhelper
314
		if(isset($config['dhcpd'][$if]['numberoptions']['item']))
315
			unset($config['dhcpd'][$if]['numberoptions']['item']);
316
		for($x=0; $x<99; $x++) {
317
			if(isset($_POST["number{$x}"]) && ctype_digit($_POST["number{$x}"])) {
318
				$numbervalue = array();
319
				$numbervalue['number'] = htmlspecialchars($_POST["number{$x}"]);
320
				$numbervalue['value'] = htmlspecialchars($_POST["value{$x}"]);
321
				$config['dhcpd'][$if]['numberoptions']['item'][] = $numbervalue;
322
			}
323
		}
324
		
325
		// Reload the new pconfig variable that the forum uses.
326
		$pconfig['numberoptions'] = $config['dhcpd'][$if]['numberoptions'];
327

    
328
		write_config();
329

    
330
		/* static arp configuration */
331
		interfaces_staticarp_configure($if);
332

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

    
358
if ($_GET['act'] == "del") {
359
	if ($a_maps[$_GET['id']]) {
360
		unset($a_maps[$_GET['id']]);
361
		write_config();
362
		if(isset($config['dhcpd'][$if]['enable'])) {
363
			mark_subsystem_dirty('staticmaps');
364
			if (isset($config['dnsmasq']['regdhcpstatic']))
365
				mark_subsystem_dirty('hosts');
366
		}
367
		header("Location: services_dhcp.php?if={$if}");
368
		exit;
369
	}
370
}
371

    
372
$pgtitle = array("Services","DHCP server");
373
include("head.inc");
374

    
375
?>
376

    
377
<script type="text/javascript" src="/javascript/row_helper.js">
378
</script>
379

    
380
<script type="text/javascript">
381
	rowname[0] = "number";
382
	rowtype[0] = "textbox";
383
	rowsize[0] = "10";
384
	rowname[1] = "value";
385
	rowtype[1] = "textbox";
386
	rowsize[1] = "55";
387
</script>
388

    
389
<script type="text/javascript" language="JavaScript">
390
	function enable_change(enable_over) {
391
		var endis;
392
		endis = !(document.iform.enable.checked || enable_over);
393
		document.iform.range_from.disabled = endis;
394
		document.iform.range_to.disabled = endis;
395
		document.iform.wins1.disabled = endis;
396
		document.iform.wins2.disabled = endis;
397
		document.iform.dns1.disabled = endis;
398
		document.iform.dns2.disabled = endis;
399
		document.iform.deftime.disabled = endis;
400
		document.iform.maxtime.disabled = endis;
401
		document.iform.gateway.disabled = endis;
402
		document.iform.failover_peerip.disabled = endis;
403
		document.iform.domain.disabled = endis;
404
		document.iform.domainsearchlist.disabled = endis;
405
		document.iform.staticarp.disabled = endis;
406
		document.iform.ddnsdomain.disabled = endis;
407
		document.iform.ddnsupdate.disabled = endis;
408
		document.iform.ntp1.disabled = endis;
409
		document.iform.ntp2.disabled = endis;
410
		document.iform.tftp.disabled = endis;
411
		document.iform.ldap.disabled = endis;
412
		document.iform.netboot.disabled = endis;
413
		document.iform.nextserver.disabled = endis;
414
		document.iform.filename.disabled = endis;
415
		document.iform.rootpath.disabled = endis;
416
		document.iform.denyunknown.disabled = endis;
417
	}
418

    
419
	function show_shownumbervalue() {
420
		document.getElementById("shownumbervaluebox").innerHTML='';
421
		aodiv = document.getElementById('shownumbervalue');
422
		aodiv.style.display = "block";
423
	}
424

    
425
	function show_ddns_config() {
426
		document.getElementById("showddnsbox").innerHTML='';
427
		aodiv = document.getElementById('showddns');
428
		aodiv.style.display = "block";
429
	}
430

    
431
	function show_ntp_config() {
432
		document.getElementById("showntpbox").innerHTML='';
433
		aodiv = document.getElementById('showntp');
434
		aodiv.style.display = "block";
435
	}
436

    
437
	function show_tftp_config() {
438
		document.getElementById("showtftpbox").innerHTML='';
439
		aodiv = document.getElementById('showtftp');
440
		aodiv.style.display = "block";
441
	}
442

    
443
	function show_ldap_config() {
444
		document.getElementById("showldapbox").innerHTML='';
445
		aodiv = document.getElementById('showldap');
446
		aodiv.style.display = "block";
447
	}
448

    
449
	function show_netboot_config() {
450
		document.getElementById("shownetbootbox").innerHTML='';
451
		aodiv = document.getElementById('shownetboot');
452
		aodiv.style.display = "block";
453
	}
454
</script>
455

    
456
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
457
<?php include("fbegin.inc"); ?>
458
<form action="services_dhcp.php" method="post" name="iform" id="iform">
459
<?php if ($input_errors) print_input_errors($input_errors); ?>
460
<?php if ($savemsg) print_info_box($savemsg); ?>
461
<?php 
462
	if ($dhcrelay_enabled) {
463
		echo "DHCP Relay is currently enabled.  Cannot enable the DHCP Server service while the DHCP Relay is enabled on any interface.";
464
		include("fend.inc"); 
465
		echo "</body>";
466
		echo "</html>";
467
		exit;
468
	}
469
?>
470
<?php if (is_subsystem_dirty('staticmaps')): ?><p>
471
<?php print_info_box_np("The static mapping configuration has been changed.<br>You must apply the changes in order for them to take effect.");?><br>
472
<?php endif; ?>
473
<table width="100%" border="0" cellpadding="0" cellspacing="0">
474
  <tr><td>
475
  <?php
476
	/* active tabs */
477
	$tab_array = array();
478
	$tabscounter = 0;
479
	$i = 0;
480
	foreach ($iflist as $ifent => $ifname) {
481
        	$oc = $config['interfaces'][$ifent];
482
		if ((is_array($config['dhcpd'][$ifent]) && !isset($config['dhcpd'][$ifent]['enable']) && (!is_ipaddr($oc['ipaddr']))) || 
483
			(!is_array($config['dhcpd'][$ifent]) && (!is_ipaddr($oc['ipaddr']))))
484
			continue;
485
		if ($ifent == $if)
486
			$active = true;
487
		else
488
			$active = false;
489
		$tab_array[] = array($ifname, $active, "services_dhcp.php?if={$ifent}");
490
		$tabscounter++;
491
	}
492
	if ($tabscounter == 0) {
493
		echo "</td></tr></table></form>";
494
		include("fend.inc");
495
		echo "</body>";
496
		echo "</html>";
497
		exit;
498
	}
499
	display_top_tabs($tab_array);
500
  ?>
501
  </td></tr>
502
  <tr>
503
    <td>
504
	<div id="mainarea">
505
              <table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
506
                      <tr>
507
                        <td width="22%" valign="top" class="vtable">&nbsp;</td>
508
                        <td width="78%" class="vtable">
509
			  			<input name="enable" type="checkbox" value="yes" <?php if ($pconfig['enable']) echo "checked"; ?> onClick="enable_change(false)">
510
                          <strong>Enable DHCP server on
511
                          <?=htmlspecialchars($iflist[$if]);?>
512
                          interface</strong></td>
513
                      </tr>
514
				  <tr>
515
	              <td width="22%" valign="top" class="vtable">&nbsp;</td>
516
                      <td width="78%" class="vtable">
517
					  <input name="denyunknown" id="denyunknown" type="checkbox" value="yes" <?php if ($pconfig['denyunknown']) echo "checked"; ?>>
518
                      <strong>Deny unknown clients</strong><br>
519
                      If this is checked, only the clients defined below will get DHCP leases from this server. </td>
520
		      		  </tr>
521
                      <tr>
522
                        <td width="22%" valign="top" class="vncellreq">Subnet</td>
523
                        <td width="78%" class="vtable">
524
                          <?=gen_subnet($ifcfgip, $ifcfgsn);?>
525
                        </td>
526
                      </tr>
527
                      <tr>
528
                        <td width="22%" valign="top" class="vncellreq">Subnet mask</td>
529
                        <td width="78%" class="vtable">
530
                          <?=gen_subnet_mask($ifcfgsn);?>
531
                        </td>
532
                      </tr>
533
                      <tr>
534
                        <td width="22%" valign="top" class="vncellreq">Available range</td>
535
                        <td width="78%" class="vtable">
536
                          <?php 
537
								$range_from = ip2long(long2ip(ip2long($ifcfgip) & gen_subnet_mask_long($ifcfgsn))); 
538
								$range_from++;
539
								echo long2ip($range_from);
540
							?>
541
                          -
542
                          <?php
543
								$range_to = ip2long(long2ip(ip2long($ifcfgip) | (~gen_subnet_mask_long($ifcfgsn))));
544
								$range_to--;
545
								echo long2ip($range_to);
546
						  ?>
547
                        </td>
548
                      </tr>
549
					  <?php if($is_olsr_enabled): ?>
550
                      <tr>
551
                        <td width="22%" valign="top" class="vncellreq">Subnet Mask</td>
552
                        <td width="78%" class="vtable">
553
	                        <select name="netmask" class="formselect" id="netmask">
554
							<?php
555
							for ($i = 32; $i > 0; $i--) {
556
								if($i <> 31) {
557
									echo "<option value=\"{$i}\" ";
558
									if ($i == $pconfig['netmask']) echo "selected";
559
									echo ">" . $i . "</option>";
560
								}
561
							}
562
							?>
563
							</select>
564
                        </td>
565
                      </tr>
566
                      <?php endif; ?>
567
                      <tr>
568
                        <td width="22%" valign="top" class="vncellreq">Range</td>
569
                        <td width="78%" class="vtable">
570
                          <input name="range_from" type="text" class="formfld unknown" id="range_from" size="20" value="<?=htmlspecialchars($pconfig['range_from']);?>">
571
                          &nbsp;to&nbsp; <input name="range_to" type="text" class="formfld unknown" id="range_to" size="20" value="<?=htmlspecialchars($pconfig['range_to']);?>">
572
					   </td>
573
                      </tr>
574
                      <tr>
575
                        <td width="22%" valign="top" class="vncell">WINS servers</td>
576
                        <td width="78%" class="vtable">
577
                          <input name="wins1" type="text" class="formfld unknown" id="wins1" size="20" value="<?=htmlspecialchars($pconfig['wins1']);?>"><br>
578
                          <input name="wins2" type="text" class="formfld unknown" id="wins2" size="20" value="<?=htmlspecialchars($pconfig['wins2']);?>">
579
					   </td>
580
                      </tr>
581
                      <tr>
582
                        <td width="22%" valign="top" class="vncell">DNS servers</td>
583
                        <td width="78%" class="vtable">
584
                          <input name="dns1" type="text" class="formfld unknown" id="dns1" size="20" value="<?=htmlspecialchars($pconfig['dns1']);?>"><br>
585
                          <input name="dns2" type="text" class="formfld unknown" id="dns2" size="20" value="<?=htmlspecialchars($pconfig['dns2']);?>"><br>
586
					   	  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.  
587
					   </td>
588
                      </tr>
589
                     <tr>
590
                       <td width="22%" valign="top" class="vncell">Gateway</td>
591
                       <td width="78%" class="vtable">
592
                         <input name="gateway" type="text" class="formfld host" id="gateway" size="20" value="<?=htmlspecialchars($pconfig['gateway']);?>"><br>
593
			 			 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.
594
					   </td>
595
                     </tr>
596
                      <tr>
597
                       <td width="22%" valign="top" class="vncell">Domain name</td>
598
                       <td width="78%" class="vtable">
599
                         <input name="domain" type="text" class="formfld unknown" id="domain" size="20" value="<?=htmlspecialchars($pconfig['domain']);?>"><br>
600
			 			 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.
601
					 </td>
602
                     </tr>
603
                      <tr>
604
                       <td width="22%" valign="top" class="vncell">Domain search list</td>
605
                       <td width="78%" class="vtable">
606
                         <input name="domainsearchlist" type="text" class="formfld unknown" id="domainsearchlist" size="20" value="<?=htmlspecialchars($pconfig['domainsearchlist']);?>"><br>
607
			 				The DHCP server can optionally provide a domain search list.
608
						</td>
609
                     </tr>                     
610
                      <tr>
611
                        <td width="22%" valign="top" class="vncell">Default lease time</td>
612
                        <td width="78%" class="vtable">
613
                          <input name="deftime" type="text" class="formfld unknown" id="deftime" size="10" value="<?=htmlspecialchars($pconfig['deftime']);?>">
614
                          seconds<br>
615
                          This is used for clients that do not ask for a specific
616
                          expiration time.<br>
617
                          The default is 7200 seconds.
618
					   </td>
619
                      </tr>
620
                      <tr>
621
                        <td width="22%" valign="top" class="vncell">Maximum lease time</td>
622
                        <td width="78%" class="vtable">
623
                          <input name="maxtime" type="text" class="formfld unknown" id="maxtime" size="10" value="<?=htmlspecialchars($pconfig['maxtime']);?>">
624
                          seconds<br>
625
                          This is the maximum lease time for clients that ask
626
                          for a specific expiration time.<br>
627
                          The default is 86400 seconds.
628
					   </td>
629
                      </tr>
630
                      <tr>
631
                        <td width="22%" valign="top" class="vncell">Failover peer IP:</td>
632
                        <td width="78%" class="vtable">
633
				<input name="failover_peerip" type="text" class="formfld host" id="failover_peerip" size="20" value="<?=htmlspecialchars($pconfig['failover_peerip']);?>"><br>
634
				Leave blank to disable.  Enter the interface IP address of the other machine.  Machines must be using CARP.
635
			</td>
636
			</tr>
637
			<tr>
638
				<td width="22%" valign="top" class="vncell">
639
					Static ARP
640
				</td>
641
				<td width="78%" class="vtable">
642
					<table>
643
						<tr>
644
							<td>
645
								<input valign="middle" type="checkbox" value="yes" name="staticarp" id="staticarp" <?php if($pconfig['staticarp']) echo " checked"; ?>>&nbsp;
646
							</td>
647
							<td>
648
								<b>Enable Static ARP entries</b>
649
							</td>
650
						</tr>
651
						<tr>
652
							<td>
653
								&nbsp;
654
							</td>
655
							<td>
656
								<span class="red"><strong>Note:</strong></span> Only the machines listed below will be able to communicate with the firewall on this NIC.
657
							</td>
658
						</tr>
659
					</table>
660
				</td>
661
			</tr>
662
			<tr>
663
				<td width="22%" valign="top" class="vncell">
664
					Dynamic DNS
665
				</td>
666
				<td width="78%" class="vtable">
667
					<div id="showddnsbox">
668
						<input type="button" onClick="show_ddns_config()" value="Advanced"></input> - Show Dynamic DNS</a>
669
					</div>
670
					<div id="showddns" style="display:none">
671
						<input valign="middle" type="checkbox" value="yes" name="ddnsupdate" id="ddnsupdate" <?php if($pconfig['ddnsupdate']) echo " checked"; ?>>&nbsp;
672
						<b>Enable registration of DHCP client names in DNS.</b><br />
673
						<p>
674
						<input name="ddnsdomain" type="text" class="formfld unknown" id="ddnsdomain" size="20" value="<?=htmlspecialchars($pconfig['ddnsdomain']);?>"><br />
675
						Note: Leave blank to disable dynamic DNS registration.<br />
676
						Enter the dynamic DNS domain which will be used to register client names in the DNS server.
677
					</div>
678
				</td>
679
		      </tr>
680
			<tr>
681
				<td width="22%" valign="top" class="vncell">NTP servers</td>
682
				<td width="78%" class="vtable">
683
				<div id="showntpbox">
684
					<input type="button" onClick="show_ntp_config()" value="Advanced"></input> - Show NTP configuration</a>
685
				</div>
686
				<div id="showntp" style="display:none">
687
					<input name="ntp1" type="text" class="formfld unknown" id="ntp1" size="20" value="<?=htmlspecialchars($pconfig['ntp1']);?>"><br>
688
					<input name="ntp2" type="text" class="formfld unknown" id="ntp2" size="20" value="<?=htmlspecialchars($pconfig['ntp2']);?>">
689
				</div>
690
			</td>
691
			</tr>
692
			<tr>
693
				<td width="22%" valign="top" class="vncell">
694
					TFTP server
695
				</td>
696
				<td width="78%" class="vtable">
697
				<div id="showtftpbox">
698
					<input type="button" onClick="show_tftp_config()" value="Advanced"></input> - 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
					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">LDAP URI</td>
708
					<td width="78%" class="vtable">
709
						<div id="showldapbox">
710
							<input type="button" onClick="show_ldap_config()" value="Advanced"></input> - 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
							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">Enable network booting</td>
720
				<td width="78%" class="vtable">
721
					<div id="shownetbootbox">
722
						<input type="button" onClick="show_netboot_config()" value="Advanced"></input> - 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>Enables network booting.</b>
727
						<p>
728
						Enter the IP of the <b>next-server</b>
729
						<input name="nextserver" type="text" class="formfld unknown" id="nextserver" size="20" value="<?=htmlspecialchars($pconfig['nextserver']);?>">
730
						and the filename					
731
						<input name="filename" type="text" class="formfld unknown" id="filename" size="20" value="<?=htmlspecialchars($pconfig['filename']);?>"><br>
732
						Note: You need both a filename and a boot server configured for this to work!
733
					  	<p>
734
						Enter the <b>root-path</b>-string
735
	          			<input name="rootpath" type="text" class="formfld unknown" id="rootpath" size="90" value="<?=htmlspecialchars($pconfig['rootpath']);?>"><br>
736
	          			Note: string-format: iscsi:(servername):(protocol):(port):(LUN):targetname
737
        			</div>
738
			</td>
739
			</tr>
740
			<tr>
741

    
742

    
743
				<td width="22%" valign="top" class="vncell">
744
					Additional BOOTP/DHCP Options
745
				</td>
746
				<td width="78%" class="vtable">
747
					<div id="shownumbervaluebox">
748
						<input type="button" onClick="show_shownumbervalue()" value="Advanced"></input> - Show Additional BOOTP/DHCP Options</a>
749
					</div>
750
					<div id="shownumbervalue" style="display:none">
751
			    <table id="maintable">
752
			        <tbody>
753
			          <tr>
754
			            <td colspan="3">
755
			      		    <div style="padding:5px; margin-top: 16px; margin-bottom: 16px; border:1px dashed #000066; background-color: #ffffff; color: #000000; font-size: 8pt;" id="itemhelp">
756
								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">URL</a>.
757
							</div>
758
			            </td>
759
			          </tr>
760
			          <tr>
761
			            <td><div id="onecolumn">Number</div></td>
762
			            <td><div id="twocolumn">Value</div></td>
763
			          </tr>
764
				<?php $counter = 0; ?>
765
				<?php 
766
					if($pconfig['numberoptions'])
767
				 		foreach($pconfig['numberoptions']['item'] as $item): 
768
				?>
769
					<?php
770
						$number = $item['number'];
771
						$value = $item['value'];
772
					?>
773
			          <tr>
774
			            <td>
775
							<input autocomplete="off" name="number<?php echo $counter; ?>" type="text" class="formfld" id="number<?php echo $counter; ?>" size="10" value="<?=htmlspecialchars($number);?>" />
776
			            </td>
777
			            <td>
778
							<input autocomplete="off" name="value<?php echo $counter; ?>" type="text" class="formfld" id="value<?php echo $counter; ?>" size="55" value="<?=htmlspecialchars($value);?>" />
779
						</td>
780
			            <td>
781
			    		<input type="image" src="/themes/<?echo $g['theme'];?>/images/icons/icon_x.gif" onclick="removeRow(this); return false;" value="Delete" />
782
				      </td>
783
			          </tr>
784
				<?php $counter++; ?>
785
				<?php endforeach; ?>
786
			        </tbody>
787
			        <tfoot>
788
			        </tfoot>
789
				</table>
790
				<a onclick="javascript:addRowTo('maintable', 'formfldalias'); return false;" href="#">
791
					<img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="add another entry" />
792
				</a>
793
				<script type="text/javascript">
794
					field_counter_js = 2;
795
					rows = 1;
796
					totalrows = <?php echo $counter; ?>;
797
					loaded = <?php echo $counter; ?>;
798
				</script>
799
				</div>
800

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