Project

General

Profile

Download (9.73 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php 
3
/* $Id$ */
4
/*
5
	services_proxyarp_edit.php
6
	part of m0n0wall (http://m0n0.ch/wall)
7
	
8
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
9
	All rights reserved.
10
	
11
	Redistribution and use in source and binary forms, with or without
12
	modification, are permitted provided that the following conditions are met:
13
	
14
	1. Redistributions of source code must retain the above copyright notice,
15
	   this list of conditions and the following disclaimer.
16
	
17
	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
	
21
	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
	if ($a_proxyarp[$id]['interface'])
47
		$pconfig['interface'] = $a_proxyarp[$id]['interface'];
48
	else
49
		$pconfig['interface'] = "wan";
50
	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
	$pconfig['interface'] = "wan";
59
	$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
	
80
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
81
	
82
	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
		
97
		if (($_POST['type'] == "range") && isset($arpent['range'])) {
98
			if (($_POST['range_from'] == $arpent['range']['from']) && 
99
				($_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
		$arpent['interface'] = $_POST['interface'];
114
		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
		
126
		touch($d_proxyarpdirty_path);
127
		
128
		write_config();
129
		
130
		header("Location: services_proxyarp.php");
131
		exit;
132
	}
133
}
134

    
135
$pgtitle = "Services: Proxy ARP: Edit";
136
include("head.inc");
137

    
138
?>
139

    
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

    
167
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
168
<?php include("fbegin.inc"); ?>
169
<p class="pgtitle"><?=$pgtitle?></p>
170
<?php if ($input_errors) print_input_errors($input_errors); ?>
171
            <form action="services_proxyarp_edit.php" method="post" name="iform" id="iform">
172
              <?display_topbar()?>
173
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
174
                <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
                  <td valign="top" class="vncellreq">Network</td>
191
                  <td class="vtable">
192
                    <table border="0" cellspacing="0" cellpadding="0">
193
                      <tr> 
194
                        <td>Type:&nbsp;&nbsp;</td>
195
                        <td><select name="type" class="formfld" onChange="typesel_change()">
196
                            <option value="single" <?php if (!$pconfig['range_from'] && $pconfig['subnet_bits'] == 32) echo "selected"; ?>> 
197
                            Single address</option>
198
                            <option value="network" <?php if (!$pconfig['range_from'] && $pconfig['subnet_bits'] != 32) echo "selected"; ?>> 
199
                            Network</option>
200
                            <option value="range" <?php if ($pconfig['range_from']) echo "selected"; ?>> 
201
                            Range</option>
202
                          </select></td>
203
                      </tr>
204
                      <tr> 
205
                        <td>Address:&nbsp;&nbsp;</td>
206
                        <td><input name="subnet" type="text" class="formfld" id="subnet" size="20" value="<?=htmlspecialchars($pconfig['subnet']);?>">
207
                  / 
208
                          <select name="subnet_bits" class="formfld" id="select">
209
                            <?php for ($i = 31; $i >= 0; $i--): ?>
210
                            <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
                      <tr> 
218
                        <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
- 
221
                          <input name="range_to" type="text" class="formfld" id="range_to" size="20" value="<?=htmlspecialchars($pconfig['range_to']);?>">                          
222
                          </td>
223
                      </tr>
224
                    </table>
225
                  </td>
226
                </tr>
227
				<tr>
228
                  <td width="22%" valign="top" class="vncell">Description</td>
229
                  <td width="78%" class="vtable"> 
230
                    <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
                  <td width="78%"> 
237
                    <input name="Submit" type="submit" class="formbtn" value="Save"> <input class="formbtn" type="button" value="Cancel" onclick="history.back()">
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>
(105-105/147)