Project

General

Profile

Download (9.82 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php 
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
<!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
                <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">
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>
(72-72/99)