Project

General

Profile

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