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