Project

General

Profile

Download (14.1 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(gettext("Interfaces"),gettext("QinQ"), gettext("Edit"));
40
$shortcut_section = "interfaces";
41

    
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
$id = $_GET['id'];
63
if (isset($_POST['id']))
64
	$id = $_POST['id'];
65

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

    
79
if ($_POST) {
80

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

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

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

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

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

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

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

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

    
199
		write_config();
200

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

    
210
include("head.inc");
211

    
212
?>
213

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

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

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

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

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

    
252
        td.innerHTML = '<a onclick="removeRow(this);return false;" href="#"><img border="0" src="/themes/' + theme + '/images/icons/icon_x.gif" /></a>';
253
        tr.appendChild(td);
254
        tbody.appendChild(tr);
255
        totalrows++;
256
    });
257
})();
258

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

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

    
270
	rowname[0] = <?=gettext("members");?>;
271
	rowtype[0] = "textbox";
272
	rowsize[0] = "30";
273

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

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

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

    
360
	<?php
361
	$counter = 0;
362
	$members = $pconfig['members'];
363
	if ($members <> "") {
364
		$item = explode(" ", $members);
365
		foreach($item as $ww) {
366
			$member = $item[$counter];
367
	?>
368
        <tr>
369
	<td class="vtable">
370
	        <input name="members<?php echo $counter; ?>" class="formselect" id="members<?php echo $counter; ?>" value="<?php echo $member;?>">
371
	</td>
372
        <td>
373
	<a onclick="removeRow(this); return false;" href="#"><img border="0" src="/themes/<?echo $g['theme'];?>/images/icons/icon_x.gif" /></a>
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="<?=gettext("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="<?=gettext("Save");?>" />
396
      <a href="interfaces_qinq.php"><input id="cancelbutton" name="cancelbutton" type="button" class="formbtn" value="<?=gettext("Cancel");?>" /></a>
397
      <?php if (isset($id) && $a_qinqs[$id]): ?>
398
      <input name="id" type="hidden" value="<?=htmlspecialchars($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>
(108-108/248)