Project

General

Profile

Download (9.67 KB) Statistics
| Branch: | Tag: | Revision:
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
$pgtitle = "Services: Proxy ARP: Edit";
135
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 74f446e8 Bill Marquette
<p class="pgtitle"><?=$pgtitle?></p>
169 5b237745 Scott Ullrich
<?php if ($input_errors) print_input_errors($input_errors); ?>
170
            <form action="services_proxyarp_edit.php" method="post" name="iform" id="iform">
171
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
172 26ef3f74 Scott Ullrich
                <tr> 
173
                  <td width="22%" valign="top" class="vncellreq">Interface</td>
174
                  <td width="78%" class="vtable">
175
					<select name="interface" class="formfld">
176
                      <?php $interfaces = array('wan' => 'WAN', 'lan' => 'LAN');
177
					  for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
178
					  	$interfaces['opt' . $i] = $config['interfaces']['opt' . $i]['descr'];
179
					  }
180
					  foreach ($interfaces as $iface => $ifacename): ?>
181
                      <option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected"; ?>> 
182
                      <?=htmlspecialchars($ifacename);?>
183
                      </option>
184
                      <?php endforeach; ?>
185
                    </select> </td>
186
                </tr>
187
                <tr> 
188 5b237745 Scott Ullrich
                  <td valign="top" class="vncellreq">Network</td>
189
                  <td class="vtable">
190
                    <table border="0" cellspacing="0" cellpadding="0">
191 26ef3f74 Scott Ullrich
                      <tr> 
192 5b237745 Scott Ullrich
                        <td>Type:&nbsp;&nbsp;</td>
193
                        <td><select name="type" class="formfld" onChange="typesel_change()">
194 26ef3f74 Scott Ullrich
                            <option value="single" <?php if (!$pconfig['range_from'] && $pconfig['subnet_bits'] == 32) echo "selected"; ?>> 
195 5b237745 Scott Ullrich
                            Single address</option>
196 26ef3f74 Scott Ullrich
                            <option value="network" <?php if (!$pconfig['range_from'] && $pconfig['subnet_bits'] != 32) echo "selected"; ?>> 
197 5b237745 Scott Ullrich
                            Network</option>
198 26ef3f74 Scott Ullrich
                            <option value="range" <?php if ($pconfig['range_from']) echo "selected"; ?>> 
199 5b237745 Scott Ullrich
                            Range</option>
200
                          </select></td>
201
                      </tr>
202 26ef3f74 Scott Ullrich
                      <tr> 
203 5b237745 Scott Ullrich
                        <td>Address:&nbsp;&nbsp;</td>
204
                        <td><input name="subnet" type="text" class="formfld" id="subnet" size="20" value="<?=htmlspecialchars($pconfig['subnet']);?>">
205 26ef3f74 Scott Ullrich
                  / 
206 5b237745 Scott Ullrich
                          <select name="subnet_bits" class="formfld" id="select">
207 26ef3f74 Scott Ullrich
                            <?php for ($i = 31; $i >= 0; $i--): ?>
208 5b237745 Scott Ullrich
                            <option value="<?=$i;?>" <?php if ($i == $pconfig['subnet_bits']) echo "selected"; ?>>
209
                            <?=$i;?>
210
                      </option>
211
                            <?php endfor; ?>
212
                      </select>
213
 </td>
214
                      </tr>
215 26ef3f74 Scott Ullrich
                      <tr> 
216 5b237745 Scott Ullrich
                        <td>Range:&nbsp;&nbsp;</td>
217
                        <td><input name="range_from" type="text" class="formfld" id="range_from" size="20" value="<?=htmlspecialchars($pconfig['range_from']);?>">
218 26ef3f74 Scott Ullrich
- 
219
                          <input name="range_to" type="text" class="formfld" id="range_to" size="20" value="<?=htmlspecialchars($pconfig['range_to']);?>">                          
220 5b237745 Scott Ullrich
                          </td>
221
                      </tr>
222
                    </table>
223
                  </td>
224
                </tr>
225 26ef3f74 Scott Ullrich
				<tr>
226 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncell">Description</td>
227 26ef3f74 Scott Ullrich
                  <td width="78%" class="vtable"> 
228 5b237745 Scott Ullrich
                    <input name="descr" type="text" class="formfld" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
229
                    <br> <span class="vexpl">You may enter a description here
230
                    for your reference (not parsed).</span></td>
231
                </tr>
232
                <tr>
233
                  <td width="22%" valign="top">&nbsp;</td>
234 26ef3f74 Scott Ullrich
                  <td width="78%"> 
235 fc01e414 Scott Ullrich
                    <input name="Submit" type="submit" class="formbtn" value="Save"> <input class="formbtn" type="button" value="Cancel" onclick="history.back()">
236 5b237745 Scott Ullrich
                    <?php if (isset($id) && $a_proxyarp[$id]): ?>
237
                    <input name="id" type="hidden" value="<?=$id;?>">
238
                    <?php endif; ?>
239
                  </td>
240
                </tr>
241
              </table>
242
</form>
243
<script language="JavaScript">
244
<!--
245
typesel_change();
246
//-->
247
</script>
248
<?php include("fend.inc"); ?>
249
</body>
250
</html>