1 |
de068d0b
|
Scott Ullrich
|
<?php
|
2 |
b46bfcf5
|
Bill Marquette
|
/* $Id$ */
|
3 |
5b237745
|
Scott Ullrich
|
/*
|
4 |
|
|
interfaces_vlan_edit.php
|
5 |
|
|
part of m0n0wall (http://m0n0.ch/wall)
|
6 |
de068d0b
|
Scott Ullrich
|
|
7 |
5b237745
|
Scott Ullrich
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
8 |
ce77a9c4
|
Phil Davis
|
Copyright (C) 2013-2015 Electric Sheep Fencing, LP
|
9 |
5b237745
|
Scott Ullrich
|
All rights reserved.
|
10 |
de068d0b
|
Scott Ullrich
|
|
11 |
5b237745
|
Scott Ullrich
|
Redistribution and use in source and binary forms, with or without
|
12 |
|
|
modification, are permitted provided that the following conditions are met:
|
13 |
de068d0b
|
Scott Ullrich
|
|
14 |
5b237745
|
Scott Ullrich
|
1. Redistributions of source code must retain the above copyright notice,
|
15 |
|
|
this list of conditions and the following disclaimer.
|
16 |
de068d0b
|
Scott Ullrich
|
|
17 |
5b237745
|
Scott Ullrich
|
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 |
de068d0b
|
Scott Ullrich
|
|
21 |
5b237745
|
Scott Ullrich
|
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 |
7ac5a4cb
|
Scott Ullrich
|
/*
|
33 |
|
|
pfSense_MODULE: interfaces
|
34 |
|
|
*/
|
35 |
5b237745
|
Scott Ullrich
|
|
36 |
6b07c15a
|
Matthew Grooms
|
##|+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 |
5b237745
|
Scott Ullrich
|
require("guiconfig.inc");
|
44 |
|
|
|
45 |
62424bdb
|
Renato Botelho
|
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/interfaces_vlan.php');
|
46 |
|
|
|
47 |
5b237745
|
Scott Ullrich
|
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 |
a0188aa6
|
Ermal Luci
|
/* add LAGG interfaces */
|
55 |
|
|
if (is_array($config['laggs']['lagg']) && count($config['laggs']['lagg'])) {
|
56 |
465f17a3
|
Thane Gill
|
foreach ($config['laggs']['lagg'] as $lagg)
|
57 |
|
|
$portlist[$lagg['laggif']] = $lagg;
|
58 |
a0188aa6
|
Ermal Luci
|
}
|
59 |
|
|
|
60 |
e41ec584
|
Renato Botelho
|
if (is_numericint($_GET['id']))
|
61 |
|
|
$id = $_GET['id'];
|
62 |
|
|
if (isset($_POST['id']) && is_numericint($_POST['id']))
|
63 |
5b237745
|
Scott Ullrich
|
$id = $_POST['id'];
|
64 |
|
|
|
65 |
|
|
if (isset($id) && $a_vlans[$id]) {
|
66 |
|
|
$pconfig['if'] = $a_vlans[$id]['if'];
|
67 |
a3f9082f
|
Ermal Luçi
|
$pconfig['vlanif'] = $a_vlans[$id]['vlanif'];
|
68 |
5b237745
|
Scott Ullrich
|
$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 |
cbdc84ea
|
Rafael Lucas
|
$reqdfields = explode(" ", "if tag");
|
79 |
|
|
$reqdfieldsn = array(gettext("Parent interface"),gettext("VLAN tag"));
|
80 |
de068d0b
|
Scott Ullrich
|
|
81 |
1e9b4611
|
Renato Botelho
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
|
82 |
de068d0b
|
Scott Ullrich
|
|
83 |
e5d58b68
|
Phil Davis
|
if (isset($_POST['tag']) && (!is_numericint($_POST['tag']) || ($_POST['tag'] < '1') || ($_POST['tag'] > '4094'))) {
|
84 |
c24e9a11
|
Rafael Lucas
|
$input_errors[] = gettext("The VLAN tag must be an integer between 1 and 4094.");
|
85 |
5b237745
|
Scott Ullrich
|
}
|
86 |
|
|
|
87 |
0e22dda5
|
Ermal
|
if (!does_interface_exist($_POST['if']))
|
88 |
|
|
$input_errors[] = gettext("Interface supplied as parent is invalid");
|
89 |
|
|
|
90 |
1ca626e7
|
Ermal
|
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 |
5b237745
|
Scott Ullrich
|
foreach ($a_vlans as $vlan) {
|
97 |
|
|
if (isset($id) && ($a_vlans[$id]) && ($a_vlans[$id] === $vlan))
|
98 |
|
|
continue;
|
99 |
de068d0b
|
Scott Ullrich
|
|
100 |
5b237745
|
Scott Ullrich
|
if (($vlan['if'] == $_POST['if']) && ($vlan['tag'] == $_POST['tag'])) {
|
101 |
c24e9a11
|
Rafael Lucas
|
$input_errors[] = sprintf(gettext("A VLAN with the tag %s is already defined on this interface."),$vlan['tag']);
|
102 |
5b237745
|
Scott Ullrich
|
break;
|
103 |
de068d0b
|
Scott Ullrich
|
}
|
104 |
5b237745
|
Scott Ullrich
|
}
|
105 |
c6196310
|
Ermal Lu?i
|
if (is_array($config['qinqs']['qinqentry'])) {
|
106 |
|
|
foreach ($config['qinqs']['qinqentry'] as $qinq)
|
107 |
|
|
if ($qinq['tag'] == $_POST['tag'] && $qinq['if'] == $_POST['if'])
|
108 |
c24e9a11
|
Rafael Lucas
|
$input_errors[] = gettext("A QinQ VLAN exists with this tag please remove it to use this tag with.");
|
109 |
c6196310
|
Ermal Lu?i
|
}
|
110 |
5b237745
|
Scott Ullrich
|
|
111 |
|
|
if (!$input_errors) {
|
112 |
0f70d563
|
Ermal
|
if (isset($id) && $a_vlans[$id]) {
|
113 |
695a35ae
|
Ermal
|
if (($a_vlans[$id]['if'] != $_POST['if']) || ($a_vlans[$id]['tag'] != $_POST['tag'])) {
|
114 |
b0d6223f
|
Ermal
|
if (!empty($a_vlans[$id]['vlanif'])) {
|
115 |
|
|
$confif = convert_real_interface_to_friendly_interface_name($vlan['vlanif']);
|
116 |
6b421a0f
|
Ermal
|
// Destroy previous vlan
|
117 |
|
|
pfSense_interface_destroy($a_vlans[$id]['vlanif']);
|
118 |
b0d6223f
|
Ermal
|
} else {
|
119 |
6b421a0f
|
Ermal
|
pfSense_interface_destroy("{$a_vlans[$id]['if']}_vlan{$a_vlans[$id]['tag']}");
|
120 |
b0d6223f
|
Ermal
|
$confif = convert_real_interface_to_friendly_interface_name("{$a_vlans[$id]['if']}_vlan{$a_vlans[$id]['tag']}");
|
121 |
|
|
}
|
122 |
465f17a3
|
Thane Gill
|
if ($confif != "")
|
123 |
b0d6223f
|
Ermal
|
$config['interfaces'][$confif]['if'] = "{$_POST['if']}_vlan{$_POST['tag']}";
|
124 |
6b421a0f
|
Ermal
|
}
|
125 |
0f70d563
|
Ermal
|
}
|
126 |
5b237745
|
Scott Ullrich
|
$vlan = array();
|
127 |
|
|
$vlan['if'] = $_POST['if'];
|
128 |
|
|
$vlan['tag'] = $_POST['tag'];
|
129 |
|
|
$vlan['descr'] = $_POST['descr'];
|
130 |
48315e65
|
Ermal Luci
|
$vlan['vlanif'] = "{$_POST['if']}_vlan{$_POST['tag']}";
|
131 |
5f1e1d26
|
Ermal Lu?i
|
$vlan['vlanif'] = interface_vlan_configure($vlan);
|
132 |
465f17a3
|
Thane Gill
|
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 |
de068d0b
|
Scott Ullrich
|
|
140 |
465f17a3
|
Thane Gill
|
write_config();
|
141 |
de068d0b
|
Scott Ullrich
|
|
142 |
465f17a3
|
Thane Gill
|
if ($confif != "")
|
143 |
69e5a8be
|
Ermal Luçi
|
interface_configure($confif);
|
144 |
a3f9082f
|
Ermal Luçi
|
header("Location: interfaces_vlan.php");
|
145 |
|
|
exit;
|
146 |
|
|
}
|
147 |
5b237745
|
Scott Ullrich
|
}
|
148 |
|
|
}
|
149 |
7f43ca88
|
Scott Ullrich
|
|
150 |
baca83aa
|
gnhb
|
$pgtitle = array(gettext("Interfaces"),gettext("VLAN"),gettext("Edit"));
|
151 |
b32dd0a6
|
jim-p
|
$shortcut_section = "interfaces";
|
152 |
7f43ca88
|
Scott Ullrich
|
include("head.inc");
|
153 |
|
|
|
154 |
465f17a3
|
Thane Gill
|
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 |
5b237745
|
Scott Ullrich
|
|
218 |
465f17a3
|
Thane Gill
|
$form->add($section);
|
219 |
|
|
print $form;
|
220 |
|
|
|
221 |
|
|
include("foot.inc");
|
222 |
|
|
?>
|