1 |
5b237745
|
Scott Ullrich
|
#!/usr/local/bin/php
|
2 |
|
|
<?php
|
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 |
|
|
require("guiconfig.inc");
|
33 |
|
|
|
34 |
|
|
$if = $_GET['if'];
|
35 |
|
|
if ($_POST['if'])
|
36 |
|
|
$if = $_POST['if'];
|
37 |
|
|
|
38 |
|
|
$iflist = array("lan" => "LAN");
|
39 |
|
|
|
40 |
|
|
for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
|
41 |
|
|
$oc = $config['interfaces']['opt' . $i];
|
42 |
|
|
|
43 |
|
|
if (isset($oc['enable']) && $oc['if'] && (!$oc['bridge'])) {
|
44 |
|
|
$iflist['opt' . $i] = $oc['descr'];
|
45 |
|
|
}
|
46 |
|
|
}
|
47 |
|
|
|
48 |
|
|
if (!$if || !isset($iflist[$if]))
|
49 |
|
|
$if = "lan";
|
50 |
|
|
|
51 |
|
|
$pconfig['range_from'] = $config['dhcpd'][$if]['range']['from'];
|
52 |
|
|
$pconfig['range_to'] = $config['dhcpd'][$if]['range']['to'];
|
53 |
|
|
$pconfig['deftime'] = $config['dhcpd'][$if]['defaultleasetime'];
|
54 |
|
|
$pconfig['maxtime'] = $config['dhcpd'][$if]['maxleasetime'];
|
55 |
|
|
list($pconfig['wins1'],$pconfig['wins2']) = $config['dhcpd'][$if]['winsserver'];
|
56 |
|
|
$pconfig['enable'] = isset($config['dhcpd'][$if]['enable']);
|
57 |
|
|
$pconfig['denyunknown'] = isset($config['dhcpd'][$if]['denyunknown']);
|
58 |
|
|
|
59 |
|
|
$ifcfg = $config['interfaces'][$if];
|
60 |
|
|
|
61 |
|
|
if (!is_array($config['dhcpd'][$if]['staticmap'])) {
|
62 |
|
|
$config['dhcpd'][$if]['staticmap'] = array();
|
63 |
|
|
}
|
64 |
|
|
staticmaps_sort($if);
|
65 |
|
|
$a_maps = &$config['dhcpd'][$if]['staticmap'];
|
66 |
|
|
|
67 |
|
|
if ($_POST) {
|
68 |
|
|
|
69 |
|
|
unset($input_errors);
|
70 |
|
|
$pconfig = $_POST;
|
71 |
|
|
|
72 |
|
|
/* input validation */
|
73 |
|
|
if ($_POST['enable']) {
|
74 |
|
|
$reqdfields = explode(" ", "range_from range_to");
|
75 |
|
|
$reqdfieldsn = explode(",", "Range begin,Range end");
|
76 |
|
|
|
77 |
|
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
|
78 |
|
|
|
79 |
|
|
if (($_POST['range_from'] && !is_ipaddr($_POST['range_from']))) {
|
80 |
|
|
$input_errors[] = "A valid range must be specified.";
|
81 |
|
|
}
|
82 |
|
|
if (($_POST['range_to'] && !is_ipaddr($_POST['range_to']))) {
|
83 |
|
|
$input_errors[] = "A valid range must be specified.";
|
84 |
|
|
}
|
85 |
|
|
if (($_POST['wins1'] && !is_ipaddr($_POST['wins1'])) || ($_POST['wins2'] && !is_ipaddr($_POST['wins2']))) {
|
86 |
|
|
$input_errors[] = "A valid IP address must be specified for the primary/secondary WINS server.";
|
87 |
|
|
}
|
88 |
|
|
if ($_POST['deftime'] && (!is_numeric($_POST['deftime']) || ($_POST['deftime'] < 60))) {
|
89 |
|
|
$input_errors[] = "The default lease time must be at least 60 seconds.";
|
90 |
|
|
}
|
91 |
|
|
if ($_POST['maxtime'] && (!is_numeric($_POST['maxtime']) || ($_POST['maxtime'] < 60) || ($_POST['maxtime'] <= $_POST['deftime']))) {
|
92 |
|
|
$input_errors[] = "The maximum lease time must be at least 60 seconds and higher than the default lease time.";
|
93 |
|
|
}
|
94 |
|
|
|
95 |
|
|
if (!$input_errors) {
|
96 |
|
|
/* make sure the range lies within the current subnet */
|
97 |
|
|
$subnet_start = (ip2long($ifcfg['ipaddr']) & gen_subnet_mask_long($ifcfg['subnet']));
|
98 |
|
|
$subnet_end = (ip2long($ifcfg['ipaddr']) | (~gen_subnet_mask_long($ifcfg['subnet'])));
|
99 |
|
|
|
100 |
|
|
if ((ip2long($_POST['range_from']) < $subnet_start) || (ip2long($_POST['range_from']) > $subnet_end) ||
|
101 |
|
|
(ip2long($_POST['range_to']) < $subnet_start) || (ip2long($_POST['range_to']) > $subnet_end)) {
|
102 |
|
|
$input_errors[] = "The specified range lies outside of the current subnet.";
|
103 |
|
|
}
|
104 |
|
|
|
105 |
|
|
if (ip2long($_POST['range_from']) > ip2long($_POST['range_to']))
|
106 |
|
|
$input_errors[] = "The range is invalid (first element higher than second element).";
|
107 |
|
|
|
108 |
|
|
/* make sure that the DHCP Relay isn't enabled on this interface */
|
109 |
|
|
if (isset($config['dhcrelay'][$if]['enable']))
|
110 |
|
|
$input_errors[] = "You must disable the DHCP relay on the {$iflist[$if]} interface before enabling the DHCP server.";
|
111 |
|
|
}
|
112 |
|
|
}
|
113 |
|
|
|
114 |
|
|
if (!$input_errors) {
|
115 |
|
|
$config['dhcpd'][$if]['range']['from'] = $_POST['range_from'];
|
116 |
|
|
$config['dhcpd'][$if]['range']['to'] = $_POST['range_to'];
|
117 |
|
|
$config['dhcpd'][$if]['defaultleasetime'] = $_POST['deftime'];
|
118 |
|
|
$config['dhcpd'][$if]['maxleasetime'] = $_POST['maxtime'];
|
119 |
|
|
$config['dhcpd'][$if]['enable'] = $_POST['enable'] ? true : false;
|
120 |
|
|
$config['dhcpd'][$if]['denyunknown'] = $_POST['denyunknown'] ? true : false;
|
121 |
|
|
|
122 |
|
|
unset($config['dhcpd'][$if]['winsserver']);
|
123 |
|
|
if ($_POST['wins1'])
|
124 |
|
|
$config['dhcpd'][$if]['winsserver'][] = $_POST['wins1'];
|
125 |
|
|
if ($_POST['wins2'])
|
126 |
|
|
$config['dhcpd'][$if]['winsserver'][] = $_POST['wins2'];
|
127 |
|
|
|
128 |
|
|
write_config();
|
129 |
|
|
|
130 |
|
|
$retval = 0;
|
131 |
|
|
if (!file_exists($d_sysrebootreqd_path)) {
|
132 |
|
|
config_lock();
|
133 |
|
|
$retval = services_dhcpd_configure();
|
134 |
|
|
config_unlock();
|
135 |
|
|
}
|
136 |
|
|
$savemsg = get_std_save_message($retval);
|
137 |
|
|
|
138 |
|
|
if ($retval == 0) {
|
139 |
|
|
if (file_exists($d_staticmapsdirty_path))
|
140 |
|
|
unlink($d_staticmapsdirty_path);
|
141 |
|
|
}
|
142 |
|
|
}
|
143 |
|
|
}
|
144 |
|
|
|
145 |
|
|
if ($_GET['act'] == "del") {
|
146 |
|
|
if ($a_maps[$_GET['id']]) {
|
147 |
|
|
unset($a_maps[$_GET['id']]);
|
148 |
|
|
write_config();
|
149 |
|
|
touch($d_staticmapsdirty_path);
|
150 |
|
|
header("Location: services_dhcp.php?if={$if}");
|
151 |
|
|
exit;
|
152 |
|
|
}
|
153 |
|
|
}
|
154 |
|
|
?>
|
155 |
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
156 |
|
|
<html>
|
157 |
|
|
<head>
|
158 |
|
|
<title><?=gentitle("Services: DHCP server");?></title>
|
159 |
|
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
160 |
|
|
<link href="gui.css" rel="stylesheet" type="text/css">
|
161 |
|
|
<script language="JavaScript">
|
162 |
|
|
<!--
|
163 |
|
|
function enable_change(enable_over) {
|
164 |
|
|
if (document.iform.enable.checked || enable_over) {
|
165 |
|
|
document.iform.range_from.disabled = 0;
|
166 |
|
|
document.iform.range_to.disabled = 0;
|
167 |
|
|
document.iform.wins1.disabled = 0;
|
168 |
|
|
document.iform.wins2.disabled = 0;
|
169 |
|
|
document.iform.deftime.disabled = 0;
|
170 |
|
|
document.iform.maxtime.disabled = 0;
|
171 |
|
|
} else {
|
172 |
|
|
document.iform.range_from.disabled = 1;
|
173 |
|
|
document.iform.range_to.disabled = 1;
|
174 |
|
|
document.iform.wins1.disabled = 1;
|
175 |
|
|
document.iform.wins2.disabled = 1;
|
176 |
|
|
document.iform.deftime.disabled = 1;
|
177 |
|
|
document.iform.maxtime.disabled = 1;
|
178 |
|
|
}
|
179 |
|
|
}
|
180 |
|
|
//-->
|
181 |
|
|
</script>
|
182 |
|
|
</head>
|
183 |
|
|
|
184 |
|
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
185 |
|
|
<?php include("fbegin.inc"); ?>
|
186 |
|
|
<p class="pgtitle">Services: DHCP server</p>
|
187 |
|
|
<form action="services_dhcp.php" method="post" name="iform" id="iform">
|
188 |
|
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
189 |
|
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
190 |
|
|
<?php if (file_exists($d_staticmapsdirty_path)): ?><p>
|
191 |
|
|
<?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>
|
192 |
|
|
<input name="apply" type="submit" class="formbtn" id="apply" value="Apply changes"></p>
|
193 |
|
|
<?php endif; ?>
|
194 |
|
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
195 |
|
|
<tr><td>
|
196 |
|
|
<ul id="tabnav">
|
197 |
|
|
<?php foreach ($iflist as $ifent => $ifname):
|
198 |
|
|
if ($ifent == $if): ?>
|
199 |
|
|
<li class="tabact"><?=htmlspecialchars($ifname);?></li>
|
200 |
|
|
<?php else: ?>
|
201 |
|
|
<li class="tabinact"><a href="services_dhcp.php?if=<?=$ifent;?>"><?=htmlspecialchars($ifname);?></a></li>
|
202 |
|
|
<?php endif; ?>
|
203 |
|
|
<?php endforeach; ?>
|
204 |
|
|
</ul>
|
205 |
|
|
</td></tr>
|
206 |
|
|
<tr>
|
207 |
|
|
<td class="tabcont">
|
208 |
|
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
209 |
|
|
<tr>
|
210 |
|
|
<td width="22%" valign="top" class="vtable"> </td>
|
211 |
|
|
<td width="78%" class="vtable">
|
212 |
|
|
<input name="enable" type="checkbox" value="yes" <?php if ($pconfig['enable']) echo "checked"; ?> onClick="enable_change(false)">
|
213 |
|
|
<strong>Enable DHCP server on
|
214 |
|
|
<?=htmlspecialchars($iflist[$if]);?>
|
215 |
|
|
interface</strong></td>
|
216 |
|
|
</tr>
|
217 |
|
|
<tr>
|
218 |
|
|
<td width="22%" valign="top" class="vtable"> </td>
|
219 |
|
|
<td width="78%" class="vtable">
|
220 |
|
|
<input name="denyunknown" type="checkbox" value="yes" <?php if ($pconfig['denyunknown']) echo "checked"; ?>>
|
221 |
|
|
<strong>Deny unknown clients</strong><br>
|
222 |
|
|
If this is checked, only the clients defined below will get DHCP leases from this server. </td>
|
223 |
|
|
</tr>
|
224 |
|
|
<tr>
|
225 |
|
|
<td width="22%" valign="top" class="vncellreq">Subnet</td>
|
226 |
|
|
<td width="78%" class="vtable">
|
227 |
|
|
<?=gen_subnet($ifcfg['ipaddr'], $ifcfg['subnet']);?>
|
228 |
|
|
</td>
|
229 |
|
|
</tr>
|
230 |
|
|
<tr>
|
231 |
|
|
<td width="22%" valign="top" class="vncellreq">Subnet
|
232 |
|
|
mask</td>
|
233 |
|
|
<td width="78%" class="vtable">
|
234 |
|
|
<?=gen_subnet_mask($ifcfg['subnet']);?>
|
235 |
|
|
</td>
|
236 |
|
|
</tr>
|
237 |
|
|
<tr>
|
238 |
|
|
<td width="22%" valign="top" class="vncellreq">Available
|
239 |
|
|
range</td>
|
240 |
|
|
<td width="78%" class="vtable">
|
241 |
|
|
<?=long2ip(ip2long($ifcfg['ipaddr']) & gen_subnet_mask_long($ifcfg['subnet']));?>
|
242 |
|
|
-
|
243 |
|
|
<?=long2ip(ip2long($ifcfg['ipaddr']) | (~gen_subnet_mask_long($ifcfg['subnet']))); ?>
|
244 |
|
|
</td>
|
245 |
|
|
</tr>
|
246 |
|
|
<tr>
|
247 |
|
|
<td width="22%" valign="top" class="vncellreq">Range</td>
|
248 |
|
|
<td width="78%" class="vtable">
|
249 |
|
|
<input name="range_from" type="text" class="formfld" id="range_from" size="20" value="<?=htmlspecialchars($pconfig['range_from']);?>">
|
250 |
|
|
to <input name="range_to" type="text" class="formfld" id="range_to" size="20" value="<?=htmlspecialchars($pconfig['range_to']);?>"></td>
|
251 |
|
|
</tr>
|
252 |
|
|
<tr>
|
253 |
|
|
<td width="22%" valign="top" class="vncell">WINS servers</td>
|
254 |
|
|
<td width="78%" class="vtable">
|
255 |
|
|
<input name="wins1" type="text" class="formfld" id="wins1" size="20" value="<?=htmlspecialchars($pconfig['wins1']);?>"><br>
|
256 |
|
|
<input name="wins2" type="text" class="formfld" id="wins2" size="20" value="<?=htmlspecialchars($pconfig['wins2']);?>"></td>
|
257 |
|
|
</tr>
|
258 |
|
|
<tr>
|
259 |
|
|
<td width="22%" valign="top" class="vncell">Default lease
|
260 |
|
|
time</td>
|
261 |
|
|
<td width="78%" class="vtable">
|
262 |
|
|
<input name="deftime" type="text" class="formfld" id="deftime" size="10" value="<?=htmlspecialchars($pconfig['deftime']);?>">
|
263 |
|
|
seconds<br>
|
264 |
|
|
This is used for clients that do not ask for a specific
|
265 |
|
|
expiration time.<br>
|
266 |
|
|
The default is 7200 seconds.</td>
|
267 |
|
|
</tr>
|
268 |
|
|
<tr>
|
269 |
|
|
<td width="22%" valign="top" class="vncell">Maximum lease
|
270 |
|
|
time</td>
|
271 |
|
|
<td width="78%" class="vtable">
|
272 |
|
|
<input name="maxtime" type="text" class="formfld" id="maxtime" size="10" value="<?=htmlspecialchars($pconfig['maxtime']);?>">
|
273 |
|
|
seconds<br>
|
274 |
|
|
This is the maximum lease time for clients that ask
|
275 |
|
|
for a specific expiration time.<br>
|
276 |
|
|
The default is 86400 seconds.</td>
|
277 |
|
|
</tr>
|
278 |
|
|
<tr>
|
279 |
|
|
<td width="22%" valign="top"> </td>
|
280 |
|
|
<td width="78%">
|
281 |
|
|
<input name="if" type="hidden" value="<?=$if;?>">
|
282 |
|
|
<input name="Submit" type="submit" class="formbtn" value="Save" onclick="enable_change(true)">
|
283 |
|
|
</td>
|
284 |
|
|
</tr>
|
285 |
|
|
<tr>
|
286 |
|
|
<td width="22%" valign="top"> </td>
|
287 |
|
|
<td width="78%"> <p><span class="vexpl"><span class="red"><strong>Note:<br>
|
288 |
|
|
</strong></span>The DNS servers entered in <a href="system.php">System:
|
289 |
|
|
General setup</a> (or the <a href="services_dnsmasq.php">DNS
|
290 |
|
|
forwarder</a>, if enabled) </span><span class="vexpl">will
|
291 |
|
|
be assigned to clients by the DHCP server.<br>
|
292 |
|
|
<br>
|
293 |
|
|
The DHCP lease table can be viewed on the <a href="diag_dhcp_leases.php">Diagnostics:
|
294 |
|
|
DHCP leases</a> page.<br>
|
295 |
|
|
</span></p></td>
|
296 |
|
|
</tr>
|
297 |
|
|
</table>
|
298 |
|
|
<br>
|
299 |
|
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
300 |
|
|
<tr>
|
301 |
|
|
<td width="35%" class="listhdrr">MAC address </td>
|
302 |
|
|
<td width="20%" class="listhdrr">IP address</td>
|
303 |
|
|
<td width="35%" class="listhdr">Description</td>
|
304 |
|
|
<td width="10%" class="list"></td>
|
305 |
|
|
</tr>
|
306 |
|
|
<?php $i = 0; foreach ($a_maps as $mapent): ?>
|
307 |
|
|
<tr>
|
308 |
|
|
<td class="listlr">
|
309 |
|
|
<?=htmlspecialchars($mapent['mac']);?>
|
310 |
|
|
</td>
|
311 |
|
|
<td class="listr">
|
312 |
|
|
<?=htmlspecialchars($mapent['ipaddr']);?>
|
313 |
|
|
</td>
|
314 |
|
|
<td class="listbg">
|
315 |
|
|
<?=htmlspecialchars($mapent['descr']);?>
|
316 |
|
|
</td>
|
317 |
|
|
<td valign="middle" nowrap class="list"> <a href="services_dhcp_edit.php?if=<?=$if;?>&id=<?=$i;?>"><img src="e.gif" width="17" height="17" border="0"></a>
|
318 |
|
|
<a href="services_dhcp.php?if=<?=$if;?>&act=del&id=<?=$i;?>" onclick="return confirm('Do you really want to delete this mapping?')"><img src="x.gif" width="17" height="17" border="0"></a></td>
|
319 |
|
|
</tr>
|
320 |
|
|
<?php $i++; endforeach; ?>
|
321 |
|
|
<tr>
|
322 |
|
|
<td class="list" colspan="3"></td>
|
323 |
|
|
<td class="list"> <a href="services_dhcp_edit.php?if=<?=$if;?>"><img src="plus.gif" width="17" height="17" border="0"></a></td>
|
324 |
|
|
</tr>
|
325 |
|
|
</table>
|
326 |
|
|
</td>
|
327 |
|
|
</tr>
|
328 |
|
|
</table>
|
329 |
|
|
</form>
|
330 |
|
|
<script language="JavaScript">
|
331 |
|
|
<!--
|
332 |
|
|
enable_change(false);
|
333 |
|
|
//-->
|
334 |
|
|
</script>
|
335 |
|
|
<?php include("fend.inc"); ?>
|
336 |
|
|
</body>
|
337 |
|
|
</html>
|