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

    
200
		write_config();
201

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

    
211
include("head.inc");
212

    
213
?>
214

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

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

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

    
234
var field_counter_js = 0;
235
var loaded = 0;
236
var is_streaming_progress_bar = 0;
237
var temp_streaming_text = "";
238

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

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

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

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

    
271
	rowname[0] = "members";
272
	rowtype[0] = "textbox";
273
	rowsize[0] = "30";
274

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

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

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

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

    
381
		} // end foreach
382
	} // end if
383
?>
384
        </tbody>
385
        <tfoot>
386

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

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

    
414
<?php include("fend.inc"); ?>
415
</body>
416
</html>
(94-94/217)