Project

General

Profile

Download (9.91 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
<!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
                <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
                  <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="formfld" 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" id="subnet" size="20" value="<?=htmlspecialchars($pconfig['subnet']);?>">
208
                  / 
209
                          <select name="subnet_bits" class="formfld" 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" id="range_from" size="20" value="<?=htmlspecialchars($pconfig['range_from']);?>">
221
- 
222
                          <input name="range_to" type="text" class="formfld" 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" 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>
(83-83/117)