1
|
<?php
|
2
|
/* $Id$ */
|
3
|
/*
|
4
|
interfaces_vlan_edit.php
|
5
|
part of m0n0wall (http://m0n0.ch/wall)
|
6
|
|
7
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
8
|
Copyright (C) 2013-2015 Electric Sheep Fencing, LP
|
9
|
All rights reserved.
|
10
|
|
11
|
Redistribution and use in source and binary forms, with or without
|
12
|
modification, are permitted provided that the following conditions are met:
|
13
|
|
14
|
1. Redistributions of source code must retain the above copyright notice,
|
15
|
this list of conditions and the following disclaimer.
|
16
|
|
17
|
2. Redistributions in binary form must reproduce the above copyright
|
18
|
notice, this list of conditions and the following disclaimer in the
|
19
|
documentation and/or other materials provided with the distribution.
|
20
|
|
21
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
22
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
23
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
24
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
25
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
26
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
27
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
28
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
29
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30
|
POSSIBILITY OF SUCH DAMAGE.
|
31
|
*/
|
32
|
/*
|
33
|
pfSense_MODULE: interfaces
|
34
|
*/
|
35
|
|
36
|
##|+PRIV
|
37
|
##|*IDENT=page-interfaces-vlan-edit
|
38
|
##|*NAME=Interfaces: VLAN: Edit page
|
39
|
##|*DESCR=Allow access to the 'Interfaces: VLAN: Edit' page.
|
40
|
##|*MATCH=interfaces_vlan_edit.php*
|
41
|
##|-PRIV
|
42
|
|
43
|
require("guiconfig.inc");
|
44
|
|
45
|
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/interfaces_vlan.php');
|
46
|
|
47
|
if (!is_array($config['vlans']['vlan']))
|
48
|
$config['vlans']['vlan'] = array();
|
49
|
|
50
|
$a_vlans = &$config['vlans']['vlan'];
|
51
|
|
52
|
$portlist = get_interface_list();
|
53
|
|
54
|
/* add LAGG interfaces */
|
55
|
if (is_array($config['laggs']['lagg']) && count($config['laggs']['lagg'])) {
|
56
|
foreach ($config['laggs']['lagg'] as $lagg)
|
57
|
$portlist[$lagg['laggif']] = $lagg;
|
58
|
}
|
59
|
|
60
|
if (is_numericint($_GET['id']))
|
61
|
$id = $_GET['id'];
|
62
|
if (isset($_POST['id']) && is_numericint($_POST['id']))
|
63
|
$id = $_POST['id'];
|
64
|
|
65
|
if (isset($id) && $a_vlans[$id]) {
|
66
|
$pconfig['if'] = $a_vlans[$id]['if'];
|
67
|
$pconfig['vlanif'] = $a_vlans[$id]['vlanif'];
|
68
|
$pconfig['tag'] = $a_vlans[$id]['tag'];
|
69
|
$pconfig['descr'] = $a_vlans[$id]['descr'];
|
70
|
}
|
71
|
|
72
|
if ($_POST) {
|
73
|
|
74
|
unset($input_errors);
|
75
|
$pconfig = $_POST;
|
76
|
|
77
|
/* input validation */
|
78
|
$reqdfields = explode(" ", "if tag");
|
79
|
$reqdfieldsn = array(gettext("Parent interface"),gettext("VLAN tag"));
|
80
|
|
81
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
|
82
|
|
83
|
if ($_POST['tag'] && (!is_numericint($_POST['tag']) || ($_POST['tag'] < '1') || ($_POST['tag'] > '4094'))) {
|
84
|
$input_errors[] = gettext("The VLAN tag must be an integer between 1 and 4094.");
|
85
|
}
|
86
|
|
87
|
if (!does_interface_exist($_POST['if']))
|
88
|
$input_errors[] = gettext("Interface supplied as parent is invalid");
|
89
|
|
90
|
if (isset($id)) {
|
91
|
if ($_POST['tag'] && $_POST['tag'] != $a_vlans[$id]['tag']) {
|
92
|
if (!empty($a_vlans[$id]['vlanif']) && convert_real_interface_to_friendly_interface_name($a_vlans[$id]['vlanif']) != NULL)
|
93
|
$input_errors[] = gettext("Interface is assigned and you cannot change the VLAN tag while assigned.");
|
94
|
}
|
95
|
}
|
96
|
foreach ($a_vlans as $vlan) {
|
97
|
if (isset($id) && ($a_vlans[$id]) && ($a_vlans[$id] === $vlan))
|
98
|
continue;
|
99
|
|
100
|
if (($vlan['if'] == $_POST['if']) && ($vlan['tag'] == $_POST['tag'])) {
|
101
|
$input_errors[] = sprintf(gettext("A VLAN with the tag %s is already defined on this interface."),$vlan['tag']);
|
102
|
break;
|
103
|
}
|
104
|
}
|
105
|
if (is_array($config['qinqs']['qinqentry'])) {
|
106
|
foreach ($config['qinqs']['qinqentry'] as $qinq)
|
107
|
if ($qinq['tag'] == $_POST['tag'] && $qinq['if'] == $_POST['if'])
|
108
|
$input_errors[] = gettext("A QinQ VLAN exists with this tag please remove it to use this tag with.");
|
109
|
}
|
110
|
|
111
|
if (!$input_errors) {
|
112
|
if (isset($id) && $a_vlans[$id]) {
|
113
|
if (($a_vlans[$id]['if'] != $_POST['if']) || ($a_vlans[$id]['tag'] != $_POST['tag'])) {
|
114
|
if (!empty($a_vlans[$id]['vlanif'])) {
|
115
|
$confif = convert_real_interface_to_friendly_interface_name($vlan['vlanif']);
|
116
|
// Destroy previous vlan
|
117
|
pfSense_interface_destroy($a_vlans[$id]['vlanif']);
|
118
|
} else {
|
119
|
pfSense_interface_destroy("{$a_vlans[$id]['if']}_vlan{$a_vlans[$id]['tag']}");
|
120
|
$confif = convert_real_interface_to_friendly_interface_name("{$a_vlans[$id]['if']}_vlan{$a_vlans[$id]['tag']}");
|
121
|
}
|
122
|
if ($confif != "")
|
123
|
$config['interfaces'][$confif]['if'] = "{$_POST['if']}_vlan{$_POST['tag']}";
|
124
|
}
|
125
|
}
|
126
|
$vlan = array();
|
127
|
$vlan['if'] = $_POST['if'];
|
128
|
$vlan['tag'] = $_POST['tag'];
|
129
|
$vlan['descr'] = $_POST['descr'];
|
130
|
$vlan['vlanif'] = "{$_POST['if']}_vlan{$_POST['tag']}";
|
131
|
$vlan['vlanif'] = interface_vlan_configure($vlan);
|
132
|
if ($vlan['vlanif'] == "" || !stristr($vlan['vlanif'], "vlan"))
|
133
|
$input_errors[] = gettext("Error occurred creating interface, please retry.");
|
134
|
else {
|
135
|
if (isset($id) && $a_vlans[$id])
|
136
|
$a_vlans[$id] = $vlan;
|
137
|
else
|
138
|
$a_vlans[] = $vlan;
|
139
|
|
140
|
write_config();
|
141
|
|
142
|
if ($confif != "")
|
143
|
interface_configure($confif);
|
144
|
header("Location: interfaces_vlan.php");
|
145
|
exit;
|
146
|
}
|
147
|
}
|
148
|
}
|
149
|
|
150
|
$pgtitle = array(gettext("Interfaces"),gettext("VLAN"),gettext("Edit"));
|
151
|
$shortcut_section = "interfaces";
|
152
|
include("head.inc");
|
153
|
|
154
|
if ($input_errors) {
|
155
|
print_input_errors($input_errors);
|
156
|
}
|
157
|
|
158
|
require('classes/Form.class.php');
|
159
|
$form = new Form;
|
160
|
$section = new Form_Section('Interface VLAN Edit');
|
161
|
|
162
|
$section->addInput(new Form_Select(
|
163
|
'if',
|
164
|
'Parent Interface',
|
165
|
$pconfig['if'],
|
166
|
array_combine(
|
167
|
array_keys($portlist),
|
168
|
array_map(
|
169
|
function($key, $value) {
|
170
|
return (is_jumbo_capable($key)) ? "{$key} ({$value['mac']})" : $value;
|
171
|
},
|
172
|
array_keys($portlist),
|
173
|
array_values($portlist)
|
174
|
)
|
175
|
),
|
176
|
false
|
177
|
))->setWidth(6)->setHelp('Only VLAN capable interfaces will be shown.');
|
178
|
|
179
|
$section->addInput(new Form_Input(
|
180
|
'tag',
|
181
|
'VLAN Tag',
|
182
|
'text',
|
183
|
$pconfig['tag'],
|
184
|
['placeholder' => '1']
|
185
|
))->setWidth(6)->setHelp(gettext('802.1Q VLAN tag (between 1 and 4094).'));
|
186
|
|
187
|
$section->addInput(new Form_Input(
|
188
|
'descr',
|
189
|
'Description',
|
190
|
'text',
|
191
|
$pconfig['descr'],
|
192
|
['placeholder' => 'Description']
|
193
|
))->setWidth(6)->setHelp('You may enter a group description here '.
|
194
|
'for your reference (not parsed).');
|
195
|
|
196
|
$form->addGlobal(new Form_Input(
|
197
|
'vlanif',
|
198
|
'vlanif',
|
199
|
'hidden',
|
200
|
$pconfig['vlanif']
|
201
|
));
|
202
|
|
203
|
if (isset($id) && $a_vlans[$id]) {
|
204
|
$form->addGlobal(new Form_Input(
|
205
|
'id',
|
206
|
'id',
|
207
|
'hidden',
|
208
|
$id
|
209
|
));
|
210
|
}
|
211
|
|
212
|
$form->addGlobal(new Form_Button(
|
213
|
'cancel',
|
214
|
'Cancel',
|
215
|
$referer
|
216
|
));
|
217
|
|
218
|
$form->add($section);
|
219
|
print $form;
|
220
|
|
221
|
include("foot.inc");
|
222
|
?>
|