1 |
26ef3f74
|
Scott Ullrich
|
<?php
|
2 |
b46bfcf5
|
Bill Marquette
|
/* $Id$ */
|
3 |
5b237745
|
Scott Ullrich
|
/*
|
4 |
|
|
services_proxyarp_edit.php
|
5 |
26ef3f74
|
Scott Ullrich
|
part of m0n0wall (http://m0n0.ch/wall)
|
6 |
|
|
|
7 |
5b237745
|
Scott Ullrich
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
8 |
|
|
All rights reserved.
|
9 |
26ef3f74
|
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 |
26ef3f74
|
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 |
26ef3f74
|
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 |
26ef3f74
|
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 |
|
|
require("guiconfig.inc");
|
33 |
|
|
|
34 |
|
|
if (!is_array($config['proxyarp']['proxyarpnet'])) {
|
35 |
|
|
$config['proxyarp']['proxyarpnet'] = array();
|
36 |
|
|
}
|
37 |
|
|
proxyarp_sort();
|
38 |
|
|
$a_proxyarp = &$config['proxyarp']['proxyarpnet'];
|
39 |
|
|
|
40 |
|
|
$id = $_GET['id'];
|
41 |
|
|
if (isset($_POST['id']))
|
42 |
|
|
$id = $_POST['id'];
|
43 |
|
|
|
44 |
|
|
if (isset($id) && $a_proxyarp[$id]) {
|
45 |
26ef3f74
|
Scott Ullrich
|
if ($a_proxyarp[$id]['interface'])
|
46 |
|
|
$pconfig['interface'] = $a_proxyarp[$id]['interface'];
|
47 |
|
|
else
|
48 |
|
|
$pconfig['interface'] = "wan";
|
49 |
5b237745
|
Scott Ullrich
|
if (isset($a_proxyarp[$id]['network']))
|
50 |
|
|
list($pconfig['subnet'], $pconfig['subnet_bits']) = explode("/", $a_proxyarp[$id]['network']);
|
51 |
|
|
else if (isset($a_proxyarp[$id]['range'])) {
|
52 |
|
|
$pconfig['range_from'] = $a_proxyarp[$id]['range']['from'];
|
53 |
|
|
$pconfig['range_to'] = $a_proxyarp[$id]['range']['to'];
|
54 |
|
|
}
|
55 |
|
|
$pconfig['descr'] = $a_proxyarp[$id]['descr'];
|
56 |
|
|
} else {
|
57 |
26ef3f74
|
Scott Ullrich
|
$pconfig['interface'] = "wan";
|
58 |
5b237745
|
Scott Ullrich
|
$pconfig['subnet_bits'] = 32;
|
59 |
|
|
}
|
60 |
|
|
|
61 |
|
|
if ($_POST) {
|
62 |
|
|
|
63 |
|
|
unset($input_errors);
|
64 |
|
|
$pconfig = $_POST;
|
65 |
|
|
|
66 |
|
|
/* input validation */
|
67 |
|
|
if ($_POST['type'] == "single") {
|
68 |
|
|
$reqdfields = explode(" ", "subnet");
|
69 |
|
|
$reqdfieldsn = explode(",", "Address");
|
70 |
|
|
$_POST['subnet_bits'] = 32;
|
71 |
|
|
} else if ($_POST['type'] == "network") {
|
72 |
|
|
$reqdfields = explode(" ", "subnet subnet_bits");
|
73 |
|
|
$reqdfieldsn = explode(",", "Network,Network mask");
|
74 |
|
|
} else if ($_POST['type'] == "range") {
|
75 |
|
|
$reqdfields = explode(" ", "range_from range_to");
|
76 |
|
|
$reqdfieldsn = explode(",", "Range start,Range end");
|
77 |
|
|
}
|
78 |
26ef3f74
|
Scott Ullrich
|
|
79 |
5b237745
|
Scott Ullrich
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
|
80 |
26ef3f74
|
Scott Ullrich
|
|
81 |
5b237745
|
Scott Ullrich
|
if ((($_POST['type'] != "range") && $_POST['subnet'] && !is_ipaddr($_POST['subnet']))) {
|
82 |
|
|
$input_errors[] = "A valid address must be specified.";
|
83 |
|
|
}
|
84 |
|
|
if ((($_POST['type'] == "range") && $_POST['range_from'] && !is_ipaddr($_POST['range_from']))) {
|
85 |
|
|
$input_errors[] = "A valid range start must be specified.";
|
86 |
|
|
}
|
87 |
|
|
if ((($_POST['type'] == "range") && $_POST['range_to'] && !is_ipaddr($_POST['range_to']))) {
|
88 |
|
|
$input_errors[] = "A valid range end must be specified.";
|
89 |
|
|
}
|
90 |
|
|
|
91 |
|
|
/* check for overlaps */
|
92 |
|
|
foreach ($a_proxyarp as $arpent) {
|
93 |
|
|
if (isset($id) && ($a_proxyarp[$id]) && ($a_proxyarp[$id] === $arpent))
|
94 |
|
|
continue;
|
95 |
26ef3f74
|
Scott Ullrich
|
|
96 |
5b237745
|
Scott Ullrich
|
if (($_POST['type'] == "range") && isset($arpent['range'])) {
|
97 |
26ef3f74
|
Scott Ullrich
|
if (($_POST['range_from'] == $arpent['range']['from']) &&
|
98 |
5b237745
|
Scott Ullrich
|
($_POST['range_to'] == $arpent['range']['to'])) {
|
99 |
|
|
$input_errors[] = "This range already exists.";
|
100 |
|
|
break;
|
101 |
|
|
}
|
102 |
|
|
} else if (isset($arpent['network'])) {
|
103 |
|
|
if (($arpent['network'] == "{$_POST['subnet']}/{$_POST['subnet_bits']}")) {
|
104 |
|
|
$input_errors[] = "This network already exists.";
|
105 |
|
|
break;
|
106 |
|
|
}
|
107 |
|
|
}
|
108 |
|
|
}
|
109 |
|
|
|
110 |
|
|
if (!$input_errors) {
|
111 |
|
|
$arpent = array();
|
112 |
26ef3f74
|
Scott Ullrich
|
$arpent['interface'] = $_POST['interface'];
|
113 |
5b237745
|
Scott Ullrich
|
if ($_POST['type'] == "range") {
|
114 |
|
|
$arpent['range']['from'] = $_POST['range_from'];
|
115 |
|
|
$arpent['range']['to'] = $_POST['range_to'];
|
116 |
|
|
} else
|
117 |
|
|
$arpent['network'] = $_POST['subnet'] . "/" . $_POST['subnet_bits'];
|
118 |
|
|
$arpent['descr'] = $_POST['descr'];
|
119 |
|
|
|
120 |
|
|
if (isset($id) && $a_proxyarp[$id])
|
121 |
|
|
$a_proxyarp[$id] = $arpent;
|
122 |
|
|
else
|
123 |
|
|
$a_proxyarp[] = $arpent;
|
124 |
26ef3f74
|
Scott Ullrich
|
|
125 |
5b237745
|
Scott Ullrich
|
touch($d_proxyarpdirty_path);
|
126 |
26ef3f74
|
Scott Ullrich
|
|
127 |
5b237745
|
Scott Ullrich
|
write_config();
|
128 |
26ef3f74
|
Scott Ullrich
|
|
129 |
5b237745
|
Scott Ullrich
|
header("Location: services_proxyarp.php");
|
130 |
|
|
exit;
|
131 |
|
|
}
|
132 |
|
|
}
|
133 |
4df96eff
|
Scott Ullrich
|
|
134 |
d88c6a9f
|
Scott Ullrich
|
$pgtitle = array("Services","Proxy ARP","Edit");
|
135 |
4df96eff
|
Scott Ullrich
|
include("head.inc");
|
136 |
|
|
|
137 |
5b237745
|
Scott Ullrich
|
?>
|
138 |
4df96eff
|
Scott Ullrich
|
|
139 |
5b237745
|
Scott Ullrich
|
<script language="JavaScript">
|
140 |
|
|
<!--
|
141 |
|
|
function typesel_change() {
|
142 |
|
|
switch (document.iform.type.selectedIndex) {
|
143 |
|
|
case 0: // single
|
144 |
|
|
document.iform.subnet.disabled = 0;
|
145 |
|
|
document.iform.subnet_bits.disabled = 1;
|
146 |
|
|
document.iform.range_from.disabled = 1;
|
147 |
|
|
document.iform.range_to.disabled = 1;
|
148 |
|
|
break;
|
149 |
|
|
case 1: // network
|
150 |
|
|
document.iform.subnet.disabled = 0;
|
151 |
|
|
document.iform.subnet_bits.disabled = 0;
|
152 |
|
|
document.iform.range_from.disabled = 1;
|
153 |
|
|
document.iform.range_to.disabled = 1;
|
154 |
|
|
break;
|
155 |
|
|
case 2: // range
|
156 |
|
|
document.iform.subnet.disabled = 1;
|
157 |
|
|
document.iform.subnet_bits.disabled = 1;
|
158 |
|
|
document.iform.range_from.disabled = 0;
|
159 |
|
|
document.iform.range_to.disabled = 0;
|
160 |
|
|
break;
|
161 |
|
|
}
|
162 |
|
|
}
|
163 |
|
|
//-->
|
164 |
|
|
</script>
|
165 |
|
|
|
166 |
|
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
167 |
c44f1bd5
|
Bill Marquette
|
<?php include("fbegin.inc"); ?>
|
168 |
5b237745
|
Scott Ullrich
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
169 |
|
|
<form action="services_proxyarp_edit.php" method="post" name="iform" id="iform">
|
170 |
|
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
171 |
26ef3f74
|
Scott Ullrich
|
<tr>
|
172 |
|
|
<td width="22%" valign="top" class="vncellreq">Interface</td>
|
173 |
|
|
<td width="78%" class="vtable">
|
174 |
b5c78501
|
Seth Mos
|
<select name="interface" class="formselect">
|
175 |
612bb4f3
|
Scott Ullrich
|
<?php
|
176 |
|
|
if($config['interfaces']['lan'])
|
177 |
|
|
$interfaces = array('wan' => 'WAN', 'lan' => 'LAN');
|
178 |
|
|
else
|
179 |
|
|
$interfaces = array('wan' => 'WAN');
|
180 |
26ef3f74
|
Scott Ullrich
|
for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
|
181 |
|
|
$interfaces['opt' . $i] = $config['interfaces']['opt' . $i]['descr'];
|
182 |
|
|
}
|
183 |
|
|
foreach ($interfaces as $iface => $ifacename): ?>
|
184 |
|
|
<option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected"; ?>>
|
185 |
|
|
<?=htmlspecialchars($ifacename);?>
|
186 |
|
|
</option>
|
187 |
|
|
<?php endforeach; ?>
|
188 |
|
|
</select> </td>
|
189 |
|
|
</tr>
|
190 |
|
|
<tr>
|
191 |
5b237745
|
Scott Ullrich
|
<td valign="top" class="vncellreq">Network</td>
|
192 |
|
|
<td class="vtable">
|
193 |
|
|
<table border="0" cellspacing="0" cellpadding="0">
|
194 |
26ef3f74
|
Scott Ullrich
|
<tr>
|
195 |
5b237745
|
Scott Ullrich
|
<td>Type: </td>
|
196 |
b5c78501
|
Seth Mos
|
<td><select name="type" class="formselect" onChange="typesel_change()">
|
197 |
26ef3f74
|
Scott Ullrich
|
<option value="single" <?php if (!$pconfig['range_from'] && $pconfig['subnet_bits'] == 32) echo "selected"; ?>>
|
198 |
5b237745
|
Scott Ullrich
|
Single address</option>
|
199 |
26ef3f74
|
Scott Ullrich
|
<option value="network" <?php if (!$pconfig['range_from'] && $pconfig['subnet_bits'] != 32) echo "selected"; ?>>
|
200 |
5b237745
|
Scott Ullrich
|
Network</option>
|
201 |
26ef3f74
|
Scott Ullrich
|
<option value="range" <?php if ($pconfig['range_from']) echo "selected"; ?>>
|
202 |
5b237745
|
Scott Ullrich
|
Range</option>
|
203 |
|
|
</select></td>
|
204 |
|
|
</tr>
|
205 |
26ef3f74
|
Scott Ullrich
|
<tr>
|
206 |
5b237745
|
Scott Ullrich
|
<td>Address: </td>
|
207 |
b5c78501
|
Seth Mos
|
<td><input name="subnet" type="text" class="formfld unknown" id="subnet" size="20" value="<?=htmlspecialchars($pconfig['subnet']);?>">
|
208 |
26ef3f74
|
Scott Ullrich
|
/
|
209 |
b5c78501
|
Seth Mos
|
<select name="subnet_bits" class="formselect" id="select">
|
210 |
26ef3f74
|
Scott Ullrich
|
<?php for ($i = 31; $i >= 0; $i--): ?>
|
211 |
5b237745
|
Scott Ullrich
|
<option value="<?=$i;?>" <?php if ($i == $pconfig['subnet_bits']) echo "selected"; ?>>
|
212 |
|
|
<?=$i;?>
|
213 |
|
|
</option>
|
214 |
|
|
<?php endfor; ?>
|
215 |
|
|
</select>
|
216 |
|
|
</td>
|
217 |
|
|
</tr>
|
218 |
26ef3f74
|
Scott Ullrich
|
<tr>
|
219 |
5b237745
|
Scott Ullrich
|
<td>Range: </td>
|
220 |
b5c78501
|
Seth Mos
|
<td><input name="range_from" type="text" class="formfld unknown" id="range_from" size="20" value="<?=htmlspecialchars($pconfig['range_from']);?>">
|
221 |
26ef3f74
|
Scott Ullrich
|
-
|
222 |
b5c78501
|
Seth Mos
|
<input name="range_to" type="text" class="formfld unknown" id="range_to" size="20" value="<?=htmlspecialchars($pconfig['range_to']);?>">
|
223 |
5b237745
|
Scott Ullrich
|
</td>
|
224 |
|
|
</tr>
|
225 |
|
|
</table>
|
226 |
|
|
</td>
|
227 |
|
|
</tr>
|
228 |
26ef3f74
|
Scott Ullrich
|
<tr>
|
229 |
5b237745
|
Scott Ullrich
|
<td width="22%" valign="top" class="vncell">Description</td>
|
230 |
26ef3f74
|
Scott Ullrich
|
<td width="78%" class="vtable">
|
231 |
b5c78501
|
Seth Mos
|
<input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
|
232 |
5b237745
|
Scott Ullrich
|
<br> <span class="vexpl">You may enter a description here
|
233 |
|
|
for your reference (not parsed).</span></td>
|
234 |
|
|
</tr>
|
235 |
|
|
<tr>
|
236 |
|
|
<td width="22%" valign="top"> </td>
|
237 |
26ef3f74
|
Scott Ullrich
|
<td width="78%">
|
238 |
fc01e414
|
Scott Ullrich
|
<input name="Submit" type="submit" class="formbtn" value="Save"> <input class="formbtn" type="button" value="Cancel" onclick="history.back()">
|
239 |
5b237745
|
Scott Ullrich
|
<?php if (isset($id) && $a_proxyarp[$id]): ?>
|
240 |
|
|
<input name="id" type="hidden" value="<?=$id;?>">
|
241 |
|
|
<?php endif; ?>
|
242 |
|
|
</td>
|
243 |
|
|
</tr>
|
244 |
|
|
</table>
|
245 |
|
|
</form>
|
246 |
|
|
<script language="JavaScript">
|
247 |
|
|
<!--
|
248 |
|
|
typesel_change();
|
249 |
|
|
//-->
|
250 |
|
|
</script>
|
251 |
|
|
<?php include("fend.inc"); ?>
|
252 |
|
|
</body>
|
253 |
|
|
</html>
|