Project

General

Profile

Download (6.93 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	interfaces_gif_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-gif-edit
37
##|*NAME=Interfaces: GIF: Edit page
38
##|*DESCR=Allow access to the 'Interfaces: GIF: Edit' page.
39
##|*MATCH=interfaces_gif_edit.php*
40
##|-PRIV
41

    
42
require("guiconfig.inc");
43

    
44
if (!is_array($config['gifs']['gif']))
45
	$config['gifs']['gif'] = array();
46

    
47
$a_gifs = &$config['gifs']['gif'];
48

    
49
if (is_numericint($_GET['id'])) {
50
	$id = $_GET['id'];
51
}
52
if (isset($_POST['id']) && is_numericint($_POST['id'])) {
53
	$id = $_POST['id'];
54
}
55

    
56
if (isset($id) && $a_gifs[$id]) {
57
	$pconfig['if'] = $a_gifs[$id]['if'];
58
	if (!empty($a_gifs[$id]['ipaddr'])) {
59
		$pconfig['if'] = $pconfig['if'] . '|' . $a_gifs[$id]['ipaddr'];
60
	}
61
	$pconfig['gifif'] = $a_gifs[$id]['gifif'];
62
	$pconfig['remote-addr'] = $a_gifs[$id]['remote-addr'];
63
	$pconfig['tunnel-remote-net'] = $a_gifs[$id]['tunnel-remote-net'];
64
	$pconfig['tunnel-local-addr'] = $a_gifs[$id]['tunnel-local-addr'];
65
	$pconfig['tunnel-remote-addr'] = $a_gifs[$id]['tunnel-remote-addr'];
66
	$pconfig['link1'] = isset($a_gifs[$id]['link1']);
67
	$pconfig['link0'] = isset($a_gifs[$id]['link0']);
68
	$pconfig['descr'] = $a_gifs[$id]['descr'];
69
}
70

    
71
if ($_POST) {
72
	unset($input_errors);
73
	$pconfig = $_POST;
74

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

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

    
81
	if ((!is_ipaddr($_POST['tunnel-local-addr'])) ||
82
	    (!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
	$alias = strstr($_POST['if'], '|');
88
	if ((is_ipaddrv4($alias) && !is_ipaddrv4($_POST['remote-addr'])) ||
89
	    (is_ipaddrv6($alias) && !is_ipaddrv6($_POST['remote-addr']))) {
90
		$input_errors[] = gettext("The alias IP address family has to match the family of the remote peer address.");
91
	}
92

    
93
	foreach ($a_gifs as $gif) {
94
		if (isset($id) && ($a_gifs[$id]) && ($a_gifs[$id] === $gif)) {
95
			continue;
96
		}
97

    
98
		/* FIXME: needs to perform proper subnet checks in the future */
99
		if (($gif['if'] == $interface) && ($gif['tunnel-remote-addr'] == $_POST['tunnel-remote-addr'])) {
100
			$input_errors[] = sprintf(gettext("A gif with the network %s is already defined."), $gif['tunnel-remote-addr']);
101
			break;
102
		}
103
	}
104

    
105
	if (!$input_errors) {
106
		$gif = array();
107
		list($gif['if'], $gif['ipaddr']) = explode("|", $_POST['if']);
108
		$gif['tunnel-local-addr'] = $_POST['tunnel-local-addr'];
109
		$gif['tunnel-remote-addr'] = $_POST['tunnel-remote-addr'];
110
		$gif['tunnel-remote-net'] = $_POST['tunnel-remote-net'];
111
		$gif['remote-addr'] = $_POST['remote-addr'];
112
		$gif['descr'] = $_POST['descr'];
113
		$gif['link1'] = isset($_POST['link1']);
114
		$gif['link0'] = isset($_POST['link0']);
115
		$gif['gifif'] = $_POST['gifif'];
116
		$gif['gifif'] = interface_gif_configure($gif);
117

    
118
		if ($gif['gifif'] == "" || !stristr($gif['gifif'], "gif"))
119
			$input_errors[] = gettext("Error occurred creating interface, please retry.");
120
		else {
121
			if (isset($id) && $a_gifs[$id])
122
				$a_gifs[$id] = $gif;
123
			else
124
				$a_gifs[] = $gif;
125

    
126
			write_config();
127

    
128
			$confif = convert_real_interface_to_friendly_interface_name($gif['gifif']);
129

    
130
			if ($confif != "")
131
				interface_configure($confif);
132

    
133
			header("Location: interfaces_gif.php");
134
			exit;
135
		}
136
	}
137
}
138

    
139
function build_parent_list() {
140
	$parentlist = array();
141
	$portlist = get_possible_listen_ips();
142
	foreach ($portlist as $ifn => $ifinfo)
143
		$parentlist[$ifn] = $ifinfo;
144

    
145
	return($parentlist);
146
}
147

    
148
$pgtitle = array(gettext("Interfaces"),gettext("GIF"),gettext("Edit"));
149
$shortcut_section = "interfaces";
150
include("head.inc");
151
require('classes/Form.class.php');
152

    
153
$form = new Form();
154

    
155
$section = new Form_Section('GIF Configuration');
156

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

    
164
$section->addInput(new Form_IpAddress(
165
	'remote-addr',
166
	'GIF Remote Address',
167
	$pconfig['remote-addr']
168
))->setHelp('Peer address where encapsulated gif packets will be sent.');
169

    
170
$section->addInput(new Form_IpAddress(
171
	'tunnel-local-addr',
172
	'GIF tunnel local address',
173
	$pconfig['tunnel-local-addr']
174
))->setHelp('Local gif tunnel endpoint.');
175

    
176
$section->addInput(new Form_IpAddress(
177
	'tunnel-remote-addr',
178
	'GIF tunnel remote address',
179
	$pconfig['tunnel-remote-addr']
180
))->setHelp('Remote GIF address endpoint.');
181

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

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

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

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

    
210
$section->addInput(new Form_Input(
211
	'gifif',
212
	null,
213
	'hidden',
214
	$pconfig['gifif']
215
));
216

    
217
if (isset($id) && $a_gifs[$id]) {
218
	$section->addInput(new Form_Input(
219
		'id',
220
		null,
221
		'hidden',
222
		$id
223
	));
224
}
225

    
226
$form->add($section);
227
print($form);
228

    
229
include("foot.inc");
(88-88/238)