Project

General

Profile

Download (13.8 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
<?php
219
	include("fbegin.inc");
220
?>
221
222
<script type="text/javascript">
223
// Global Variables
224
var rowname = new Array(9999);
225
var rowtype = new Array(9999);
226
var newrow  = new Array(9999);
227
var rowsize = new Array(9999);
228
229
for (i = 0; i < 9999; i++) {
230 9cf46050 Ermal
        rowname[i] = 'members';
231 b991e3b5 Ermal Lu?i
        rowtype[i] = 'select';
232
        newrow[i] = '';
233
        rowsize[i] = '30';
234
}
235
236
var field_counter_js = 0;
237
var loaded = 0;
238
var is_streaming_progress_bar = 0;
239
var temp_streaming_text = "";
240
241
var addRowTo = (function() {
242
    return (function (tableId) {
243
        var d, tbody, tr, td, bgc, i, ii, j;
244
        d = document;
245
        tbody = d.getElementById(tableId).getElementsByTagName("tbody").item(0);
246
        tr = d.createElement("tr");
247
        for (i = 0; i < field_counter_js; i++) {
248
                td = d.createElement("td");
249
		td.innerHTML="<INPUT type='hidden' value='" + totalrows +"' name='" + rowname[i] + "_row-" + totalrows + "'></input><input size='" + rowsize[i] + "' class='formfld unknown' name='" + rowname[i] + totalrows + "'></input> ";
250
                tr.appendChild(td);
251
        }
252
        td = d.createElement("td");
253
        td.rowSpan = "1";
254
255 bddc8818 Erik Fonnesbeck
        td.innerHTML = '<a onclick="removeRow(this);return false;" href="#"><img border="0" src="/themes/' + theme + '/images/icons/icon_x.gif" /></a>';
256 b991e3b5 Ermal Lu?i
        tr.appendChild(td);
257
        tbody.appendChild(tr);
258
        totalrows++;
259
    });
260
})();
261
262
function removeRow(el) {
263
    var cel;
264
    while (el && el.nodeName.toLowerCase() != "tr")
265
            el = el.parentNode;
266
267
    if (el && el.parentNode) {
268
        cel = el.getElementsByTagName("td").item(0);
269
        el.parentNode.removeChild(el);
270
    }
271
}
272
273 93bcbb6a Renato Botelho
	rowname[0] = <?=gettext("members");?>;
274 b991e3b5 Ermal Lu?i
	rowtype[0] = "textbox";
275
	rowsize[0] = "30";
276
277 93bcbb6a Renato Botelho
	rowname[2] = <?=gettext("detail");?>;
278 b991e3b5 Ermal Lu?i
	rowtype[2] = "textbox";
279
	rowsize[2] = "50";
280
</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
<table width="100%" border="0" cellpadding="6" cellspacing="0">
288
  <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
				echo "selected";
301
                        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 a3381369 Colin Fleming
		<input type="checkbox" value="yes" name="autoassign" id="autoassign" <?php if ($pconfig['autoassign']) echo checked;?>/>
327 b991e3b5 Ermal Lu?i
		<span class="vexpl"> Auto assign interface so it can be configured with ip etc...</span>
328
		<br/>
329 a3381369 Colin Fleming
		<input type="checkbox" value="yes" name="autoenable" id="autoenable" <?php if ($pconfig['autoenable']) echo checked;?>/>
330 b991e3b5 Ermal Lu?i
		<span class="vexpl"> Auto enable interface so it can be used on filter rules.</span>
331
		<br/>
332 a3381369 Colin Fleming
		<input type="checkbox" value="yes" name="autoadjustmtu" id="autoadjustmtu" <?php if ($pconfig['autoadjustmtu']) echo "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 a3381369 Colin Fleming
		<input name="autogroup" type="checkbox" value="yes" id="autogroup" <?php if ($pconfig['autogroup']) echo "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 a80281c6 Ermal Lu?i
	<span vlass="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 b991e3b5 Ermal Lu?i
      <table id="maintable">
358
        <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 a3381369 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 bddc8818 Erik Fonnesbeck
	<a onclick="removeRow(this); return false;" href="#"><img border="0" src="/themes/<?echo $g['theme'];?>/images/icons/icon_x.gif" /></a>
377 b991e3b5 Ermal Lu?i
	      </td>
378
          </tr>
379
<?php
380
		$counter++;
381
382
		} // end foreach
383
	} // end if
384
?>
385
        </tbody>
386
        <tfoot>
387
388
        </tfoot>
389
		  </table>
390
			<a onclick="javascript:addRowTo('maintable'); return false;" href="#">
391 93bcbb6a Renato Botelho
        <img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="<?=gettext("add another entry");?>" />
392 b991e3b5 Ermal Lu?i
      </a>
393
		</td>
394
  </tr>
395
  <tr>
396
    <td width="22%" valign="top">&nbsp;</td>
397
    <td width="78%">
398 93bcbb6a Renato Botelho
      <input id="submit" name="submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
399
      <a href="interfaces_qinq.php"><input id="cancelbutton" name="cancelbutton" type="button" class="formbtn" value="<?=gettext("Cancel");?>" /></a>
400 b991e3b5 Ermal Lu?i
      <?php if (isset($id) && $a_qinqs[$id]): ?>
401 225a2f0b Scott Ullrich
      <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
402 b991e3b5 Ermal Lu?i
      <?php endif; ?>
403
    </td>
404
  </tr>
405
</table>
406
</form>
407
408
<script type="text/javascript">
409
	field_counter_js = 1;
410
	rows = 1;
411
	totalrows = <?php echo $counter; ?>;
412
	loaded = <?php echo $counter; ?>;
413
</script>
414
415
<?php include("fend.inc"); ?>
416
</body>
417
</html>