Project

General

Profile

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