Project

General

Profile

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

    
96
$if = $_GET['if'];
97
if ($_POST['if'])
98
	$if = $_POST['if'];
99

    
100
/* if OLSRD is enabled, allow WAN to house DHCP. */
101
if($config['installedpackages']['olsrd']) {
102
	foreach($config['installedpackages']['olsrd']['config'] as $olsrd) {
103
			if($olsrd['enable']) {
104
				$is_olsr_enabled = true;
105
				break;
106
			}
107
	}
108
}
109

    
110
if (!$_GET['if'])
111
	$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>";
112

    
113
$iflist = get_configured_interface_with_descr();
114

    
115
/* set the starting interface */
116
if($config['interfaces']['lan']) {
117
	if (!$if || !isset($iflist[$if]))
118
		$if = "lan";
119
} else
120
	$if = "wan";
121

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

    
154
$ifcfgip = get_interface_ip($if);
155
$ifcfgsn = get_interface_subnet($if);
156

    
157

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

    
163
$dhcrelay_enabled = false;
164
$dhcrelaycfg = $config['dhcrelay'];
165

    
166
if(is_array($dhcrelaycfg)) {
167
	foreach ($dhcrelaycfg as $dhcrelayif => $dhcrelayifconf) {
168
		if (isset($dhcrelayifconf['enable']) &&
169
			(($dhcrelayif == "lan") ||
170
			(isset($config['interfaces'][$dhcrelayif]['enable']) &&
171
			$config['interfaces'][$dhcrelayif]['if'] && (!link_interface_to_bridge($dhcrelayif)))))
172
			$dhcrelay_enabled = true;
173
	}
174
}
175

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

    
183
if ($_POST) {
184

    
185
	unset($input_errors);
186

    
187
	$pconfig = $_POST;
188

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

    
194
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
195
		
196
		if (($_POST['range_from'] && !is_ipaddr($_POST['range_from']))) {
197
			$input_errors[] = "A valid range must be specified.";
198
		}
199
		if (($_POST['range_to'] && !is_ipaddr($_POST['range_to']))) {
200
			$input_errors[] = "A valid range must be specified.";
201
		}
202
		if (($_POST['gateway'] && !is_ipaddr($_POST['gateway']))) {
203
			$input_errors[] = "A valid IP address must be specified for the gateway.";
204
		}
205
		if (($_POST['wins1'] && !is_ipaddr($_POST['wins1'])) || ($_POST['wins2'] && !is_ipaddr($_POST['wins2']))) {
206
			$input_errors[] = "A valid IP address must be specified for the primary/secondary WINS servers.";
207
		}
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
		}
214
		if ($_POST['maxtime'] && (!is_numeric($_POST['maxtime']) || ($_POST['maxtime'] < 60) || ($_POST['maxtime'] <= $_POST['deftime']))) {
215
			$input_errors[] = "The maximum lease time must be at least 60 seconds and higher than the default lease time.";
216
		}
217
		if (($_POST['ddnsdomain'] && !is_domain($_POST['ddnsdomain']))) {
218
			$input_errors[] = "A valid domain name must be specified for the dynamic DNS registration.";
219
		}
220
		if (($_POST['ntp1'] && !is_ipaddr($_POST['ntp1'])) || ($_POST['ntp2'] && !is_ipaddr($_POST['ntp2']))) {
221
			$input_errors[] = "A valid IP address must be specified for the primary/secondary NTP servers.";
222
		}
223
		if (($_POST['domain'] && !is_domain($_POST['domain']))) {
224
			$input_errors[] = "A valid domain name must be specified for the DNS domain.";
225
    }
226
		if (($_POST['tftp'] && !is_ipaddr($_POST['tftp']))) {
227
			$input_errors[] = "A valid IP address must be specified for the tftp server.";
228
		}
229
		if (($_POST['nextserver'] && !is_ipaddr($_POST['nextserver']))) {
230
			$input_errors[] = "A valid IP address must be specified for the network boot server.";
231
		}
232

    
233
		if (!$input_errors) {
234
			/* make sure the range lies within the current subnet */
235
			$subnet_start = (ip2long($ifcfgip) & gen_subnet_mask_long($ifcfgsn));
236
			$subnet_end = (ip2long($ifcfgip) | (~gen_subnet_mask_long($ifcfgsn)));
237

    
238
			if ((ip2long($_POST['range_from']) < $subnet_start) || (ip2long($_POST['range_from']) > $subnet_end) ||
239
			    (ip2long($_POST['range_to']) < $subnet_start) || (ip2long($_POST['range_to']) > $subnet_end)) {
240
				$input_errors[] = "The specified range lies outside of the current subnet.";
241
			}
242

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

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

    
252
	if (!$input_errors) {
253
		if (!is_array($config['dhcpd'][$if]))
254
			$config['dhcpd'][$if] = array();
255
		if (!is_array($config['dhcpd'][$if]['range']))
256
			$config['dhcpd'][$if]['range'] = array();
257

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

    
267
		$config['dhcpd'][$if]['failover_peerip'] = $_POST['failover_peerip'];
268

    
269
		unset($config['dhcpd'][$if]['winsserver']);
270
		if ($_POST['wins1'])
271
			$config['dhcpd'][$if]['winsserver'][] = $_POST['wins1'];
272
		if ($_POST['wins2'])
273
			$config['dhcpd'][$if]['winsserver'][] = $_POST['wins2'];
274

    
275
		unset($config['dhcpd'][$if]['dnsserver']);
276
		if ($_POST['dns1'])
277
			$config['dhcpd'][$if]['dnsserver'][] = $_POST['dns1'];
278
		if ($_POST['dns2'])
279
			$config['dhcpd'][$if]['dnsserver'][] = $_POST['dns2'];
280

    
281
		$config['dhcpd'][$if]['gateway'] = $_POST['gateway'];
282
		$config['dhcpd'][$if]['domain'] = $_POST['domain'];
283
		$config['dhcpd'][$if]['domainsearchlist'] = $_POST['domainsearchlist'];
284
		$config['dhcpd'][$if]['denyunknown'] = ($_POST['denyunknown']) ? true : false;
285
		$config['dhcpd'][$if]['enable'] = ($_POST['enable']) ? true : false;
286
		$config['dhcpd'][$if]['staticarp'] = ($_POST['staticarp']) ? true : false;
287
		$config['dhcpd'][$if]['ddnsdomain'] = $_POST['ddnsdomain'];
288
		$config['dhcpd'][$if]['ddnsupdate'] = ($_POST['ddnsupdate']) ? true : false;
289

    
290
		unset($config['dhcpd'][$if]['ntpserver']);
291
		if ($_POST['ntp1'])
292
			$config['dhcpd'][$if]['ntpserver'][] = $_POST['ntp1'];
293
		if ($_POST['ntp2'])
294
			$config['dhcpd'][$if]['ntpserver'][] = $_POST['ntp2'];
295

    
296
		$config['dhcpd'][$if]['tftp'] = $_POST['tftp'];
297
		$config['dhcpd'][$if]['ldap'] = $_POST['ldap'];
298
		$config['dhcpd'][$if]['netboot'] = ($_POST['netboot']) ? true : false;
299
		$config['dhcpd'][$if]['next-server'] = $_POST['nextserver'];
300
		$config['dhcpd'][$if]['filename'] = $_POST['filename'];
301
		$config['dhcpd'][$if]['rootpath'] = $_POST['rootpath'];
302

    
303
		// Handle the custom options rowhelper
304
		$numbervalue = array();
305
		unset($config['dhcpd'][$if]['numberoptions']['item']);
306
		for($x=0; $x<isset($_POST["number{$x}"]); $x++) {
307
			if(is_int(intval($_POST["number{$x}"]))) {
308
				$numbervalue['number'] = htmlspecialchars($_POST["number{$x}"]);
309
				$numbervalue['value'] = htmlspecialchars($_POST["value{$x}"]);
310
				$config['dhcpd'][$if]['numberoptions']['item'][] = $numbervalue;
311
			}
312
		}
313
		
314
		// Reload the new pconfig variable that the forum uses.
315
		$pconfig['numberoptions'] = $config['dhcpd'][$if]['numberoptions'];
316

    
317
		write_config();
318

    
319
		/* static arp configuration */
320
		interfaces_staticarp_configure($if);
321

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

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

    
361
$pgtitle = array("Services","DHCP server");
362
include("head.inc");
363

    
364
?>
365

    
366
<script type="text/javascript" src="/javascript/row_helper.js">
367
</script>
368

    
369
<script type="text/javascript">
370
	rowname[0] = "number";
371
	rowtype[0] = "textbox";
372
	rowsize[0] = "10";
373
	rowname[1] = "value";
374
	rowtype[1] = "textbox";
375
	rowsize[1] = "55";
376
</script>
377

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

    
408
	function show_shownumbervalue() {
409
		document.getElementById("shownumbervaluebox").innerHTML='';
410
		aodiv = document.getElementById('shownumbervalue');
411
		aodiv.style.display = "block";
412
	}
413

    
414
	function show_ddns_config() {
415
		document.getElementById("showddnsbox").innerHTML='';
416
		aodiv = document.getElementById('showddns');
417
		aodiv.style.display = "block";
418
	}
419

    
420
	function show_ntp_config() {
421
		document.getElementById("showntpbox").innerHTML='';
422
		aodiv = document.getElementById('showntp');
423
		aodiv.style.display = "block";
424
	}
425

    
426
	function show_tftp_config() {
427
		document.getElementById("showtftpbox").innerHTML='';
428
		aodiv = document.getElementById('showtftp');
429
		aodiv.style.display = "block";
430
	}
431

    
432
	function show_ldap_config() {
433
		document.getElementById("showldapbox").innerHTML='';
434
		aodiv = document.getElementById('showldap');
435
		aodiv.style.display = "block";
436
	}
437

    
438
	function show_netboot_config() {
439
		document.getElementById("shownetbootbox").innerHTML='';
440
		aodiv = document.getElementById('shownetboot');
441
		aodiv.style.display = "block";
442
	}
443
</script>
444

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

    
724

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

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