Project

General

Profile

Download (14.1 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	interfaces_qinq_edit.php
4

    
5
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
6
	Copyright (C) 2009 Ermal Luçi
7
	All rights reserved.
8

    
9
	Redistribution and use in source and binary forms, with or without
10
	modification, are permitted provided that the following conditions are met:
11

    
12
	1. Redistributions of source code must retain the above copyright notice,
13
	   this list of conditions and the following disclaimer.
14

    
15
	2. Redistributions in binary form must reproduce the above copyright
16
	   notice, this list of conditions and the following disclaimer in the
17
	   documentation and/or other materials provided with the distribution.
18

    
19
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
20
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
23
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
	POSSIBILITY OF SUCH DAMAGE.
29
*/
30
/*
31
	pfSense_BUILDER_BINARIES:	/usr/sbin/ngctl	
32
	pfSense_MODULE:	interfaces
33
*/
34

    
35
##|+PRIV
36
##|*IDENT=page-interfaces-qinq-edit
37
##|*NAME=Interfaces: QinQ: Edit page
38
##|*DESCR=Allow access to 'Interfaces: QinQ: Edit' page
39
##|*MATCH=interfaces_qinq_edit.php*
40
##|-PRIV
41

    
42
$pgtitle = array(gettext("Interfaces"),gettext("QinQ"), gettext("Edit"));
43
$shortcut_section = "interfaces";
44

    
45
require("guiconfig.inc");
46

    
47
if (!is_array($config['qinqs']['qinqentry']))
48
	$config['qinqs']['qinqentry'] = array();
49

    
50
$a_qinqs = &$config['qinqs']['qinqentry'];
51

    
52
$portlist = get_interface_list();
53

    
54
/* add LAGG interfaces */
55
if (is_array($config['laggs']['lagg']) && count($config['laggs']['lagg'])) {
56
        foreach ($config['laggs']['lagg'] as $lagg)
57
                $portlist[$lagg['laggif']] = $lagg;
58
}
59

    
60
if (count($portlist) < 1) {
61
	header("Location: interfaces_qinq.php");
62
	exit;
63
}
64

    
65
if (is_numericint($_GET['id']))
66
	$id = $_GET['id'];
67
if (isset($_POST['id']) && is_numericint($_POST['id']))
68
	$id = $_POST['id'];
69

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

    
83
if ($_POST) {
84

    
85
	unset($input_errors);
86
	$pconfig = $_POST;
87

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

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

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

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

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

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

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

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

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

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

    
206
		write_config();
207

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

    
217
include("head.inc");
218

    
219
?>
220

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

    
224
<script type="text/javascript">
225
//<![CDATA[
226
// Global Variables
227
var rowname = new Array(9999);
228
var rowtype = new Array(9999);
229
var newrow  = new Array(9999);
230
var rowsize = new Array(9999);
231

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

    
239
var field_counter_js = 0;
240
var loaded = 0;
241
var is_streaming_progress_bar = 0;
242
var temp_streaming_text = "";
243

    
244
var addRowTo = (function() {
245
    return (function (tableId) {
246
        var d, tbody, tr, td, bgc, i, ii, j;
247
        d = document;
248
        tbody = d.getElementById(tableId).getElementsByTagName("tbody").item(0);
249
        tr = d.createElement("tr");
250
        for (i = 0; i < field_counter_js; i++) {
251
                td = d.createElement("td");
252
		td.innerHTML="<input type='hidden' value='" + totalrows +"' name='" + rowname[i] + "_row-" + totalrows + "' /><input size='" + rowsize[i] + "' class='formfld unknown' name='" + rowname[i] + totalrows + "' /> ";
253
                tr.appendChild(td);
254
        }
255
        td = d.createElement("td");
256
        td.rowSpan = "1";
257

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

    
265
function removeRow(el) {
266
    var cel;
267
    while (el && el.nodeName.toLowerCase() != "tr")
268
            el = el.parentNode;
269

    
270
    if (el && el.parentNode) {
271
        cel = el.getElementsByTagName("td").item(0);
272
        el.parentNode.removeChild(el);
273
    }
274
}
275

    
276
	rowname[0] = <?=gettext("members");?>;
277
	rowtype[0] = "textbox";
278
	rowsize[0] = "30";
279

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

    
287
<?php if ($input_errors) print_input_errors($input_errors); ?>
288
<div id="inputerrors"></div>
289

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

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

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

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

    
418
<?php include("fend.inc"); ?>
419
</body>
420
</html>
(110-110/256)