Project

General

Profile

Download (9.63 KB) Statistics
| Branch: | Tag: | Revision:
1 ead45104 Ermal Luçi
<?php
2
/* $Id$ */
3
/*
4
	interfaces_gre_edit.php
5
6
	Copyright (C) 2008 Ermal Lu?i
7
	All rights reserved.
8
9
	Redistribution and use in source and binary forms, with or without
10
	modification, are permitted provided that the following conditions are met:
11
12
	1. Redistributions of source code must retain the above copyright notice,
13
	   this list of conditions and the following disclaimer.
14
15
	2. Redistributions in binary form must reproduce the above copyright
16
	   notice, this list of conditions and the following disclaimer in the
17
	   documentation and/or other materials provided with the distribution.
18
19
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
20
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
23
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
	POSSIBILITY OF SUCH DAMAGE.
29
*/
30
31 6b07c15a Matthew Grooms
##|+PRIV
32
##|*IDENT=page-interfaces-gre-edit
33
##|*NAME=Interfaces: GRE: Edit page
34
##|*DESCR=Allow access to the 'Interfaces: GRE: Edit' page.
35
##|*MATCH=interfaces_gre_edit.php*
36
##|-PRIV
37
38
39 ead45104 Ermal Luçi
require("guiconfig.inc");
40
41
if (!is_array($config['gres']['gre']))
42
	$config['gres']['gre'] = array();
43
44
$a_gres = &$config['gres']['gre'];
45
46
47
$id = $_GET['id'];
48
if (isset($_POST['id']))
49
	$id = $_POST['id'];
50
51
if (isset($id) && $a_gres[$id]) {
52
	$pconfig['if'] = $a_gres[$id]['if'];
53
	$pconfig['greif'] = $a_gres[$id]['greif'];
54
	$pconfig['remote-addr'] = $a_gres[$id]['remote-addr'];
55
	$pconfig['tunnel-remote-net'] = $a_gres[$id]['tunnel-remote-net'];
56
	$pconfig['tunnel-local-addr'] = $a_gres[$id]['tunnel-local-addr'];
57
	$pconfig['tunnel-remote-addr'] = $a_gres[$id]['tunnel-remote-addr'];
58
	$pconfig['link1'] = isset($a_gres[$id]['link1']);
59
	$pconfig['link2'] = isset($a_gres[$id]['link2']);
60
	$pconfig['link0'] = isset($a_gres[$id]['link0']);
61
	$pconfig['descr'] = $a_gres[$id]['descr'];
62
}
63
64
if ($_POST) {
65
66
	unset($input_errors);
67
	$pconfig = $_POST;
68
69
	/* input validation */
70
	$reqdfields = explode(" ", "if tunnel-remote-addr tunnel-remote-net tunnel-local-addr");
71
	$reqdfieldsn = explode(",", "Parent interface,Local address, Remote tunnel address, Remote tunnel network, Local tunnel address");
72
73
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
74
75
	if ((!is_ipaddr($_POST['tunnel-local-addr'])) || (!is_ipaddr($_POST['tunnel-remote-addr'])) ||
76
			(!is_ipaddr($_POST['remote-addr']))) {
77
		$input_errors[] = "All fildes must have valid ip addresses.";
78
	}
79
80
	foreach ($a_gres as $gre) {
81
		if (isset($id) && ($a_gres[$id]) && ($a_gres[$id] === $gre))
82
			continue;
83
84
		if (($gre['if'] == $_POST['if']) && ($gre['tunnel-remote-net'] == $_POST['tunnel-remote-net'])) {
85
			$input_errors[] = "A gre with the network {$gre['remote-network']} is already defined.";
86
			break;
87
		}
88
	}
89
90
	if (!$input_errors) {
91
		$gre = array();
92
		$gre['if'] = $_POST['if'];
93
		$gre['tunnel-local-addr'] = $_POST['tunnel-local-addr'];
94
		$gre['tunnel-remote-addr'] = $_POST['tunnel-remote-addr'];
95
		$gre['tunnel-remote-net'] = $_POST['tunnel-remote-net'];
96
		$gre['remote-addr'] = $_POST['remote-addr'];
97
		$gre['descr'] = $_POST['descr'];
98
		$gre['link1'] = isset($_POST['link1']);
99
		$gre['link2'] = isset($_POST['link2']);
100
		$gre['link0'] = isset($_POST['link0']);
101
		$gre['greif'] = $_POST['greif'];
102
103
                $gre['greif'] = interface_gre_configure($gre);
104
                if ($gre['greif'] == "" || !stristr($gre['greif'], "gre"))
105
                        $input_errors[] = "Error occured creating interface, please retry.";
106
                else {
107
                        if (isset($id) && $a_gres[$id])
108
                                $a_gres[$id] = $gre;
109
                        else
110
                                $a_gres[] = $gre;
111
112
                        write_config();
113
114
			header("Location: interfaces_gre.php");
115
			exit;
116
		}
117
	}
118
}
119
120
$pgtitle = array("Firewall","GRE","Edit");
121
include("head.inc");
122
123
?>
124
125
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
126
<?php include("fbegin.inc"); ?>
127
<?php if ($input_errors) print_input_errors($input_errors); ?>
128
            <form action="interfaces_gre_edit.php" method="post" name="iform" id="iform">
129
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
130
				<tr>
131 16dcce2a Scott Ullrich
					<td colspan="2" valign="top" class="listtopic">GRE configuration</td>
132
				</tr>
133
				<tr>
134 ead45104 Ermal Luçi
                  <td width="22%" valign="top" class="vncellreq">Parent interface</td>
135
                  <td width="78%" class="vtable">
136
                    <select name="if" class="formselect">
137
                      <?php
138
						$portlist = get_configured_interface_with_descr();
139
					  	foreach ($portlist as $ifn => $ifinfo) {
140
							echo "<option value=\"{$ifn}\"";
141
							if ($ifn == $pconfig['if'])
142
								echo "selected";
143
							echo ">{$ifinfo}</option>";
144
						}
145
		      		?>
146
                    </select>
147
			<br/>
148 b040124a Chris Buechler
			<span class="vexpl">The interface here serves as the local address to be used for the GRE tunnel.</span></td>
149 ead45104 Ermal Luçi
                </tr>
150
				<tr>
151 b040124a Chris Buechler
                  <td valign="top" class="vncellreq">GRE remote address</td>
152 ead45104 Ermal Luçi
                  <td class="vtable">
153
                    <input name="remote-addr" type="text" class="formfld unknown" id="remote-addr" size="16" value="<?=$pconfig['remote-addr'];?>">
154
                    <br>
155 b040124a Chris Buechler
                    <span class="vexpl">Peer address where encapsulated GRE packets will be sent </span></td>
156 ead45104 Ermal Luçi
			    </tr>
157
				<tr>
158 b040124a Chris Buechler
                  <td valign="top" class="vncellreq">GRE tunnel local address </td>
159 ead45104 Ermal Luçi
                  <td class="vtable">
160
                    <input name="tunnel-local-addr" type="text" class="formfld unknown" id="tunnel-local-addr" size="16" value="<?=$pconfig['tunnel-local-addr'];?>">
161
                    <br>
162 b040124a Chris Buechler
                    <span class="vexpl">Local GRE tunnel endpoint</span></td>
163 ead45104 Ermal Luçi
			    </tr>
164
				<tr>
165 b040124a Chris Buechler
                  <td valign="top" class="vncellreq">GRE tunnel remote address </td>
166 ead45104 Ermal Luçi
                  <td class="vtable">
167
                    <input name="tunnel-remote-addr" type="text" class="formfld unknown" id="tunnel-remote-addr" size="16" value="<?=$pconfig['tunnel-remote-addr'];?>">
168
                    <select name="tunnel-remote-net" class="formselect" id="tunnel-remote-net">
169
                                        <?php
170
                                        for ($i = 32; $i > 0; $i--) {
171
                                                if($i <> 31) {
172
                                                        echo "<option value=\"{$i}\" ";
173
                                                        if ($i == $pconfig['tunnel-remote-net']) echo "selected";
174
                                                        echo ">" . $i . "</option>";
175
                                                }
176
                                        }
177
                                        ?>
178
                    </select>					
179
                    <br/>
180 b040124a Chris Buechler
                    <span class="vexpl">Remote GRE address endpoint. The subnet part is used for the determining the network that is tunneled.</span></td>
181 ead45104 Ermal Luçi
			    </tr>
182
				<tr>
183 b040124a Chris Buechler
                  <td valign="top" class="vncell">Mobile tunnel</td>
184 ead45104 Ermal Luçi
                  <td class="vtable">
185
                    <input name="link0" type="checkbox" id="link0" <?if ($pconfig['link0']) echo "checked";?>>
186
                    <br>
187 b040124a Chris Buechler
                    <span class="vexpl">Specify which encapsulation method the tunnel should use. </span></td>
188 ead45104 Ermal Luçi
			    </tr>
189
				<tr>
190 b040124a Chris Buechler
                  <td valign="top" class="vncell">Route search type</td>
191 ead45104 Ermal Luçi
                  <td class="vtable">
192
                    <input name="link1" type="checkbox" id="link1" <?if ($pconfig['link1']) echo "checked";?>>
193
                    <br>
194
                    <span class="vexpl">
195 b040124a Chris Buechler
     For correct operation, the GRE device needs a route to the destination
196 ead45104 Ermal Luçi
     that is less specific than the one over the tunnel.  (Basically, there
197
     needs to be a route to the decapsulating host that does not run over the
198 b040124a Chris Buechler
     tunnel, as this would be a loop.)
199 ead45104 Ermal Luçi
					 </span></td>
200
			    </tr>
201
				<tr>
202 b040124a Chris Buechler
                  <td valign="top" class="vncell">WCCP version</td>
203 ead45104 Ermal Luçi
                  <td class="vtable">
204
                    <input name="link2" type="checkbox" id="link2" <?if ($pconfig['link2']) echo "checked";?>>
205
                    <br>
206 b040124a Chris Buechler
                    <span class="vexpl">Specify which WCCP encapsulation(version 1 or 2) method the tunnel should use</span></td>
207 ead45104 Ermal Luçi
			    </tr>
208
				<tr>
209
                  <td width="22%" valign="top" class="vncell">Description</td>
210
                  <td width="78%" class="vtable">
211
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
212
                    <br> <span class="vexpl">You may enter a description here
213
                    for your reference (not parsed).</span></td>
214
                </tr>
215
                <tr>
216
                  <td width="22%" valign="top">&nbsp;</td>
217
                  <td width="78%">
218
		    <input type="hidden" name="greif" value="<?=$pconfig['greif']; ?>">
219
                    <input name="Submit" type="submit" class="formbtn" value="Save"> <input type="button" value="Cancel" onclick="history.back()">
220
                    <?php if (isset($id) && $a_gres[$id]): ?>
221
                    <input name="id" type="hidden" value="<?=$id;?>">
222
                    <?php endif; ?>
223
                  </td>
224
                </tr>
225
              </table>
226
</form>
227
<?php include("fend.inc"); ?>
228
</body>
229
</html>