Project

General

Profile

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