Project

General

Profile

Download (6.64 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
##|+PRIV
33
##|*IDENT=page-interfaces-vlan-edit
34
##|*NAME=Interfaces: VLAN: Edit page
35
##|*DESCR=Allow access to the 'Interfaces: VLAN: Edit' page.
36
##|*MATCH=interfaces_vlan_edit.php*
37
##|-PRIV
38

    
39

    
40
require("guiconfig.inc");
41

    
42
if (!is_array($config['vlans']['vlan']))
43
	$config['vlans']['vlan'] = array();
44

    
45
$a_vlans = &$config['vlans']['vlan'];
46

    
47
$portlist = get_interface_list();
48

    
49
/* add LAGG interfaces */
50
if (is_array($config['laggs']['lagg']) && count($config['laggs']['lagg'])) {
51
        foreach ($config['laggs']['lagg'] as $lagg)
52
                $portlist[$lagg['laggif']] = $lagg;
53
}
54

    
55
$id = $_GET['id'];
56
if (isset($_POST['id']))
57
	$id = $_POST['id'];
58

    
59
if (isset($id) && $a_vlans[$id]) {
60
	$pconfig['if'] = $a_vlans[$id]['if'];
61
	$pconfig['vlanif'] = $a_vlans[$id]['vlanif'];
62
	$pconfig['tag'] = $a_vlans[$id]['tag'];
63
	$pconfig['descr'] = $a_vlans[$id]['descr'];
64
}
65

    
66
if ($_POST) {
67

    
68
	unset($input_errors);
69
	$pconfig = $_POST;
70

    
71
	/* input validation */
72
	$reqdfields = explode(" ", "if tag");
73
	$reqdfieldsn = explode(",", "Parent interface,VLAN tag");
74

    
75
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
76

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

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

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

    
96
	if (!$input_errors) {
97
		$vlan = array();
98
		$vlan['if'] = $_POST['if'];
99
		$vlan['tag'] = $_POST['tag'];
100
		$vlan['descr'] = $_POST['descr'];
101
		$vlan['vlanif'] = "{$_POST['if']}.vlan{$_POST['tag']}";
102

    
103
		$vlan['vlanif'] = interface_vlan_configure($vlan);
104
                if ($vlan['vlanif'] == "" || !stristr($vlan['vlanif'], "vlan"))
105
                        $input_errors[] = "Error occured creating interface, please retry.";
106
                else {
107
                        if (isset($id) && $a_vlans[$id])
108
                                $a_vlans[$id] = $vlan;
109
                        else
110
                                $a_vlans[] = $vlan;
111

    
112
                        write_config();
113

    
114
			$confif = convert_real_interface_to_friendly_interface_name($vlan['vlanif']);
115
			if ($confif <> "")
116
				interface_configure($confif);
117
				
118
			header("Location: interfaces_vlan.php");
119
			exit;
120
		}
121
	}
122
}
123

    
124
$pgtitle = array("Firewall","VLAN","Edit");
125
include("head.inc");
126

    
127
?>
128

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