Project

General

Profile

Download (8.32 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 29aef6c4 Jim Thompson
        Copyright (C) 2013-2014 Electric Sheep Fencing, LP
9 5b237745 Scott Ullrich
	All rights reserved.
10 de068d0b Scott Ullrich
11 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
12
	modification, are permitted provided that the following conditions are met:
13 de068d0b Scott Ullrich
14 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
15
	   this list of conditions and the following disclaimer.
16 de068d0b Scott Ullrich
17 5b237745 Scott Ullrich
	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 de068d0b Scott Ullrich
21 5b237745 Scott Ullrich
	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 7ac5a4cb Scott Ullrich
/*
33
	pfSense_MODULE:	interfaces
34
*/
35 5b237745 Scott Ullrich
36 6b07c15a Matthew Grooms
##|+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 5b237745 Scott Ullrich
require("guiconfig.inc");
44
45 62424bdb Renato Botelho
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/interfaces_vlan.php');
46
47 5b237745 Scott Ullrich
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 a0188aa6 Ermal Luci
/* add LAGG interfaces */
55
if (is_array($config['laggs']['lagg']) && count($config['laggs']['lagg'])) {
56 983271b3 Ermal Luci
        foreach ($config['laggs']['lagg'] as $lagg)
57 a0188aa6 Ermal Luci
                $portlist[$lagg['laggif']] = $lagg;
58
}
59
60 e41ec584 Renato Botelho
if (is_numericint($_GET['id']))
61
	$id = $_GET['id'];
62
if (isset($_POST['id']) && is_numericint($_POST['id']))
63 5b237745 Scott Ullrich
	$id = $_POST['id'];
64
65
if (isset($id) && $a_vlans[$id]) {
66
	$pconfig['if'] = $a_vlans[$id]['if'];
67 a3f9082f Ermal Luçi
	$pconfig['vlanif'] = $a_vlans[$id]['vlanif'];
68 5b237745 Scott Ullrich
	$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 cbdc84ea Rafael Lucas
	$reqdfields = explode(" ", "if tag");
79
	$reqdfieldsn = array(gettext("Parent interface"),gettext("VLAN tag"));
80 de068d0b Scott Ullrich
81 1e9b4611 Renato Botelho
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
82 de068d0b Scott Ullrich
83 5b237745 Scott Ullrich
	if ($_POST['tag'] && (!is_numericint($_POST['tag']) || ($_POST['tag'] < '1') || ($_POST['tag'] > '4094'))) {
84 c24e9a11 Rafael Lucas
		$input_errors[] = gettext("The VLAN tag must be an integer between 1 and 4094.");
85 5b237745 Scott Ullrich
	}
86
87 0e22dda5 Ermal
	if (!does_interface_exist($_POST['if']))
88
		$input_errors[] = gettext("Interface supplied as parent is invalid");
89
90 1ca626e7 Ermal
	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 5b237745 Scott Ullrich
	foreach ($a_vlans as $vlan) {
97
		if (isset($id) && ($a_vlans[$id]) && ($a_vlans[$id] === $vlan))
98
			continue;
99 de068d0b Scott Ullrich
100 5b237745 Scott Ullrich
		if (($vlan['if'] == $_POST['if']) && ($vlan['tag'] == $_POST['tag'])) {
101 c24e9a11 Rafael Lucas
			$input_errors[] = sprintf(gettext("A VLAN with the tag %s is already defined on this interface."),$vlan['tag']);
102 5b237745 Scott Ullrich
			break;
103 de068d0b Scott Ullrich
		}
104 5b237745 Scott Ullrich
	}
105 c6196310 Ermal Lu?i
	if (is_array($config['qinqs']['qinqentry'])) {
106
		foreach ($config['qinqs']['qinqentry'] as $qinq)
107
			if ($qinq['tag'] == $_POST['tag'] && $qinq['if'] == $_POST['if'])
108 c24e9a11 Rafael Lucas
				$input_errors[] = gettext("A QinQ VLAN exists with this tag please remove it to use this tag with.");
109 c6196310 Ermal Lu?i
	}
110 5b237745 Scott Ullrich
111
	if (!$input_errors) {
112 0f70d563 Ermal
		if (isset($id) && $a_vlans[$id]) {
113 695a35ae Ermal
			if (($a_vlans[$id]['if'] != $_POST['if']) || ($a_vlans[$id]['tag'] != $_POST['tag'])) {
114 b0d6223f Ermal
				if (!empty($a_vlans[$id]['vlanif'])) {
115
					$confif = convert_real_interface_to_friendly_interface_name($vlan['vlanif']);
116 6b421a0f Ermal
					// Destroy previous vlan
117
					pfSense_interface_destroy($a_vlans[$id]['vlanif']);
118 b0d6223f Ermal
				} else {
119 6b421a0f Ermal
					pfSense_interface_destroy("{$a_vlans[$id]['if']}_vlan{$a_vlans[$id]['tag']}");
120 b0d6223f Ermal
					$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 6b421a0f Ermal
			}
125 0f70d563 Ermal
		}
126 5b237745 Scott Ullrich
		$vlan = array();
127
		$vlan['if'] = $_POST['if'];
128
		$vlan['tag'] = $_POST['tag'];
129
		$vlan['descr'] = $_POST['descr'];
130 48315e65 Ermal Luci
		$vlan['vlanif'] = "{$_POST['if']}_vlan{$_POST['tag']}";
131 5b237745 Scott Ullrich
132 5f1e1d26 Ermal Lu?i
		$vlan['vlanif'] = interface_vlan_configure($vlan);
133 a3f9082f Ermal Luçi
                if ($vlan['vlanif'] == "" || !stristr($vlan['vlanif'], "vlan"))
134 ab9dc5be Chris Buechler
                        $input_errors[] = gettext("Error occurred creating interface, please retry.");
135 a3f9082f Ermal Luçi
                else {
136
                        if (isset($id) && $a_vlans[$id])
137
                                $a_vlans[$id] = $vlan;
138
                        else
139
                                $a_vlans[] = $vlan;
140 de068d0b Scott Ullrich
141 a3f9082f Ermal Luçi
                        write_config();
142 de068d0b Scott Ullrich
143 4476d447 Ermal Luçi
			if ($confif <> "")
144 69e5a8be Ermal Luçi
				interface_configure($confif);
145 d0c04a66 Ermal Luçi
				
146 a3f9082f Ermal Luçi
			header("Location: interfaces_vlan.php");
147
			exit;
148
		}
149 5b237745 Scott Ullrich
	}
150
}
151 7f43ca88 Scott Ullrich
152 baca83aa gnhb
$pgtitle = array(gettext("Interfaces"),gettext("VLAN"),gettext("Edit"));
153 b32dd0a6 jim-p
$shortcut_section = "interfaces";
154 7f43ca88 Scott Ullrich
include("head.inc");
155
156 5b237745 Scott Ullrich
?>
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 32bb88e5 Colin Fleming
              <table width="100%" border="0" cellpadding="6" cellspacing="0" summary="interfaces vlan edit">
163 5b237745 Scott Ullrich
				<tr>
164 c24e9a11 Rafael Lucas
					<td colspan="2" valign="top" class="listtopic"><?=gettext("VLAN configuration");?></td>
165 9dad4f31 Scott Ullrich
				</tr>
166
				<tr>
167 c24e9a11 Rafael Lucas
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Parent interface");?></td>
168 de068d0b Scott Ullrich
                  <td width="78%" class="vtable">
169 b5c78501 Seth Mos
                    <select name="if" class="formselect">
170 5b237745 Scott Ullrich
                      <?php
171 de068d0b Scott Ullrich
					  foreach ($portlist as $ifn => $ifinfo)
172 bc0caea7 Bill Marquette
						if (is_jumbo_capable($ifn)) {
173
							echo "<option value=\"{$ifn}\"";
174
							if ($ifn == $pconfig['if'])
175 32bb88e5 Colin Fleming
								echo " selected=\"selected\"";
176 bc0caea7 Bill Marquette
							echo ">";
177
                      				        echo htmlspecialchars($ifn . " (" . $ifinfo['mac'] . ")");
178
                      					echo "</option>";
179
						}
180
		      ?>
181
                    </select>
182 8cd558b6 ayvis
			<br />
183 c24e9a11 Rafael Lucas
			<span class="vexpl"><?=gettext("Only VLAN capable interfaces will be shown.");?></span></td>
184 5b237745 Scott Ullrich
                </tr>
185
				<tr>
186 c24e9a11 Rafael Lucas
                  <td valign="top" class="vncellreq"><?=gettext("VLAN tag ");?></td>
187 5b237745 Scott Ullrich
                  <td class="vtable">
188 32bb88e5 Colin Fleming
                    <input name="tag" type="text" class="formfld unknown" id="tag" size="6" value="<?=htmlspecialchars($pconfig['tag']);?>" />
189 8cd558b6 ayvis
                    <br />
190 c24e9a11 Rafael Lucas
                    <span class="vexpl"><?=gettext("802.1Q VLAN tag (between 1 and 4094) ");?></span></td>
191 5b237745 Scott Ullrich
			    </tr>
192
				<tr>
193 c24e9a11 Rafael Lucas
                  <td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
194 de068d0b Scott Ullrich
                  <td width="78%" class="vtable">
195 32bb88e5 Colin Fleming
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
196 8cd558b6 ayvis
                    <br /> <span class="vexpl"><?=gettext("You may enter a description here ".
197 83171778 Vinicius Coque
                    "for your reference (not parsed).");?></span></td>
198 5b237745 Scott Ullrich
                </tr>
199
                <tr>
200
                  <td width="22%" valign="top">&nbsp;</td>
201 de068d0b Scott Ullrich
                  <td width="78%">
202 32bb88e5 Colin Fleming
		    <input type="hidden" name="vlanif" value="<?=htmlspecialchars($pconfig['vlanif']); ?>" />
203 62424bdb Renato Botelho
                    <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 5b237745 Scott Ullrich
                    <?php if (isset($id) && $a_vlans[$id]): ?>
206 32bb88e5 Colin Fleming
                    <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
207 5b237745 Scott Ullrich
                    <?php endif; ?>
208
                  </td>
209
                </tr>
210
              </table>
211
</form>
212
<?php include("fend.inc"); ?>
213
</body>
214
</html>