Project

General

Profile

Download (9.66 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	interfaces_gre_edit.php
5

    
6
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
7
	Copyright (C) 2008 Ermal Luçi
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
	pfSense_MODULE:	interfaces
33
*/
34

    
35
##|+PRIV
36
##|*IDENT=page-interfaces-gre-edit
37
##|*NAME=Interfaces: GRE: Edit page
38
##|*DESCR=Allow access to the 'Interfaces: GRE: Edit' page.
39
##|*MATCH=interfaces_gre_edit.php*
40
##|-PRIV
41

    
42
require("guiconfig.inc");
43
require_once("functions.inc");
44

    
45
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/interfaces_gre.php');
46

    
47
if (!is_array($config['gres']['gre'])) {
48
	$config['gres']['gre'] = array();
49
}
50

    
51
$a_gres = &$config['gres']['gre'];
52

    
53
if (is_numericint($_GET['id'])) {
54
	$id = $_GET['id'];
55
}
56
if (isset($_POST['id']) && is_numericint($_POST['id'])) {
57
	$id = $_POST['id'];
58
}
59

    
60
if (isset($id) && $a_gres[$id]) {
61
	$pconfig['if'] = $a_gres[$id]['if'];
62
	$pconfig['greif'] = $a_gres[$id]['greif'];
63
	$pconfig['remote-addr'] = $a_gres[$id]['remote-addr'];
64
	$pconfig['tunnel-remote-net'] = $a_gres[$id]['tunnel-remote-net'];
65
	$pconfig['tunnel-local-addr'] = $a_gres[$id]['tunnel-local-addr'];
66
	$pconfig['tunnel-remote-addr'] = $a_gres[$id]['tunnel-remote-addr'];
67
	$pconfig['link1'] = isset($a_gres[$id]['link1']);
68
	$pconfig['link2'] = isset($a_gres[$id]['link2']);
69
	$pconfig['link0'] = isset($a_gres[$id]['link0']);
70
	$pconfig['descr'] = $a_gres[$id]['descr'];
71
}
72

    
73
if ($_POST) {
74

    
75
	unset($input_errors);
76
	$pconfig = $_POST;
77

    
78
	/* input validation */
79
	$reqdfields = explode(" ", "if tunnel-remote-addr tunnel-remote-net tunnel-local-addr");
80
	$reqdfieldsn = array(gettext("Parent interface"),gettext("Local address"),gettext("Remote tunnel address"),gettext("Remote tunnel network"), gettext("Local tunnel address"));
81

    
82
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
83

    
84
	if ((!is_ipaddr($_POST['tunnel-local-addr'])) ||
85
	    (!is_ipaddr($_POST['tunnel-remote-addr'])) ||
86
	    (!is_ipaddr($_POST['remote-addr']))) {
87
		$input_errors[] = gettext("The tunnel local and tunnel remote fields must have valid IP addresses.");
88
	}
89

    
90
	foreach ($a_gres as $gre) {
91
		if (isset($id) && ($a_gres[$id]) && ($a_gres[$id] === $gre)) {
92
			continue;
93
		}
94

    
95
		if (($gre['if'] == $_POST['if']) && ($gre['tunnel-remote-addr'] == $_POST['tunnel-remote-addr'])) {
96
			$input_errors[] = sprintf(gettext("A GRE tunnel with the network %s is already defined."),$gre['remote-network']);
97
			break;
98
		}
99
	}
100

    
101
	if (!$input_errors) {
102
		$gre = array();
103
		$gre['if'] = $_POST['if'];
104
		$gre['tunnel-local-addr'] = $_POST['tunnel-local-addr'];
105
		$gre['tunnel-remote-addr'] = $_POST['tunnel-remote-addr'];
106
		$gre['tunnel-remote-net'] = $_POST['tunnel-remote-net'];
107
		$gre['remote-addr'] = $_POST['remote-addr'];
108
		$gre['descr'] = $_POST['descr'];
109
		$gre['link1'] = isset($_POST['link1']);
110
		$gre['link2'] = isset($_POST['link2']);
111
		$gre['link0'] = isset($_POST['link0']);
112
		$gre['greif'] = $_POST['greif'];
113

    
114
		$gre['greif'] = interface_gre_configure($gre);
115
		if ($gre['greif'] == "" || !stristr($gre['greif'], "gre")) {
116
			$input_errors[] = gettext("Error occurred creating interface, please retry.");
117
		} else {
118
			if (isset($id) && $a_gres[$id]) {
119
				$a_gres[$id] = $gre;
120
			} else {
121
				$a_gres[] = $gre;
122
			}
123

    
124
			write_config();
125

    
126
			$confif = convert_real_interface_to_friendly_interface_name($gre['greif']);
127
			if ($confif <> "") {
128
				interface_configure($confif);
129
			}
130

    
131
			header("Location: interfaces_gre.php");
132
			exit;
133
		}
134
	}
135
}
136

    
137
$pgtitle = array(gettext("Interfaces"),gettext("GRE"),gettext("Edit"));
138
$shortcut_section = "interfaces";
139
include("head.inc");
140

    
141
?>
142

    
143
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
144
<script type="text/javascript" src="/javascript/jquery.ipv4v6ify.js"></script>
145
<?php include("fbegin.inc"); ?>
146
<?php if ($input_errors) print_input_errors($input_errors); ?>
147
<form action="interfaces_gre_edit.php" method="post" name="iform" id="iform">
148
	<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="interfaces gre edit">
149
		<tr>
150
			<td colspan="2" valign="top" class="listtopic"><?=gettext("GRE configuration");?></td>
151
		</tr>
152
		<tr>
153
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Parent interface");?></td>
154
			<td width="78%" class="vtable">
155
				<select name="if" class="formselect">
156
				<?php
157
					$portlist = get_possible_listen_ips();
158
					foreach ($portlist as $ifn => $ifinfo) {
159
						echo "<option value=\"{$ifn}\"";
160
						if ($ifn == $pconfig['if']) {
161
							echo " selected=\"selected\"";
162
						}
163
						echo ">" . htmlspecialchars($ifinfo) . "</option>\n";
164
					}
165
				?>
166
				</select>
167
				<br />
168
				<span class="vexpl"><?=gettext("The interface here serves as the local address to be used for the GRE tunnel.");?></span>
169
			</td>
170
		</tr>
171
		<tr>
172
			<td valign="top" class="vncellreq"><?=gettext("Remote tunnel endpoint IP address");?></td>
173
			<td class="vtable">
174
				<input name="remote-addr" type="text" class="formfld unknown" id="remote-addr" size="16" value="<?=htmlspecialchars($pconfig['remote-addr']);?>" />
175
				<br />
176
				<span class="vexpl"><?=gettext("Peer address where encapsulated GRE packets will be sent ");?></span>
177
			</td>
178
		</tr>
179
		<tr>
180
			<td valign="top" class="vncellreq"><?=gettext("Local tunnel IP address ");?></td>
181
			<td class="vtable">
182
				<input name="tunnel-local-addr" type="text" class="formfld unknown" id="tunnel-local-addr" size="16" value="<?=htmlspecialchars($pconfig['tunnel-local-addr']);?>" />
183
				<br />
184
				<span class="vexpl"><?=gettext("Local IP address assigned inside this tunnel");?></span>
185
			</td>
186
		</tr>
187
		<tr>
188
			<td valign="top" class="vncellreq"><?=gettext("Remote tunnel IP address ");?></td>
189
			<td class="vtable">
190
				<input name="tunnel-remote-addr" type="text" class="formfld unknown ipv4v6" id="tunnel-remote-addr" size="16" value="<?=htmlspecialchars($pconfig['tunnel-remote-addr']);?>" />
191
				<select name="tunnel-remote-net" class="formselect ipv4v6" id="tunnel-remote-net">
192
				<?php
193
					for ($i = 128; $i > 0; $i--) {
194
						echo "<option value=\"{$i}\"";
195
						if ($i == $pconfig['tunnel-remote-net']) {
196
							echo " selected=\"selected\"";
197
						}
198
						echo ">" . $i . "</option>";
199
					}
200
				?>
201
				</select>
202
				<br />
203
				<span class="vexpl"><?=gettext("IP address inside this tunnel on the remote end. The subnet part is used for the determining the network that is tunneled.");?></span>
204
			</td>
205
		</tr>
206
		<tr>
207
			<td valign="top" class="vncell"><?=gettext("Mobile encapsulation");?></td>
208
			<td class="vtable">
209
				<input name="link0" type="checkbox" id="link0" <?if ($pconfig['link0']) echo "checked=\"checked\"";?> />
210
				<br />
211
				<span class="vexpl"><?=gettext("Check this box to use mobile encapsulation (IP protocol 55, RFC 2004). When unchecked, uses GRE encapsulation (IP protocol 47, RFCs 1701, 1702).");?></span>
212
			</td>
213
		</tr>
214
		<tr>
215
			<td valign="top" class="vncell"><?=gettext("Route search type");?></td>
216
			<td class="vtable">
217
				<input name="link1" type="checkbox" id="link1" <?if ($pconfig['link1']) echo "checked=\"checked\"";?> />
218
				<br />
219
				<span class="vexpl">
220
					<?=gettext("For correct operation, the GRE device needs a route to the destination".
221
					" that is less specific than the one over the tunnel.  (Basically, there".
222
					" needs to be a route to the decapsulating host that does not run over the".
223
					" tunnel, as this would be a loop.");?>
224
				</span>
225
			</td>
226
		</tr>
227
		<tr>
228
			<td valign="top" class="vncell"><?=gettext("WCCP version");?></td>
229
			<td class="vtable">
230
				<input name="link2" type="checkbox" id="link2" <?if ($pconfig['link2']) echo "checked=\"checked\"";?> />
231
				<br />
232
				<span class="vexpl"><?=gettext("Check this box for WCCP encapsulation version 2, or leave unchecked for version 1.");?></span>
233
			</td>
234
		</tr>
235
		<tr>
236
			<td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
237
			<td width="78%" class="vtable">
238
				<input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
239
				<br /> <span class="vexpl"><?=gettext("You may enter a description here for your reference (not parsed).");?></span>
240
			</td>
241
		</tr>
242
		<tr>
243
			<td width="22%" valign="top">&nbsp;</td>
244
			<td width="78%">
245
				<input type="hidden" name="greif" value="<?=htmlspecialchars($pconfig['greif']); ?>" />
246
				<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
247
				<input type="button" class="formbtn" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=$referer;?>'" />
248
			<?php if (isset($id) && $a_gres[$id]): ?>
249
				<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
250
			<?php endif; ?>
251
			</td>
252
		</tr>
253
	</table>
254
</form>
255
<?php include("fend.inc"); ?>
256
</body>
257
</html>
(102-102/252)