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
|
if (isset($_POST['referer'])) {
|
46
|
$referer = $_POST['referer'];
|
47
|
} else {
|
48
|
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/interfaces_vlan.php');
|
49
|
}
|
50
|
|
51
|
if (!is_array($config['vlans']['vlan'])) {
|
52
|
$config['vlans']['vlan'] = array();
|
53
|
}
|
54
|
|
55
|
$a_vlans = &$config['vlans']['vlan'];
|
56
|
|
57
|
$portlist = get_interface_list();
|
58
|
|
59
|
/* add LAGG interfaces */
|
60
|
if (is_array($config['laggs']['lagg']) && count($config['laggs']['lagg'])) {
|
61
|
foreach ($config['laggs']['lagg'] as $lagg) {
|
62
|
$portlist[$lagg['laggif']] = $lagg;
|
63
|
}
|
64
|
}
|
65
|
|
66
|
if (is_numericint($_GET['id'])) {
|
67
|
$id = $_GET['id'];
|
68
|
}
|
69
|
if (isset($_POST['id']) && is_numericint($_POST['id'])) {
|
70
|
$id = $_POST['id'];
|
71
|
}
|
72
|
|
73
|
if (isset($id) && $a_vlans[$id]) {
|
74
|
$pconfig['if'] = $a_vlans[$id]['if'];
|
75
|
$pconfig['vlanif'] = $a_vlans[$id]['vlanif'];
|
76
|
$pconfig['tag'] = $a_vlans[$id]['tag'];
|
77
|
$pconfig['descr'] = $a_vlans[$id]['descr'];
|
78
|
}
|
79
|
|
80
|
if ($_POST) {
|
81
|
|
82
|
unset($input_errors);
|
83
|
$pconfig = $_POST;
|
84
|
|
85
|
/* input validation */
|
86
|
$reqdfields = explode(" ", "if tag");
|
87
|
$reqdfieldsn = array(gettext("Parent interface"), gettext("VLAN tag"));
|
88
|
|
89
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
|
90
|
|
91
|
if (isset($_POST['tag']) && (!is_numericint($_POST['tag']) || ($_POST['tag'] < '1') || ($_POST['tag'] > '4094'))) {
|
92
|
$input_errors[] = gettext("The VLAN tag must be an integer between 1 and 4094.");
|
93
|
}
|
94
|
|
95
|
if (!does_interface_exist($_POST['if'])) {
|
96
|
$input_errors[] = gettext("Interface supplied as parent is invalid");
|
97
|
}
|
98
|
|
99
|
if (isset($id)) {
|
100
|
if ($_POST['tag'] && $_POST['tag'] != $a_vlans[$id]['tag']) {
|
101
|
if (!empty($a_vlans[$id]['vlanif']) && convert_real_interface_to_friendly_interface_name($a_vlans[$id]['vlanif']) != NULL) {
|
102
|
$input_errors[] = gettext("Interface is assigned and you cannot change the VLAN tag while assigned.");
|
103
|
}
|
104
|
}
|
105
|
}
|
106
|
foreach ($a_vlans as $vlan) {
|
107
|
if (isset($id) && ($a_vlans[$id]) && ($a_vlans[$id] === $vlan)) {
|
108
|
continue;
|
109
|
}
|
110
|
|
111
|
if (($vlan['if'] == $_POST['if']) && ($vlan['tag'] == $_POST['tag'])) {
|
112
|
$input_errors[] = sprintf(gettext("A VLAN with the tag %s is already defined on this interface."), $vlan['tag']);
|
113
|
break;
|
114
|
}
|
115
|
}
|
116
|
if (is_array($config['qinqs']['qinqentry'])) {
|
117
|
foreach ($config['qinqs']['qinqentry'] as $qinq) {
|
118
|
if ($qinq['tag'] == $_POST['tag'] && $qinq['if'] == $_POST['if']) {
|
119
|
$input_errors[] = gettext("A QinQ VLAN exists with this tag please remove it to use this tag with.");
|
120
|
}
|
121
|
}
|
122
|
}
|
123
|
|
124
|
if (!$input_errors) {
|
125
|
if (isset($id) && $a_vlans[$id]) {
|
126
|
if (($a_vlans[$id]['if'] != $_POST['if']) || ($a_vlans[$id]['tag'] != $_POST['tag'])) {
|
127
|
if (!empty($a_vlans[$id]['vlanif'])) {
|
128
|
$confif = convert_real_interface_to_friendly_interface_name($vlan['vlanif']);
|
129
|
// Destroy previous vlan
|
130
|
pfSense_interface_destroy($a_vlans[$id]['vlanif']);
|
131
|
} else {
|
132
|
pfSense_interface_destroy("{$a_vlans[$id]['if']}_vlan{$a_vlans[$id]['tag']}");
|
133
|
$confif = convert_real_interface_to_friendly_interface_name("{$a_vlans[$id]['if']}_vlan{$a_vlans[$id]['tag']}");
|
134
|
}
|
135
|
if ($confif <> "") {
|
136
|
$config['interfaces'][$confif]['if'] = "{$_POST['if']}_vlan{$_POST['tag']}";
|
137
|
}
|
138
|
}
|
139
|
}
|
140
|
$vlan = array();
|
141
|
$vlan['if'] = $_POST['if'];
|
142
|
$vlan['tag'] = $_POST['tag'];
|
143
|
$vlan['descr'] = $_POST['descr'];
|
144
|
$vlan['vlanif'] = "{$_POST['if']}_vlan{$_POST['tag']}";
|
145
|
|
146
|
$vlan['vlanif'] = interface_vlan_configure($vlan);
|
147
|
if ($vlan['vlanif'] == "" || !stristr($vlan['vlanif'], "vlan")) {
|
148
|
$input_errors[] = gettext("Error occurred creating interface, please retry.");
|
149
|
} else {
|
150
|
if (isset($id) && $a_vlans[$id]) {
|
151
|
$a_vlans[$id] = $vlan;
|
152
|
} else {
|
153
|
$a_vlans[] = $vlan;
|
154
|
}
|
155
|
|
156
|
write_config();
|
157
|
|
158
|
if ($confif <> "") {
|
159
|
interface_configure($confif);
|
160
|
}
|
161
|
|
162
|
header("Location: interfaces_vlan.php");
|
163
|
exit;
|
164
|
}
|
165
|
}
|
166
|
}
|
167
|
|
168
|
$pgtitle = array(gettext("Interfaces"), gettext("VLAN"), gettext("Edit"));
|
169
|
$shortcut_section = "interfaces";
|
170
|
include("head.inc");
|
171
|
|
172
|
?>
|
173
|
|
174
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
175
|
<?php include("fbegin.inc"); ?>
|
176
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
177
|
<form action="interfaces_vlan_edit.php" method="post" name="iform" id="iform">
|
178
|
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="interfaces vlan edit">
|
179
|
<tr>
|
180
|
<td colspan="2" valign="top" class="listtopic"><?=gettext("VLAN configuration");?></td>
|
181
|
</tr>
|
182
|
<tr>
|
183
|
<td width="22%" valign="top" class="vncellreq"><?=gettext("Parent interface");?></td>
|
184
|
<td width="78%" class="vtable">
|
185
|
<select name="if" class="formselect">
|
186
|
<?php
|
187
|
foreach ($portlist as $ifn => $ifinfo) {
|
188
|
if (is_jumbo_capable($ifn)) {
|
189
|
echo "<option value=\"{$ifn}\"";
|
190
|
if ($ifn == $pconfig['if']) {
|
191
|
echo " selected=\"selected\"";
|
192
|
}
|
193
|
echo ">";
|
194
|
echo htmlspecialchars($ifn . " (" . $ifinfo['mac'] . ")");
|
195
|
echo "</option>";
|
196
|
}
|
197
|
}
|
198
|
?>
|
199
|
</select>
|
200
|
<br />
|
201
|
<span class="vexpl"><?=gettext("Only VLAN capable interfaces will be shown.");?></span>
|
202
|
</td>
|
203
|
</tr>
|
204
|
<tr>
|
205
|
<td valign="top" class="vncellreq"><?=gettext("VLAN tag ");?></td>
|
206
|
<td class="vtable">
|
207
|
<input name="tag" type="text" class="formfld unknown" id="tag" size="6" value="<?=htmlspecialchars($pconfig['tag']);?>" />
|
208
|
<br />
|
209
|
<span class="vexpl"><?=gettext("802.1Q VLAN tag (between 1 and 4094) ");?></span>
|
210
|
</td>
|
211
|
</tr>
|
212
|
<tr>
|
213
|
<td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
|
214
|
<td width="78%" class="vtable">
|
215
|
<input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
|
216
|
<br />
|
217
|
<span class="vexpl"><?=gettext("You may enter a description here for your reference (not parsed).");?></span>
|
218
|
</td>
|
219
|
</tr>
|
220
|
<tr>
|
221
|
<td width="22%" valign="top"> </td>
|
222
|
<td width="78%">
|
223
|
<input type="hidden" name="vlanif" value="<?=htmlspecialchars($pconfig['vlanif']); ?>" />
|
224
|
<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
|
225
|
<input type="button" class="formbtn" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=$referer;?>'" />
|
226
|
<input name="referer" type="hidden" value="<?=$referer;?>" />
|
227
|
<?php if (isset($id) && $a_vlans[$id]): ?>
|
228
|
<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
|
229
|
<?php endif; ?>
|
230
|
</td>
|
231
|
</tr>
|
232
|
</table>
|
233
|
</form>
|
234
|
<?php include("fend.inc"); ?>
|
235
|
</body>
|
236
|
</html>
|