Project

General

Profile

Download (35.6 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
	$pconfig['numberoptions'] = $config['dhcpd'][$if]['numberoptions'];
145
	if (!is_array($config['dhcpd'][$if]['staticmap'])) 
146
        	$config['dhcpd'][$if]['staticmap'] = array();
147
	$a_maps = &$config['dhcpd'][$if]['staticmap'];
148
}
149

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

    
153

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

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

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

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

    
179
if ($_POST) {
180

    
181
	unset($input_errors);
182

    
183
	$pconfig = $_POST;
184

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

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

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

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

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

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

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

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

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

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

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

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

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

    
299
		$numbervalue = array();
300
		unset($config['dhcpd'][$if]['numberoptions']['item']);
301
		for($x=0; $x<isset($_POST["number{$x}"]); $x++) {
302
			if(is_int($_POST["number{$x}"])) {
303
				$numbervalue['number'] = htmlspecialchars($_POST["number{$x}"]);
304
				$numbervalue['value'] = htmlspecialchars($_POST["value{$x}"]);
305
				$config['dhcpd'][$if]['numberoptions']['item'][] = $numbervalue;
306
			}
307
		}
308
		$pconfig['numberoptions'] = $config['dhcpd'][$if]['numberoptions'];
309

    
310
		write_config();
311

    
312
		/* static arp configuration */
313
		interfaces_staticarp_configure($if);
314

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

    
340
if ($_GET['act'] == "del") {
341
	if ($a_maps[$_GET['id']]) {
342
		unset($a_maps[$_GET['id']]);
343
		write_config();
344
		if(isset($config['dhcpd'][$if]['enable'])) {
345
			mark_subsystem_dirty('staticmaps');
346
			if (isset($config['dnsmasq']['regdhcpstatic']))
347
				mark_subsystem_dirty('hosts');
348
		}
349
		header("Location: services_dhcp.php?if={$if}");
350
		exit;
351
	}
352
}
353

    
354
$pgtitle = array("Services","DHCP server");
355
include("head.inc");
356

    
357
?>
358

    
359
<script type="text/javascript" src="/javascript/row_helper.js">
360
</script>
361

    
362
<script type="text/javascript">
363
	rowname[0] = "number";
364
	rowtype[0] = "textbox";
365
	rowsize[0] = "30";
366
	rowname[1] = "value";
367
	rowtype[1] = "textbox";
368
	rowsize[1] = "30";
369
</script>
370

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

    
401
	function show_ddns_config() {
402
		document.getElementById("showddnsbox").innerHTML='';
403
		aodiv = document.getElementById('showddns');
404
		aodiv.style.display = "block";
405
	}
406

    
407
	function show_ntp_config() {
408
		document.getElementById("showntpbox").innerHTML='';
409
		aodiv = document.getElementById('showntp');
410
		aodiv.style.display = "block";
411
	}
412

    
413
	function show_tftp_config() {
414
		document.getElementById("showtftpbox").innerHTML='';
415
		aodiv = document.getElementById('showtftp');
416
		aodiv.style.display = "block";
417
	}
418

    
419
	function show_ldap_config() {
420
		document.getElementById("showldapbox").innerHTML='';
421
		aodiv = document.getElementById('showldap');
422
		aodiv.style.display = "block";
423
	}
424

    
425
	function show_netboot_config() {
426
		document.getElementById("shownetbootbox").innerHTML='';
427
		aodiv = document.getElementById('shownetboot');
428
		aodiv.style.display = "block";
429
	}
430
</script>
431

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

    
711

    
712
				<td width="22%" valign="top" class="vncell">
713
					Additional BOOTP/DHCP Options
714
				</td>
715
				<td width="78%" class="vtable">
716
			    <table id="maintable">
717
			        <tbody>
718
			          <tr>
719
			            <td colspan="3">
720
			      		    <div style="padding:5px; margin-top: 16px; margin-bottom: 16px; border:1px dashed #000066; background-color: #ffffff; color: #000000; font-size: 8pt;" id="itemhelp">
721
								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>.
722
							</div>
723
			            </td>
724
			          </tr>
725
			          <tr>
726
			            <td><div id="onecolumn">Number</div></td>
727
			            <td><div id="twocolumn">Value</div></td>
728
			          </tr>
729
				<?php $counter = 0; ?>
730
				<?php 
731
					if($pconfig['numberoptions'])
732
				 		foreach($pconfig['numberoptions']['item'] as $item): 
733
				?>
734
					<?php
735
						$number = $item['number'];
736
						$value = $item['value'];
737
					?>
738
			          <tr>
739
			            <td>
740
							<input autocomplete="off" name="number<?php echo $counter; ?>" type="text" class="formfld" id="number<?php echo $counter; ?>" size="30" value="<?=htmlspecialchars($number);?>" />
741
			            </td>
742
			            <td>
743
							<input autocomplete="off" name="value<?php echo $counter; ?>" type="text" class="formfld" id="value<?php echo $counter; ?>" size="30" value="<?=htmlspecialchars($value);?>" />
744
						</td>
745
			            <td>
746
			    		<input type="image" src="/themes/<?echo $g['theme'];?>/images/icons/icon_x.gif" onclick="removeRow(this); return false;" value="Delete" />
747
				      </td>
748
			          </tr>
749
				<?php $counter++; ?>
750
				<?php endforeach; ?>
751
			        </tbody>
752
			        <tfoot>
753
			        </tfoot>
754
				</table>
755
				<a onclick="javascript:addRowTo('maintable', 'formfldalias'); return false;" href="#">
756
					<img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="add another entry" />
757
				</a>
758
				<script type="text/javascript">
759
					field_counter_js = 2;
760
					rows = 1;
761
					totalrows = <?php echo $counter; ?>;
762
					loaded = <?php echo $counter; ?>;
763
				</script>
764

    
765

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