Project

General

Profile

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

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

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

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

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

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

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

    
43
require("guiconfig.inc");
44

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

    
50
/*  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> The interfaces not configured with static ip will not 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']) &&
173
			(($dhcrelayif == "lan") ||
174
			(isset($config['interfaces'][$dhcrelayif]['enable']) &&
175
			$config['interfaces'][$dhcrelayif]['if'] && (!link_interface_to_bridge($dhcrelayif)))))
176
			$dhcrelay_enabled = true;
177
	}
178
}
179

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

    
187
if ($_POST) {
188

    
189
	unset($input_errors);
190

    
191
	$pconfig = $_POST;
192

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

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

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

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

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

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

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

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

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

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

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

    
274
		$config['dhcpd'][$if]['failover_peerip'] = $_POST['failover_peerip'];
275

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

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

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

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

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

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

    
324
		write_config();
325

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

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

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

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

    
371
?>
372

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

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

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

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

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

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

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

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

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

    
452
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
453
<?php include("fbegin.inc"); ?>
454
<form action="services_dhcp.php" method="post" name="iform" id="iform">
455
<?php if ($input_errors) print_input_errors($input_errors); ?>
456
<?php if ($savemsg) print_info_box($savemsg); ?>
457
<?php 
458
	if ($dhcrelay_enabled) {
459
		echo "DHCP Relay is currently enabled.  Cannot enable the DHCP Server service while the DHCP Relay is enabled on any interface.";
460
		include("fend.inc"); 
461
		echo "</body>";
462
		echo "</html>";
463
		exit;
464
	}
465
?>
466
<?php if (is_subsystem_dirty('staticmaps')): ?><p>
467
<?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>
468
<?php endif; ?>
469
<table width="100%" border="0" cellpadding="0" cellspacing="0">
470
  <tr><td>
471
  <?php
472
	/* active tabs */
473
	$tab_array = array();
474
	$tabscounter = 0;
475
	$i = 0;
476
	foreach ($iflist as $ifent => $ifname) {
477
        	$oc = $config['interfaces'][$ifent];
478
        	if (!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>
(128-128/214)