Project

General

Profile

Download (14.1 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
        Copyright (C) 2013-2014 Electric Sheep Fencing, LP
4
	Copyright (C) 2009 Ermal Luçi
5
	All rights reserved.
6

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

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

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

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

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

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

    
43
require("guiconfig.inc");
44

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

    
48
$a_qinqs = &$config['qinqs']['qinqentry'];
49

    
50
$portlist = get_interface_list();
51

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

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

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

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

    
81
if ($_POST) {
82

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

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

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

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

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

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

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

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

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

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

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

    
204
		write_config();
205

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

    
215
include("head.inc");
216

    
217
?>
218

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

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

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

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

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

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

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

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

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

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

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

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

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

    
384
		} // end foreach
385
	} // end if
386
?>
387
        </tbody>
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="<?=gettext("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="<?=gettext("Save");?>" />
398
      <a href="interfaces_qinq.php"><input id="cancelbutton" name="cancelbutton" type="button" class="formbtn" value="<?=gettext("Cancel");?>" /></a>
399
      <?php if (isset($id) && $a_qinqs[$id]): ?>
400
      <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
401
      <?php endif; ?>
402
    </td>
403
  </tr>
404
</table>
405
</form>
406

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

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