Project

General

Profile

Download (8.32 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	interfaces_vlan_edit.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6

    
7
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
9
	All rights reserved.
10

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

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

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

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

    
36
##|+PRIV
37
##|*IDENT=page-interfaces-vlan-edit
38
##|*NAME=Interfaces: VLAN: Edit page
39
##|*DESCR=Allow access to the 'Interfaces: VLAN: Edit' page.
40
##|*MATCH=interfaces_vlan_edit.php*
41
##|-PRIV
42

    
43
require("guiconfig.inc");
44

    
45
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/interfaces_vlan.php');
46

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

    
50
$a_vlans = &$config['vlans']['vlan'];
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 (is_numericint($_GET['id']))
61
	$id = $_GET['id'];
62
if (isset($_POST['id']) && is_numericint($_POST['id']))
63
	$id = $_POST['id'];
64

    
65
if (isset($id) && $a_vlans[$id]) {
66
	$pconfig['if'] = $a_vlans[$id]['if'];
67
	$pconfig['vlanif'] = $a_vlans[$id]['vlanif'];
68
	$pconfig['tag'] = $a_vlans[$id]['tag'];
69
	$pconfig['descr'] = $a_vlans[$id]['descr'];
70
}
71

    
72
if ($_POST) {
73

    
74
	unset($input_errors);
75
	$pconfig = $_POST;
76

    
77
	/* input validation */
78
	$reqdfields = explode(" ", "if tag");
79
	$reqdfieldsn = array(gettext("Parent interface"),gettext("VLAN tag"));
80

    
81
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
82

    
83
	if (isset($_POST['tag']) && (!is_numericint($_POST['tag']) || ($_POST['tag'] < '1') || ($_POST['tag'] > '4094'))) {
84
		$input_errors[] = gettext("The VLAN tag must be an integer between 1 and 4094.");
85
	}
86

    
87
	if (!does_interface_exist($_POST['if']))
88
		$input_errors[] = gettext("Interface supplied as parent is invalid");
89

    
90
	if (isset($id)) {
91
		if ($_POST['tag'] && $_POST['tag'] != $a_vlans[$id]['tag']) {
92
			if (!empty($a_vlans[$id]['vlanif']) && convert_real_interface_to_friendly_interface_name($a_vlans[$id]['vlanif']) != NULL)
93
				$input_errors[] = gettext("Interface is assigned and you cannot change the VLAN tag while assigned.");
94
		}
95
	}
96
	foreach ($a_vlans as $vlan) {
97
		if (isset($id) && ($a_vlans[$id]) && ($a_vlans[$id] === $vlan))
98
			continue;
99

    
100
		if (($vlan['if'] == $_POST['if']) && ($vlan['tag'] == $_POST['tag'])) {
101
			$input_errors[] = sprintf(gettext("A VLAN with the tag %s is already defined on this interface."),$vlan['tag']);
102
			break;
103
		}
104
	}
105
	if (is_array($config['qinqs']['qinqentry'])) {
106
		foreach ($config['qinqs']['qinqentry'] as $qinq)
107
			if ($qinq['tag'] == $_POST['tag'] && $qinq['if'] == $_POST['if'])
108
				$input_errors[] = gettext("A QinQ VLAN exists with this tag please remove it to use this tag with.");
109
	}
110

    
111
	if (!$input_errors) {
112
		if (isset($id) && $a_vlans[$id]) {
113
			if (($a_vlans[$id]['if'] != $_POST['if']) || ($a_vlans[$id]['tag'] != $_POST['tag'])) {
114
				if (!empty($a_vlans[$id]['vlanif'])) {
115
					$confif = convert_real_interface_to_friendly_interface_name($vlan['vlanif']);
116
					// Destroy previous vlan
117
					pfSense_interface_destroy($a_vlans[$id]['vlanif']);
118
				} else {
119
					pfSense_interface_destroy("{$a_vlans[$id]['if']}_vlan{$a_vlans[$id]['tag']}");
120
					$confif = convert_real_interface_to_friendly_interface_name("{$a_vlans[$id]['if']}_vlan{$a_vlans[$id]['tag']}");
121
				}
122
				if ($confif <> "")
123
					$config['interfaces'][$confif]['if'] = "{$_POST['if']}_vlan{$_POST['tag']}";
124
			}
125
		}
126
		$vlan = array();
127
		$vlan['if'] = $_POST['if'];
128
		$vlan['tag'] = $_POST['tag'];
129
		$vlan['descr'] = $_POST['descr'];
130
		$vlan['vlanif'] = "{$_POST['if']}_vlan{$_POST['tag']}";
131

    
132
		$vlan['vlanif'] = interface_vlan_configure($vlan);
133
                if ($vlan['vlanif'] == "" || !stristr($vlan['vlanif'], "vlan"))
134
                        $input_errors[] = gettext("Error occurred creating interface, please retry.");
135
                else {
136
                        if (isset($id) && $a_vlans[$id])
137
                                $a_vlans[$id] = $vlan;
138
                        else
139
                                $a_vlans[] = $vlan;
140

    
141
                        write_config();
142

    
143
			if ($confif <> "")
144
				interface_configure($confif);
145
				
146
			header("Location: interfaces_vlan.php");
147
			exit;
148
		}
149
	}
150
}
151

    
152
$pgtitle = array(gettext("Interfaces"),gettext("VLAN"),gettext("Edit"));
153
$shortcut_section = "interfaces";
154
include("head.inc");
155

    
156
?>
157

    
158
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
159
<?php include("fbegin.inc"); ?>
160
<?php if ($input_errors) print_input_errors($input_errors); ?>
161
            <form action="interfaces_vlan_edit.php" method="post" name="iform" id="iform">
162
              <table width="100%" border="0" cellpadding="6" cellspacing="0" summary="interfaces vlan edit">
163
				<tr>
164
					<td colspan="2" valign="top" class="listtopic"><?=gettext("VLAN configuration");?></td>
165
				</tr>
166
				<tr>
167
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Parent interface");?></td>
168
                  <td width="78%" class="vtable">
169
                    <select name="if" class="formselect">
170
                      <?php
171
					  foreach ($portlist as $ifn => $ifinfo)
172
						if (is_jumbo_capable($ifn)) {
173
							echo "<option value=\"{$ifn}\"";
174
							if ($ifn == $pconfig['if'])
175
								echo " selected=\"selected\"";
176
							echo ">";
177
                      				        echo htmlspecialchars($ifn . " (" . $ifinfo['mac'] . ")");
178
                      					echo "</option>";
179
						}
180
		      ?>
181
                    </select>
182
			<br />
183
			<span class="vexpl"><?=gettext("Only VLAN capable interfaces will be shown.");?></span></td>
184
                </tr>
185
				<tr>
186
                  <td valign="top" class="vncellreq"><?=gettext("VLAN tag ");?></td>
187
                  <td class="vtable">
188
                    <input name="tag" type="text" class="formfld unknown" id="tag" size="6" value="<?=htmlspecialchars($pconfig['tag']);?>" />
189
                    <br />
190
                    <span class="vexpl"><?=gettext("802.1Q VLAN tag (between 1 and 4094) ");?></span></td>
191
			    </tr>
192
				<tr>
193
                  <td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
194
                  <td width="78%" class="vtable">
195
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
196
                    <br /> <span class="vexpl"><?=gettext("You may enter a description here ".
197
                    "for your reference (not parsed).");?></span></td>
198
                </tr>
199
                <tr>
200
                  <td width="22%" valign="top">&nbsp;</td>
201
                  <td width="78%">
202
		    <input type="hidden" name="vlanif" value="<?=htmlspecialchars($pconfig['vlanif']); ?>" />
203
                    <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
204
                    <input type="button" class="formbtn" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=$referer;?>'" />
205
                    <?php if (isset($id) && $a_vlans[$id]): ?>
206
                    <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
207
                    <?php endif; ?>
208
                  </td>
209
                </tr>
210
              </table>
211
</form>
212
<?php include("fend.inc"); ?>
213
</body>
214
</html>
(112-112/256)