Project

General

Profile

Download (13.6 KB) Statistics
| Branch: | Tag: | Revision:
1
<?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

    
28
##|+PRIV
29
##|*IDENT=page-interfacess-qinq
30
##|*NAME=Interfaces: QinQ: Edit page
31
##|*DESCR=Edit Interface qinq
32
##|*MATCH=interfaces_qinq_edit.php*
33
##|-PRIV
34

    
35

    
36
$pgtitle = array("Interfaces","QinQ", "Edit");
37

    
38
require("guiconfig.inc");
39

    
40
if (!is_array($config['qinqs']['qinqentry']))
41
	$config['qinqs']['qinqentry'] = array();
42

    
43
$a_qinqs = &$config['qinqs']['qinqentry'];
44

    
45
$portlist = get_interface_list();
46

    
47
/* add LAGG interfaces */
48
if (is_array($config['laggs']['lagg']) && count($config['laggs']['lagg'])) {
49
        foreach ($config['laggs']['lagg'] as $lagg)
50
                $portlist[$lagg['laggif']] = $lagg;
51
}
52

    
53
if (count($portlist) < 1) {
54
	header("Location: interfaces_qinq.php");
55
	exit;
56
}
57

    
58
$id = $_GET['id'];
59
if (isset($_POST['id']))
60
	$id = $_POST['id'];
61

    
62
if (isset($id) && $a_qinqs[$id]) {
63
	$pconfig['if'] = $a_qinqs[$id]['if'];
64
	$pconfig['tag'] = $a_qinqs[$id]['tag'];
65
	$pconfig['members'] = $a_qinqs[$id]['members'];
66
	$pconfig['descr'] = html_entity_decode($a_qinqs[$id]['descr']);
67
/*
68
	$pconfig['autoassign'] = isset($a_qinqs[$id]['autoassign']);
69
	$pconfig['autoenable'] = isset($a_qinqs[$id]['autoenable']);
70
*/
71
	$pconfig['autogroup'] = isset($a_qinqs[$id]['autogroup']);
72
	$pconfig['autoadjustmtu'] = isset($a_qinqs[$id]['autoadjustmtu']);
73
}
74

    
75
if ($_POST) {
76

    
77
	unset($input_errors);
78
	$pconfig = $_POST;
79

    
80
	if (empty($_POST['tag']))
81
		$input_errors[] = "First level tag cannot be empty.";
82
	if (isset($id) && $a_qinqs[$id]['tag'] != $_POST['tag'])
83
		$input_errors[] = "You are editing an existing entry and modifying the first level tag is not allowed.";
84
	if (isset($id) && $a_qinqs[$id]['if'] != $_POST['if'])
85
		$input_errors[] = "You are editing an existing entry and modifying the interface is not allowed.";
86
	if (!isset($id)) {
87
		foreach ($a_qinqs as $qinqentry)
88
			if ($qinqentry['tag'] == $_POST['tag'] && $qinqentry['if'] == $_POST['if'])
89
				$input_errors[] = "QinQ level already exists for this interface, edit it!";
90
		if (is_array($config['vlans']['vlan'])) {
91
			foreach ($config['vlans']['vlan'] as $vlan)
92
				if ($vlan['tag'] == $_POST['tag'] && $vlan['if'] == $_POST['if'])
93
					$input_errors[] = "A normal VLAN exists with this tag please remove it to use this tag for QinQ first level.";
94
		}
95
	}
96

    
97
	$qinqentry = array();
98
	$qinqentry['if'] = $_POST['if'];
99
	$qinqentry['tag'] = $_POST['tag'];
100
/*
101
	if ($_POST['autoassign'] == "yes") {
102
		$qinqentry['autoassign'] = true;
103
	if ($_POST['autoenable'] == "yes")
104
		$qinqentry['autoenable'] = true;
105
	if ($_POST['autoadjust'] == "yes")
106
		$qinqentry['autoadjustmtu'] = true;
107
*/
108
	if ($_POST['autogroup'] == "yes")
109
		$qinqentry['autogroup'] = true;
110

    
111
	$members = "";
112
	$isfirst = 0;
113
	/* item is a normal qinqentry type */
114
	for($x=0; $x<9999; $x++) {
115
		if($_POST["members{$x}"] <> "") {
116
			$member = explode("-", $_POST["members{$x}"]);
117
			if (count($member) > 1) {
118
				if (preg_match("/([^0-9])+/", $member[0], $match)  ||
119
					preg_match("/([^0-9])+/", $member[1], $match))
120
					$input_errors[] = "Tags can contain only numbers or a range in format #-#.";
121

    
122
				for ($i = $member[0]; $i <= $member[1]; $i++) {
123
					if ($isfirst > 0)
124
						$members .= " ";
125
					$members .= $i;
126
					$isfirst++;
127
				}
128
			} else {
129
				if (preg_match("/([^0-9])+/", $_POST["members{$x}"], $match))
130
					$input_errors[] = "Tags can contain only numbers or a range in format #-#.";
131

    
132
				if ($isfirst > 0)
133
					$members .= " ";
134
				$members .= $_POST["members{$x}"];
135
				$isfirst++;
136
			}
137
		}
138
	}
139

    
140
	if (!$input_errors) {
141
		$qinqentry['members'] = $members;
142
		$qinqentry['descr'] = mb_convert_encoding($_POST['descr'],"HTML-ENTITIES","auto");
143
		$qinqentry['vlanif'] = "vlan{$_POST['tag']}";
144
		$nmembers = explode(" ", $members);
145

    
146
		if (isset($id) && $a_qinqs[$id]) {
147
			$omembers = explode(" ", $a_qinqs[$id]['members']);
148
			$delmembers = array_diff($omembers, $nmembers);
149
			if (count($delmembers) > 0) {
150
				foreach ($delmembers as $tag) {
151
					mwexec("/usr/sbin/ngctl shutdown vlan{$_POST['tag']}h{$tag}:");
152
					mwexec("/usr/sbin/ngctl msg vlan{$_POST['tag']}qinq: delfilter \\\"vlan{$_POST['tag']}{$tag}\\\"");
153
				}
154
			}
155
			$addmembers = array_diff($nmembers, $omembers);
156
			if (count($addmembers) > 0) {
157
				foreach ($addmembers as $member) {
158
					$if = "vlan{$_POST['tag']}";
159
					$vlanif = "{$if}_{$member}";
160
					$macaddr = get_interface_mac($if);
161
					mwexec("/usr/sbin/ngctl mkpeer {$if}qinq: eiface {$if}{$member} ether");
162
					mwexec("/usr/sbin/ngctl name {$if}qinq:{$if}{$tag} {$if}h{$member}");
163
					mwexec("/usr/sbin/ngctl msg {$if}qinq: addfilter '{ vlan={$member} hook=\\\"{$if}{$member}\\\" }'");
164
					mwexec("/usr/sbin/ngctl msg {$if}h{$tag}: setifname \\\"{$vlanif}\\\"");
165
					mwexec("/usr/sbin/ngctl msg {$vlanif}: setenaddr {$macaddr}");
166
				}
167
			}
168
			$a_qinqs[$id] = $qinqentry;
169
		} else {
170
			interface_qinq_configure($qinqentry);
171
			$a_qinqs[] = $qinqentry;
172
		}
173
		if ($_POST['autogroup'] == "yes") {
174
			if (!is_array($config['ifgroups']['ifgroupentry']))
175
				$config['ifgroups']['ifgroupentry'] = array();
176
			foreach ($config['ifgroups']['ifgroupentry'] as $gid => $group) {
177
				if ($group['ifname'] == "QinQ") {
178
					$found = true;
179
					break;
180
				}
181
			}
182
			$additions = "";
183
			foreach($nmembers as $qtag)
184
				$additions .= "vlan{$qinqentry['tag']}_{$qtag} ";
185
			$additions .= "vlan{$qinqentry['tag']} ";
186
			if ($found == true)
187
				$config['ifgroups']['ifgroupentry'][$gid]['members'] .= " {$additions}";
188
			else {
189
				$gentry = array();
190
				$gentry['ifname'] = "QinQ";
191
				$gentry['members'] = "{$additions}";
192
				$gentry['descr'] = "QinQ VLANs group";
193
				$config['ifgroup']['ifgroupentry'][] = $gentry;
194
			}
195
		}
196

    
197
		write_config();
198

    
199
		header("Location: interfaces_qinq.php");
200
		exit;
201
	} else {
202
		$pconfig['descr'] = mb_convert_encoding($_POST['descr'],"HTML-ENTITIES","auto");
203
		$pconfig['tag'] = $_POST['tag'];
204
		$pconfig['members'] = $members;
205
	}
206
}
207

    
208
include("head.inc");
209

    
210
?>
211

    
212
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
213
<?php
214
	include("fbegin.inc");
215
?>
216

    
217
<script type="text/javascript">
218
// Global Variables
219
var rowname = new Array(9999);
220
var rowtype = new Array(9999);
221
var newrow  = new Array(9999);
222
var rowsize = new Array(9999);
223

    
224
for (i = 0; i < 9999; i++) {
225
        rowname[i] = '';
226
        rowtype[i] = 'select';
227
        newrow[i] = '';
228
        rowsize[i] = '30';
229
}
230

    
231
var field_counter_js = 0;
232
var loaded = 0;
233
var is_streaming_progress_bar = 0;
234
var temp_streaming_text = "";
235

    
236
var addRowTo = (function() {
237
    return (function (tableId) {
238
        var d, tbody, tr, td, bgc, i, ii, j;
239
        d = document;
240
        tbody = d.getElementById(tableId).getElementsByTagName("tbody").item(0);
241
        tr = d.createElement("tr");
242
        for (i = 0; i < field_counter_js; i++) {
243
                td = d.createElement("td");
244
		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> ";
245
                tr.appendChild(td);
246
        }
247
        td = d.createElement("td");
248
        td.rowSpan = "1";
249

    
250
        td.innerHTML = '<input type="image" src="/themes/' + theme + '/images/icons/icon_x.gif" onclick="removeRow(this);return false;" value="Delete">';
251
        tr.appendChild(td);
252
        tbody.appendChild(tr);
253
        totalrows++;
254
    });
255
})();
256

    
257
function removeRow(el) {
258
    var cel;
259
    while (el && el.nodeName.toLowerCase() != "tr")
260
            el = el.parentNode;
261

    
262
    if (el && el.parentNode) {
263
        cel = el.getElementsByTagName("td").item(0);
264
        el.parentNode.removeChild(el);
265
    }
266
}
267

    
268
	rowname[0] = "members";
269
	rowtype[0] = "textbox";
270
	rowsize[0] = "30";
271

    
272
	rowname[2] = "detail";
273
	rowtype[2] = "textbox";
274
	rowsize[2] = "50";
275
</script>
276
<input type='hidden' name='members_type' value='textbox' class="formfld unknown" />
277

    
278
<?php if ($input_errors) print_input_errors($input_errors); ?>
279
<div id="inputerrors"></div>
280

    
281
<form action="interfaces_qinq_edit.php" method="post" name="iform" id="iform">
282
<table width="100%" border="0" cellpadding="6" cellspacing="0">
283
  <tr>
284
	<td colspan="2" valign="top" class="listtopic">Interface QinQ Edit</td>
285
  </tr>
286
  <tr>
287
    <td width="22%" valign="top" class="vncellreq">Parent interface</td>
288
    <td width="78%" class="vtable">
289
    <select name="if" id="if" class="formselect">
290
    <?php
291
        foreach ($portlist as $ifn => $ifinfo) {
292
		if (is_jumbo_capable($ifn)) {
293
			echo "<option value=\"{$ifn}\"";
294
                        if ($ifn == $pconfig['if'])
295
				echo "selected";
296
                        echo ">";
297
                        echo htmlspecialchars($ifn . " (" . $ifinfo['mac'] . ")");
298
                        echo "</option>";
299
                }
300
	}
301
    ?>
302
    </select>
303
    <br/>
304
    <span class="vexpl">Only QinQ capable interfaces will be shown.</span></td>
305
  </tr>
306
  <tr>
307
    <td width="22%" valign="top" class="vncellreq">First level tag</td>
308
    <td width="78%" class="vtable">
309
      <input name="tag" type="text" class="formfld unknown" id="tag" size="10" value="<?=$pconfig['tag'];?>" />
310
      <br />
311
      <span class="vexpl">
312
	This is the first level VLAN tag. On top of this are stacked the member VLANs defined below.
313
      </span>
314
    </td>
315
  </tr>
316
  <tr>
317
	<td width="22%" valign="top" class="vncell">Options</td>
318
	<td width="78%" class="vtable">
319
<?php /* ?>
320
		<br/>
321
		<input type="checkbox" value="yes" name="autoassign" id="autoassign" <? if ($pconfig['autoassign']) echo checked;?>/>
322
		<span class="vexpl"> Auto assign interface so it can be configured with ip etc...</span>
323
		<br/>
324
		<input type="checkbox" value="yes" name="autoenable" id="autoenable" <? if ($pconfig['autoenable']) echo checked;?>/>
325
		<span class="vexpl"> Auto enable interface so it can be used on filter rules.</span>
326
		<br/>
327
		<input type="checkbox" value="yes" name="autoadjustmtu" id="autoadjustmtu" <? if ($pconfig['autoadjustmtu']) echo "checked";?>>
328
		<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>
329
<?php */ ?>
330
		<br/>
331
		<input name="autogroup" type="checkbox" value="yes" id="autogroup" <? if ($pconfig['autogroup']) echo "checked";?>>
332
		<span class="vexpl"> Adds interface to QinQ interface groups so you can write filter rules easily.</span>
333
	</td>
334
  </tr>
335
  <tr>
336
    <td width="22%" valign="top" class="vncell">Description</td>
337
    <td width="78%" class="vtable">
338
      <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=$pconfig['descr'];?>" />
339
      <br />
340
      <span class="vexpl">
341
        You may enter a description here for your reference (not parsed).
342
      </span>
343
    </td>
344
  </tr>
345
  <tr>
346
    <td width="22%" valign="top" class="vncellreq"><div id="membersnetworkport">Member (s)</div></td>
347
    <td width="78%" class="vtable">
348
	<span vlass="vexpl">
349
		You can specify ranges in the input below. The format is pretty simple i.e 9-100 or 10.20...
350
	</span>
351
	<br/>
352
      <table id="maintable">
353
        <tbody>
354
          <tr>
355
            <td><div id="onecolumn">Tag</div></td>
356
          </tr>
357

    
358
	<?php
359
	$counter = 0;
360
	$members = $pconfig['members'];
361
	if ($members <> "") {
362
		$item = explode(" ", $members);
363
		foreach($item as $ww) {
364
			$members = $item[$counter];
365
			$tracker = $counter;
366
	?>
367
        <tr>
368
	<td class="vtable">
369
	        <input name="members<?php echo $tracker; ?>" class="formselect" id="members<?php echo $tracker; ?>" value="<? echo $members;?>">
370
	</td>
371
        <td>
372
	<input type="image" src="/themes/<?echo $g['theme'];?>/images/icons/icon_x.gif" onclick="removeRow(this); return false;" value="Delete" />
373
	      </td>
374
          </tr>
375
<?php
376
		$counter++;
377

    
378
		} // end foreach
379
	} // end if
380
?>
381
        </tbody>
382
        <tfoot>
383

    
384
        </tfoot>
385
		  </table>
386
			<a onclick="javascript:addRowTo('maintable'); return false;" href="#">
387
        <img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="add another entry" />
388
      </a>
389
		</td>
390
  </tr>
391
  <tr>
392
    <td width="22%" valign="top">&nbsp;</td>
393
    <td width="78%">
394
      <input id="submit" name="submit" type="submit" class="formbtn" value="Save" />
395
      <a href="interfaces_qinq.php"><input id="cancelbutton" name="cancelbutton" type="button" class="formbtn" value="Cancel" /></a>
396
      <?php if (isset($id) && $a_qinqs[$id]): ?>
397
      <input name="id" type="hidden" value="<?=$id;?>" />
398
      <?php endif; ?>
399
    </td>
400
  </tr>
401
</table>
402
</form>
403

    
404
<script type="text/javascript">
405
	field_counter_js = 1;
406
	rows = 1;
407
	totalrows = <?php echo $counter; ?>;
408
	loaded = <?php echo $counter; ?>;
409
</script>
410

    
411
<?php include("fend.inc"); ?>
412
</body>
413
</html>
(94-94/217)