Project

General

Profile

Download (6.85 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
$a_gres = &$config['gres']['gre'];
51

    
52
if (is_numericint($_GET['id']))
53
	$id = $_GET['id'];
54

    
55
if (isset($_POST['id']) && is_numericint($_POST['id']))
56
	$id = $_POST['id'];
57

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

    
71
if ($_POST) {
72

    
73
	unset($input_errors);
74
	$pconfig = $_POST;
75

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

    
80
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
81

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

    
87
	foreach ($a_gres as $gre) {
88
		if (isset($id) && ($a_gres[$id]) && ($a_gres[$id] === $gre))
89
			continue;
90

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

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

    
110
		$gre['greif'] = interface_gre_configure($gre);
111
		if ($gre['greif'] == "" || !stristr($gre['greif'], "gre"))
112
			$input_errors[] = gettext("Error occurred creating interface, please retry.");
113
		else {
114
			if (isset($id) && $a_gres[$id])
115
				$a_gres[$id] = $gre;
116
			else
117
				$a_gres[] = $gre;
118

    
119
			write_config();
120
			$confif = convert_real_interface_to_friendly_interface_name($gre['greif']);
121

    
122
			if ($confif != "")
123
				interface_configure($confif);
124

    
125
			header("Location: interfaces_gre.php");
126
			exit;
127
		}
128
	}
129
}
130

    
131
function build_parent_list() {
132
	$parentlist = array();
133
	$portlist = get_possible_listen_ips();
134
	foreach ($portlist as $ifn => $ifinfo)
135
		$parentlist[$ifn] = $ifinfo;
136

    
137
	return($parentlist);
138
}
139

    
140
$pgtitle = array(gettext("Interfaces"),gettext("GRE"),gettext("Edit"));
141
$shortcut_section = "interfaces";
142
include("head.inc");
143
require('classes/Form.class.php');
144

    
145
$form = new Form();
146
$form->addGlobal(new Form_Button(
147
	'cancel',
148
	'Cancel',
149
	$referer
150
));
151

    
152
$section = new Form_Section('GRE Configuration');
153

    
154
$section->addInput(new Form_Select(
155
	'if',
156
	'Parent Interface',
157
	$pconfig['if'],
158
	build_parent_list()
159
))->setHelp('This interface serves as the local address to be used for the GRE tunnel.');
160

    
161
$section->addInput(new Form_IpAddress(
162
	'remote-addr',
163
	'GRE Remote Address',
164
	$pconfig['remote-addr']
165
))->setHelp('Peer address where encapsulated GRE packets will be sent.');
166

    
167
$section->addInput(new Form_IpAddress(
168
	'tunnel-local-addr',
169
	'GRE tunnel local address',
170
	$pconfig['tunnel-local-addr']
171
))->setHelp('Local GRE tunnel endpoint.');
172

    
173
$section->addInput(new Form_IpAddress(
174
	'tunnel-remote-addr',
175
	'GRE tunnel remote address',
176
	$pconfig['tunnel-remote-addr']
177
))->setHelp('Remote GRE address endpoint.');
178

    
179
$section->addInput(new Form_Select(
180
	'tunnel-remote-net',
181
	'GRE tunnel remote subnet',
182
	$pconfig['tunnel-remote-net'],
183
	array_combine(range(128, 1, -1), range(128, 1, -1))
184
))->setHelp('The subnet is used for determining the network that is tunnelled');
185

    
186
$section->addInput(new Form_Checkbox(
187
	'link0',
188
	'Route Caching',
189
	'Specify if route caching can be enabled. (Be careful with these settings on dynamic networks.)',
190
	$pconfig['link0']
191
));
192

    
193
$section->addInput(new Form_Checkbox(
194
	'link1',
195
	'ECN friendly behavior',
196
	'ECN friendly behavior violates RFC2893. This should be used in mutual agreement with the peer. ',
197
	$pconfig['link1']
198
));
199

    
200
$section->addInput(new Form_Checkbox(
201
	'link2',
202
	'WCCP Version',
203
	'Check this box for WCCP encapsulation version 2, or leave unchecked for version 1.',
204
	$pconfig['link2']
205
));
206

    
207
$section->addInput(new Form_Input(
208
	'descr',
209
	'Description',
210
	'text',
211
	$pconfig['descr']
212
))->setHelp('You may enter a description here for your reference (not parsed).');
213

    
214
$section->addInput(new Form_Input(
215
	'greif',
216
	null,
217
	'hidden',
218
	$pconfig['greif']
219
));
220

    
221
if (isset($id) && $a_gres[$id]) {
222
	$section->addInput(new Form_Input(
223
		'id',
224
		null,
225
		'hidden',
226
		$id
227
	));
228
}
229

    
230
$form->add($section);
231
print($form);
232

    
233
include("foot.inc");
(89-89/241)