Project

General

Profile

Download (7.29 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
	All rights reserved.
9

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

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

    
16
	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

    
20
	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
/*
32
	pfSense_MODULE:	interfaces
33
*/
34

    
35
##|+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
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
/* add LAGG interfaces */
52
if (is_array($config['laggs']['lagg']) && count($config['laggs']['lagg'])) {
53
        foreach ($config['laggs']['lagg'] as $lagg)
54
                $portlist[$lagg['laggif']] = $lagg;
55
}
56

    
57
$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
	$pconfig['vlanif'] = $a_vlans[$id]['vlanif'];
64
	$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
	$reqdfields = explode(" ", "if tag");
75
	$reqdfieldsn = array(gettext("Parent interface"),gettext("VLAN tag"));
76

    
77
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
78

    
79
	if ($_POST['tag'] && (!is_numericint($_POST['tag']) || ($_POST['tag'] < '1') || ($_POST['tag'] > '4094'))) {
80
		$input_errors[] = gettext("The VLAN tag must be an integer between 1 and 4094.");
81
	}
82

    
83
	foreach ($a_vlans as $vlan) {
84
		if (isset($id) && ($a_vlans[$id]) && ($a_vlans[$id] === $vlan))
85
			continue;
86

    
87
		if (($vlan['if'] == $_POST['if']) && ($vlan['tag'] == $_POST['tag'])) {
88
			$input_errors[] = sprintf(gettext("A VLAN with the tag %s is already defined on this interface."),$vlan['tag']);
89
			break;
90
		}
91
	}
92
	if (is_array($config['qinqs']['qinqentry'])) {
93
		foreach ($config['qinqs']['qinqentry'] as $qinq)
94
			if ($qinq['tag'] == $_POST['tag'] && $qinq['if'] == $_POST['if'])
95
				$input_errors[] = gettext("A QinQ VLAN exists with this tag please remove it to use this tag with.");
96
	}
97

    
98
	if (!$input_errors) {
99
		if (isset($id) && $a_vlans[$id]) {
100
			if (($a_vlans[$id]['if'] != $_POST['if']) || ($a_vlans[$id]['tag'] != $_POST['tag'])) {
101
				if (!empty($a_vlans[$id]['vlanif']))
102
					// Destroy previous vlan
103
					pfSense_interface_destroy($a_vlans[$id]['vlanif']);
104
				else
105
					pfSense_interface_destroy("{$a_vlans[$id]['if']}_vlan{$a_vlans[$id]['tag']}");
106
			}
107
		}
108
		$vlan = array();
109
		$vlan['if'] = $_POST['if'];
110
		$vlan['tag'] = $_POST['tag'];
111
		$vlan['descr'] = $_POST['descr'];
112
		$vlan['vlanif'] = "{$_POST['if']}_vlan{$_POST['tag']}";
113

    
114
		$vlan['vlanif'] = interface_vlan_configure($vlan);
115
                if ($vlan['vlanif'] == "" || !stristr($vlan['vlanif'], "vlan"))
116
                        $input_errors[] = gettext("Error occured creating interface, please retry.");
117
                else {
118
                        if (isset($id) && $a_vlans[$id])
119
                                $a_vlans[$id] = $vlan;
120
                        else
121
                                $a_vlans[] = $vlan;
122

    
123
                        write_config();
124

    
125
			$confif = convert_real_interface_to_friendly_interface_name($vlan['vlanif']);
126
			if ($confif <> "")
127
				interface_configure($confif);
128
				
129
			header("Location: interfaces_vlan.php");
130
			exit;
131
		}
132
	}
133
}
134

    
135
$pgtitle = array(gettext("Interfaces"),gettext("VLAN"),gettext("Edit"));
136
include("head.inc");
137

    
138
?>
139

    
140
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
141
<?php include("fbegin.inc"); ?>
142
<?php if ($input_errors) print_input_errors($input_errors); ?>
143
            <form action="interfaces_vlan_edit.php" method="post" name="iform" id="iform">
144
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
145
				<tr>
146
					<td colspan="2" valign="top" class="listtopic"><?=gettext("VLAN configuration");?></td>
147
				</tr>
148
				<tr>
149
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Parent interface");?></td>
150
                  <td width="78%" class="vtable">
151
                    <select name="if" class="formselect">
152
                      <?php
153
					  foreach ($portlist as $ifn => $ifinfo)
154
						if (is_jumbo_capable($ifn)) {
155
							echo "<option value=\"{$ifn}\"";
156
							if ($ifn == $pconfig['if'])
157
								echo "selected";
158
							echo ">";
159
                      				        echo htmlspecialchars($ifn . " (" . $ifinfo['mac'] . ")");
160
                      					echo "</option>";
161
						}
162
		      ?>
163
                    </select>
164
			<br/>
165
			<span class="vexpl"><?=gettext("Only VLAN capable interfaces will be shown.");?></span></td>
166
                </tr>
167
				<tr>
168
                  <td valign="top" class="vncellreq"><?=gettext("VLAN tag ");?></td>
169
                  <td class="vtable">
170
                    <input name="tag" type="text" class="formfld unknown" id="tag" size="6" value="<?=htmlspecialchars($pconfig['tag']);?>">
171
                    <br>
172
                    <span class="vexpl"><?=gettext("802.1Q VLAN tag (between 1 and 4094) ");?></span></td>
173
			    </tr>
174
				<tr>
175
                  <td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
176
                  <td width="78%" class="vtable">
177
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
178
                    <br> <span class="vexpl"><?=gettext("You may enter a description here ".
179
                    "for your reference (not parsed).");?></span></td>
180
                </tr>
181
                <tr>
182
                  <td width="22%" valign="top">&nbsp;</td>
183
                  <td width="78%">
184
		    <input type="hidden" name="vlanif" value="<?=htmlspecialchars($pconfig['vlanif']); ?>">
185
                    <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>"> <input type="button" value="<?=gettext("Cancel");?>" onclick="history.back()">
186
                    <?php if (isset($id) && $a_vlans[$id]): ?>
187
                    <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>">
188
                    <?php endif; ?>
189
                  </td>
190
                </tr>
191
              </table>
192
</form>
193
<?php include("fend.inc"); ?>
194
</body>
195
</html>
(101-101/225)