Project

General

Profile

Download (31.7 KB) Statistics
| Branch: | Tag: | Revision:
1 e9f147c8 Scott Ullrich
<?php
2 b46bfcf5 Bill Marquette
/* $Id$ */
3 5b237745 Scott Ullrich
/*
4
	services_dhcp.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6 e9f147c8 Scott Ullrich
7 5b237745 Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
	All rights reserved.
9 e9f147c8 Scott Ullrich
10 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12 e9f147c8 Scott Ullrich
13 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15 e9f147c8 Scott Ullrich
16 5b237745 Scott Ullrich
	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 e9f147c8 Scott Ullrich
20 5b237745 Scott Ullrich
	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 6b07c15a Matthew Grooms
##|+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
40 b7597d4e Bill Marquette
require("guiconfig.inc");
41 5b237745 Scott Ullrich
42
$if = $_GET['if'];
43
if ($_POST['if'])
44
	$if = $_POST['if'];
45 e9f147c8 Scott Ullrich
46 11bc553c Scott Ullrich
/* if OLSRD is enabled, allow WAN to house DHCP. */
47 a3b466b5 Scott Ullrich
if($config['installedpackages']['olsrd']) {
48
	foreach($config['installedpackages']['olsrd']['config'] as $olsrd) {
49 bc15a1b9 Scott Ullrich
			if($olsrd['enable']) {
50 48ab0cd2 Scott Ullrich
				$is_olsr_enabled = true;
51 a3b466b5 Scott Ullrich
				break;
52
			}
53
	}
54 11bc553c Scott Ullrich
}
55
56 934240ef Ermal Luçi
if (!$_GET['if'])
57
	$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>";
58 5b237745 Scott Ullrich
59 934240ef Ermal Luçi
$iflist = get_configured_interface_with_descr();
60 5b237745 Scott Ullrich
61 1c451b06 Scott Ullrich
/* set the starting interface */
62 0a2c6a5b Scott Ullrich
if($config['interfaces']['lan']) {
63 1c451b06 Scott Ullrich
	if (!$if || !isset($iflist[$if]))
64
		$if = "lan";
65 89019922 Ermal Luçi
} else
66 1c451b06 Scott Ullrich
	$if = "wan";
67 0a2c6a5b Scott Ullrich
68 89019922 Ermal Luçi
if (is_array($config['dhcpd'][$if])){
69
	if (is_array($config['dhcpd'][$if]['range'])) {
70
		$pconfig['range_from'] = $config['dhcpd'][$if]['range']['from'];
71
		$pconfig['range_to'] = $config['dhcpd'][$if]['range']['to'];
72
	}
73
	$pconfig['deftime'] = $config['dhcpd'][$if]['defaultleasetime'];
74
	$pconfig['maxtime'] = $config['dhcpd'][$if]['maxleasetime'];
75
	$pconfig['gateway'] = $config['dhcpd'][$if]['gateway'];
76
	$pconfig['domain'] = $config['dhcpd'][$if]['domain'];
77
	$pconfig['domainsearchlist'] = $config['dhcpd'][$if]['domainsearchlist'];
78
	list($pconfig['wins1'],$pconfig['wins2']) = $config['dhcpd'][$if]['winsserver'];
79
	list($pconfig['dns1'],$pconfig['dns2']) = $config['dhcpd'][$if]['dnsserver'];
80
	$pconfig['enable'] = isset($config['dhcpd'][$if]['enable']);
81
	$pconfig['denyunknown'] = isset($config['dhcpd'][$if]['denyunknown']);
82
	$pconfig['staticarp'] = isset($config['dhcpd'][$if]['staticarp']);
83
	$pconfig['ddnsdomain'] = $config['dhcpd'][$if]['ddnsdomain'];
84
	$pconfig['ddnsupdate'] = isset($config['dhcpd'][$if]['ddnsupdate']);
85
	list($pconfig['ntp1'],$pconfig['ntp2']) = $config['dhcpd'][$if]['ntpserver'];
86
	$pconfig['tftp'] = $config['dhcpd'][$if]['tftp'];
87
	$pconfig['ldap'] = $config['dhcpd'][$if]['ldap'];
88
	$pconfig['netboot'] = isset($config['dhcpd'][$if]['netboot']);
89
	$pconfig['nextserver'] = $config['dhcpd'][$if]['next-server'];
90
	$pconfig['filename'] = $config['dhcpd'][$if]['filename'];
91
	$pconfig['rootpath'] = $config['dhcpd'][$if]['rootpath'];
92
	$pconfig['failover_peerip'] = $config['dhcpd'][$if]['failover_peerip'];
93
	$pconfig['netmask'] = $config['dhcpd'][$if]['netmask'];
94
	if (!is_array($config['dhcpd'][$if]['staticmap'])) 
95
        	$config['dhcpd'][$if]['staticmap'] = array();
96
	staticmaps_sort($if);
97
	$a_maps = &$config['dhcpd'][$if]['staticmap'];
98
}
99 31c59d0d Scott Ullrich
100 5b237745 Scott Ullrich
$ifcfg = $config['interfaces'][$if];
101
102 3d7b7757 Chris Buechler
103
/*   set the enabled flag which will tell us if DHCP relay is enabled
104
 *   on any interface.   We will use this to disable DHCP server since
105
 *   the two are not compatible with each other.
106
 */
107
108
$dhcrelay_enabled = false;
109
$dhcrelaycfg = $config['dhcrelay'];
110
111
if(is_array($dhcrelaycfg)) {
112
	foreach ($dhcrelaycfg as $dhcrelayif => $dhcrelayifconf) {
113
		if (isset($dhcrelayifconf['enable']) &&
114
			(($dhcrelayif == "lan") ||
115
			(isset($config['interfaces'][$dhcrelayif]['enable']) &&
116 74d65827 Ermal Luçi
			$config['interfaces'][$dhcrelayif]['if'] && (!link_int_to_bridge_interface($dhcrelayif)))))
117 3d7b7757 Chris Buechler
			$dhcrelay_enabled = true;
118
	}
119
}
120
121 0ea7462d Bill Marquette
function is_inrange($test, $start, $end) {
122 dd5b2ec6 Bill Marquette
	if ( (ip2long($test) < ip2long($end)) && (ip2long($test) > ip2long($start)) )
123 0ea7462d Bill Marquette
		return true;
124
	else
125
		return false;
126
}
127 b7597d4e Bill Marquette
128 5b237745 Scott Ullrich
if ($_POST) {
129
130
	unset($input_errors);
131 b7597d4e Bill Marquette
132 5b237745 Scott Ullrich
	$pconfig = $_POST;
133
134
	/* input validation */
135
	if ($_POST['enable']) {
136
		$reqdfields = explode(" ", "range_from range_to");
137
		$reqdfieldsn = explode(",", "Range begin,Range end");
138 e9f147c8 Scott Ullrich
139 5b237745 Scott Ullrich
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
140 e2bce342 Scott Ullrich
		
141 5b237745 Scott Ullrich
		if (($_POST['range_from'] && !is_ipaddr($_POST['range_from']))) {
142
			$input_errors[] = "A valid range must be specified.";
143
		}
144
		if (($_POST['range_to'] && !is_ipaddr($_POST['range_to']))) {
145
			$input_errors[] = "A valid range must be specified.";
146
		}
147 6a01ea44 Bill Marquette
		if (($_POST['gateway'] && !is_ipaddr($_POST['gateway']))) {
148 f9261419 Bill Marquette
			$input_errors[] = "A valid IP address must be specified for the gateway.";
149 6a01ea44 Bill Marquette
		}
150 5b237745 Scott Ullrich
		if (($_POST['wins1'] && !is_ipaddr($_POST['wins1'])) || ($_POST['wins2'] && !is_ipaddr($_POST['wins2']))) {
151 4cab31d0 Scott Ullrich
			$input_errors[] = "A valid IP address must be specified for the primary/secondary WINS servers.";
152
		}
153
		if (($_POST['dns1'] && !is_ipaddr($_POST['dns1'])) || ($_POST['dns2'] && !is_ipaddr($_POST['dns2']))) {
154
			$input_errors[] = "A valid IP address must be specified for the primary/secondary DNS servers.";
155 5b237745 Scott Ullrich
		}
156
		if ($_POST['deftime'] && (!is_numeric($_POST['deftime']) || ($_POST['deftime'] < 60))) {
157
			$input_errors[] = "The default lease time must be at least 60 seconds.";
158
		}
159
		if ($_POST['maxtime'] && (!is_numeric($_POST['maxtime']) || ($_POST['maxtime'] < 60) || ($_POST['maxtime'] <= $_POST['deftime']))) {
160
			$input_errors[] = "The maximum lease time must be at least 60 seconds and higher than the default lease time.";
161
		}
162 4e9cd828 Seth Mos
		if (($_POST['ddnsdomain'] && !is_domain($_POST['ddnsdomain']))) {
163
			$input_errors[] = "A valid domain name must be specified for the dynamic DNS registration.";
164
		}
165 ad171999 Seth Mos
		if (($_POST['ntp1'] && !is_ipaddr($_POST['ntp1'])) || ($_POST['ntp2'] && !is_ipaddr($_POST['ntp2']))) {
166
			$input_errors[] = "A valid IP address must be specified for the primary/secondary NTP servers.";
167
		}
168 ee1b024e Martin Fuchs
		if (($_POST['domain'] && !is_domain($_POST['domain']))) {
169
			$input_errors[] = "A valid domain name must be specified for the DNS domain.";
170
    }
171
		if (($_POST['tftp'] && !is_ipaddr($_POST['tftp']))) {
172
			$input_errors[] = "A valid IP address must be specified for the tftp server.";
173 53f926df Martin Fuchs
		}
174 4e9cd828 Seth Mos
		if (($_POST['nextserver'] && !is_ipaddr($_POST['nextserver']))) {
175
			$input_errors[] = "A valid IP address must be specified for the network boot server.";
176
		}
177 e9f147c8 Scott Ullrich
178 5b237745 Scott Ullrich
		if (!$input_errors) {
179
			/* make sure the range lies within the current subnet */
180
			$subnet_start = (ip2long($ifcfg['ipaddr']) & gen_subnet_mask_long($ifcfg['subnet']));
181
			$subnet_end = (ip2long($ifcfg['ipaddr']) | (~gen_subnet_mask_long($ifcfg['subnet'])));
182 e9f147c8 Scott Ullrich
183 5b237745 Scott Ullrich
			if ((ip2long($_POST['range_from']) < $subnet_start) || (ip2long($_POST['range_from']) > $subnet_end) ||
184
			    (ip2long($_POST['range_to']) < $subnet_start) || (ip2long($_POST['range_to']) > $subnet_end)) {
185 e9f147c8 Scott Ullrich
				$input_errors[] = "The specified range lies outside of the current subnet.";
186 5b237745 Scott Ullrich
			}
187 e9f147c8 Scott Ullrich
188 5b237745 Scott Ullrich
			if (ip2long($_POST['range_from']) > ip2long($_POST['range_to']))
189
				$input_errors[] = "The range is invalid (first element higher than second element).";
190 e9f147c8 Scott Ullrich
191 5b237745 Scott Ullrich
			/* make sure that the DHCP Relay isn't enabled on this interface */
192
			if (isset($config['dhcrelay'][$if]['enable']))
193
				$input_errors[] = "You must disable the DHCP relay on the {$iflist[$if]} interface before enabling the DHCP server.";
194
		}
195
	}
196
197
	if (!$input_errors) {
198 89019922 Ermal Luçi
		if (!is_array($config['dhcpd'][$if]))
199
			$config['dhcpd'][$if] = array();
200
		if (!is_array($config['dhcpd'][$if]['range']))
201
			$config['dhcpd'][$if]['range'] = array();
202
203 5b237745 Scott Ullrich
		$config['dhcpd'][$if]['range']['from'] = $_POST['range_from'];
204
		$config['dhcpd'][$if]['range']['to'] = $_POST['range_to'];
205
		$config['dhcpd'][$if]['defaultleasetime'] = $_POST['deftime'];
206
		$config['dhcpd'][$if]['maxleasetime'] = $_POST['maxtime'];
207 48ab0cd2 Scott Ullrich
		$config['dhcpd'][$if]['netmask'] = $_POST['netmask'];
208 d378c59b Scott Ullrich
		$previous = $config['dhcpd'][$if]['failover_peerip'];
209
		if($previous <> $_POST['failover_peerip']) {
210 e9f147c8 Scott Ullrich
			mwexec("rm -rf /var/dhcpd/var/db/*");
211
		}
212 ea166a33 Scott Ullrich
		$config['dhcpd'][$if]['failover_peerip'] = $_POST['failover_peerip'];
213 e9f147c8 Scott Ullrich
214 5b237745 Scott Ullrich
		unset($config['dhcpd'][$if]['winsserver']);
215
		if ($_POST['wins1'])
216
			$config['dhcpd'][$if]['winsserver'][] = $_POST['wins1'];
217
		if ($_POST['wins2'])
218
			$config['dhcpd'][$if]['winsserver'][] = $_POST['wins2'];
219 4cab31d0 Scott Ullrich
220 94a9cf1a Scott Ullrich
		unset($config['dhcpd'][$if]['dnsserver']);
221 e9f147c8 Scott Ullrich
		if ($_POST['dns1'])
222 06d754d4 Scott Ullrich
			$config['dhcpd'][$if]['dnsserver'][] = $_POST['dns1'];
223 e9f147c8 Scott Ullrich
		if ($_POST['dns2'])
224 06d754d4 Scott Ullrich
			$config['dhcpd'][$if]['dnsserver'][] = $_POST['dns2'];
225 e9f147c8 Scott Ullrich
226 f9261419 Bill Marquette
		$config['dhcpd'][$if]['gateway'] = $_POST['gateway'];
227 1ebf937f Martin Fuchs
		$config['dhcpd'][$if]['domain'] = $_POST['domain'];
228 9be23653 Martin Fuchs
		$config['dhcpd'][$if]['domainsearchlist'] = $_POST['domainsearchlist'];
229 6a01ea44 Bill Marquette
		$config['dhcpd'][$if]['denyunknown'] = ($_POST['denyunknown']) ? true : false;
230
		$config['dhcpd'][$if]['enable'] = ($_POST['enable']) ? true : false;
231
		$config['dhcpd'][$if]['staticarp'] = ($_POST['staticarp']) ? true : false;
232 4e9cd828 Seth Mos
		$config['dhcpd'][$if]['ddnsdomain'] = $_POST['ddnsdomain'];
233
		$config['dhcpd'][$if]['ddnsupdate'] = ($_POST['ddnsupdate']) ? true : false;
234 ad171999 Seth Mos
235
		unset($config['dhcpd'][$if]['ntpserver']);
236
		if ($_POST['ntp1'])
237
			$config['dhcpd'][$if]['ntpserver'][] = $_POST['ntp1'];
238
		if ($_POST['ntp2'])
239
			$config['dhcpd'][$if]['ntpserver'][] = $_POST['ntp2'];
240
241 6c23757b Martin Fuchs
		$config['dhcpd'][$if]['tftp'] = $_POST['tftp'];
242
		$config['dhcpd'][$if]['ldap'] = $_POST['ldap'];
243 4e9cd828 Seth Mos
		$config['dhcpd'][$if]['netboot'] = ($_POST['netboot']) ? true : false;
244
		$config['dhcpd'][$if]['next-server'] = $_POST['nextserver'];
245
		$config['dhcpd'][$if]['filename'] = $_POST['filename'];
246 ee1b024e Martin Fuchs
		$config['dhcpd'][$if]['rootpath'] = $_POST['rootpath'];
247 9c748b70 Scott Ullrich
248 5b237745 Scott Ullrich
		write_config();
249 80933129 Bill Marquette
250
		/* static arp configuration */
251 c5a0fd3c Scott Ullrich
		interfaces_staticarp_configure($if);
252 e9f147c8 Scott Ullrich
253 5b237745 Scott Ullrich
		$retval = 0;
254 6a01ea44 Bill Marquette
		$retvaldhcp = 0;
255
		$retvaldns = 0;
256 824edb6c Scott Ullrich
		config_lock();
257 6a01ea44 Bill Marquette
		/* dnsmasq_configure calls dhcpd_configure */
258
		/* no need to restart dhcpd twice */
259
		if (isset($config['dnsmasq']['regdhcpstatic']))	{
260
			$retvaldns = services_dnsmasq_configure();
261
			if ($retvaldns == 0) {
262
				if (file_exists($d_hostsdirty_path))
263
					unlink($d_hostsdirty_path);
264
				if (file_exists($d_staticmapsdirty_path))
265
					unlink($d_staticmapsdirty_path);
266
			}					
267
		} else {
268
			$retvaldhcp = services_dhcpd_configure();	
269
			if ($retvaldhcp == 0) {
270
				if (file_exists($d_staticmapsdirty_path))
271
					unlink($d_staticmapsdirty_path);
272
			}
273
		}	
274 824edb6c Scott Ullrich
		config_unlock();
275 6a01ea44 Bill Marquette
		if($retvaldhcp == 1 || $retvaldns == 1)
276
			$retval = 1;
277 5b237745 Scott Ullrich
		$savemsg = get_std_save_message($retval);
278
	}
279
}
280
281
if ($_GET['act'] == "del") {
282
	if ($a_maps[$_GET['id']]) {
283
		unset($a_maps[$_GET['id']]);
284
		write_config();
285 6a01ea44 Bill Marquette
		if(isset($config['dhcpd'][$if]['enable'])) {
286
			touch($d_staticmapsdirty_path);
287
			if (isset($config['dnsmasq']['regdhcpstatic']))
288
				touch($d_hostsdirty_path);
289
		}
290 5b237745 Scott Ullrich
		header("Location: services_dhcp.php?if={$if}");
291
		exit;
292
	}
293
}
294 4df96eff Scott Ullrich
295 d88c6a9f Scott Ullrich
$pgtitle = array("Services","DHCP server");
296 4df96eff Scott Ullrich
include("head.inc");
297
298 5b237745 Scott Ullrich
?>
299 4df96eff Scott Ullrich
300 4e9cd828 Seth Mos
<script type="text/javascript" language="JavaScript">
301
302 5b237745 Scott Ullrich
function enable_change(enable_over) {
303 07bd3f83 Scott Ullrich
	var endis;
304
	endis = !(document.iform.enable.checked || enable_over);
305
	document.iform.range_from.disabled = endis;
306
	document.iform.range_to.disabled = endis;
307
	document.iform.wins1.disabled = endis;
308
	document.iform.wins2.disabled = endis;
309 4cab31d0 Scott Ullrich
	document.iform.dns1.disabled = endis;
310
	document.iform.dns2.disabled = endis;
311 07bd3f83 Scott Ullrich
	document.iform.deftime.disabled = endis;
312
	document.iform.maxtime.disabled = endis;
313 f9261419 Bill Marquette
	document.iform.gateway.disabled = endis;
314 fcffbd13 Scott Ullrich
	document.iform.failover_peerip.disabled = endis;
315 1ebf937f Martin Fuchs
	document.iform.domain.disabled = endis;
316 9be23653 Martin Fuchs
	document.iform.domainsearchlist.disabled = endis;
317 db6b2be4 Scott Ullrich
	document.iform.staticarp.disabled = endis;
318 4e9cd828 Seth Mos
	document.iform.ddnsdomain.disabled = endis;
319
	document.iform.ddnsupdate.disabled = endis;
320 ad171999 Seth Mos
	document.iform.ntp1.disabled = endis;
321
	document.iform.ntp2.disabled = endis;
322 6c23757b Martin Fuchs
	document.iform.tftp.disabled = endis;
323
	document.iform.ldap.disabled = endis;
324 4e9cd828 Seth Mos
	document.iform.netboot.disabled = endis;
325
	document.iform.nextserver.disabled = endis;
326
	document.iform.filename.disabled = endis;
327 ee1b024e Martin Fuchs
	document.iform.rootpath.disabled = endis;
328 7ceb4368 Scott Ullrich
	document.iform.denyunknown.disabled = endis;
329 5b237745 Scott Ullrich
}
330 4e9cd828 Seth Mos
331
function show_ddns_config() {
332
	document.getElementById("showddnsbox").innerHTML='';
333
	aodiv = document.getElementById('showddns');
334
	aodiv.style.display = "block";
335
}
336
337 ad171999 Seth Mos
function show_ntp_config() {
338
	document.getElementById("showntpbox").innerHTML='';
339
	aodiv = document.getElementById('showntp');
340
	aodiv.style.display = "block";
341
}
342
343 6c23757b Martin Fuchs
function show_tftp_config() {
344
	document.getElementById("showtftpbox").innerHTML='';
345
	aodiv = document.getElementById('showtftp');
346
	aodiv.style.display = "block";
347
}
348
349
function show_ldap_config() {
350
	document.getElementById("showldapbox").innerHTML='';
351
	aodiv = document.getElementById('showldap');
352
	aodiv.style.display = "block";
353
}
354
355 4e9cd828 Seth Mos
function show_netboot_config() {
356
	document.getElementById("shownetbootbox").innerHTML='';
357
	aodiv = document.getElementById('shownetboot');
358
	aodiv.style.display = "block";
359
}
360
361 5b237745 Scott Ullrich
</script>
362
363
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
364 b7597d4e Bill Marquette
<?php include("fbegin.inc"); ?>
365 5b237745 Scott Ullrich
<form action="services_dhcp.php" method="post" name="iform" id="iform">
366
<?php if ($input_errors) print_input_errors($input_errors); ?>
367
<?php if ($savemsg) print_info_box($savemsg); ?>
368 3d7b7757 Chris Buechler
<?php 
369
	if ($dhcrelay_enabled) {
370
		echo "DHCP Relay is currently enabled.  Cannot enable the DHCP Server service while the DHCP Relay is enabled on any interface.";
371
		include("fend.inc"); 
372
		echo "</body>";
373
		echo "</html>";
374
		exit;
375
	}
376
?>
377 5b237745 Scott Ullrich
<?php if (file_exists($d_staticmapsdirty_path)): ?><p>
378
<?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>
379
<?php endif; ?>
380
<table width="100%" border="0" cellpadding="0" cellspacing="0">
381
  <tr><td>
382 f0cdf141 Scott Ullrich
  <?php
383
	/* active tabs */
384
	$tab_array = array();
385
	$tabscounter = 0;
386
	$i = 0;
387
	foreach ($iflist as $ifent => $ifname) {
388 934240ef Ermal Luçi
        	$oc = $config['interfaces'][$ifent];
389
        	if (!is_ipaddr($oc['ipaddr']))
390
			continue;
391 f0cdf141 Scott Ullrich
		if ($ifent == $if)
392
			$active = true;
393
		else
394
			$active = false;
395
		$tab_array[] = array($ifname, $active, "services_dhcp.php?if={$ifent}");
396 934240ef Ermal Luçi
		$tabscounter++;
397
	}
398
	if ($tabscounter == 0) {
399
		echo "</td></tr></table></form>";
400
		include("fend.inc");
401
		echo "</body>";
402
		echo "</html>";
403
		exit;
404 f0cdf141 Scott Ullrich
	}
405
	display_top_tabs($tab_array);
406
  ?>
407 5b237745 Scott Ullrich
  </td></tr>
408 e9f147c8 Scott Ullrich
  <tr>
409 d732f186 Bill Marquette
    <td>
410
	<div id="mainarea">
411
              <table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
412 e9f147c8 Scott Ullrich
                      <tr>
413 5b237745 Scott Ullrich
                        <td width="22%" valign="top" class="vtable">&nbsp;</td>
414
                        <td width="78%" class="vtable">
415 8c65eb75 Scott Ullrich
			  <input name="enable" type="checkbox" value="yes" <?php if ($pconfig['enable']) echo "checked"; ?> onClick="enable_change(false)">
416 e9f147c8 Scott Ullrich
                          <strong>Enable DHCP server on
417 5b237745 Scott Ullrich
                          <?=htmlspecialchars($iflist[$if]);?>
418
                          interface</strong></td>
419
                      </tr>
420
				  <tr>
421
	              <td width="22%" valign="top" class="vtable">&nbsp;</td>
422
                      <td width="78%" class="vtable">
423 8c65eb75 Scott Ullrich
			<input name="denyunknown" id="denyunknown" type="checkbox" value="yes" <?php if ($pconfig['denyunknown']) echo "checked"; ?>>
424 5b237745 Scott Ullrich
                      <strong>Deny unknown clients</strong><br>
425
                      If this is checked, only the clients defined below will get DHCP leases from this server. </td>
426
		      		  </tr>
427 e9f147c8 Scott Ullrich
                      <tr>
428 5b237745 Scott Ullrich
                        <td width="22%" valign="top" class="vncellreq">Subnet</td>
429 e9f147c8 Scott Ullrich
                        <td width="78%" class="vtable">
430 5b237745 Scott Ullrich
                          <?=gen_subnet($ifcfg['ipaddr'], $ifcfg['subnet']);?>
431
                        </td>
432
                      </tr>
433 e9f147c8 Scott Ullrich
                      <tr>
434
                        <td width="22%" valign="top" class="vncellreq">Subnet
435 5b237745 Scott Ullrich
                          mask</td>
436 e9f147c8 Scott Ullrich
                        <td width="78%" class="vtable">
437 5b237745 Scott Ullrich
                          <?=gen_subnet_mask($ifcfg['subnet']);?>
438
                        </td>
439
                      </tr>
440 e9f147c8 Scott Ullrich
                      <tr>
441
                        <td width="22%" valign="top" class="vncellreq">Available
442 5b237745 Scott Ullrich
                          range</td>
443 e9f147c8 Scott Ullrich
                        <td width="78%" class="vtable">
444 5b237745 Scott Ullrich
                          <?=long2ip(ip2long($ifcfg['ipaddr']) & gen_subnet_mask_long($ifcfg['subnet']));?>
445 e9f147c8 Scott Ullrich
                          -
446 5b237745 Scott Ullrich
                          <?=long2ip(ip2long($ifcfg['ipaddr']) | (~gen_subnet_mask_long($ifcfg['subnet']))); ?>
447
                        </td>
448
                      </tr>
449 48ab0cd2 Scott Ullrich
					  <?php if($is_olsr_enabled): ?>
450 e9f147c8 Scott Ullrich
                      <tr>
451 48ab0cd2 Scott Ullrich
                        <td width="22%" valign="top" class="vncellreq">Subnet Mask</td>
452 e9f147c8 Scott Ullrich
                        <td width="78%" class="vtable">
453 b5c78501 Seth Mos
	                        <select name="netmask" class="formselect" id="netmask">
454 48ab0cd2 Scott Ullrich
							<?php
455
							for ($i = 32; $i > 0; $i--) {
456
								if($i <> 31) {
457
									echo "<option value=\"{$i}\" ";
458 983c0b1f Scott Ullrich
									if ($i == $pconfig['netmask']) echo "selected";
459 48ab0cd2 Scott Ullrich
									echo ">" . $i . "</option>";
460
								}
461
							}
462
							?>
463
							</select>
464
                        </td>
465
                      </tr>
466 e9f147c8 Scott Ullrich
                      <?php endif; ?>
467
                      <tr>
468 5b237745 Scott Ullrich
                        <td width="22%" valign="top" class="vncellreq">Range</td>
469 e9f147c8 Scott Ullrich
                        <td width="78%" class="vtable">
470 b5c78501 Seth Mos
                          <input name="range_from" type="text" class="formfld unknown" id="range_from" size="20" value="<?=htmlspecialchars($pconfig['range_from']);?>">
471
                          &nbsp;to&nbsp; <input name="range_to" type="text" class="formfld unknown" id="range_to" size="20" value="<?=htmlspecialchars($pconfig['range_to']);?>">
472 25e031a1 Scott Ullrich
			</td>
473 5b237745 Scott Ullrich
                      </tr>
474 e9f147c8 Scott Ullrich
                      <tr>
475 5b237745 Scott Ullrich
                        <td width="22%" valign="top" class="vncell">WINS servers</td>
476 e9f147c8 Scott Ullrich
                        <td width="78%" class="vtable">
477 b5c78501 Seth Mos
                          <input name="wins1" type="text" class="formfld unknown" id="wins1" size="20" value="<?=htmlspecialchars($pconfig['wins1']);?>"><br>
478
                          <input name="wins2" type="text" class="formfld unknown" id="wins2" size="20" value="<?=htmlspecialchars($pconfig['wins2']);?>">
479 25e031a1 Scott Ullrich
			</td>
480 5b237745 Scott Ullrich
                      </tr>
481 e9f147c8 Scott Ullrich
                      <tr>
482 4cab31d0 Scott Ullrich
                        <td width="22%" valign="top" class="vncell">DNS servers</td>
483 e9f147c8 Scott Ullrich
                        <td width="78%" class="vtable">
484 b5c78501 Seth Mos
                          <input name="dns1" type="text" class="formfld unknown" id="dns1" size="20" value="<?=htmlspecialchars($pconfig['dns1']);?>"><br>
485
                          <input name="dns2" type="text" class="formfld unknown" id="dns2" size="20" value="<?=htmlspecialchars($pconfig['dns2']);?>"><br>
486 f5fc3deb Chris Buechler
			  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.  
487 25e031a1 Scott Ullrich
			</td>
488 4cab31d0 Scott Ullrich
                      </tr>
489 e9f147c8 Scott Ullrich
                     <tr>
490 b7597d4e Bill Marquette
                       <td width="22%" valign="top" class="vncell">Gateway</td>
491 e9f147c8 Scott Ullrich
                       <td width="78%" class="vtable">
492 b5c78501 Seth Mos
                         <input name="gateway" type="text" class="formfld host" id="gateway" size="20" value="<?=htmlspecialchars($pconfig['gateway']);?>"><br>
493 f5fc3deb Chris Buechler
			 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.
494 e9f147c8 Scott Ullrich
			</td>
495 1ebf937f Martin Fuchs
                     </tr>
496 9be23653 Martin Fuchs
                      <tr>
497 1ebf937f Martin Fuchs
                       <td width="22%" valign="top" class="vncell">Domain-Name</td>
498
                       <td width="78%" class="vtable">
499 b5c78501 Seth Mos
                         <input name="domain" type="text" class="formfld unknown" id="domain" size="20" value="<?=htmlspecialchars($pconfig['domain']);?>"><br>
500 1ebf937f Martin Fuchs
			 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.
501
			</td>
502 2af4c579 Scott Ullrich
                     </tr>
503 e9f147c8 Scott Ullrich
                      <tr>
504 9be23653 Martin Fuchs
                       <td width="22%" valign="top" class="vncell">Domain-Searchlist</td>
505
                       <td width="78%" class="vtable">
506 b5c78501 Seth Mos
                         <input name="domainsearchlist" type="text" class="formfld unknown" id="domainsearchlist" size="20" value="<?=htmlspecialchars($pconfig['domainsearchlist']);?>"><br>
507 9be23653 Martin Fuchs
			 DNS-Searchlist: the DHCP server can serve a list of domains to be searched.
508
			</td>
509
                     </tr>                     
510
                      <tr>
511
                        <td width="22%" valign="top" class="vncell">Default lease time</td>
512 e9f147c8 Scott Ullrich
                        <td width="78%" class="vtable">
513 b5c78501 Seth Mos
                          <input name="deftime" type="text" class="formfld unknown" id="deftime" size="10" value="<?=htmlspecialchars($pconfig['deftime']);?>">
514 5b237745 Scott Ullrich
                          seconds<br>
515 e9f147c8 Scott Ullrich
                          This is used for clients that do not ask for a specific
516 5b237745 Scott Ullrich
                          expiration time.<br>
517 2af4c579 Scott Ullrich
                          The default is 7200 seconds.
518
			</td>
519 5b237745 Scott Ullrich
                      </tr>
520 e9f147c8 Scott Ullrich
                      <tr>
521 9be23653 Martin Fuchs
                        <td width="22%" valign="top" class="vncell">Maximum lease time</td>
522 e9f147c8 Scott Ullrich
                        <td width="78%" class="vtable">
523 b5c78501 Seth Mos
                          <input name="maxtime" type="text" class="formfld unknown" id="maxtime" size="10" value="<?=htmlspecialchars($pconfig['maxtime']);?>">
524 5b237745 Scott Ullrich
                          seconds<br>
525 e9f147c8 Scott Ullrich
                          This is the maximum lease time for clients that ask
526 5b237745 Scott Ullrich
                          for a specific expiration time.<br>
527 2af4c579 Scott Ullrich
                          The default is 86400 seconds.
528
			</td>
529 5b237745 Scott Ullrich
                      </tr>
530 ea166a33 Scott Ullrich
                      <tr>
531
                        <td width="22%" valign="top" class="vncell">Failover peer IP:</td>
532
                        <td width="78%" class="vtable">
533 b5c78501 Seth Mos
				<input name="failover_peerip" type="text" class="formfld host" id="failover_peerip" size="20" value="<?=htmlspecialchars($pconfig['failover_peerip']);?>"><br>
534 be586e5f Scott Ullrich
				Leave blank to disable.  Enter the REAL address of the other machine.  Machines must be using CARP.
535 ea166a33 Scott Ullrich
			</td>
536
		      </tr>
537 f1da88f6 Bill Marquette
                      <tr>
538
                        <td width="22%" valign="top" class="vncell">Static ARP</td>
539 e44a0096 Scott Ullrich
                        <td width="78%" class="vtable">
540
				<table>
541 2af4c579 Scott Ullrich
					<tr>
542
						<td>
543
							<input valign="middle" type="checkbox" value="yes" name="staticarp" id="staticarp" <?php if($pconfig['staticarp']) echo " checked"; ?>>&nbsp;
544
						</td>
545
						<td>
546
							<b>Enable Static ARP entries</b>
547
						</td>
548
					</tr>
549
					<tr>
550
						<td>
551
							&nbsp;
552
						</td>
553
						<td>
554 c5a0fd3c Scott Ullrich
							<span class="red"><strong>Note:</strong></span> Only the machines listed below will be able to communicate with the firewall on this NIC.
555 2af4c579 Scott Ullrich
						</td>
556
					</tr>
557 e44a0096 Scott Ullrich
				</table>
558
			</td>
559 f1da88f6 Bill Marquette
                      </tr>
560 4e9cd828 Seth Mos
                      <tr>
561
                        <td width="22%" valign="top" class="vncell">Dynamic DNS</td>
562
                        <td width="78%" class="vtable">
563
				<div id="showddnsbox">
564
					<input type="button" onClick="show_ddns_config()" value="Advanced"></input> - Show Dynamic DNS</a>
565
				</div>
566
				<div id="showddns" style="display:none">
567
					<input valign="middle" type="checkbox" value="yes" name="ddnsupdate" id="ddnsupdate" <?php if($pconfig['ddnsupdate']) echo " checked"; ?>>&nbsp;
568
					<b>Enable registration of DHCP client names in DNS.</b><br />
569
					<p>
570 b5c78501 Seth Mos
					<input name="ddnsdomain" type="text" class="formfld unknown" id="ddnsdomain" size="20" value="<?=htmlspecialchars($pconfig['ddnsdomain']);?>"><br />
571 4e9cd828 Seth Mos
					Note: Leave blank to disable dynamic DNS registration.<br />
572
					Enter the dynamic DNS domain which will be used to register client names in the DNS server.
573
				</div>
574
			</td>
575
		      </tr>
576 ad171999 Seth Mos
                      <tr>
577
                        <td width="22%" valign="top" class="vncell">NTP servers</td>
578
                        <td width="78%" class="vtable">
579
				<div id="showntpbox">
580
					<input type="button" onClick="show_ntp_config()" value="Advanced"></input> - Show NTP configuration</a>
581
				</div>
582
				<div id="showntp" style="display:none">
583 b5c78501 Seth Mos
					<input name="ntp1" type="text" class="formfld unknown" id="ntp1" size="20" value="<?=htmlspecialchars($pconfig['ntp1']);?>"><br>
584
					<input name="ntp2" type="text" class="formfld unknown" id="ntp2" size="20" value="<?=htmlspecialchars($pconfig['ntp2']);?>">
585 ad171999 Seth Mos
				</div>
586
			</td>
587
                      </tr>
588 6c23757b Martin Fuchs
                      <tr>
589
                        <td width="22%" valign="top" class="vncell">TFTP server</td>
590
                        <td width="78%" class="vtable">
591
				<div id="showtftpbox">
592
					<input type="button" onClick="show_tftp_config()" value="Advanced"></input> - Show TFTP configuration</a>
593
				</div>
594
				<div id="showtftp" style="display:none">
595 b5c78501 Seth Mos
					<input name="tftp" type="text" class="formfld unknown" id="tftp" size="50" value="<?=htmlspecialchars($pconfig['tftp']);?>"><br>
596 6c23757b Martin Fuchs
					Leave blank to disable.  Enter a full hostname or IP for the TFTP server.
597
				</div>
598
			</td>
599
                      </tr>
600
                      <tr>
601
                        <td width="22%" valign="top" class="vncell">LDAP URI</td>
602
                        <td width="78%" class="vtable">
603
				<div id="showldapbox">
604
					<input type="button" onClick="show_ldap_config()" value="Advanced"></input> - Show LDAP configuration</a>
605
				</div>
606
				<div id="showldap" style="display:none">
607 b5c78501 Seth Mos
					<input name="ldap" type="text" class="formfld unknown" id="ldap" size="80" value="<?=htmlspecialchars($pconfig['ldap']);?>"><br>
608 6c23757b Martin Fuchs
					Leave blank to disable.  Enter a full URI for the LDAP server in the form ldap://ldap.example.com/dc=example,dc=com
609
				</div>
610
			</td>
611
                      </tr>
612 4e9cd828 Seth Mos
                      <tr>
613
                        <td width="22%" valign="top" class="vncell">Enable Network booting</td>
614
                        <td width="78%" class="vtable">
615
				<div id="shownetbootbox">
616
					<input type="button" onClick="show_netboot_config()" value="Advanced"></input> - Show Network booting</a>
617
				</div>
618
				<div id="shownetboot" style="display:none">
619
					<input valign="middle" type="checkbox" value="yes" name="netboot" id="netboot" <?php if($pconfig['netboot']) echo " checked"; ?>>&nbsp;
620
					<b>Enables network booting.</b>
621
					<p>
622 ee1b024e Martin Fuchs
					Enter the IP of the <b>next-server</b>
623 b5c78501 Seth Mos
					<input name="nextserver" type="text" class="formfld unknown" id="nextserver" size="20" value="<?=htmlspecialchars($pconfig['nextserver']);?>">
624 ee1b024e Martin Fuchs
					and the filename					
625 b5c78501 Seth Mos
					<input name="filename" type="text" class="formfld unknown" id="filename" size="20" value="<?=htmlspecialchars($pconfig['filename']);?>"><br>
626 4e9cd828 Seth Mos
					Note: You need both a filename and a boot server configured for this to work!
627 ee1b024e Martin Fuchs
				  <p>
628 ca126e03 Martin Fuchs
					Enter the <b>root-path</b>-string
629 b5c78501 Seth Mos
          <input name="rootpath" type="text" class="formfld unknown" id="rootpath" size="90" value="<?=htmlspecialchars($pconfig['rootpath']);?>"><br>
630 ca126e03 Martin Fuchs
          Note: string-format: iscsi:(servername):(protocol):(port):(LUN):targetname
631 ee1b024e Martin Fuchs
        </div>
632 4e9cd828 Seth Mos
			</td>
633 ee1b024e Martin Fuchs
		                  </tr>
634 e9f147c8 Scott Ullrich
                      <tr>
635 5b237745 Scott Ullrich
                        <td width="22%" valign="top">&nbsp;</td>
636 e9f147c8 Scott Ullrich
                        <td width="78%">
637
                          <input name="if" type="hidden" value="<?=$if;?>">
638
                          <input name="Submit" type="submit" class="formbtn" value="Save" onclick="enable_change(true)">
639 5b237745 Scott Ullrich
                        </td>
640
                      </tr>
641 e9f147c8 Scott Ullrich
                      <tr>
642 5b237745 Scott Ullrich
                        <td width="22%" valign="top">&nbsp;</td>
643
                        <td width="78%"> <p><span class="vexpl"><span class="red"><strong>Note:<br>
644 e9f147c8 Scott Ullrich
                            </strong></span>The DNS servers entered in <a href="system.php">System:
645
                            General setup</a> (or the <a href="services_dnsmasq.php">DNS
646
                            forwarder</a>, if enabled) </span><span class="vexpl">will
647 5b237745 Scott Ullrich
                            be assigned to clients by the DHCP server.<br>
648
                            <br>
649 f056270d Scott Ullrich
                            The DHCP lease table can be viewed on the <a href="diag_dhcp_leases.php">Status:
650 5b237745 Scott Ullrich
                            DHCP leases</a> page.<br>
651 2af4c579 Scott Ullrich
                            </span></p>
652
			</td>
653 5b237745 Scott Ullrich
                      </tr>
654
                    </table>
655 d732f186 Bill Marquette
              <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
656 5b237745 Scott Ullrich
                <tr>
657 6a01ea44 Bill Marquette
                  <td width="25%" class="listhdrr">MAC address</td>
658
                  <td width="15%" class="listhdrr">IP address</td>
659
				  <td width="20%" class="listhdrr">Hostname</td>
660
                  <td width="30%" class="listhdr">Description</td>
661 2af4c579 Scott Ullrich
                  <td width="10%" class="list">
662 d415d821 Seth Mos
                    <table border="0" cellspacing="0" cellpadding="1">
663
                      <tr>
664
			<td valign="middle" width="17"></td>
665
                        <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>
666
                      </tr>
667
                    </table>
668 2af4c579 Scott Ullrich
		  </td>
669
		</tr>
670 6f5b2c3e Scott Ullrich
			  <?php if(is_array($a_maps)): ?>
671 5b237745 Scott Ullrich
			  <?php $i = 0; foreach ($a_maps as $mapent): ?>
672 11c9bb94 Scott Ullrich
			  <?php if($mapent['mac'] <> "" or $mapent['ipaddr'] <> ""): ?>
673 5b237745 Scott Ullrich
                <tr>
674 2d165eff Bill Marquette
                  <td class="listlr" ondblclick="document.location='services_dhcp_edit.php?if=<?=$if;?>&id=<?=$i;?>';">
675 5b237745 Scott Ullrich
                    <?=htmlspecialchars($mapent['mac']);?>
676
                  </td>
677 2d165eff Bill Marquette
                  <td class="listr" ondblclick="document.location='services_dhcp_edit.php?if=<?=$if;?>&id=<?=$i;?>';">
678 5b237745 Scott Ullrich
                    <?=htmlspecialchars($mapent['ipaddr']);?>&nbsp;
679
                  </td>
680 6a01ea44 Bill Marquette
                  <td class="listr" ondblclick="document.location='services_dhcp_edit.php?if=<?=$if;?>&id=<?=$i;?>';">
681
                    <?=htmlspecialchars($mapent['hostname']);?>&nbsp;
682
                  </td>	
683 2d165eff Bill Marquette
                  <td class="listbg" ondblclick="document.location='services_dhcp_edit.php?if=<?=$if;?>&id=<?=$i;?>';">
684 d4da6249 Scott Ullrich
                    <?=htmlspecialchars($mapent['descr']);?>&nbsp;
685 5b237745 Scott Ullrich
                  </td>
686 75a70796 Bill Marquette
                  <td valign="middle" nowrap class="list">
687
                    <table border="0" cellspacing="0" cellpadding="1">
688
                      <tr>
689 677c0869 Erik Kristensen
                        <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>
690
                        <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>
691 75a70796 Bill Marquette
                      </tr>
692
                    </table>
693
                  </td>
694
                </tr>
695 6f5b2c3e Scott Ullrich
		<?php endif; ?>
696 75a70796 Bill Marquette
		<?php $i++; endforeach; ?>
697 6f5b2c3e Scott Ullrich
		<?php endif; ?>
698 e9f147c8 Scott Ullrich
                <tr>
699 6a01ea44 Bill Marquette
                  <td class="list" colspan="4"></td>
700 75a70796 Bill Marquette
                  <td class="list">
701
                    <table border="0" cellspacing="0" cellpadding="1">
702
                      <tr>
703 d415d821 Seth Mos
			<td valign="middle" width="17"></td>
704 677c0869 Erik Kristensen
                        <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>
705 75a70796 Bill Marquette
                      </tr>
706
                    </table>
707
                  </td>
708
                </tr>
709 5b237745 Scott Ullrich
              </table>
710 d732f186 Bill Marquette
	</div>
711 5b237745 Scott Ullrich
    </td>
712
  </tr>
713
</table>
714
</form>
715
<script language="JavaScript">
716
<!--
717
enable_change(false);
718
//-->
719
</script>
720 b7597d4e Bill Marquette
<?php include("fend.inc"); ?>
721 5b237745 Scott Ullrich
</body>
722
</html>