Project

General

Profile

Download (36.3 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

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

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

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

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

    
188
if ($_POST) {
189

    
190
	unset($input_errors);
191

    
192
	$pconfig = $_POST;
193

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

    
199
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
200
		
201
		if (($_POST['range_from'] && !is_ipaddr($_POST['range_from']))) {
202
			$input_errors[] = "A valid range must be specified.";
203
		}
204
		if (($_POST['range_to'] && !is_ipaddr($_POST['range_to']))) {
205
			$input_errors[] = "A valid range must be specified.";
206
		}
207
		if (($_POST['gateway'] && !is_ipaddr($_POST['gateway']))) {
208
			$input_errors[] = "A valid IP address must be specified for the gateway.";
209
		}
210
		if (($_POST['wins1'] && !is_ipaddr($_POST['wins1'])) || ($_POST['wins2'] && !is_ipaddr($_POST['wins2']))) {
211
			$input_errors[] = "A valid IP address must be specified for the primary/secondary WINS servers.";
212
		}
213
		if (($_POST['dns1'] && !is_ipaddr($_POST['dns1'])) || ($_POST['dns2'] && !is_ipaddr($_POST['dns2']))) {
214
			$input_errors[] = "A valid IP address must be specified for the primary/secondary DNS servers.";
215
		}
216
		if ($_POST['deftime'] && (!is_numeric($_POST['deftime']) || ($_POST['deftime'] < 60))) {
217
			$input_errors[] = "The default lease time must be at least 60 seconds.";
218
		}
219
		if ($_POST['maxtime'] && (!is_numeric($_POST['maxtime']) || ($_POST['maxtime'] < 60) || ($_POST['maxtime'] <= $_POST['deftime']))) {
220
			$input_errors[] = "The maximum lease time must be at least 60 seconds and higher than the default lease time.";
221
		}
222
		if (($_POST['ddnsdomain'] && !is_domain($_POST['ddnsdomain']))) {
223
			$input_errors[] = "A valid domain name must be specified for the dynamic DNS registration.";
224
		}
225
		if (($_POST['ntp1'] && !is_ipaddr($_POST['ntp1'])) || ($_POST['ntp2'] && !is_ipaddr($_POST['ntp2']))) {
226
			$input_errors[] = "A valid IP address must be specified for the primary/secondary NTP servers.";
227
		}
228
		if (($_POST['domain'] && !is_domain($_POST['domain']))) {
229
			$input_errors[] = "A valid domain name must be specified for the DNS domain.";
230
    }
231
		if (($_POST['tftp'] && !is_ipaddr($_POST['tftp']))) {
232
			$input_errors[] = "A valid IP address must be specified for the tftp server.";
233
		}
234
		if (($_POST['nextserver'] && !is_ipaddr($_POST['nextserver']))) {
235
			$input_errors[] = "A valid IP address must be specified for the network boot server.";
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
		$numbervalue = array();
310
		unset($config['dhcpd'][$if]['numberoptions']['item']);
311
		for($x=0; $x<isset($_POST["number{$x}"]); $x++) {
312
			if(is_int(intval($_POST["number{$x}"]))) {
313
				$numbervalue['number'] = htmlspecialchars($_POST["number{$x}"]);
314
				$numbervalue['value'] = htmlspecialchars($_POST["value{$x}"]);
315
				$config['dhcpd'][$if]['numberoptions']['item'][] = $numbervalue;
316
			}
317
		}
318
		
319
		// Reload the new pconfig variable that the forum uses.
320
		$pconfig['numberoptions'] = $config['dhcpd'][$if]['numberoptions'];
321

    
322
		write_config();
323

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

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

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

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

    
369
?>
370

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

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

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

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

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

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

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

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

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

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

    
729

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

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