Projet

Général

Profil

Télécharger (8,11 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / interfaces_vlan_edit.php @ fab1cd2f

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
if (is_numericint($_GET['id']))
58
	$id = $_GET['id'];
59
if (isset($_POST['id']) && is_numericint($_POST['id']))
60
	$id = $_POST['id'];
61

    
62
if (isset($id) && $a_vlans[$id]) {
63
	$pconfig['if'] = $a_vlans[$id]['if'];
64
	$pconfig['vlanif'] = $a_vlans[$id]['vlanif'];
65
	$pconfig['tag'] = $a_vlans[$id]['tag'];
66
	$pconfig['descr'] = $a_vlans[$id]['descr'];
67
}
68

    
69
if ($_POST) {
70

    
71
	unset($input_errors);
72
	$pconfig = $_POST;
73

    
74
	/* input validation */
75
	$reqdfields = explode(" ", "if tag");
76
	$reqdfieldsn = array(gettext("Parent interface"),gettext("VLAN tag"));
77

    
78
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
79

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

    
84
	if (!does_interface_exist($_POST['if']))
85
		$input_errors[] = gettext("Interface supplied as parent is invalid");
86

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

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

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

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

    
138
                        write_config();
139

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

    
149
$pgtitle = array(gettext("Interfaces"),gettext("VLAN"),gettext("Edit"));
150
$shortcut_section = "interfaces";
151
include("head.inc");
152

    
153
?>
154

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