Project

General

Profile

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