Project

General

Profile

Download (8.05 KB) Statistics
| Branch: | Tag: | Revision:
1 de068d0b Scott Ullrich
<?php
2 b46bfcf5 Bill Marquette
/* $Id$ */
3 5b237745 Scott Ullrich
/*
4
	interfaces_vlan_edit.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6 de068d0b Scott Ullrich
7 5b237745 Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
	All rights reserved.
9 de068d0b Scott Ullrich
10 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12 de068d0b Scott Ullrich
13 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15 de068d0b Scott Ullrich
16 5b237745 Scott Ullrich
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19 de068d0b Scott Ullrich
20 5b237745 Scott Ullrich
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30
*/
31 7ac5a4cb Scott Ullrich
/*
32
	pfSense_MODULE:	interfaces
33
*/
34 5b237745 Scott Ullrich
35 6b07c15a Matthew Grooms
##|+PRIV
36
##|*IDENT=page-interfaces-vlan-edit
37
##|*NAME=Interfaces: VLAN: Edit page
38
##|*DESCR=Allow access to the 'Interfaces: VLAN: Edit' page.
39
##|*MATCH=interfaces_vlan_edit.php*
40
##|-PRIV
41
42 5b237745 Scott Ullrich
require("guiconfig.inc");
43
44
if (!is_array($config['vlans']['vlan']))
45
	$config['vlans']['vlan'] = array();
46
47
$a_vlans = &$config['vlans']['vlan'];
48
49
$portlist = get_interface_list();
50
51 a0188aa6 Ermal Luci
/* add LAGG interfaces */
52
if (is_array($config['laggs']['lagg']) && count($config['laggs']['lagg'])) {
53 983271b3 Ermal Luci
        foreach ($config['laggs']['lagg'] as $lagg)
54 a0188aa6 Ermal Luci
                $portlist[$lagg['laggif']] = $lagg;
55
}
56
57 5b237745 Scott Ullrich
$id = $_GET['id'];
58
if (isset($_POST['id']))
59
	$id = $_POST['id'];
60
61
if (isset($id) && $a_vlans[$id]) {
62
	$pconfig['if'] = $a_vlans[$id]['if'];
63 a3f9082f Ermal Luçi
	$pconfig['vlanif'] = $a_vlans[$id]['vlanif'];
64 5b237745 Scott Ullrich
	$pconfig['tag'] = $a_vlans[$id]['tag'];
65
	$pconfig['descr'] = $a_vlans[$id]['descr'];
66
}
67
68
if ($_POST) {
69
70
	unset($input_errors);
71
	$pconfig = $_POST;
72
73
	/* input validation */
74 cbdc84ea Rafael Lucas
	$reqdfields = explode(" ", "if tag");
75
	$reqdfieldsn = array(gettext("Parent interface"),gettext("VLAN tag"));
76 de068d0b Scott Ullrich
77 5b237745 Scott Ullrich
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
78 de068d0b Scott Ullrich
79 5b237745 Scott Ullrich
	if ($_POST['tag'] && (!is_numericint($_POST['tag']) || ($_POST['tag'] < '1') || ($_POST['tag'] > '4094'))) {
80 c24e9a11 Rafael Lucas
		$input_errors[] = gettext("The VLAN tag must be an integer between 1 and 4094.");
81 5b237745 Scott Ullrich
	}
82
83 0e22dda5 Ermal
	if (!does_interface_exist($_POST['if']))
84
		$input_errors[] = gettext("Interface supplied as parent is invalid");
85
86 9e768daf Ermal
	if (isset($id)) {
87
		if ($_POST['tag'] && $_POST['tag'] != $a_vlans[$id]['tag']) {
88
			if (!empty($a_vlans[$id]['vlanif']) && convert_real_interface_to_friendly_interface_name($a_vlans[$id]['vlanif']) != NULL)
89
				$input_errors[] = gettext("Interface is assigned and you cannot change the VLAN tag while assigned.");
90
		}
91
	}
92 5b237745 Scott Ullrich
	foreach ($a_vlans as $vlan) {
93
		if (isset($id) && ($a_vlans[$id]) && ($a_vlans[$id] === $vlan))
94
			continue;
95 de068d0b Scott Ullrich
96 5b237745 Scott Ullrich
		if (($vlan['if'] == $_POST['if']) && ($vlan['tag'] == $_POST['tag'])) {
97 c24e9a11 Rafael Lucas
			$input_errors[] = sprintf(gettext("A VLAN with the tag %s is already defined on this interface."),$vlan['tag']);
98 5b237745 Scott Ullrich
			break;
99 de068d0b Scott Ullrich
		}
100 5b237745 Scott Ullrich
	}
101 c6196310 Ermal Lu?i
	if (is_array($config['qinqs']['qinqentry'])) {
102
		foreach ($config['qinqs']['qinqentry'] as $qinq)
103
			if ($qinq['tag'] == $_POST['tag'] && $qinq['if'] == $_POST['if'])
104 c24e9a11 Rafael Lucas
				$input_errors[] = gettext("A QinQ VLAN exists with this tag please remove it to use this tag with.");
105 c6196310 Ermal Lu?i
	}
106 5b237745 Scott Ullrich
107
	if (!$input_errors) {
108 0f70d563 Ermal
		if (isset($id) && $a_vlans[$id]) {
109 695a35ae Ermal
			if (($a_vlans[$id]['if'] != $_POST['if']) || ($a_vlans[$id]['tag'] != $_POST['tag'])) {
110 b0d6223f Ermal
				if (!empty($a_vlans[$id]['vlanif'])) {
111
					$confif = convert_real_interface_to_friendly_interface_name($vlan['vlanif']);
112 6b421a0f Ermal
					// Destroy previous vlan
113
					pfSense_interface_destroy($a_vlans[$id]['vlanif']);
114 b0d6223f Ermal
				} else {
115 6b421a0f Ermal
					pfSense_interface_destroy("{$a_vlans[$id]['if']}_vlan{$a_vlans[$id]['tag']}");
116 b0d6223f Ermal
					$confif = convert_real_interface_to_friendly_interface_name("{$a_vlans[$id]['if']}_vlan{$a_vlans[$id]['tag']}");
117
				}
118
				if ($confif <> "")
119
					$config['interfaces'][$confif]['if'] = "{$_POST['if']}_vlan{$_POST['tag']}";
120 6b421a0f Ermal
			}
121 0f70d563 Ermal
		}
122 5b237745 Scott Ullrich
		$vlan = array();
123
		$vlan['if'] = $_POST['if'];
124
		$vlan['tag'] = $_POST['tag'];
125
		$vlan['descr'] = $_POST['descr'];
126 48315e65 Ermal Luci
		$vlan['vlanif'] = "{$_POST['if']}_vlan{$_POST['tag']}";
127 5b237745 Scott Ullrich
128 5f1e1d26 Ermal Lu?i
		$vlan['vlanif'] = interface_vlan_configure($vlan);
129 a3f9082f Ermal Luçi
                if ($vlan['vlanif'] == "" || !stristr($vlan['vlanif'], "vlan"))
130 e2967ba6 Chris Buechler
                        $input_errors[] = gettext("Error occurred creating interface, please retry.");
131 a3f9082f Ermal Luçi
                else {
132
                        if (isset($id) && $a_vlans[$id])
133
                                $a_vlans[$id] = $vlan;
134
                        else
135
                                $a_vlans[] = $vlan;
136 de068d0b Scott Ullrich
137 a3f9082f Ermal Luçi
                        write_config();
138 de068d0b Scott Ullrich
139 4476d447 Ermal Luçi
			if ($confif <> "")
140 69e5a8be Ermal Luçi
				interface_configure($confif);
141 d0c04a66 Ermal Luçi
				
142 a3f9082f Ermal Luçi
			header("Location: interfaces_vlan.php");
143
			exit;
144
		}
145 5b237745 Scott Ullrich
	}
146
}
147 7f43ca88 Scott Ullrich
148 baca83aa gnhb
$pgtitle = array(gettext("Interfaces"),gettext("VLAN"),gettext("Edit"));
149 b32dd0a6 jim-p
$shortcut_section = "interfaces";
150 7f43ca88 Scott Ullrich
include("head.inc");
151
152 5b237745 Scott Ullrich
?>
153
154
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
155
<?php include("fbegin.inc"); ?>
156
<?php if ($input_errors) print_input_errors($input_errors); ?>
157
            <form action="interfaces_vlan_edit.php" method="post" name="iform" id="iform">
158 32bb88e5 Colin Fleming
              <table width="100%" border="0" cellpadding="6" cellspacing="0" summary="interfaces vlan edit">
159 5b237745 Scott Ullrich
				<tr>
160 c24e9a11 Rafael Lucas
					<td colspan="2" valign="top" class="listtopic"><?=gettext("VLAN configuration");?></td>
161 9dad4f31 Scott Ullrich
				</tr>
162
				<tr>
163 c24e9a11 Rafael Lucas
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Parent interface");?></td>
164 de068d0b Scott Ullrich
                  <td width="78%" class="vtable">
165 b5c78501 Seth Mos
                    <select name="if" class="formselect">
166 5b237745 Scott Ullrich
                      <?php
167 de068d0b Scott Ullrich
					  foreach ($portlist as $ifn => $ifinfo)
168 bc0caea7 Bill Marquette
						if (is_jumbo_capable($ifn)) {
169
							echo "<option value=\"{$ifn}\"";
170
							if ($ifn == $pconfig['if'])
171 32bb88e5 Colin Fleming
								echo " selected=\"selected\"";
172 bc0caea7 Bill Marquette
							echo ">";
173
                      				        echo htmlspecialchars($ifn . " (" . $ifinfo['mac'] . ")");
174
                      					echo "</option>";
175
						}
176
		      ?>
177
                    </select>
178
			<br/>
179 c24e9a11 Rafael Lucas
			<span class="vexpl"><?=gettext("Only VLAN capable interfaces will be shown.");?></span></td>
180 5b237745 Scott Ullrich
                </tr>
181
				<tr>
182 c24e9a11 Rafael Lucas
                  <td valign="top" class="vncellreq"><?=gettext("VLAN tag ");?></td>
183 5b237745 Scott Ullrich
                  <td class="vtable">
184 32bb88e5 Colin Fleming
                    <input name="tag" type="text" class="formfld unknown" id="tag" size="6" value="<?=htmlspecialchars($pconfig['tag']);?>" />
185
                    <br/>
186 c24e9a11 Rafael Lucas
                    <span class="vexpl"><?=gettext("802.1Q VLAN tag (between 1 and 4094) ");?></span></td>
187 5b237745 Scott Ullrich
			    </tr>
188
				<tr>
189 c24e9a11 Rafael Lucas
                  <td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
190 de068d0b Scott Ullrich
                  <td width="78%" class="vtable">
191 32bb88e5 Colin Fleming
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
192
                    <br/> <span class="vexpl"><?=gettext("You may enter a description here ".
193 83171778 Vinicius Coque
                    "for your reference (not parsed).");?></span></td>
194 5b237745 Scott Ullrich
                </tr>
195
                <tr>
196
                  <td width="22%" valign="top">&nbsp;</td>
197 de068d0b Scott Ullrich
                  <td width="78%">
198 32bb88e5 Colin Fleming
		    <input type="hidden" name="vlanif" value="<?=htmlspecialchars($pconfig['vlanif']); ?>" />
199
                    <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" /> <input type="button" value="<?=gettext("Cancel");?>" onclick="history.back()" />
200 5b237745 Scott Ullrich
                    <?php if (isset($id) && $a_vlans[$id]): ?>
201 32bb88e5 Colin Fleming
                    <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
202 5b237745 Scott Ullrich
                    <?php endif; ?>
203
                  </td>
204
                </tr>
205
              </table>
206
</form>
207
<?php include("fend.inc"); ?>
208
</body>
209
</html>