Projet

Général

Profil

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

univnautes / usr / local / www / interfaces_vlan_edit.php @ 62424bdb

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
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/interfaces_vlan.php');
45

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

    
49
$a_vlans = &$config['vlans']['vlan'];
50

    
51
$portlist = get_interface_list();
52

    
53
/* add LAGG interfaces */
54
if (is_array($config['laggs']['lagg']) && count($config['laggs']['lagg'])) {
55
        foreach ($config['laggs']['lagg'] as $lagg)
56
                $portlist[$lagg['laggif']] = $lagg;
57
}
58

    
59
if (is_numericint($_GET['id']))
60
	$id = $_GET['id'];
61
if (isset($_POST['id']) && is_numericint($_POST['id']))
62
	$id = $_POST['id'];
63

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

    
71
if ($_POST) {
72

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

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

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

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

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

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

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

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

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

    
140
                        write_config();
141

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

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

    
155
?>
156

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