Project

General

Profile

Download (13.8 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
	pfSense_BUILDER_BINARIES:	/usr/sbin/ngctl	
29
	pfSense_MODULE:	interfaces
30
*/
31

    
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
$pgtitle = array("Interfaces","QinQ", "Edit");
40

    
41
require("guiconfig.inc");
42

    
43
if (!is_array($config['qinqs']['qinqentry']))
44
	$config['qinqs']['qinqentry'] = array();
45

    
46
$a_qinqs = &$config['qinqs']['qinqentry'];
47

    
48
$portlist = get_interface_list();
49

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

    
56
if (count($portlist) < 1) {
57
	header("Location: interfaces_qinq.php");
58
	exit;
59
}
60

    
61
$id = $_GET['id'];
62
if (isset($_POST['id']))
63
	$id = $_POST['id'];
64

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

    
78
if ($_POST) {
79

    
80
	unset($input_errors);
81
	$pconfig = $_POST;
82

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

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

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

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

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

    
143
	if (!$input_errors) {
144
		$qinqentry['members'] = $members;
145
		$qinqentry['descr'] = mb_convert_encoding($_POST['descr'],"HTML-ENTITIES","auto");
146
		$qinqentry['vlanif'] = "{$_POST['if']}_{$_POST['tag']}";
147
		$nmembers = explode(" ", $members);
148

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

    
198
		write_config();
199

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

    
209
include("head.inc");
210

    
211
?>
212

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
412
<?php include("fend.inc"); ?>
413
</body>
414
</html>
(93-93/216)