1 |
5b237745
|
Scott Ullrich
|
#!/usr/local/bin/php
|
2 |
|
|
<?php
|
3 |
b46bfcf5
|
Bill Marquette
|
/* $Id$ */
|
4 |
5b237745
|
Scott Ullrich
|
/*
|
5 |
|
|
services_dhcp_edit.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 |
|
|
if (!$if) {
|
40 |
|
|
header("Location: services_dhcp.php");
|
41 |
|
|
exit;
|
42 |
|
|
}
|
43 |
|
|
|
44 |
|
|
if (!is_array($config['dhcpd'][$if]['staticmap'])) {
|
45 |
|
|
$config['dhcpd'][$if]['staticmap'] = array();
|
46 |
|
|
}
|
47 |
|
|
staticmaps_sort($if);
|
48 |
|
|
$a_maps = &$config['dhcpd'][$if]['staticmap'];
|
49 |
|
|
$ifcfg = &$config['interfaces'][$if];
|
50 |
|
|
|
51 |
|
|
$id = $_GET['id'];
|
52 |
|
|
if (isset($_POST['id']))
|
53 |
|
|
$id = $_POST['id'];
|
54 |
|
|
|
55 |
|
|
if (isset($id) && $a_maps[$id]) {
|
56 |
|
|
$pconfig['mac'] = $a_maps[$id]['mac'];
|
57 |
|
|
$pconfig['ipaddr'] = $a_maps[$id]['ipaddr'];
|
58 |
|
|
$pconfig['descr'] = $a_maps[$id]['descr'];
|
59 |
|
|
}
|
60 |
|
|
|
61 |
|
|
if ($_POST) {
|
62 |
|
|
|
63 |
|
|
unset($input_errors);
|
64 |
|
|
$pconfig = $_POST;
|
65 |
|
|
|
66 |
|
|
/* input validation */
|
67 |
|
|
$reqdfields = explode(" ", "mac");
|
68 |
|
|
$reqdfieldsn = explode(",", "MAC address");
|
69 |
|
|
|
70 |
|
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
|
71 |
4f3401e0
|
Bill Marquette
|
|
72 |
|
|
/* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
|
73 |
|
|
$_POST['mac'] = strtolower(str_replace("-", ":", $_POST['mac']));
|
74 |
5b237745
|
Scott Ullrich
|
|
75 |
|
|
if (($_POST['ipaddr'] && !is_ipaddr($_POST['ipaddr']))) {
|
76 |
|
|
$input_errors[] = "A valid IP address must be specified.";
|
77 |
|
|
}
|
78 |
|
|
if (($_POST['mac'] && !is_macaddr($_POST['mac']))) {
|
79 |
|
|
$input_errors[] = "A valid MAC address must be specified.";
|
80 |
|
|
}
|
81 |
|
|
|
82 |
|
|
/* check for overlaps */
|
83 |
|
|
foreach ($a_maps as $mapent) {
|
84 |
|
|
if (isset($id) && ($a_maps[$id]) && ($a_maps[$id] === $mapent))
|
85 |
|
|
continue;
|
86 |
|
|
|
87 |
|
|
if (($mapent['mac'] == $_POST['mac']) || ($_POST['ipaddr'] && (ip2long($mapent['ipaddr']) == ip2long($_POST['ipaddr'])))) {
|
88 |
|
|
$input_errors[] = "This IP or MAC address already exists.";
|
89 |
|
|
break;
|
90 |
|
|
}
|
91 |
|
|
}
|
92 |
|
|
|
93 |
|
|
/* make sure it's not within the dynamic subnet */
|
94 |
|
|
if ($_POST['ipaddr']) {
|
95 |
|
|
$dynsubnet_start = ip2long($config['dhcpd'][$if]['range']['from']);
|
96 |
|
|
$dynsubnet_end = ip2long($config['dhcpd'][$if]['range']['to']);
|
97 |
|
|
$lansubnet_start = (ip2long($ifcfg['ipaddr']) & gen_subnet_mask_long($ifcfg['subnet']));
|
98 |
|
|
$lansubnet_end = (ip2long($ifcfg['ipaddr']) | (~gen_subnet_mask_long($ifcfg['subnet'])));
|
99 |
|
|
|
100 |
|
|
if ((ip2long($_POST['ipaddr']) >= $dynsubnet_start) &&
|
101 |
|
|
(ip2long($_POST['ipaddr']) <= $dynsubnet_end)) {
|
102 |
|
|
$input_errors[] = "Static IP addresses may not lie within the dynamic client range.";
|
103 |
|
|
}
|
104 |
|
|
if ((ip2long($_POST['ipaddr']) < $lansubnet_start) ||
|
105 |
|
|
(ip2long($_POST['ipaddr']) > $lansubnet_end)) {
|
106 |
|
|
$input_errors[] = "The IP address must lie in the {$ifcfg['descr']} subnet.";
|
107 |
|
|
}
|
108 |
|
|
}
|
109 |
|
|
|
110 |
|
|
if (!$input_errors) {
|
111 |
|
|
$mapent = array();
|
112 |
|
|
$mapent['mac'] = $_POST['mac'];
|
113 |
|
|
$mapent['ipaddr'] = $_POST['ipaddr'];
|
114 |
|
|
$mapent['descr'] = $_POST['descr'];
|
115 |
|
|
|
116 |
|
|
if (isset($id) && $a_maps[$id])
|
117 |
|
|
$a_maps[$id] = $mapent;
|
118 |
|
|
else
|
119 |
|
|
$a_maps[] = $mapent;
|
120 |
|
|
|
121 |
|
|
touch($d_staticmapsdirty_path);
|
122 |
|
|
|
123 |
|
|
write_config();
|
124 |
|
|
|
125 |
|
|
header("Location: services_dhcp.php?if={$if}");
|
126 |
|
|
exit;
|
127 |
|
|
}
|
128 |
|
|
}
|
129 |
4df96eff
|
Scott Ullrich
|
|
130 |
|
|
$pgtitle = "Services: DHCP: Edit static mapping";
|
131 |
|
|
include("head.inc");
|
132 |
|
|
|
133 |
5b237745
|
Scott Ullrich
|
?>
|
134 |
|
|
|
135 |
|
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
136 |
|
|
<?php include("fbegin.inc"); ?>
|
137 |
74f446e8
|
Bill Marquette
|
<p class="pgtitle"><?=$pgtitle?></p>
|
138 |
5b237745
|
Scott Ullrich
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
139 |
|
|
<form action="services_dhcp_edit.php" method="post" name="iform" id="iform">
|
140 |
ef97ce1b
|
Bill Marquette
|
<?display_topbar()?>
|
141 |
5b237745
|
Scott Ullrich
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
142 |
|
|
<tr>
|
143 |
|
|
<td width="22%" valign="top" class="vncellreq">MAC address</td>
|
144 |
|
|
<td width="78%" class="vtable">
|
145 |
f183b092
|
Scott Ullrich
|
<input name="mac" type="text" class="formfld" id="mac" size="30" value="<?=htmlspecialchars($pconfig['mac']);?>">
|
146 |
|
|
<?php
|
147 |
|
|
$ip = getenv('REMOTE_ADDR');
|
148 |
|
|
$mac = `/usr/sbin/arp -an | grep {$ip} | cut -d" " -f4`;
|
149 |
|
|
$mac = str_replace("\n","",$mac);
|
150 |
|
|
?>
|
151 |
|
|
<a OnClick="document.forms[0].mac.value='<?=$mac?>';" href="#">Copy my MAC address</a>
|
152 |
5b237745
|
Scott Ullrich
|
<br>
|
153 |
|
|
<span class="vexpl">Enter a MAC address in the following format:
|
154 |
|
|
xx:xx:xx:xx:xx:xx</span></td>
|
155 |
|
|
</tr>
|
156 |
|
|
<tr>
|
157 |
|
|
<td width="22%" valign="top" class="vncell">IP address</td>
|
158 |
|
|
<td width="78%" class="vtable">
|
159 |
|
|
<input name="ipaddr" type="text" class="formfld" id="ipaddr" size="20" value="<?=htmlspecialchars($pconfig['ipaddr']);?>">
|
160 |
|
|
<br>
|
161 |
|
|
If no IP address is given, one will be dynamically allocated from the pool.</td>
|
162 |
|
|
</tr>
|
163 |
|
|
<tr>
|
164 |
|
|
<td width="22%" valign="top" class="vncell">Description</td>
|
165 |
|
|
<td width="78%" class="vtable">
|
166 |
|
|
<input name="descr" type="text" class="formfld" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
|
167 |
|
|
<br> <span class="vexpl">You may enter a description here
|
168 |
|
|
for your reference (not parsed).</span></td>
|
169 |
|
|
</tr>
|
170 |
|
|
<tr>
|
171 |
|
|
<td width="22%" valign="top"> </td>
|
172 |
|
|
<td width="78%">
|
173 |
fc01e414
|
Scott Ullrich
|
<input name="Submit" type="submit" class="formbtn" value="Save"> <input class="formbtn" type="button" value="Cancel" onclick="history.back()">
|
174 |
5b237745
|
Scott Ullrich
|
<?php if (isset($id) && $a_maps[$id]): ?>
|
175 |
|
|
<input name="id" type="hidden" value="<?=$id;?>">
|
176 |
|
|
<?php endif; ?>
|
177 |
|
|
<input name="if" type="hidden" value="<?=$if;?>">
|
178 |
|
|
</td>
|
179 |
|
|
</tr>
|
180 |
|
|
</table>
|
181 |
|
|
</form>
|
182 |
|
|
<?php include("fend.inc"); ?>
|
183 |
|
|
</body>
|
184 |
|
|
</html>
|