Project

General

Profile

Download (14.1 KB) Statistics
| Branch: | Tag: | Revision:

univnautes / usr / local / www / interfaces_qinq_edit.php @ a1b66bec

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-interfaces-qinq-edit
34
##|*NAME=Interfaces: QinQ: Edit page
35
##|*DESCR=Allow access to 'Interfaces: QinQ: Edit' page
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
if (is_numericint($_GET['id']))
63
	$id = $_GET['id'];
64
if (isset($_POST['id']) && is_numericint($_POST['id']))
65
	$id = $_POST['id'];
66

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

    
80
if ($_POST) {
81

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

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

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

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

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

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

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

    
151
		if (isset($id) && $a_qinqs[$id]) {
152
			$omembers = explode(" ", $a_qinqs[$id]['members']);
153
			$delmembers = array_diff($omembers, $nmembers);
154
			$addmembers = array_diff($nmembers, $omembers);
155

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

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

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

    
203
		write_config();
204

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

    
214
include("head.inc");
215

    
216
?>
217

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

    
221
<script type="text/javascript">
222
//<![CDATA[
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 size='" + rowsize[i] + "' class='formfld unknown' name='" + rowname[i] + totalrows + "' /> ";
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" alt="remove" /><\/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
//]]>
281
</script>
282
<input type='hidden' name='members_type' value='textbox' class="formfld unknown" />
283

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

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

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

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

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

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