Project

General

Profile

Download (33.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
##|+PRIV
33
##|*IDENT=page-services-dhcpserver
34
##|*NAME=Services: DHCP server page
35
##|*DESCR=Allow access to the 'Services: DHCP server' page.
36
##|*MATCH=services_dhcp.php*
37
##|-PRIV
38

    
39
require("guiconfig.inc");
40

    
41
if(!$g['services_dhcp_server_enable']) {
42
	Header("Location: /");
43
	exit;
44
}
45

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

    
92
$if = $_GET['if'];
93
if ($_POST['if'])
94
	$if = $_POST['if'];
95

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

    
106
if (!$_GET['if'])
107
	$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>";
108

    
109
$iflist = get_configured_interface_with_descr();
110

    
111
/* set the starting interface */
112
if($config['interfaces']['lan']) {
113
	if (!$if || !isset($iflist[$if]))
114
		$if = "lan";
115
} else
116
	$if = "wan";
117

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

    
149
$ifcfgip = get_interface_ip($if);
150
$ifcfgsn = get_interface_subnet($if);
151

    
152

    
153
/*   set the enabled flag which will tell us if DHCP relay is enabled
154
 *   on any interface.   We will use this to disable DHCP server since
155
 *   the two are not compatible with each other.
156
 */
157

    
158
$dhcrelay_enabled = false;
159
$dhcrelaycfg = $config['dhcrelay'];
160

    
161
if(is_array($dhcrelaycfg)) {
162
	foreach ($dhcrelaycfg as $dhcrelayif => $dhcrelayifconf) {
163
		if (isset($dhcrelayifconf['enable']) &&
164
			(($dhcrelayif == "lan") ||
165
			(isset($config['interfaces'][$dhcrelayif]['enable']) &&
166
			$config['interfaces'][$dhcrelayif]['if'] && (!link_interface_to_bridge($dhcrelayif)))))
167
			$dhcrelay_enabled = true;
168
	}
169
}
170

    
171
function is_inrange($test, $start, $end) {
172
	if ( (ip2long($test) < ip2long($end)) && (ip2long($test) > ip2long($start)) )
173
		return true;
174
	else
175
		return false;
176
}
177

    
178
if ($_POST) {
179

    
180
	unset($input_errors);
181

    
182
	$pconfig = $_POST;
183

    
184
	/* input validation */
185
	if ($_POST['enable']) {
186
		$reqdfields = explode(" ", "range_from range_to");
187
		$reqdfieldsn = explode(",", "Range begin,Range end");
188

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

    
228
		if (!$input_errors) {
229
			/* make sure the range lies within the current subnet */
230
			$subnet_start = (ip2long($ifcfgip) & gen_subnet_mask_long($ifcfgsn));
231
			$subnet_end = (ip2long($ifcfgip) | (~gen_subnet_mask_long($ifcfgsn)));
232

    
233
			if ((ip2long($_POST['range_from']) < $subnet_start) || (ip2long($_POST['range_from']) > $subnet_end) ||
234
			    (ip2long($_POST['range_to']) < $subnet_start) || (ip2long($_POST['range_to']) > $subnet_end)) {
235
				$input_errors[] = "The specified range lies outside of the current subnet.";
236
			}
237

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

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

    
247
	if (!$input_errors) {
248
		if (!is_array($config['dhcpd'][$if]))
249
			$config['dhcpd'][$if] = array();
250
		if (!is_array($config['dhcpd'][$if]['range']))
251
			$config['dhcpd'][$if]['range'] = array();
252

    
253
		$config['dhcpd'][$if]['range']['from'] = $_POST['range_from'];
254
		$config['dhcpd'][$if]['range']['to'] = $_POST['range_to'];
255
		$config['dhcpd'][$if]['defaultleasetime'] = $_POST['deftime'];
256
		$config['dhcpd'][$if]['maxleasetime'] = $_POST['maxtime'];
257
		$config['dhcpd'][$if]['netmask'] = $_POST['netmask'];
258
		$previous = $config['dhcpd'][$if]['failover_peerip'];
259
		if($previous <> $_POST['failover_peerip']) {
260
			mwexec("rm -rf /var/dhcpd/var/db/*");
261
		}
262
		$config['dhcpd'][$if]['failover_peerip'] = $_POST['failover_peerip'];
263

    
264
		unset($config['dhcpd'][$if]['winsserver']);
265
		if ($_POST['wins1'])
266
			$config['dhcpd'][$if]['winsserver'][] = $_POST['wins1'];
267
		if ($_POST['wins2'])
268
			$config['dhcpd'][$if]['winsserver'][] = $_POST['wins2'];
269

    
270
		unset($config['dhcpd'][$if]['dnsserver']);
271
		if ($_POST['dns1'])
272
			$config['dhcpd'][$if]['dnsserver'][] = $_POST['dns1'];
273
		if ($_POST['dns2'])
274
			$config['dhcpd'][$if]['dnsserver'][] = $_POST['dns2'];
275

    
276
		$config['dhcpd'][$if]['gateway'] = $_POST['gateway'];
277
		$config['dhcpd'][$if]['domain'] = $_POST['domain'];
278
		$config['dhcpd'][$if]['domainsearchlist'] = $_POST['domainsearchlist'];
279
		$config['dhcpd'][$if]['denyunknown'] = ($_POST['denyunknown']) ? true : false;
280
		$config['dhcpd'][$if]['enable'] = ($_POST['enable']) ? true : false;
281
		$config['dhcpd'][$if]['staticarp'] = ($_POST['staticarp']) ? true : false;
282
		$config['dhcpd'][$if]['ddnsdomain'] = $_POST['ddnsdomain'];
283
		$config['dhcpd'][$if]['ddnsupdate'] = ($_POST['ddnsupdate']) ? true : false;
284

    
285
		unset($config['dhcpd'][$if]['ntpserver']);
286
		if ($_POST['ntp1'])
287
			$config['dhcpd'][$if]['ntpserver'][] = $_POST['ntp1'];
288
		if ($_POST['ntp2'])
289
			$config['dhcpd'][$if]['ntpserver'][] = $_POST['ntp2'];
290

    
291
		$config['dhcpd'][$if]['tftp'] = $_POST['tftp'];
292
		$config['dhcpd'][$if]['ldap'] = $_POST['ldap'];
293
		$config['dhcpd'][$if]['netboot'] = ($_POST['netboot']) ? true : false;
294
		$config['dhcpd'][$if]['next-server'] = $_POST['nextserver'];
295
		$config['dhcpd'][$if]['filename'] = $_POST['filename'];
296
		$config['dhcpd'][$if]['rootpath'] = $_POST['rootpath'];
297

    
298
		write_config();
299

    
300
		/* static arp configuration */
301
		interfaces_staticarp_configure($if);
302

    
303
		$retval = 0;
304
		$retvaldhcp = 0;
305
		$retvaldns = 0;
306
		/* Stop DHCP so we can cleanup leases */
307
		killbyname("dhcpd");
308
		dhcp_clean_leases();
309
		/* dnsmasq_configure calls dhcpd_configure */
310
		/* no need to restart dhcpd twice */
311
		if (isset($config['dnsmasq']['regdhcpstatic']))	{
312
			$retvaldns = services_dnsmasq_configure();
313
			if ($retvaldns == 0) {
314
				clear_subsystem_dirty('hosts');
315
				clear_subsystem_dirty('staticmaps');
316
			}					
317
		} else {
318
			$retvaldhcp = services_dhcpd_configure();	
319
			if ($retvaldhcp == 0)
320
				clear_subsystem_dirty('staticmaps');
321
		}	
322
		if($retvaldhcp == 1 || $retvaldns == 1)
323
			$retval = 1;
324
		$savemsg = get_std_save_message($retval);
325
	}
326
}
327

    
328
if ($_GET['act'] == "del") {
329
	if ($a_maps[$_GET['id']]) {
330
		unset($a_maps[$_GET['id']]);
331
		write_config();
332
		if(isset($config['dhcpd'][$if]['enable'])) {
333
			mark_subsystem_dirty('staticmaps');
334
			if (isset($config['dnsmasq']['regdhcpstatic']))
335
				mark_subsystem_dirty('hosts');
336
		}
337
		header("Location: services_dhcp.php?if={$if}");
338
		exit;
339
	}
340
}
341

    
342
$pgtitle = array("Services","DHCP server");
343
include("head.inc");
344

    
345
?>
346

    
347
<script type="text/javascript" language="JavaScript">
348

    
349
function enable_change(enable_over) {
350
	var endis;
351
	endis = !(document.iform.enable.checked || enable_over);
352
	document.iform.range_from.disabled = endis;
353
	document.iform.range_to.disabled = endis;
354
	document.iform.wins1.disabled = endis;
355
	document.iform.wins2.disabled = endis;
356
	document.iform.dns1.disabled = endis;
357
	document.iform.dns2.disabled = endis;
358
	document.iform.deftime.disabled = endis;
359
	document.iform.maxtime.disabled = endis;
360
	document.iform.gateway.disabled = endis;
361
	document.iform.failover_peerip.disabled = endis;
362
	document.iform.domain.disabled = endis;
363
	document.iform.domainsearchlist.disabled = endis;
364
	document.iform.staticarp.disabled = endis;
365
	document.iform.ddnsdomain.disabled = endis;
366
	document.iform.ddnsupdate.disabled = endis;
367
	document.iform.ntp1.disabled = endis;
368
	document.iform.ntp2.disabled = endis;
369
	document.iform.tftp.disabled = endis;
370
	document.iform.ldap.disabled = endis;
371
	document.iform.netboot.disabled = endis;
372
	document.iform.nextserver.disabled = endis;
373
	document.iform.filename.disabled = endis;
374
	document.iform.rootpath.disabled = endis;
375
	document.iform.denyunknown.disabled = endis;
376
}
377

    
378
function show_ddns_config() {
379
	document.getElementById("showddnsbox").innerHTML='';
380
	aodiv = document.getElementById('showddns');
381
	aodiv.style.display = "block";
382
}
383

    
384
function show_ntp_config() {
385
	document.getElementById("showntpbox").innerHTML='';
386
	aodiv = document.getElementById('showntp');
387
	aodiv.style.display = "block";
388
}
389

    
390
function show_tftp_config() {
391
	document.getElementById("showtftpbox").innerHTML='';
392
	aodiv = document.getElementById('showtftp');
393
	aodiv.style.display = "block";
394
}
395

    
396
function show_ldap_config() {
397
	document.getElementById("showldapbox").innerHTML='';
398
	aodiv = document.getElementById('showldap');
399
	aodiv.style.display = "block";
400
}
401

    
402
function show_netboot_config() {
403
	document.getElementById("shownetbootbox").innerHTML='';
404
	aodiv = document.getElementById('shownetboot');
405
	aodiv.style.display = "block";
406
}
407

    
408
</script>
409

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