Project

General

Profile

Download (37.2 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($config['interfaces']['lan']) {
122
	if (!$if || !isset($iflist[$if]))
123
		$if = "lan";
124
} else
125
	$if = "wan";
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]['next-server'];
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
	if (!is_array($config['dhcpd'][$if]['staticmap'])) 
155
        	$config['dhcpd'][$if]['staticmap'] = array();
156
	$a_maps = &$config['dhcpd'][$if]['staticmap'];
157
}
158

    
159
$ifcfgip = get_interface_ip($if);
160
$ifcfgsn = get_interface_subnet($if);
161

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

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

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

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

    
185
if ($_POST) {
186

    
187
	unset($input_errors);
188

    
189
	$pconfig = $_POST;
190

    
191
	/* input validation */
192
	if ($_POST['enable']) {
193
		$reqdfields = explode(" ", "range_from range_to");
194
		$reqdfieldsn = explode(",", "Range begin,Range end");
195

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

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

    
224
		if(gen_subnet($ifcfgip, $ifcfgsn) == $_POST['range_from'])
225
			$input_errors[] = "You cannot use the network address in the starting subnet range.";
226
		if(gen_subnet_max($ifcfgip, $ifcfgsn) == $_POST['range_to'])
227
			$input_errors[] = "You cannot use the broadcast address in the ending subnet range.";
228

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

    
238
		if (!$input_errors) {
239
			/* make sure the range lies within the current subnet */
240
			$subnet_start = (ip2long($ifcfgip) & gen_subnet_mask_long($ifcfgsn));
241
			$subnet_end = (ip2long($ifcfgip) | (~gen_subnet_mask_long($ifcfgsn)));
242

    
243
			if ((ip2long($_POST['range_from']) < $subnet_start) || (ip2long($_POST['range_from']) > $subnet_end) ||
244
			    (ip2long($_POST['range_to']) < $subnet_start) || (ip2long($_POST['range_to']) > $subnet_end)) {
245
				$input_errors[] = "The specified range lies outside of the current subnet.";
246
			}
247

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

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

    
257
	if (!$input_errors) {
258
		if (!is_array($config['dhcpd'][$if]))
259
			$config['dhcpd'][$if] = array();
260
		if (!is_array($config['dhcpd'][$if]['range']))
261
			$config['dhcpd'][$if]['range'] = array();
262

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

    
272
		$config['dhcpd'][$if]['failover_peerip'] = $_POST['failover_peerip'];
273

    
274
		unset($config['dhcpd'][$if]['winsserver']);
275
		if ($_POST['wins1'])
276
			$config['dhcpd'][$if]['winsserver'][] = $_POST['wins1'];
277
		if ($_POST['wins2'])
278
			$config['dhcpd'][$if]['winsserver'][] = $_POST['wins2'];
279

    
280
		unset($config['dhcpd'][$if]['dnsserver']);
281
		if ($_POST['dns1'])
282
			$config['dhcpd'][$if]['dnsserver'][] = $_POST['dns1'];
283
		if ($_POST['dns2'])
284
			$config['dhcpd'][$if]['dnsserver'][] = $_POST['dns2'];
285

    
286
		$config['dhcpd'][$if]['gateway'] = $_POST['gateway'];
287
		$config['dhcpd'][$if]['domain'] = $_POST['domain'];
288
		$config['dhcpd'][$if]['domainsearchlist'] = $_POST['domainsearchlist'];
289
		$config['dhcpd'][$if]['denyunknown'] = ($_POST['denyunknown']) ? true : false;
290
		$config['dhcpd'][$if]['enable'] = ($_POST['enable']) ? true : false;
291
		$config['dhcpd'][$if]['staticarp'] = ($_POST['staticarp']) ? true : false;
292
		$config['dhcpd'][$if]['ddnsdomain'] = $_POST['ddnsdomain'];
293
		$config['dhcpd'][$if]['ddnsupdate'] = ($_POST['ddnsupdate']) ? true : false;
294

    
295
		unset($config['dhcpd'][$if]['ntpserver']);
296
		if ($_POST['ntp1'])
297
			$config['dhcpd'][$if]['ntpserver'][] = $_POST['ntp1'];
298
		if ($_POST['ntp2'])
299
			$config['dhcpd'][$if]['ntpserver'][] = $_POST['ntp2'];
300

    
301
		$config['dhcpd'][$if]['tftp'] = $_POST['tftp'];
302
		$config['dhcpd'][$if]['ldap'] = $_POST['ldap'];
303
		$config['dhcpd'][$if]['netboot'] = ($_POST['netboot']) ? true : false;
304
		$config['dhcpd'][$if]['next-server'] = $_POST['nextserver'];
305
		$config['dhcpd'][$if]['filename'] = $_POST['filename'];
306
		$config['dhcpd'][$if]['rootpath'] = $_POST['rootpath'];
307

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

    
323
		write_config();
324

    
325
		/* static arp configuration */
326
		interfaces_staticarp_configure($if);
327

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

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

    
367
$pgtitle = array("Services","DHCP server");
368
include("head.inc");
369

    
370
?>
371

    
372
<script type="text/javascript" src="/javascript/row_helper.js">
373
</script>
374

    
375
<script type="text/javascript">
376
	rowname[0] = "number";
377
	rowtype[0] = "textbox";
378
	rowsize[0] = "10";
379
	rowname[1] = "value";
380
	rowtype[1] = "textbox";
381
	rowsize[1] = "55";
382
</script>
383

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

    
414
	function show_shownumbervalue() {
415
		document.getElementById("shownumbervaluebox").innerHTML='';
416
		aodiv = document.getElementById('shownumbervalue');
417
		aodiv.style.display = "block";
418
	}
419

    
420
	function show_ddns_config() {
421
		document.getElementById("showddnsbox").innerHTML='';
422
		aodiv = document.getElementById('showddns');
423
		aodiv.style.display = "block";
424
	}
425

    
426
	function show_ntp_config() {
427
		document.getElementById("showntpbox").innerHTML='';
428
		aodiv = document.getElementById('showntp');
429
		aodiv.style.display = "block";
430
	}
431

    
432
	function show_tftp_config() {
433
		document.getElementById("showtftpbox").innerHTML='';
434
		aodiv = document.getElementById('showtftp');
435
		aodiv.style.display = "block";
436
	}
437

    
438
	function show_ldap_config() {
439
		document.getElementById("showldapbox").innerHTML='';
440
		aodiv = document.getElementById('showldap');
441
		aodiv.style.display = "block";
442
	}
443

    
444
	function show_netboot_config() {
445
		document.getElementById("shownetbootbox").innerHTML='';
446
		aodiv = document.getElementById('shownetboot');
447
		aodiv.style.display = "block";
448
	}
449
</script>
450

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

    
737

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

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