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(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
			$addmembers = array_diff($nmembers, $omembers);
154

    
155
			if ((count($delmembers) > 0) || (count($addmembers) > 0)) {
156
				$fd = fopen("{$g['tmp_path']}/netgraphcmd", "w");
157
				foreach ($delmembers as $tag) {
158
					fwrite($fd, "shutdown {$qinqentry['vlanif']}h{$tag}:\n");
159
					fwrite($fd, "msg {$qinqentry['vlanif']}qinq: delfilter \\\"{$qinqentry['vlanif']}{$tag}\\\"\n");
160
				}
161

    
162
				foreach ($addmembers as $member) {
163
					$qinq = array();
164
					$qinq['if'] = $qinqentry['vlanif'];
165
					$qinq['tag'] = $member;
166
					$macaddr = get_interface_mac($qinqentry['vlanif']);
167
					interface_qinq2_configure($qinq, $fd, $macaddr);
168
				}
169

    
170
				fclose($fd);
171
				mwexec("/usr/sbin/ngctl -f {$g['tmp_path']}/netgraphcmd");
172
			}
173
			$a_qinqs[$id] = $qinqentry;
174
		} else {
175
			interface_qinq_configure($qinqentry);
176
			$a_qinqs[] = $qinqentry;
177
		}
178
		if ($_POST['autogroup'] == "yes") {
179
			if (!is_array($config['ifgroups']['ifgroupentry']))
180
				$config['ifgroups']['ifgroupentry'] = array();
181
			foreach ($config['ifgroups']['ifgroupentry'] as $gid => $group) {
182
				if ($group['ifname'] == "QinQ") {
183
					$found = true;
184
					break;
185
				}
186
			}
187
			$additions = "";
188
			foreach($nmembers as $qtag)
189
				$additions .= "{$qinqentry['vlanif']}_{$qtag} ";
190
			$additions .= "{$qinqentry['vlanif']}";
191
			if ($found == true)
192
				$config['ifgroups']['ifgroupentry'][$gid]['members'] .= " {$additions}";
193
			else {
194
				$gentry = array();
195
				$gentry['ifname'] = "QinQ";
196
				$gentry['members'] = "{$additions}";
197
				$gentry['descr'] = gettext("QinQ VLANs group");
198
				$config['ifgroups']['ifgroupentry'][] = $gentry;
199
			}
200
		}
201

    
202
		write_config();
203

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

    
213
include("head.inc");
214

    
215
?>
216

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

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

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

    
236
var field_counter_js = 0;
237
var loaded = 0;
238
var is_streaming_progress_bar = 0;
239
var temp_streaming_text = "";
240

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

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

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

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

    
273
	rowname[0] = <?=gettext("members");?>;
274
	rowtype[0] = "textbox";
275
	rowsize[0] = "30";
276

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

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

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

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

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

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

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

    
415
<?php include("fend.inc"); ?>
416
</body>
417
</html>
(108-108/249)