Project

General

Profile

Download (10.3 KB) Statistics
| Branch: | Tag: | Revision:
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
function proxyarpcmp($a, $b) {
40
	if (isset($a['network']))
41
		list($ast,$asn) = explode("/", $a['network']);
42
	else if (isset($a['range'])) {
43
		$ast = $a['range']['from'];
44
		$asn = 32;
45
	}
46
	if (isset($b['network']))
47
		list($bst,$bsn) = explode("/", $b['network']);
48
	else if (isset($b['range'])) {
49
		$bst = $b['range']['from'];
50
		$bsn = 32;
51
	}
52
	if (ipcmp($ast, $bst) == 0)
53
		return ($asn - $bsn);
54
	else
55
		return ipcmp($ast, $bst);
56
}
57

    
58
function proxyarp_sort() {
59
        global $config;
60

    
61
        usort($config['proxyarp']['proxyarpnet'], "proxyarpcmp");
62
}
63

    
64
require("guiconfig.inc");
65

    
66
if (!is_array($config['proxyarp']['proxyarpnet'])) {
67
	$config['proxyarp']['proxyarpnet'] = array();
68
}
69
proxyarp_sort();
70
$a_proxyarp = &$config['proxyarp']['proxyarpnet'];
71

    
72
$id = $_GET['id'];
73
if (isset($_POST['id']))
74
	$id = $_POST['id'];
75

    
76
if (isset($id) && $a_proxyarp[$id]) {
77
	if ($a_proxyarp[$id]['interface'])
78
		$pconfig['interface'] = $a_proxyarp[$id]['interface'];
79
	else
80
		$pconfig['interface'] = "wan";
81
	if (isset($a_proxyarp[$id]['network']))
82
		list($pconfig['subnet'], $pconfig['subnet_bits']) = explode("/", $a_proxyarp[$id]['network']);
83
	else if (isset($a_proxyarp[$id]['range'])) {
84
		$pconfig['range_from'] = $a_proxyarp[$id]['range']['from'];
85
		$pconfig['range_to'] = $a_proxyarp[$id]['range']['to'];
86
	}
87
	$pconfig['descr'] = $a_proxyarp[$id]['descr'];
88
} else {
89
	$pconfig['interface'] = "wan";
90
	$pconfig['subnet_bits'] = 32;
91
}
92

    
93
if ($_POST) {
94

    
95
	unset($input_errors);
96
	$pconfig = $_POST;
97

    
98
	/* input validation */
99
	if ($_POST['type'] == "single") {
100
		$reqdfields = explode(" ", "subnet");
101
		$reqdfieldsn = explode(",", "Address");
102
		$_POST['subnet_bits'] = 32;
103
	} else if ($_POST['type'] == "network") {
104
		$reqdfields = explode(" ", "subnet subnet_bits");
105
		$reqdfieldsn = explode(",", "Network,Network mask");
106
	} else if ($_POST['type'] == "range") {
107
		$reqdfields = explode(" ", "range_from range_to");
108
		$reqdfieldsn = explode(",", "Range start,Range end");
109
	}
110
	
111
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
112
	
113
	if ((($_POST['type'] != "range") && $_POST['subnet'] && !is_ipaddr($_POST['subnet']))) {
114
		$input_errors[] = "A valid address must be specified.";
115
	}
116
	if ((($_POST['type'] == "range") && $_POST['range_from'] && !is_ipaddr($_POST['range_from']))) {
117
		$input_errors[] = "A valid range start must be specified.";
118
	}
119
	if ((($_POST['type'] == "range") && $_POST['range_to'] && !is_ipaddr($_POST['range_to']))) {
120
		$input_errors[] = "A valid range end must be specified.";
121
	}
122

    
123
	/* check for overlaps */
124
	foreach ($a_proxyarp as $arpent) {
125
		if (isset($id) && ($a_proxyarp[$id]) && ($a_proxyarp[$id] === $arpent))
126
			continue;
127
		
128
		if (($_POST['type'] == "range") && isset($arpent['range'])) {
129
			if (($_POST['range_from'] == $arpent['range']['from']) && 
130
				($_POST['range_to'] == $arpent['range']['to'])) {
131
				$input_errors[] = "This range already exists.";
132
				break;
133
			}
134
		} else if (isset($arpent['network'])) {
135
			if (($arpent['network'] == "{$_POST['subnet']}/{$_POST['subnet_bits']}")) {
136
				$input_errors[] = "This network already exists.";
137
				break;
138
			}
139
		}
140
	}
141

    
142
	if (!$input_errors) {
143
		$arpent = array();
144
		$arpent['interface'] = $_POST['interface'];
145
		if ($_POST['type'] == "range") {
146
			$arpent['range']['from'] = $_POST['range_from'];
147
			$arpent['range']['to'] = $_POST['range_to'];
148
		} else
149
			$arpent['network'] = $_POST['subnet'] . "/" . $_POST['subnet_bits'];
150
		$arpent['descr'] = $_POST['descr'];
151

    
152
		proxyarp_sort();
153
		if (isset($id) && $a_proxyarp[$id])
154
			$a_proxyarp[$id] = $arpent;
155
		else
156
			$a_proxyarp[] = $arpent;
157
		
158
		mark_subsystem_dirty('proxyarp');
159
		
160
		write_config();
161
		
162
		header("Location: services_proxyarp.php");
163
		exit;
164
	}
165
}
166

    
167
$pgtitle = array("Services","Proxy ARP","Edit");
168
include("head.inc");
169

    
170
?>
171

    
172
<script language="JavaScript">
173
<!--
174
function typesel_change() {
175
    switch (document.iform.type.selectedIndex) {
176
        case 0: // single
177
            document.iform.subnet.disabled = 0;
178
            document.iform.subnet_bits.disabled = 1;
179
            document.iform.range_from.disabled = 1;
180
            document.iform.range_to.disabled = 1;
181
            break;
182
        case 1: // network
183
            document.iform.subnet.disabled = 0;
184
            document.iform.subnet_bits.disabled = 0;
185
            document.iform.range_from.disabled = 1;
186
            document.iform.range_to.disabled = 1;
187
            break;
188
        case 2: // range
189
            document.iform.subnet.disabled = 1;
190
            document.iform.subnet_bits.disabled = 1;
191
            document.iform.range_from.disabled = 0;
192
            document.iform.range_to.disabled = 0;
193
            break;
194
    }
195
}
196
//-->
197
</script>
198

    
199
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
200
<?php include("fbegin.inc"); ?>
201
<?php if ($input_errors) print_input_errors($input_errors); ?>
202
            <form action="services_proxyarp_edit.php" method="post" name="iform" id="iform">
203
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
204
                <tr> 
205
                  <td width="22%" valign="top" class="vncellreq">Interface</td>
206
                  <td width="78%" class="vtable">
207
					<select name="interface" class="formselect">
208
                      <?php
209
					  $interfaces = get_configured_interface_with_descr();
210
					  foreach ($interfaces as $iface => $ifacename): ?>
211
                      <option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected"; ?>> 
212
                      <?=htmlspecialchars($ifacename);?>
213
                      </option>
214
                      <?php endforeach; ?>
215
                    </select> </td>
216
                </tr>
217
                <tr> 
218
                  <td valign="top" class="vncellreq">Network</td>
219
                  <td class="vtable">
220
                    <table border="0" cellspacing="0" cellpadding="0">
221
                      <tr> 
222
                        <td>Type:&nbsp;&nbsp;</td>
223
                        <td><select name="type" class="formselect" onChange="typesel_change()">
224
                            <option value="single" <?php if (!$pconfig['range_from'] && $pconfig['subnet_bits'] == 32) echo "selected"; ?>> 
225
                            Single address</option>
226
                            <option value="network" <?php if (!$pconfig['range_from'] && $pconfig['subnet_bits'] != 32) echo "selected"; ?>> 
227
                            Network</option>
228
                            <option value="range" <?php if ($pconfig['range_from']) echo "selected"; ?>> 
229
                            Range</option>
230
                          </select></td>
231
                      </tr>
232
                      <tr> 
233
                        <td>Address:&nbsp;&nbsp;</td>
234
                        <td><input name="subnet" type="text" class="formfld unknown" id="subnet" size="20" value="<?=htmlspecialchars($pconfig['subnet']);?>">
235
                  / 
236
                          <select name="subnet_bits" class="formselect" id="select">
237
                            <?php for ($i = 31; $i >= 0; $i--): ?>
238
                            <option value="<?=$i;?>" <?php if ($i == $pconfig['subnet_bits']) echo "selected"; ?>>
239
                            <?=$i;?>
240
                      </option>
241
                            <?php endfor; ?>
242
                      </select>
243
 </td>
244
                      </tr>
245
                      <tr> 
246
                        <td>Range:&nbsp;&nbsp;</td>
247
                        <td><input name="range_from" type="text" class="formfld unknown" id="range_from" size="20" value="<?=htmlspecialchars($pconfig['range_from']);?>">
248
- 
249
                          <input name="range_to" type="text" class="formfld unknown" id="range_to" size="20" value="<?=htmlspecialchars($pconfig['range_to']);?>">                          
250
                          </td>
251
                      </tr>
252
                    </table>
253
                  </td>
254
                </tr>
255
				<tr>
256
                  <td width="22%" valign="top" class="vncell">Description</td>
257
                  <td width="78%" class="vtable"> 
258
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
259
                    <br> <span class="vexpl">You may enter a description here
260
                    for your reference (not parsed).</span></td>
261
                </tr>
262
                <tr>
263
                  <td width="22%" valign="top">&nbsp;</td>
264
                  <td width="78%"> 
265
                    <input name="Submit" type="submit" class="formbtn" value="Save"> <input class="formbtn" type="button" value="Cancel" onclick="history.back()">
266
                    <?php if (isset($id) && $a_proxyarp[$id]): ?>
267
                    <input name="id" type="hidden" value="<?=$id;?>">
268
                    <?php endif; ?>
269
                  </td>
270
                </tr>
271
              </table>
272
</form>
273
<script language="JavaScript">
274
<!--
275
typesel_change();
276
//-->
277
</script>
278
<?php include("fend.inc"); ?>
279
</body>
280
</html>
(140-140/218)