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
|
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/interfaces_gif.php');
|
45
|
|
46
|
if (!is_array($config['gifs']['gif']))
|
47
|
$config['gifs']['gif'] = array();
|
48
|
|
49
|
$a_gifs = &$config['gifs']['gif'];
|
50
|
|
51
|
if (is_numericint($_GET['id']))
|
52
|
$id = $_GET['id'];
|
53
|
if (isset($_POST['id']) && is_numericint($_POST['id']))
|
54
|
$id = $_POST['id'];
|
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 tunnel-remote-addr tunnel-remote-net tunnel-local-addr");
|
77
|
$reqdfieldsn = array(gettext("Parent interface,Local address, Remote tunnel address, Remote tunnel network, Local tunnel address"));
|
78
|
|
79
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
|
80
|
|
81
|
if ((!is_ipaddr($_POST['tunnel-local-addr'])) || (!is_ipaddr($_POST['tunnel-remote-addr'])) ||
|
82
|
(!is_ipaddr($_POST['remote-addr']))) {
|
83
|
$input_errors[] = gettext("The tunnel local and tunnel remote fields must have valid IP addresses.");
|
84
|
}
|
85
|
|
86
|
$alias = strstr($_POST['if'],'|');
|
87
|
if ((is_ipaddrv4($alias) && !is_ipaddrv4($_POST['remote-addr'])) ||
|
88
|
(is_ipaddrv6($alias) && !is_ipaddrv6($_POST['remote-addr'])))
|
89
|
$input_errors[] = gettext("The alias IP address family has to match the family of the remote peer address.");
|
90
|
|
91
|
foreach ($a_gifs as $gif) {
|
92
|
if (isset($id) && ($a_gifs[$id]) && ($a_gifs[$id] === $gif))
|
93
|
continue;
|
94
|
|
95
|
/* FIXME: needs to perform proper subnet checks in the feature */
|
96
|
if (($gif['if'] == $interface) && ($gif['tunnel-remote-addr'] == $_POST['tunnel-remote-addr'])) {
|
97
|
$input_errors[] = sprintf(gettext("A gif with the network %s is already defined."), $gif['tunnel-remote-addr']);
|
98
|
break;
|
99
|
}
|
100
|
}
|
101
|
|
102
|
if (!$input_errors) {
|
103
|
$gif = array();
|
104
|
list($gif['if'], $gif['ipaddr']) = explode("|",$_POST['if']);
|
105
|
$gif['tunnel-local-addr'] = $_POST['tunnel-local-addr'];
|
106
|
$gif['tunnel-remote-addr'] = $_POST['tunnel-remote-addr'];
|
107
|
$gif['tunnel-remote-net'] = $_POST['tunnel-remote-net'];
|
108
|
$gif['remote-addr'] = $_POST['remote-addr'];
|
109
|
$gif['descr'] = $_POST['descr'];
|
110
|
$gif['link1'] = isset($_POST['link1']);
|
111
|
$gif['link0'] = isset($_POST['link0']);
|
112
|
$gif['gifif'] = $_POST['gifif'];
|
113
|
$gif['gifif'] = interface_gif_configure($gif);
|
114
|
|
115
|
if ($gif['gifif'] == "" || !stristr($gif['gifif'], "gif"))
|
116
|
$input_errors[] = gettext("Error occurred creating interface, please retry.");
|
117
|
else {
|
118
|
if (isset($id) && $a_gifs[$id])
|
119
|
$a_gifs[$id] = $gif;
|
120
|
else
|
121
|
$a_gifs[] = $gif;
|
122
|
|
123
|
write_config();
|
124
|
|
125
|
$confif = convert_real_interface_to_friendly_interface_name($gif['gifif']);
|
126
|
|
127
|
if ($confif != "")
|
128
|
interface_configure($confif);
|
129
|
|
130
|
header("Location: interfaces_gif.php");
|
131
|
exit;
|
132
|
}
|
133
|
}
|
134
|
}
|
135
|
|
136
|
function build_parent_list() {
|
137
|
$parentlist = array();
|
138
|
$portlist = get_possible_listen_ips();
|
139
|
foreach ($portlist as $ifn => $ifinfo)
|
140
|
$parentlist[$ifn] = $ifinfo;
|
141
|
|
142
|
return($parentlist);
|
143
|
}
|
144
|
|
145
|
$pgtitle = array(gettext("Interfaces"),gettext("GIF"),gettext("Edit"));
|
146
|
$shortcut_section = "interfaces";
|
147
|
include("head.inc");
|
148
|
require('classes/Form.class.php');
|
149
|
|
150
|
$form = new Form();
|
151
|
$form->addGlobal(new Form_Button(
|
152
|
'cancel',
|
153
|
'Cancel',
|
154
|
$referer
|
155
|
));
|
156
|
|
157
|
$section = new Form_Section('GIF Configuration');
|
158
|
|
159
|
$section->addInput(new Form_Select(
|
160
|
'if',
|
161
|
'Parent Interface',
|
162
|
$pconfig['if'],
|
163
|
build_parent_list()
|
164
|
))->setHelp('This interface serves as the local address to be used for the GIF tunnel.');
|
165
|
|
166
|
$section->addInput(new Form_IpAddress(
|
167
|
'remote-addr',
|
168
|
'GIF Remote Address',
|
169
|
$pconfig['remote-addr']
|
170
|
))->setHelp('Peer address where encapsulated gif packets will be sent.');
|
171
|
|
172
|
$section->addInput(new Form_IpAddress(
|
173
|
'tunnel-local-addr',
|
174
|
'GIF tunnel local address',
|
175
|
$pconfig['tunnel-local-addr']
|
176
|
))->setHelp('Local gif tunnel endpoint.');
|
177
|
|
178
|
$section->addInput(new Form_IpAddress(
|
179
|
'tunnel-remote-addr',
|
180
|
'GIF tunnel remote address',
|
181
|
$pconfig['tunnel-remote-addr']
|
182
|
))->setHelp('Remote GIF address endpoint.');
|
183
|
|
184
|
$section->addInput(new Form_Select(
|
185
|
'tunnel-remote-net',
|
186
|
'GIF tunnel remote subnet',
|
187
|
$pconfig['tunnel-remote-net'],
|
188
|
array_combine(range(128, 1, -1), range(128, 1, -1))
|
189
|
))->setHelp('The subnet is used for determining the network that is tunnelled');
|
190
|
|
191
|
$section->addInput(new Form_Checkbox(
|
192
|
'link0',
|
193
|
'Route Caching',
|
194
|
'Specify if route caching can be enabled. (Be careful with these settings on dynamic networks.)',
|
195
|
$pconfig['link0']
|
196
|
));
|
197
|
|
198
|
$section->addInput(new Form_Checkbox(
|
199
|
'link1',
|
200
|
'ECN friendly behavior',
|
201
|
'ECN friendly behavior violates RFC2893. This should be used in mutual agreement with the peer. ',
|
202
|
$pconfig['link1']
|
203
|
));
|
204
|
|
205
|
$section->addInput(new Form_Input(
|
206
|
'descr',
|
207
|
'Description',
|
208
|
'text',
|
209
|
$pconfig['descr']
|
210
|
))->setHelp('You may enter a description here for your reference (not parsed).');
|
211
|
|
212
|
$section->addInput(new Form_Input(
|
213
|
'gifif',
|
214
|
null,
|
215
|
'hidden',
|
216
|
$pconfig['gifif']
|
217
|
));
|
218
|
|
219
|
if (isset($id) && $a_gifs[$id]) {
|
220
|
$section->addInput(new Form_Input(
|
221
|
'id',
|
222
|
null,
|
223
|
'hidden',
|
224
|
$id
|
225
|
));
|
226
|
}
|
227
|
|
228
|
$form->add($section);
|
229
|
print($form);
|
230
|
|
231
|
include("foot.inc");
|