Project

General

Profile

Download (13.2 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
					$vlan = array();
159
					$vlan['if'] = "vlan{$_POST['tag']}";
160
					$vlan['tag'] = $member;
161
					interface_qinq2_configure($vlan);
162
				}
163
			}
164
			$a_qinqs[$id] = $qinqentry;
165
		} else {
166
			interface_qinq_configure($qinqentry);
167
			$a_qinqs[] = $qinqentry;
168
		}
169
		if ($_POST['autogroup'] == "yes") {
170
			if (!is_array($config['ifgroups']['ifgroupentry']))
171
				$config['ifgroups']['ifgroupentry'] = array();
172
			foreach ($config['ifgroups']['ifgroupentry'] as $gid => $group) {
173
				if ($group['ifname'] == "QinQ") {
174
					$found = true;
175
					break;
176
				}
177
			}
178
			$additions = "";
179
			foreach($nmembers as $qtag)
180
				$additions .= "vlan{$qinqentry['tag']}_{$qtag} ";
181
			$additions .= "vlan{$qinqentry['tag']} ";
182
			if ($found == true)
183
				$config['ifgroups']['ifgroupentry'][$gid]['members'] .= " {$additions}";
184
			else {
185
				$gentry = array();
186
				$gentry['ifname'] = "QinQ";
187
				$gentry['members'] = "{$additions}";
188
				$gentry['descr'] = "QinQ VLANs group";
189
				$config['ifgroup']['ifgroupentry'][] = $gentry;
190
			}
191
		}
192

    
193
		write_config();
194

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

    
204
include("head.inc");
205

    
206
?>
207

    
208
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
209
<?php
210
	include("fbegin.inc");
211
?>
212

    
213
<script type="text/javascript">
214
// Global Variables
215
var rowname = new Array(9999);
216
var rowtype = new Array(9999);
217
var newrow  = new Array(9999);
218
var rowsize = new Array(9999);
219

    
220
for (i = 0; i < 9999; i++) {
221
        rowname[i] = '';
222
        rowtype[i] = 'select';
223
        newrow[i] = '';
224
        rowsize[i] = '30';
225
}
226

    
227
var field_counter_js = 0;
228
var loaded = 0;
229
var is_streaming_progress_bar = 0;
230
var temp_streaming_text = "";
231

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

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

    
253
function removeRow(el) {
254
    var cel;
255
    while (el && el.nodeName.toLowerCase() != "tr")
256
            el = el.parentNode;
257

    
258
    if (el && el.parentNode) {
259
        cel = el.getElementsByTagName("td").item(0);
260
        el.parentNode.removeChild(el);
261
    }
262
}
263

    
264
	rowname[0] = "members";
265
	rowtype[0] = "textbox";
266
	rowsize[0] = "30";
267

    
268
	rowname[2] = "detail";
269
	rowtype[2] = "textbox";
270
	rowsize[2] = "50";
271
</script>
272
<input type='hidden' name='members_type' value='textbox' class="formfld unknown" />
273

    
274
<?php if ($input_errors) print_input_errors($input_errors); ?>
275
<div id="inputerrors"></div>
276

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

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

    
374
		} // end foreach
375
	} // end if
376
?>
377
        </tbody>
378
        <tfoot>
379

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

    
400
<script type="text/javascript">
401
	field_counter_js = 1;
402
	rows = 1;
403
	totalrows = <?php echo $counter; ?>;
404
	loaded = <?php echo $counter; ?>;
405
</script>
406

    
407
<?php include("fend.inc"); ?>
408
</body>
409
</html>
(87-87/205)