Project

General

Profile

Download (9.91 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
#!/usr/local/bin/php
2 26ef3f74 Scott Ullrich
<?php 
3 b46bfcf5 Bill Marquette
/* $Id$ */
4 5b237745 Scott Ullrich
/*
5
	services_proxyarp_edit.php
6 26ef3f74 Scott Ullrich
	part of m0n0wall (http://m0n0.ch/wall)
7
	
8 5b237745 Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
9
	All rights reserved.
10 26ef3f74 Scott Ullrich
	
11 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
12
	modification, are permitted provided that the following conditions are met:
13 26ef3f74 Scott Ullrich
	
14 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
15
	   this list of conditions and the following disclaimer.
16 26ef3f74 Scott Ullrich
	
17 5b237745 Scott Ullrich
	2. Redistributions in binary form must reproduce the above copyright
18
	   notice, this list of conditions and the following disclaimer in the
19
	   documentation and/or other materials provided with the distribution.
20 26ef3f74 Scott Ullrich
	
21 5b237745 Scott Ullrich
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
22
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
23
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
25
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
	POSSIBILITY OF SUCH DAMAGE.
31
*/
32
33
require("guiconfig.inc");
34
35
if (!is_array($config['proxyarp']['proxyarpnet'])) {
36
	$config['proxyarp']['proxyarpnet'] = array();
37
}
38
proxyarp_sort();
39
$a_proxyarp = &$config['proxyarp']['proxyarpnet'];
40
41
$id = $_GET['id'];
42
if (isset($_POST['id']))
43
	$id = $_POST['id'];
44
45
if (isset($id) && $a_proxyarp[$id]) {
46 26ef3f74 Scott Ullrich
	if ($a_proxyarp[$id]['interface'])
47
		$pconfig['interface'] = $a_proxyarp[$id]['interface'];
48
	else
49
		$pconfig['interface'] = "wan";
50 5b237745 Scott Ullrich
	if (isset($a_proxyarp[$id]['network']))
51
		list($pconfig['subnet'], $pconfig['subnet_bits']) = explode("/", $a_proxyarp[$id]['network']);
52
	else if (isset($a_proxyarp[$id]['range'])) {
53
		$pconfig['range_from'] = $a_proxyarp[$id]['range']['from'];
54
		$pconfig['range_to'] = $a_proxyarp[$id]['range']['to'];
55
	}
56
	$pconfig['descr'] = $a_proxyarp[$id]['descr'];
57
} else {
58 26ef3f74 Scott Ullrich
	$pconfig['interface'] = "wan";
59 5b237745 Scott Ullrich
	$pconfig['subnet_bits'] = 32;
60
}
61
62
if ($_POST) {
63
64
	unset($input_errors);
65
	$pconfig = $_POST;
66
67
	/* input validation */
68
	if ($_POST['type'] == "single") {
69
		$reqdfields = explode(" ", "subnet");
70
		$reqdfieldsn = explode(",", "Address");
71
		$_POST['subnet_bits'] = 32;
72
	} else if ($_POST['type'] == "network") {
73
		$reqdfields = explode(" ", "subnet subnet_bits");
74
		$reqdfieldsn = explode(",", "Network,Network mask");
75
	} else if ($_POST['type'] == "range") {
76
		$reqdfields = explode(" ", "range_from range_to");
77
		$reqdfieldsn = explode(",", "Range start,Range end");
78
	}
79 26ef3f74 Scott Ullrich
	
80 5b237745 Scott Ullrich
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
81 26ef3f74 Scott Ullrich
	
82 5b237745 Scott Ullrich
	if ((($_POST['type'] != "range") && $_POST['subnet'] && !is_ipaddr($_POST['subnet']))) {
83
		$input_errors[] = "A valid address must be specified.";
84
	}
85
	if ((($_POST['type'] == "range") && $_POST['range_from'] && !is_ipaddr($_POST['range_from']))) {
86
		$input_errors[] = "A valid range start must be specified.";
87
	}
88
	if ((($_POST['type'] == "range") && $_POST['range_to'] && !is_ipaddr($_POST['range_to']))) {
89
		$input_errors[] = "A valid range end must be specified.";
90
	}
91
92
	/* check for overlaps */
93
	foreach ($a_proxyarp as $arpent) {
94
		if (isset($id) && ($a_proxyarp[$id]) && ($a_proxyarp[$id] === $arpent))
95
			continue;
96 26ef3f74 Scott Ullrich
		
97 5b237745 Scott Ullrich
		if (($_POST['type'] == "range") && isset($arpent['range'])) {
98 26ef3f74 Scott Ullrich
			if (($_POST['range_from'] == $arpent['range']['from']) && 
99 5b237745 Scott Ullrich
				($_POST['range_to'] == $arpent['range']['to'])) {
100
				$input_errors[] = "This range already exists.";
101
				break;
102
			}
103
		} else if (isset($arpent['network'])) {
104
			if (($arpent['network'] == "{$_POST['subnet']}/{$_POST['subnet_bits']}")) {
105
				$input_errors[] = "This network already exists.";
106
				break;
107
			}
108
		}
109
	}
110
111
	if (!$input_errors) {
112
		$arpent = array();
113 26ef3f74 Scott Ullrich
		$arpent['interface'] = $_POST['interface'];
114 5b237745 Scott Ullrich
		if ($_POST['type'] == "range") {
115
			$arpent['range']['from'] = $_POST['range_from'];
116
			$arpent['range']['to'] = $_POST['range_to'];
117
		} else
118
			$arpent['network'] = $_POST['subnet'] . "/" . $_POST['subnet_bits'];
119
		$arpent['descr'] = $_POST['descr'];
120
121
		if (isset($id) && $a_proxyarp[$id])
122
			$a_proxyarp[$id] = $arpent;
123
		else
124
			$a_proxyarp[] = $arpent;
125 26ef3f74 Scott Ullrich
		
126 5b237745 Scott Ullrich
		touch($d_proxyarpdirty_path);
127 26ef3f74 Scott Ullrich
		
128 5b237745 Scott Ullrich
		write_config();
129 26ef3f74 Scott Ullrich
		
130 5b237745 Scott Ullrich
		header("Location: services_proxyarp.php");
131
		exit;
132
	}
133
}
134
?>
135
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
136
<html>
137
<head>
138
<title><?=gentitle("Services: Proxy ARP: Edit");?></title>
139
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
140
<link href="gui.css" rel="stylesheet" type="text/css">
141
<script language="JavaScript">
142
<!--
143
function typesel_change() {
144
    switch (document.iform.type.selectedIndex) {
145
        case 0: // single
146
            document.iform.subnet.disabled = 0;
147
            document.iform.subnet_bits.disabled = 1;
148
            document.iform.range_from.disabled = 1;
149
            document.iform.range_to.disabled = 1;
150
            break;
151
        case 1: // network
152
            document.iform.subnet.disabled = 0;
153
            document.iform.subnet_bits.disabled = 0;
154
            document.iform.range_from.disabled = 1;
155
            document.iform.range_to.disabled = 1;
156
            break;
157
        case 2: // range
158
            document.iform.subnet.disabled = 1;
159
            document.iform.subnet_bits.disabled = 1;
160
            document.iform.range_from.disabled = 0;
161
            document.iform.range_to.disabled = 0;
162
            break;
163
    }
164
}
165
//-->
166
</script>
167
</head>
168
169
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
170
<?php include("fbegin.inc"); ?>
171
<p class="pgtitle">Services: Proxy ARP: Edit</p>
172
<?php if ($input_errors) print_input_errors($input_errors); ?>
173
            <form action="services_proxyarp_edit.php" method="post" name="iform" id="iform">
174
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
175 26ef3f74 Scott Ullrich
                <tr> 
176
                  <td width="22%" valign="top" class="vncellreq">Interface</td>
177
                  <td width="78%" class="vtable">
178
					<select name="interface" class="formfld">
179
                      <?php $interfaces = array('wan' => 'WAN', 'lan' => 'LAN');
180
					  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:&nbsp;&nbsp;</td>
196
                        <td><select name="type" class="formfld" 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:&nbsp;&nbsp;</td>
207
                        <td><input name="subnet" type="text" class="formfld" id="subnet" size="20" value="<?=htmlspecialchars($pconfig['subnet']);?>">
208 26ef3f74 Scott Ullrich
                  / 
209 5b237745 Scott Ullrich
                          <select name="subnet_bits" class="formfld" 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:&nbsp;&nbsp;</td>
220
                        <td><input name="range_from" type="text" class="formfld" id="range_from" size="20" value="<?=htmlspecialchars($pconfig['range_from']);?>">
221 26ef3f74 Scott Ullrich
- 
222
                          <input name="range_to" type="text" class="formfld" 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 5b237745 Scott Ullrich
                    <input name="descr" type="text" class="formfld" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
232
                    <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">&nbsp;</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>