Project

General

Profile

Download (9.82 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
#!/usr/local/bin/php
2 26ef3f74 Scott Ullrich
<?php 
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
?>
134
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
135
<html>
136
<head>
137
<title><?=gentitle("Services: Proxy ARP: Edit");?></title>
138
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
139
<link href="gui.css" rel="stylesheet" type="text/css">
140
<script language="JavaScript">
141
<!--
142
function typesel_change() {
143
    switch (document.iform.type.selectedIndex) {
144
        case 0: // single
145
            document.iform.subnet.disabled = 0;
146
            document.iform.subnet_bits.disabled = 1;
147
            document.iform.range_from.disabled = 1;
148
            document.iform.range_to.disabled = 1;
149
            break;
150
        case 1: // network
151
            document.iform.subnet.disabled = 0;
152
            document.iform.subnet_bits.disabled = 0;
153
            document.iform.range_from.disabled = 1;
154
            document.iform.range_to.disabled = 1;
155
            break;
156
        case 2: // range
157
            document.iform.subnet.disabled = 1;
158
            document.iform.subnet_bits.disabled = 1;
159
            document.iform.range_from.disabled = 0;
160
            document.iform.range_to.disabled = 0;
161
            break;
162
    }
163
}
164
//-->
165
</script>
166
</head>
167
168
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
169
<?php include("fbegin.inc"); ?>
170
<p class="pgtitle">Services: Proxy ARP: Edit</p>
171
<?php if ($input_errors) print_input_errors($input_errors); ?>
172
            <form action="services_proxyarp_edit.php" method="post" name="iform" id="iform">
173
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
174 26ef3f74 Scott Ullrich
                <tr> 
175
                  <td width="22%" valign="top" class="vncellreq">Interface</td>
176
                  <td width="78%" class="vtable">
177
					<select name="interface" class="formfld">
178
                      <?php $interfaces = array('wan' => 'WAN', 'lan' => 'LAN');
179
					  for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
180
					  	$interfaces['opt' . $i] = $config['interfaces']['opt' . $i]['descr'];
181
					  }
182
					  foreach ($interfaces as $iface => $ifacename): ?>
183
                      <option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected"; ?>> 
184
                      <?=htmlspecialchars($ifacename);?>
185
                      </option>
186
                      <?php endforeach; ?>
187
                    </select> </td>
188
                </tr>
189
                <tr> 
190 5b237745 Scott Ullrich
                  <td valign="top" class="vncellreq">Network</td>
191
                  <td class="vtable">
192
                    <table border="0" cellspacing="0" cellpadding="0">
193 26ef3f74 Scott Ullrich
                      <tr> 
194 5b237745 Scott Ullrich
                        <td>Type:&nbsp;&nbsp;</td>
195
                        <td><select name="type" class="formfld" onChange="typesel_change()">
196 26ef3f74 Scott Ullrich
                            <option value="single" <?php if (!$pconfig['range_from'] && $pconfig['subnet_bits'] == 32) echo "selected"; ?>> 
197 5b237745 Scott Ullrich
                            Single address</option>
198 26ef3f74 Scott Ullrich
                            <option value="network" <?php if (!$pconfig['range_from'] && $pconfig['subnet_bits'] != 32) echo "selected"; ?>> 
199 5b237745 Scott Ullrich
                            Network</option>
200 26ef3f74 Scott Ullrich
                            <option value="range" <?php if ($pconfig['range_from']) echo "selected"; ?>> 
201 5b237745 Scott Ullrich
                            Range</option>
202
                          </select></td>
203
                      </tr>
204 26ef3f74 Scott Ullrich
                      <tr> 
205 5b237745 Scott Ullrich
                        <td>Address:&nbsp;&nbsp;</td>
206
                        <td><input name="subnet" type="text" class="formfld" id="subnet" size="20" value="<?=htmlspecialchars($pconfig['subnet']);?>">
207 26ef3f74 Scott Ullrich
                  / 
208 5b237745 Scott Ullrich
                          <select name="subnet_bits" class="formfld" id="select">
209 26ef3f74 Scott Ullrich
                            <?php for ($i = 31; $i >= 0; $i--): ?>
210 5b237745 Scott Ullrich
                            <option value="<?=$i;?>" <?php if ($i == $pconfig['subnet_bits']) echo "selected"; ?>>
211
                            <?=$i;?>
212
                      </option>
213
                            <?php endfor; ?>
214
                      </select>
215
 </td>
216
                      </tr>
217 26ef3f74 Scott Ullrich
                      <tr> 
218 5b237745 Scott Ullrich
                        <td>Range:&nbsp;&nbsp;</td>
219
                        <td><input name="range_from" type="text" class="formfld" id="range_from" size="20" value="<?=htmlspecialchars($pconfig['range_from']);?>">
220 26ef3f74 Scott Ullrich
- 
221
                          <input name="range_to" type="text" class="formfld" id="range_to" size="20" value="<?=htmlspecialchars($pconfig['range_to']);?>">                          
222 5b237745 Scott Ullrich
                          </td>
223
                      </tr>
224
                    </table>
225
                  </td>
226
                </tr>
227 26ef3f74 Scott Ullrich
				<tr>
228 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncell">Description</td>
229 26ef3f74 Scott Ullrich
                  <td width="78%" class="vtable"> 
230 5b237745 Scott Ullrich
                    <input name="descr" type="text" class="formfld" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
231
                    <br> <span class="vexpl">You may enter a description here
232
                    for your reference (not parsed).</span></td>
233
                </tr>
234
                <tr>
235
                  <td width="22%" valign="top">&nbsp;</td>
236 26ef3f74 Scott Ullrich
                  <td width="78%"> 
237 5b237745 Scott Ullrich
                    <input name="Submit" type="submit" class="formbtn" value="Save">
238
                    <?php if (isset($id) && $a_proxyarp[$id]): ?>
239
                    <input name="id" type="hidden" value="<?=$id;?>">
240
                    <?php endif; ?>
241
                  </td>
242
                </tr>
243
              </table>
244
</form>
245
<script language="JavaScript">
246
<!--
247
typesel_change();
248
//-->
249
</script>
250
<?php include("fend.inc"); ?>
251
</body>
252
</html>