1
|
#!/usr/local/bin/php
|
2
|
<?php
|
3
|
/* $Id$ */
|
4
|
/*
|
5
|
services_dhcp.php
|
6
|
part of m0n0wall (http://m0n0.ch/wall)
|
7
|
|
8
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
9
|
All rights reserved.
|
10
|
|
11
|
Redistribution and use in source and binary forms, with or without
|
12
|
modification, are permitted provided that the following conditions are met:
|
13
|
|
14
|
1. Redistributions of source code must retain the above copyright notice,
|
15
|
this list of conditions and the following disclaimer.
|
16
|
|
17
|
2. Redistributions in binary form must reproduce the above copyright
|
18
|
notice, this list of conditions and the following disclaimer in the
|
19
|
documentation and/or other materials provided with the distribution.
|
20
|
|
21
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
22
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
23
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
24
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
25
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
26
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
27
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
28
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
29
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30
|
POSSIBILITY OF SUCH DAMAGE.
|
31
|
*/
|
32
|
|
33
|
require("guiconfig.inc");
|
34
|
|
35
|
$if = $_GET['if'];
|
36
|
if ($_POST['if'])
|
37
|
$if = $_POST['if'];
|
38
|
|
39
|
$iflist = array("lan" => "LAN");
|
40
|
|
41
|
for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
|
42
|
$oc = $config['interfaces']['opt' . $i];
|
43
|
|
44
|
if (isset($oc['enable']) && $oc['if'] && (!$oc['bridge'])) {
|
45
|
$iflist['opt' . $i] = $oc['descr'];
|
46
|
}
|
47
|
}
|
48
|
|
49
|
if (!$if || !isset($iflist[$if]))
|
50
|
$if = "lan";
|
51
|
|
52
|
$pconfig['range_from'] = $config['dhcpd'][$if]['range']['from'];
|
53
|
$pconfig['range_to'] = $config['dhcpd'][$if]['range']['to'];
|
54
|
$pconfig['deftime'] = $config['dhcpd'][$if]['defaultleasetime'];
|
55
|
$pconfig['maxtime'] = $config['dhcpd'][$if]['maxleasetime'];
|
56
|
list($pconfig['wins1'],$pconfig['wins2']) = $config['dhcpd'][$if]['winsserver'];
|
57
|
$pconfig['enable'] = isset($config['dhcpd'][$if]['enable']);
|
58
|
$pconfig['denyunknown'] = isset($config['dhcpd'][$if]['denyunknown']);
|
59
|
$pconfig['staticarp'] = isset($config['dhcpd'][$if]['staticarp']);
|
60
|
|
61
|
$ifcfg = $config['interfaces'][$if];
|
62
|
|
63
|
if (!is_array($config['dhcpd'][$if]['staticmap'])) {
|
64
|
$config['dhcpd'][$if]['staticmap'] = array();
|
65
|
}
|
66
|
staticmaps_sort($if);
|
67
|
$a_maps = &$config['dhcpd'][$if]['staticmap'];
|
68
|
|
69
|
|
70
|
if ($_POST) {
|
71
|
|
72
|
unset($input_errors);
|
73
|
|
74
|
$pconfig = $_POST;
|
75
|
|
76
|
/* input validation */
|
77
|
if ($_POST['enable']) {
|
78
|
$reqdfields = explode(" ", "range_from range_to");
|
79
|
$reqdfieldsn = explode(",", "Range begin,Range end");
|
80
|
|
81
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
|
82
|
|
83
|
if (($_POST['range_from'] && !is_ipaddr($_POST['range_from']))) {
|
84
|
$input_errors[] = "A valid range must be specified.";
|
85
|
}
|
86
|
if (($_POST['range_to'] && !is_ipaddr($_POST['range_to']))) {
|
87
|
$input_errors[] = "A valid range must be specified.";
|
88
|
}
|
89
|
if (($_POST['gateway'] && !is_ipaddr($_POST['gateway'])))
|
90
|
$input_errors[] = "A valid IP address must be specified for the gateway.";
|
91
|
if (($_POST['wins1'] && !is_ipaddr($_POST['wins1'])) || ($_POST['wins2'] && !is_ipaddr($_POST['wins2']))) {
|
92
|
$input_errors[] = "A valid IP address must be specified for the primary/secondary WINS server.";
|
93
|
}
|
94
|
if ($_POST['deftime'] && (!is_numeric($_POST['deftime']) || ($_POST['deftime'] < 60))) {
|
95
|
$input_errors[] = "The default lease time must be at least 60 seconds.";
|
96
|
}
|
97
|
if ($_POST['maxtime'] && (!is_numeric($_POST['maxtime']) || ($_POST['maxtime'] < 60) || ($_POST['maxtime'] <= $_POST['deftime']))) {
|
98
|
$input_errors[] = "The maximum lease time must be at least 60 seconds and higher than the default lease time.";
|
99
|
}
|
100
|
|
101
|
if (!$input_errors) {
|
102
|
/* make sure the range lies within the current subnet */
|
103
|
$subnet_start = (ip2long($ifcfg['ipaddr']) & gen_subnet_mask_long($ifcfg['subnet']));
|
104
|
$subnet_end = (ip2long($ifcfg['ipaddr']) | (~gen_subnet_mask_long($ifcfg['subnet'])));
|
105
|
|
106
|
if ((ip2long($_POST['range_from']) < $subnet_start) || (ip2long($_POST['range_from']) > $subnet_end) ||
|
107
|
(ip2long($_POST['range_to']) < $subnet_start) || (ip2long($_POST['range_to']) > $subnet_end)) {
|
108
|
$input_errors[] = "The specified range lies outside of the current subnet.";
|
109
|
}
|
110
|
|
111
|
if (ip2long($_POST['range_from']) > ip2long($_POST['range_to']))
|
112
|
$input_errors[] = "The range is invalid (first element higher than second element).";
|
113
|
|
114
|
/* make sure that the DHCP Relay isn't enabled on this interface */
|
115
|
if (isset($config['dhcrelay'][$if]['enable']))
|
116
|
$input_errors[] = "You must disable the DHCP relay on the {$iflist[$if]} interface before enabling the DHCP server.";
|
117
|
}
|
118
|
}
|
119
|
|
120
|
if (!$input_errors) {
|
121
|
$config['dhcpd'][$if]['range']['from'] = $_POST['range_from'];
|
122
|
$config['dhcpd'][$if]['range']['to'] = $_POST['range_to'];
|
123
|
$config['dhcpd'][$if]['defaultleasetime'] = $_POST['deftime'];
|
124
|
$config['dhcpd'][$if]['maxleasetime'] = $_POST['maxtime'];
|
125
|
$config['dhcpd'][$if]['enable'] = $_POST['enable'] ? true : false;
|
126
|
$config['dhcpd'][$if]['denyunknown'] = $_POST['denyunknown'] ? true : false;
|
127
|
|
128
|
unset($config['dhcpd'][$if]['winsserver']);
|
129
|
if ($_POST['wins1'])
|
130
|
$config['dhcpd'][$if]['winsserver'][] = $_POST['wins1'];
|
131
|
if ($_POST['wins2'])
|
132
|
$config['dhcpd'][$if]['winsserver'][] = $_POST['wins2'];
|
133
|
|
134
|
$config['dhcpd'][$if]['gateway'] = $_POST['gateway'];
|
135
|
|
136
|
$config['dhcpd'][$if]['staticarp'] = $_POST['staticarp'] ? true : false;
|
137
|
|
138
|
|
139
|
write_config();
|
140
|
|
141
|
/* static arp configuration */
|
142
|
if (isset($config['dhcpd'][$if]['staticarp']))
|
143
|
interfaces_staticarp_configure($if);
|
144
|
|
145
|
$retval = 0;
|
146
|
if (!file_exists($d_sysrebootreqd_path)) {
|
147
|
config_lock();
|
148
|
$retval = services_dhcpd_configure();
|
149
|
config_unlock();
|
150
|
}
|
151
|
$savemsg = get_std_save_message($retval);
|
152
|
|
153
|
if ($retval == 0) {
|
154
|
if (file_exists($d_staticmapsdirty_path))
|
155
|
unlink($d_staticmapsdirty_path);
|
156
|
}
|
157
|
}
|
158
|
}
|
159
|
|
160
|
if ($_GET['act'] == "del") {
|
161
|
if ($a_maps[$_GET['id']]) {
|
162
|
unset($a_maps[$_GET['id']]);
|
163
|
write_config();
|
164
|
touch($d_staticmapsdirty_path);
|
165
|
header("Location: services_dhcp.php?if={$if}");
|
166
|
exit;
|
167
|
}
|
168
|
}
|
169
|
?>
|
170
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
171
|
<html>
|
172
|
<head>
|
173
|
<title><?=gentitle("Services: DHCP server");?></title>
|
174
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
175
|
<link href="gui.css" rel="stylesheet" type="text/css">
|
176
|
<script language="JavaScript">
|
177
|
<!--
|
178
|
function enable_change(enable_over) {
|
179
|
var endis;
|
180
|
endis = !(document.iform.enable.checked || enable_over);
|
181
|
|
182
|
document.iform.range_from.disabled = endis;
|
183
|
document.iform.range_to.disabled = endis;
|
184
|
document.iform.wins1.disabled = endis;
|
185
|
document.iform.wins2.disabled = endis;
|
186
|
document.iform.deftime.disabled = endis;
|
187
|
document.iform.maxtime.disabled = endis;
|
188
|
document.iform.gateway.disabled = endis;
|
189
|
}
|
190
|
//-->
|
191
|
</script>
|
192
|
</head>
|
193
|
|
194
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
195
|
<?php include("fbegin.inc"); ?>
|
196
|
<p class="pgtitle">Services: DHCP server</p>
|
197
|
<form action="services_dhcp.php" method="post" name="iform" id="iform">
|
198
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
199
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
200
|
<?php if (file_exists($d_staticmapsdirty_path)): ?><p>
|
201
|
<?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>
|
202
|
<input name="apply" type="submit" class="formbtn" id="apply" value="Apply changes"></p>
|
203
|
<?php endif; ?>
|
204
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
205
|
<tr><td>
|
206
|
<ul id="tabnav">
|
207
|
<?php foreach ($iflist as $ifent => $ifname):
|
208
|
if ($ifent == $if): ?>
|
209
|
<li class="tabact"><?=htmlspecialchars($ifname);?></li>
|
210
|
<?php else: ?>
|
211
|
<li class="tabinact"><a href="services_dhcp.php?if=<?=$ifent;?>"><?=htmlspecialchars($ifname);?></a></li>
|
212
|
<?php endif; ?>
|
213
|
<?php endforeach; ?>
|
214
|
</ul>
|
215
|
</td></tr>
|
216
|
<tr>
|
217
|
<td class="tabcont">
|
218
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
219
|
<tr>
|
220
|
<td width="22%" valign="top" class="vtable"> </td>
|
221
|
<td width="78%" class="vtable">
|
222
|
<input name="enable" type="checkbox" value="yes" <?php if ($pconfig['enable']) echo "checked"; ?> onClick="enable_change(false)">
|
223
|
<strong>Enable DHCP server on
|
224
|
<?=htmlspecialchars($iflist[$if]);?>
|
225
|
interface</strong></td>
|
226
|
</tr>
|
227
|
<tr>
|
228
|
<td width="22%" valign="top" class="vtable"> </td>
|
229
|
<td width="78%" class="vtable">
|
230
|
<input name="denyunknown" type="checkbox" value="yes" <?php if ($pconfig['denyunknown']) echo "checked"; ?>>
|
231
|
<strong>Deny unknown clients</strong><br>
|
232
|
If this is checked, only the clients defined below will get DHCP leases from this server. </td>
|
233
|
</tr>
|
234
|
<tr>
|
235
|
<td width="22%" valign="top" class="vncellreq">Subnet</td>
|
236
|
<td width="78%" class="vtable">
|
237
|
<?=gen_subnet($ifcfg['ipaddr'], $ifcfg['subnet']);?>
|
238
|
</td>
|
239
|
</tr>
|
240
|
<tr>
|
241
|
<td width="22%" valign="top" class="vncellreq">Subnet
|
242
|
mask</td>
|
243
|
<td width="78%" class="vtable">
|
244
|
<?=gen_subnet_mask($ifcfg['subnet']);?>
|
245
|
</td>
|
246
|
</tr>
|
247
|
<tr>
|
248
|
<td width="22%" valign="top" class="vncellreq">Available
|
249
|
range</td>
|
250
|
<td width="78%" class="vtable">
|
251
|
<?=long2ip(ip2long($ifcfg['ipaddr']) & gen_subnet_mask_long($ifcfg['subnet']));?>
|
252
|
-
|
253
|
<?=long2ip(ip2long($ifcfg['ipaddr']) | (~gen_subnet_mask_long($ifcfg['subnet']))); ?>
|
254
|
</td>
|
255
|
</tr>
|
256
|
<tr>
|
257
|
<td width="22%" valign="top" class="vncellreq">Range</td>
|
258
|
<td width="78%" class="vtable">
|
259
|
<input name="range_from" type="text" class="formfld" id="range_from" size="20" value="<?=htmlspecialchars($pconfig['range_from']);?>">
|
260
|
to <input name="range_to" type="text" class="formfld" id="range_to" size="20" value="<?=htmlspecialchars($pconfig['range_to']);?>"></td>
|
261
|
</tr>
|
262
|
<tr>
|
263
|
<td width="22%" valign="top" class="vncell">WINS servers</td>
|
264
|
<td width="78%" class="vtable">
|
265
|
<input name="wins1" type="text" class="formfld" id="wins1" size="20" value="<?=htmlspecialchars($pconfig['wins1']);?>"><br>
|
266
|
<input name="wins2" type="text" class="formfld" id="wins2" size="20" value="<?=htmlspecialchars($pconfig['wins2']);?>"></td>
|
267
|
</tr>
|
268
|
<tr>
|
269
|
<td width="22%" valign="top" class="vncell">Gateway</td>
|
270
|
<td width="78%" class="vtable">
|
271
|
<input name="gateway" type="text" class="formfld" id="gateway" size="20" value="<?=htmlspecialchars($pconfig['gateway']);?>"><br>
|
272
|
The default is to use the IP of the firewall as the gateway. Specify an alternate gateway here if this is not the correct gateway for your network.
|
273
|
</tr>
|
274
|
<tr>
|
275
|
<td width="22%" valign="top" class="vncell">Default lease
|
276
|
time</td>
|
277
|
<td width="78%" class="vtable">
|
278
|
<input name="deftime" type="text" class="formfld" id="deftime" size="10" value="<?=htmlspecialchars($pconfig['deftime']);?>">
|
279
|
seconds<br>
|
280
|
This is used for clients that do not ask for a specific
|
281
|
expiration time.<br>
|
282
|
The default is 7200 seconds.</td>
|
283
|
</tr>
|
284
|
<tr>
|
285
|
<td width="22%" valign="top" class="vncell">Maximum lease
|
286
|
time</td>
|
287
|
<td width="78%" class="vtable">
|
288
|
<input name="maxtime" type="text" class="formfld" id="maxtime" size="10" value="<?=htmlspecialchars($pconfig['maxtime']);?>">
|
289
|
seconds<br>
|
290
|
This is the maximum lease time for clients that ask
|
291
|
for a specific expiration time.<br>
|
292
|
The default is 86400 seconds.</td>
|
293
|
</tr>
|
294
|
<tr>
|
295
|
<td width="22%" valign="top" class="vncell">Static ARP</td>
|
296
|
<td width="78%" class="vtable"><input type="checkbox" value="yes" name="staticarp" id="staticarp" <?php if($pconfig['staticarp']) echo " checked"; ?>> <b>Enable Static ARP entries</b><br>
|
297
|
<span class="red"><strong>Note:</strong></span> This feature is under development. Only the machines listed below will be able to communicate with the firewall on this NIC. Disabling this has been tested to be broken, a reboot will be required to disable. Be warned!</td>
|
298
|
</tr>
|
299
|
<tr>
|
300
|
<td width="22%" valign="top"> </td>
|
301
|
<td width="78%">
|
302
|
<input name="if" type="hidden" value="<?=$if;?>">
|
303
|
<input name="Submit" type="submit" class="formbtn" value="Save" onclick="enable_change(true)">
|
304
|
</td>
|
305
|
</tr>
|
306
|
<tr>
|
307
|
<td width="22%" valign="top"> </td>
|
308
|
<td width="78%"> <p><span class="vexpl"><span class="red"><strong>Note:<br>
|
309
|
</strong></span>The DNS servers entered in <a href="system.php">System:
|
310
|
General setup</a> (or the <a href="services_dnsmasq.php">DNS
|
311
|
forwarder</a>, if enabled) </span><span class="vexpl">will
|
312
|
be assigned to clients by the DHCP server.<br>
|
313
|
<br>
|
314
|
The DHCP lease table can be viewed on the <a href="diag_dhcp_leases.php">Diagnostics:
|
315
|
DHCP leases</a> page.<br>
|
316
|
</span></p></td>
|
317
|
</tr>
|
318
|
</table>
|
319
|
|
320
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
321
|
<tr>
|
322
|
<td width="35%" class="listhdrr">MAC address </td>
|
323
|
<td width="20%" class="listhdrr">IP address</td>
|
324
|
<td width="35%" class="listhdr">Description</td>
|
325
|
<td width="10%" class="list"></td>
|
326
|
</tr>
|
327
|
<?php $i = 0; foreach ($a_maps as $mapent): ?>
|
328
|
<tr>
|
329
|
<td class="listlr">
|
330
|
<?=htmlspecialchars($mapent['mac']);?>
|
331
|
</td>
|
332
|
<td class="listr">
|
333
|
<?=htmlspecialchars($mapent['ipaddr']);?>
|
334
|
</td>
|
335
|
<td class="listbg">
|
336
|
<?=htmlspecialchars($mapent['descr']);?>
|
337
|
</td>
|
338
|
<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>
|
339
|
<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>
|
340
|
</tr>
|
341
|
<?php $i++; endforeach; ?>
|
342
|
<tr>
|
343
|
<td class="list" colspan="3"></td>
|
344
|
<td class="list"> <a href="services_dhcp_edit.php?if=<?=$if;?>"><img src="plus.gif" width="17" height="17" border="0"></a></td>
|
345
|
</tr>
|
346
|
</table>
|
347
|
</td>
|
348
|
</tr>
|
349
|
</table>
|
350
|
</form>
|
351
|
<script language="JavaScript">
|
352
|
<!--
|
353
|
enable_change(false);
|
354
|
//-->
|
355
|
</script>
|
356
|
<?php include("fend.inc"); ?>
|
357
|
</body>
|
358
|
</html>
|