Project

General

Profile

Download (6.16 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * interfaces_vlan.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8
 * Copyright (c) 2014-2024 Rubicon Communications, LLC (Netgate)
9
 * All rights reserved.
10
 *
11
 * originally based on m0n0wall (http://m0n0.ch/wall)
12
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
13
 * All rights reserved.
14
 *
15
 * Licensed under the Apache License, Version 2.0 (the "License");
16
 * you may not use this file except in compliance with the License.
17
 * You may obtain a copy of the License at
18
 *
19
 * http://www.apache.org/licenses/LICENSE-2.0
20
 *
21
 * Unless required by applicable law or agreed to in writing, software
22
 * distributed under the License is distributed on an "AS IS" BASIS,
23
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
 * See the License for the specific language governing permissions and
25
 * limitations under the License.
26
 */
27

    
28
##|+PRIV
29
##|*IDENT=page-interfaces-vlan
30
##|*NAME=Interfaces: VLAN
31
##|*DESCR=Allow access to the 'Interfaces: VLAN' page.
32
##|*MATCH=interfaces_vlan.php*
33
##|-PRIV
34

    
35
require_once("guiconfig.inc");
36
require_once("interfaces_fast.inc");
37

    
38
global $profile;
39

    
40
config_init_path('vlans/vlan');
41

    
42
if ($_POST['act'] == "del") {
43
	/*
44
	 * Check user privileges to test if the user is allowed to make changes.
45
	 * Otherwise users can end up in an inconsistent state where some changes are
46
	 * performed and others denied. See https://redmine.pfsense.org/issues/15282
47
	 */
48
	phpsession_begin();
49
	$guiuser = getUserEntry($_SESSION['Username']);
50
	$read_only = (is_array($guiuser) && userHasPrivilege($guiuser, "user-config-readonly"));
51
	phpsession_end();
52

    
53
	if ($read_only) {
54
		$input_errors = array(gettext("Insufficient privileges to make the requested change (read only)."));
55
	}
56

    
57
	$this_vlan_config = config_get_path("vlans/vlan/{$_POST['id']}");
58
	if (!isset($_POST['id'])) {
59
		$input_errors[] = gettext("Wrong parameters supplied");
60
	} else if (empty($this_vlan_config)) {
61
		$input_errors[] = gettext("Wrong index supplied");
62
	/* check if still in use */
63
	} else if (vlan_inuse($this_vlan_config)) {
64
		$input_errors[] = gettext("This VLAN cannot be deleted because it is still being used as an interface.");
65
	}
66

    
67
	if (!$input_errors) {
68
		if (does_interface_exist($this_vlan_config['vlanif'])) {
69
			pfSense_interface_destroy($this_vlan_config['vlanif']);
70
		}
71
		config_del_path("vlans/vlan/{$_POST['id']}");
72

    
73
		write_config("VLAN interface deleted");
74

    
75
		header("Location: interfaces_vlan.php");
76
		exit;
77
	}
78
}
79

    
80

    
81
$pgtitle = array(gettext("Interfaces"), gettext("VLANs"));
82
$shortcut_section = "interfaces";
83
include('head.inc');
84

    
85
if ($input_errors) print_input_errors($input_errors);
86

    
87
$tab_array = array();
88
$tab_array[] = array(gettext("Interface Assignments"), false, "interfaces_assign.php");
89
$tab_array[] = array(gettext("Interface Groups"), false, "interfaces_groups.php");
90
$tab_array[] = array(gettext("Wireless"), false, "interfaces_wireless.php");
91
$tab_array[] = array(gettext("VLANs"), true, "interfaces_vlan.php");
92
$tab_array[] = array(gettext("QinQs"), false, "interfaces_qinq.php");
93
$tab_array[] = array(gettext("PPPs"), false, "interfaces_ppps.php");
94
$tab_array[] = array(gettext("GREs"), false, "interfaces_gre.php");
95
$tab_array[] = array(gettext("GIFs"), false, "interfaces_gif.php");
96
$tab_array[] = array(gettext("Bridges"), false, "interfaces_bridge.php");
97
$tab_array[] = array(gettext("LAGGs"), false, "interfaces_lagg.php");
98
display_top_tabs($tab_array);
99

    
100
?>
101
<form action="interfaces_vlan.php" method="post">
102
	<input id="act" type="hidden" name="act" value="" />
103
	<input id="id" type="hidden" name="id" value=""/>
104

    
105
	<div class="panel panel-default">
106
		<div class="panel-heading"><h2 class="panel-title"><?=gettext('VLAN Interfaces')?></h2></div>
107
		<div class="panel-body">
108
			<div class="table-responsive">
109
				<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap table-rowdblclickedit" data-sortable>
110
					<thead>
111
						<tr>
112
							<th><?=gettext('Interface');?></th>
113
							<th><?=gettext('VLAN tag');?></th>
114
							<th><?=gettext('Priority');?></th>
115
							<th><?=gettext('Description');?></th>
116
							<th><?=gettext('Actions');?></th>
117
						</tr>
118
					</thead>
119
					<tbody>
120
<?php
121
	$i = 0;
122
	$gettext_array = array('edit'=>gettext('Edit VLAN'),'del'=>gettext('Delete VLAN'));
123
	$ifaces = convert_real_interface_to_friendly_interface_name_fast();
124
	foreach (config_get_path('vlans/vlan', []) as $vlan) {
125
?>
126
						<tr>
127
							<td>
128
<?php
129
	printf("%s", htmlspecialchars($vlan['if']));
130
	if (isset($ifaces[$vlan['if']]) && strlen($ifaces[$vlan['if']]) > 0)
131
		printf(" (%s)", htmlspecialchars($ifaces[$vlan['if']]));
132
?>
133
							</td>
134
							<td><?=htmlspecialchars($vlan['tag']);?></td>
135
							<td><?=htmlspecialchars($vlan['pcp']);?></td>
136
							<td><?=htmlspecialchars($vlan['descr']);?></td>
137
							<td>
138
								<a class="fa-solid fa-pencil"	title="<?=$gettext_array['edit']?>"	role="button" href="interfaces_vlan_edit.php?id=<?=$i?>" ></a>
139
								<a class="fa-solid fa-trash-can no-confirm"	title="<?=$gettext_array['del']?>"	role="button" id="del-<?=$i?>"></a>
140
							</td>
141
						</tr>
142
<?php
143
			$i++;
144
	}
145
?>
146
					</tbody>
147
				</table>
148
			</div>
149
		</div>
150
	</div>
151

    
152
	<nav class="action-buttons">
153
		<a class="btn btn-success btn-sm" role="button" href="interfaces_vlan_edit.php">
154
			<i class="fa-solid fa-plus icon-embed-btn"></i>
155
			<?=gettext('Add'); ?>
156
		</a>
157
	</nav>
158

    
159
</form>
160

    
161
<div class="infoblock">
162
	<?php print_info_box(sprintf(gettext('Not all drivers/NICs support 802.1Q '.
163
		'VLAN tagging properly. %1$sOn cards that do not explicitly support it, VLAN '.
164
		'tagging will still work, but the reduced MTU may cause problems.%1$sSee the '.
165
		'%2$s handbook for information on supported cards.'), '<br />', g_get('product_label')), 'info', false); ?>
166
</div>
167

    
168
<?php
169
	$delmsg = gettext("Are you sure you want to delete this VLAN?");
170
?>
171

    
172
<script type="text/javascript">
173
//<![CDATA[
174
events.push(function() {
175
	// Select 'delete button' clicks, extract the id, set the hidden input values and submit
176
	$('[id^=del-]').click(function(event) {
177
		if (confirm("<?=$delmsg?>")) {
178
			$('#act').val('del');
179
			$('#id').val(this.id.replace("del-", ""));
180
			$(this).parents('form').submit();
181
		}
182
	});
183

    
184
});
185
//]]>
186
</script>
187
<?php
188
include("foot.inc");
(89-89/232)