1
|
<?php
|
2
|
/*
|
3
|
interfaces_qinq_edit.php
|
4
|
|
5
|
Copyright (C) 2013-2015 Electric Sheep Fencing, LP
|
6
|
Copyright (C) 2009 Ermal Luçi
|
7
|
All rights reserved.
|
8
|
|
9
|
Redistribution and use in source and binary forms, with or without
|
10
|
modification, are permitted provided that the following conditions are met:
|
11
|
|
12
|
1. Redistributions of source code must retain the above copyright notice,
|
13
|
this list of conditions and the following disclaimer.
|
14
|
|
15
|
2. Redistributions in binary form must reproduce the above copyright
|
16
|
notice, this list of conditions and the following disclaimer in the
|
17
|
documentation and/or other materials provided with the distribution.
|
18
|
|
19
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
20
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
21
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
22
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
23
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
24
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
25
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
26
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
27
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28
|
POSSIBILITY OF SUCH DAMAGE.
|
29
|
*/
|
30
|
/*
|
31
|
pfSense_BUILDER_BINARIES: /usr/sbin/ngctl
|
32
|
pfSense_MODULE: interfaces
|
33
|
*/
|
34
|
|
35
|
##|+PRIV
|
36
|
##|*IDENT=page-interfaces-qinq-edit
|
37
|
##|*NAME=Interfaces: QinQ: Edit page
|
38
|
##|*DESCR=Allow access to 'Interfaces: QinQ: Edit' page
|
39
|
##|*MATCH=interfaces_qinq_edit.php*
|
40
|
##|-PRIV
|
41
|
|
42
|
$pgtitle = array(gettext("Interfaces"), gettext("QinQ"), gettext("Edit"));
|
43
|
$shortcut_section = "interfaces";
|
44
|
|
45
|
require("guiconfig.inc");
|
46
|
|
47
|
if (!is_array($config['qinqs']['qinqentry'])) {
|
48
|
$config['qinqs']['qinqentry'] = array();
|
49
|
}
|
50
|
|
51
|
$a_qinqs = &$config['qinqs']['qinqentry'];
|
52
|
|
53
|
$portlist = get_interface_list();
|
54
|
|
55
|
/* add LAGG interfaces */
|
56
|
if (is_array($config['laggs']['lagg']) && count($config['laggs']['lagg'])) {
|
57
|
foreach ($config['laggs']['lagg'] as $lagg) {
|
58
|
$portlist[$lagg['laggif']] = $lagg;
|
59
|
}
|
60
|
}
|
61
|
|
62
|
if (count($portlist) < 1) {
|
63
|
header("Location: interfaces_qinq.php");
|
64
|
exit;
|
65
|
}
|
66
|
|
67
|
if (is_numericint($_GET['id'])) {
|
68
|
$id = $_GET['id'];
|
69
|
}
|
70
|
if (isset($_POST['id']) && is_numericint($_POST['id'])) {
|
71
|
$id = $_POST['id'];
|
72
|
}
|
73
|
|
74
|
if (isset($id) && $a_qinqs[$id]) {
|
75
|
$pconfig['if'] = $a_qinqs[$id]['if'];
|
76
|
$pconfig['tag'] = $a_qinqs[$id]['tag'];
|
77
|
$pconfig['members'] = $a_qinqs[$id]['members'];
|
78
|
$pconfig['descr'] = html_entity_decode($a_qinqs[$id]['descr']);
|
79
|
/*
|
80
|
$pconfig['autoassign'] = isset($a_qinqs[$id]['autoassign']);
|
81
|
$pconfig['autoenable'] = isset($a_qinqs[$id]['autoenable']);
|
82
|
*/
|
83
|
$pconfig['autogroup'] = isset($a_qinqs[$id]['autogroup']);
|
84
|
$pconfig['autoadjustmtu'] = isset($a_qinqs[$id]['autoadjustmtu']);
|
85
|
}
|
86
|
|
87
|
if ($_POST) {
|
88
|
|
89
|
unset($input_errors);
|
90
|
$pconfig = $_POST;
|
91
|
|
92
|
if (empty($_POST['tag'])) {
|
93
|
$input_errors[] = gettext("First level tag cannot be empty.");
|
94
|
}
|
95
|
if (isset($id) && $a_qinqs[$id]['tag'] != $_POST['tag']) {
|
96
|
$input_errors[] = gettext("You are editing an existing entry and modifying the first level tag is not allowed.");
|
97
|
}
|
98
|
if (isset($id) && $a_qinqs[$id]['if'] != $_POST['if']) {
|
99
|
$input_errors[] = gettext("You are editing an existing entry and modifying the interface is not allowed.");
|
100
|
}
|
101
|
if (!isset($id)) {
|
102
|
foreach ($a_qinqs as $qinqentry) {
|
103
|
if ($qinqentry['tag'] == $_POST['tag'] && $qinqentry['if'] == $_POST['if']) {
|
104
|
$input_errors[] = gettext("QinQ level already exists for this interface, edit it!");
|
105
|
}
|
106
|
}
|
107
|
if (is_array($config['vlans']['vlan'])) {
|
108
|
foreach ($config['vlans']['vlan'] as $vlan) {
|
109
|
if ($vlan['tag'] == $_POST['tag'] && $vlan['if'] == $_POST['if']) {
|
110
|
$input_errors[] = gettext("A normal VLAN exists with this tag please remove it to use this tag for QinQ first level.");
|
111
|
}
|
112
|
}
|
113
|
}
|
114
|
}
|
115
|
|
116
|
$qinqentry = array();
|
117
|
$qinqentry['if'] = $_POST['if'];
|
118
|
$qinqentry['tag'] = $_POST['tag'];
|
119
|
/*
|
120
|
if ($_POST['autoassign'] == "yes") { {
|
121
|
$qinqentry['autoassign'] = true;
|
122
|
}
|
123
|
if ($_POST['autoenable'] == "yes") {
|
124
|
$qinqentry['autoenable'] = true;
|
125
|
}
|
126
|
if ($_POST['autoadjust'] == "yes") {
|
127
|
$qinqentry['autoadjustmtu'] = true;
|
128
|
}
|
129
|
*/
|
130
|
if ($_POST['autogroup'] == "yes") {
|
131
|
$qinqentry['autogroup'] = true;
|
132
|
}
|
133
|
|
134
|
$members = "";
|
135
|
$isfirst = 0;
|
136
|
/* item is a normal qinqentry type */
|
137
|
for ($x = 0; $x < 9999; $x++) {
|
138
|
if ($_POST["members{$x}"] <> "") {
|
139
|
$member = explode("-", $_POST["members{$x}"]);
|
140
|
if (count($member) > 1) {
|
141
|
if (preg_match("/([^0-9])+/", $member[0], $match) ||
|
142
|
preg_match("/([^0-9])+/", $member[1], $match)) {
|
143
|
$input_errors[] = gettext("Tags can contain only numbers or a range in format #-#.");
|
144
|
}
|
145
|
|
146
|
for ($i = $member[0]; $i <= $member[1]; $i++) {
|
147
|
if ($isfirst > 0) {
|
148
|
$members .= " ";
|
149
|
}
|
150
|
$members .= $i;
|
151
|
$isfirst++;
|
152
|
}
|
153
|
} else {
|
154
|
if (preg_match("/([^0-9])+/", $_POST["members{$x}"], $match)) {
|
155
|
$input_errors[] = gettext("Tags can contain only numbers or a range in format #-#.");
|
156
|
}
|
157
|
|
158
|
if ($isfirst > 0) {
|
159
|
$members .= " ";
|
160
|
}
|
161
|
$members .= $_POST["members{$x}"];
|
162
|
$isfirst++;
|
163
|
}
|
164
|
}
|
165
|
}
|
166
|
|
167
|
if (!$input_errors) {
|
168
|
$qinqentry['members'] = $members;
|
169
|
$qinqentry['descr'] = $_POST['descr'];
|
170
|
$qinqentry['vlanif'] = "{$_POST['if']}_{$_POST['tag']}";
|
171
|
$nmembers = explode(" ", $members);
|
172
|
|
173
|
if (isset($id) && $a_qinqs[$id]) {
|
174
|
$omembers = explode(" ", $a_qinqs[$id]['members']);
|
175
|
$delmembers = array_diff($omembers, $nmembers);
|
176
|
$addmembers = array_diff($nmembers, $omembers);
|
177
|
|
178
|
if ((count($delmembers) > 0) || (count($addmembers) > 0)) {
|
179
|
$fd = fopen("{$g['tmp_path']}/netgraphcmd", "w");
|
180
|
foreach ($delmembers as $tag) {
|
181
|
fwrite($fd, "shutdown {$qinqentry['vlanif']}h{$tag}:\n");
|
182
|
fwrite($fd, "msg {$qinqentry['vlanif']}qinq: delfilter \\\"{$qinqentry['vlanif']}{$tag}\\\"\n");
|
183
|
}
|
184
|
|
185
|
foreach ($addmembers as $member) {
|
186
|
$qinq = array();
|
187
|
$qinq['if'] = $qinqentry['vlanif'];
|
188
|
$qinq['tag'] = $member;
|
189
|
$macaddr = get_interface_mac($qinqentry['vlanif']);
|
190
|
interface_qinq2_configure($qinq, $fd, $macaddr);
|
191
|
}
|
192
|
|
193
|
fclose($fd);
|
194
|
mwexec("/usr/sbin/ngctl -f {$g['tmp_path']}/netgraphcmd");
|
195
|
}
|
196
|
$a_qinqs[$id] = $qinqentry;
|
197
|
} else {
|
198
|
interface_qinq_configure($qinqentry);
|
199
|
$a_qinqs[] = $qinqentry;
|
200
|
}
|
201
|
if ($_POST['autogroup'] == "yes") {
|
202
|
if (!is_array($config['ifgroups']['ifgroupentry'])) {
|
203
|
$config['ifgroups']['ifgroupentry'] = array();
|
204
|
}
|
205
|
foreach ($config['ifgroups']['ifgroupentry'] as $gid => $group) {
|
206
|
if ($group['ifname'] == "QinQ") {
|
207
|
$found = true;
|
208
|
break;
|
209
|
}
|
210
|
}
|
211
|
$additions = "";
|
212
|
foreach ($nmembers as $qtag) {
|
213
|
$additions .= "{$qinqentry['vlanif']}_{$qtag} ";
|
214
|
}
|
215
|
$additions .= "{$qinqentry['vlanif']}";
|
216
|
if ($found == true) {
|
217
|
$config['ifgroups']['ifgroupentry'][$gid]['members'] .= " {$additions}";
|
218
|
} else {
|
219
|
$gentry = array();
|
220
|
$gentry['ifname'] = "QinQ";
|
221
|
$gentry['members'] = "{$additions}";
|
222
|
$gentry['descr'] = gettext("QinQ VLANs group");
|
223
|
$config['ifgroups']['ifgroupentry'][] = $gentry;
|
224
|
}
|
225
|
}
|
226
|
|
227
|
write_config();
|
228
|
|
229
|
header("Location: interfaces_qinq.php");
|
230
|
exit;
|
231
|
} else {
|
232
|
$pconfig['descr'] = $_POST['descr'];
|
233
|
$pconfig['tag'] = $_POST['tag'];
|
234
|
$pconfig['members'] = $members;
|
235
|
}
|
236
|
}
|
237
|
|
238
|
include("head.inc");
|
239
|
|
240
|
?>
|
241
|
|
242
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
|
243
|
<?php include("fbegin.inc"); ?>
|
244
|
|
245
|
<script type="text/javascript">
|
246
|
//<![CDATA[
|
247
|
// Global Variables
|
248
|
var rowname = new Array(9999);
|
249
|
var rowtype = new Array(9999);
|
250
|
var newrow = new Array(9999);
|
251
|
var rowsize = new Array(9999);
|
252
|
|
253
|
for (i = 0; i < 9999; i++) {
|
254
|
rowname[i] = 'members';
|
255
|
rowtype[i] = 'select';
|
256
|
newrow[i] = '';
|
257
|
rowsize[i] = '30';
|
258
|
}
|
259
|
|
260
|
var field_counter_js = 0;
|
261
|
var loaded = 0;
|
262
|
var is_streaming_progress_bar = 0;
|
263
|
var temp_streaming_text = "";
|
264
|
|
265
|
var addRowTo = (function() {
|
266
|
return (function (tableId) {
|
267
|
var d, tbody, tr, td, bgc, i, ii, j;
|
268
|
d = document;
|
269
|
tbody = d.getElementById(tableId).getElementsByTagName("tbody").item(0);
|
270
|
tr = d.createElement("tr");
|
271
|
for (i = 0; i < field_counter_js; i++) {
|
272
|
td = d.createElement("td");
|
273
|
td.innerHTML="<input type='hidden' value='" + totalrows +"' name='" + rowname[i] + "_row-" + totalrows + "' /><input size='" + rowsize[i] + "' class='formfld unknown' name='" + rowname[i] + totalrows + "' /> ";
|
274
|
tr.appendChild(td);
|
275
|
}
|
276
|
td = d.createElement("td");
|
277
|
td.rowSpan = "1";
|
278
|
|
279
|
td.innerHTML = '<a onclick="removeRow(this);return false;" href="#"><img border="0" src="/themes/' + theme + '/images/icons/icon_x.gif" alt="remove" /><\/a>';
|
280
|
tr.appendChild(td);
|
281
|
tbody.appendChild(tr);
|
282
|
totalrows++;
|
283
|
});
|
284
|
})();
|
285
|
|
286
|
function removeRow(el) {
|
287
|
var cel;
|
288
|
while (el && el.nodeName.toLowerCase() != "tr") {
|
289
|
el = el.parentNode;
|
290
|
}
|
291
|
|
292
|
if (el && el.parentNode) {
|
293
|
cel = el.getElementsByTagName("td").item(0);
|
294
|
el.parentNode.removeChild(el);
|
295
|
}
|
296
|
}
|
297
|
|
298
|
rowname[0] = <?=gettext("members");?>;
|
299
|
rowtype[0] = "textbox";
|
300
|
rowsize[0] = "30";
|
301
|
|
302
|
rowname[2] = <?=gettext("detail");?>;
|
303
|
rowtype[2] = "textbox";
|
304
|
rowsize[2] = "50";
|
305
|
//]]>
|
306
|
</script>
|
307
|
<input type='hidden' name='members_type' value='textbox' class="formfld unknown" />
|
308
|
|
309
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
310
|
<div id="inputerrors"></div>
|
311
|
|
312
|
<form action="interfaces_qinq_edit.php" method="post" name="iform" id="iform">
|
313
|
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="interfaces qinq edit">
|
314
|
<tr>
|
315
|
<td colspan="2" valign="top" class="listtopic"><?=gettext("Interface QinQ Edit");?></td>
|
316
|
</tr>
|
317
|
<tr>
|
318
|
<td width="22%" valign="top" class="vncellreq"><?=gettext("Parent interface");?></td>
|
319
|
<td width="78%" class="vtable">
|
320
|
<select name="if" id="if" class="formselect">
|
321
|
<?php
|
322
|
foreach ($portlist as $ifn => $ifinfo) {
|
323
|
if (is_jumbo_capable($ifn)) {
|
324
|
echo "<option value=\"{$ifn}\"";
|
325
|
if ($ifn == $pconfig['if']) {
|
326
|
echo " selected=\"selected\"";
|
327
|
}
|
328
|
echo ">";
|
329
|
echo htmlspecialchars($ifn . " (" . $ifinfo['mac'] . ")");
|
330
|
echo "</option>";
|
331
|
}
|
332
|
}
|
333
|
?>
|
334
|
</select>
|
335
|
<br />
|
336
|
<span class="vexpl"><?=gettext("Only QinQ capable interfaces will be shown.");?></span>
|
337
|
</td>
|
338
|
</tr>
|
339
|
<tr>
|
340
|
<td width="22%" valign="top" class="vncellreq"><?=gettext("First level tag");?></td>
|
341
|
<td width="78%" class="vtable">
|
342
|
<input name="tag" type="text" class="formfld unknown" id="tag" size="10" value="<?=htmlspecialchars($pconfig['tag']);?>" />
|
343
|
<br />
|
344
|
<span class="vexpl">
|
345
|
<?=gettext("This is the first level VLAN tag. On top of this are stacked the member VLANs defined below.");?>
|
346
|
</span>
|
347
|
</td>
|
348
|
</tr>
|
349
|
<tr>
|
350
|
<td width="22%" valign="top" class="vncell"><?=gettext("Options");?></td>
|
351
|
<td width="78%" class="vtable">
|
352
|
<?php /* ?>
|
353
|
<br />
|
354
|
<input type="checkbox" value="yes" name="autoassign" id="autoassign" <?php if ($pconfig['autoassign']) echo "checked=\"checked\""; ?> />
|
355
|
<span class="vexpl"> Auto assign interface so it can be configured with ip etc...</span>
|
356
|
<br />
|
357
|
<input type="checkbox" value="yes" name="autoenable" id="autoenable" <?php if ($pconfig['autoenable']) echo "checked=\"checked\""; ?> />
|
358
|
<span class="vexpl"> Auto enable interface so it can be used on filter rules.</span>
|
359
|
<br />
|
360
|
<input type="checkbox" value="yes" name="autoadjustmtu" id="autoadjustmtu" <?php if ($pconfig['autoadjustmtu']) echo "checked=\"checked\""; ?> />
|
361
|
<span class="vexpl"> Allows to keep clients mtu unchanged(1500). <br />NOTE: if you are using jumbo frames this option is not needed and may produce incorrect results!</span>
|
362
|
<?php */ ?>
|
363
|
<br />
|
364
|
<input name="autogroup" type="checkbox" value="yes" id="autogroup" <?php if ($pconfig['autogroup']) echo "checked=\"checked\""; ?> />
|
365
|
<span class="vexpl"><?=gettext("Adds interface to QinQ interface groups so you can write filter rules easily.");?></span>
|
366
|
</td>
|
367
|
</tr>
|
368
|
<tr>
|
369
|
<td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
|
370
|
<td width="78%" class="vtable">
|
371
|
<input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
|
372
|
<br />
|
373
|
<span class="vexpl">
|
374
|
<?=gettext("You may enter a description here for your reference (not parsed).");?>
|
375
|
</span>
|
376
|
</td>
|
377
|
</tr>
|
378
|
<tr>
|
379
|
<td width="22%" valign="top" class="vncellreq"><div id="membersnetworkport"><?=gettext("Member (s)");?></div></td>
|
380
|
<td width="78%" class="vtable">
|
381
|
<span class="vexpl">
|
382
|
<?=gettext("You can specify ranges in the input below. The format is pretty simple i.e 9-100 or 10.20...");?>
|
383
|
</span>
|
384
|
<br />
|
385
|
<table id="maintable" summary="main table">
|
386
|
<tbody>
|
387
|
<tr>
|
388
|
<td><div id="onecolumn"><?=gettext("Tag");?></div></td>
|
389
|
</tr>
|
390
|
|
391
|
<?php
|
392
|
$counter = 0;
|
393
|
$members = $pconfig['members'];
|
394
|
if ($members <> "") {
|
395
|
$item = explode(" ", $members);
|
396
|
foreach ($item as $ww) {
|
397
|
$member = $item[$counter];
|
398
|
?>
|
399
|
<tr>
|
400
|
<td class="vtable">
|
401
|
<input name="members<?php echo $counter; ?>" class="formselect" id="members<?php echo $counter; ?>" value="<?php echo htmlspecialchars($member);?>" />
|
402
|
</td>
|
403
|
<td>
|
404
|
<a onclick="removeRow(this); return false;" href="#"><img border="0" src="/themes/<?echo $g['theme'];?>/images/icons/icon_x.gif" alt="remove" /></a>
|
405
|
</td>
|
406
|
</tr>
|
407
|
<?php
|
408
|
$counter++;
|
409
|
|
410
|
} // end foreach
|
411
|
} // end if
|
412
|
?>
|
413
|
</tbody>
|
414
|
</table>
|
415
|
<a onclick="javascript:addRowTo('maintable'); return false;" href="#">
|
416
|
<img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="<?=gettext("add another entry");?>" />
|
417
|
</a>
|
418
|
</td>
|
419
|
</tr>
|
420
|
<tr>
|
421
|
<td width="22%" valign="top"> </td>
|
422
|
<td width="78%">
|
423
|
<input id="submit" name="submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
|
424
|
<a href="interfaces_qinq.php"><input id="cancelbutton" name="cancelbutton" type="button" class="formbtn" value="<?=gettext("Cancel");?>" /></a>
|
425
|
<?php if (isset($id) && $a_qinqs[$id]): ?>
|
426
|
<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
|
427
|
<?php endif; ?>
|
428
|
</td>
|
429
|
</tr>
|
430
|
</table>
|
431
|
</form>
|
432
|
|
433
|
<script type="text/javascript">
|
434
|
//<![CDATA[
|
435
|
field_counter_js = 1;
|
436
|
rows = 1;
|
437
|
totalrows = <?php echo $counter; ?>;
|
438
|
loaded = <?php echo $counter; ?>;
|
439
|
//]]>
|
440
|
</script>
|
441
|
|
442
|
<?php include("fend.inc"); ?>
|
443
|
</body>
|
444
|
</html>
|