Project

General

Profile

Download (9.79 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
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
	if ($a_proxyarp[$id]['interface'])
46
		$pconfig['interface'] = $a_proxyarp[$id]['interface'];
47
	else
48
		$pconfig['interface'] = "wan";
49
	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
	$pconfig['interface'] = "wan";
58
	$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
	
79
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
80
	
81
	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
		
96
		if (($_POST['type'] == "range") && isset($arpent['range'])) {
97
			if (($_POST['range_from'] == $arpent['range']['from']) && 
98
				($_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
		$arpent['interface'] = $_POST['interface'];
113
		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
		
125
		touch($d_proxyarpdirty_path);
126
		
127
		write_config();
128
		
129
		header("Location: services_proxyarp.php");
130
		exit;
131
	}
132
}
133

    
134
$pgtitle = array("Services","Proxy ARP","Edit");
135
include("head.inc");
136

    
137
?>
138

    
139
<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
<?php include("fbegin.inc"); ?>
168
<?php if ($input_errors) print_input_errors($input_errors); ?>
169
            <form action="services_proxyarp_edit.php" method="post" name="iform" id="iform">
170
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
171
                <tr> 
172
                  <td width="22%" valign="top" class="vncellreq">Interface</td>
173
                  <td width="78%" class="vtable">
174
					<select name="interface" class="formselect">
175
                      <?php
176
 						if($config['interfaces']['lan'])
177
							$interfaces = array('wan' => 'WAN', 'lan' => 'LAN');
178
						else 
179
							$interfaces = array('wan' => 'WAN');
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
                  <td valign="top" class="vncellreq">Network</td>
192
                  <td class="vtable">
193
                    <table border="0" cellspacing="0" cellpadding="0">
194
                      <tr> 
195
                        <td>Type:&nbsp;&nbsp;</td>
196
                        <td><select name="type" class="formselect" onChange="typesel_change()">
197
                            <option value="single" <?php if (!$pconfig['range_from'] && $pconfig['subnet_bits'] == 32) echo "selected"; ?>> 
198
                            Single address</option>
199
                            <option value="network" <?php if (!$pconfig['range_from'] && $pconfig['subnet_bits'] != 32) echo "selected"; ?>> 
200
                            Network</option>
201
                            <option value="range" <?php if ($pconfig['range_from']) echo "selected"; ?>> 
202
                            Range</option>
203
                          </select></td>
204
                      </tr>
205
                      <tr> 
206
                        <td>Address:&nbsp;&nbsp;</td>
207
                        <td><input name="subnet" type="text" class="formfld unknown" id="subnet" size="20" value="<?=htmlspecialchars($pconfig['subnet']);?>">
208
                  / 
209
                          <select name="subnet_bits" class="formselect" id="select">
210
                            <?php for ($i = 31; $i >= 0; $i--): ?>
211
                            <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
                      <tr> 
219
                        <td>Range:&nbsp;&nbsp;</td>
220
                        <td><input name="range_from" type="text" class="formfld unknown" id="range_from" size="20" value="<?=htmlspecialchars($pconfig['range_from']);?>">
221
- 
222
                          <input name="range_to" type="text" class="formfld unknown" id="range_to" size="20" value="<?=htmlspecialchars($pconfig['range_to']);?>">                          
223
                          </td>
224
                      </tr>
225
                    </table>
226
                  </td>
227
                </tr>
228
				<tr>
229
                  <td width="22%" valign="top" class="vncell">Description</td>
230
                  <td width="78%" class="vtable"> 
231
                    <input name="descr" type="text" class="formfld unknown" 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
                  <td width="78%"> 
238
                    <input name="Submit" type="submit" class="formbtn" value="Save"> <input class="formbtn" type="button" value="Cancel" onclick="history.back()">
239
                    <?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>
(122-122/189)