Project

General

Profile

Download (5.8 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
	All rights reserved.
9 de068d0b Scott Ullrich
10 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12 de068d0b Scott Ullrich
13 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15 de068d0b Scott Ullrich
16 5b237745 Scott Ullrich
	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 de068d0b Scott Ullrich
20 5b237745 Scott Ullrich
	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
require("guiconfig.inc");
33
34
if (!is_array($config['vlans']['vlan']))
35
	$config['vlans']['vlan'] = array();
36
37
$a_vlans = &$config['vlans']['vlan'];
38
39
$portlist = get_interface_list();
40
41
$id = $_GET['id'];
42
if (isset($_POST['id']))
43
	$id = $_POST['id'];
44
45
if (isset($id) && $a_vlans[$id]) {
46
	$pconfig['if'] = $a_vlans[$id]['if'];
47
	$pconfig['tag'] = $a_vlans[$id]['tag'];
48
	$pconfig['descr'] = $a_vlans[$id]['descr'];
49
}
50
51
if ($_POST) {
52
53
	unset($input_errors);
54
	$pconfig = $_POST;
55
56
	/* input validation */
57
	$reqdfields = explode(" ", "if tag");
58
	$reqdfieldsn = explode(",", "Parent interface,VLAN tag");
59 de068d0b Scott Ullrich
60 5b237745 Scott Ullrich
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
61 de068d0b Scott Ullrich
62 5b237745 Scott Ullrich
	if ($_POST['tag'] && (!is_numericint($_POST['tag']) || ($_POST['tag'] < '1') || ($_POST['tag'] > '4094'))) {
63
		$input_errors[] = "The VLAN tag must be an integer between 1 and 4094.";
64
	}
65
66
	foreach ($a_vlans as $vlan) {
67
		if (isset($id) && ($a_vlans[$id]) && ($a_vlans[$id] === $vlan))
68
			continue;
69 de068d0b Scott Ullrich
70 5b237745 Scott Ullrich
		if (($vlan['if'] == $_POST['if']) && ($vlan['tag'] == $_POST['tag'])) {
71
			$input_errors[] = "A VLAN with the tag {$vlan['tag']} is already defined on this interface.";
72
			break;
73 de068d0b Scott Ullrich
		}
74 5b237745 Scott Ullrich
	}
75
76
	if (!$input_errors) {
77
		$vlan = array();
78
		$vlan['if'] = $_POST['if'];
79
		$vlan['tag'] = $_POST['tag'];
80
		$vlan['descr'] = $_POST['descr'];
81
82
		if (isset($id) && $a_vlans[$id])
83
			$a_vlans[$id] = $vlan;
84
		else
85
			$a_vlans[] = $vlan;
86 de068d0b Scott Ullrich
87
		write_config();
88
89 124ea6b8 Chris Buechler
		/* TODO sometime post-1.2 release
90
		this does not always work, some systems require
91
		a reboot before VLANs function properly
92
		
93
		This portion of code is also very slow, this is why
94
		it takes a long time to add a new VLAN.
95
		Benchmark_Timer on a 800 MHz VIA: 
96
			interfaces_lan_configure() takes about 6 seconds 
97
			interfaces_wan_configure() takes about 9.5 seconds
98
			interfaces_optional_configure() takes about 5 seconds
99
		*/
100
		
101 f6f3b7e0 Chris Buechler
		mwexec("touch /tmp/vlanchanged");
102
		
103 de068d0b Scott Ullrich
		interfaces_vlan_configure();
104 4b7d5741 Scott Ullrich
		interfaces_lan_configure();
105
		interfaces_wan_configure();
106
		interfaces_optional_configure();
107 de068d0b Scott Ullrich
108 5b237745 Scott Ullrich
		header("Location: interfaces_vlan.php");
109
		exit;
110
	}
111
}
112 7f43ca88 Scott Ullrich
113
$pgtitle = "Firewall: VLAN: Edit";
114
include("head.inc");
115
116 5b237745 Scott Ullrich
?>
117
118
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
119
<?php include("fbegin.inc"); ?>
120 ccff927c Bill Marquette
<p class="pgtitle"><?=$pgtitle?></p>
121 5b237745 Scott Ullrich
<?php if ($input_errors) print_input_errors($input_errors); ?>
122
            <form action="interfaces_vlan_edit.php" method="post" name="iform" id="iform">
123
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
124
				<tr>
125
                  <td width="22%" valign="top" class="vncellreq">Parent interface</td>
126 de068d0b Scott Ullrich
                  <td width="78%" class="vtable">
127 5b237745 Scott Ullrich
                    <select name="if" class="formfld">
128
                      <?php
129 de068d0b Scott Ullrich
					  foreach ($portlist as $ifn => $ifinfo)
130 bc0caea7 Bill Marquette
						if (is_jumbo_capable($ifn)) {
131
							echo "<option value=\"{$ifn}\"";
132
							if ($ifn == $pconfig['if'])
133
								echo "selected";
134
							echo ">";
135
                      				        echo htmlspecialchars($ifn . " (" . $ifinfo['mac'] . ")");
136
                      					echo "</option>";
137
						}
138
		      ?>
139
                    </select>
140
			<br/>
141
			<span class="vexpl">Only VLAN capable interfaces will be shown.</span></td>
142 5b237745 Scott Ullrich
                </tr>
143
				<tr>
144
                  <td valign="top" class="vncellreq">VLAN tag </td>
145
                  <td class="vtable">
146
                    <input name="tag" type="text" class="formfld" id="tag" size="6" value="<?=htmlspecialchars($pconfig['tag']);?>">
147
                    <br>
148
                    <span class="vexpl">802.1Q VLAN tag (between 1 and 4094) </span></td>
149
			    </tr>
150
				<tr>
151
                  <td width="22%" valign="top" class="vncell">Description</td>
152 de068d0b Scott Ullrich
                  <td width="78%" class="vtable">
153 5b237745 Scott Ullrich
                    <input name="descr" type="text" class="formfld" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
154
                    <br> <span class="vexpl">You may enter a description here
155
                    for your reference (not parsed).</span></td>
156
                </tr>
157
                <tr>
158
                  <td width="22%" valign="top">&nbsp;</td>
159 de068d0b Scott Ullrich
                  <td width="78%">
160 28b86d64 Scott Ullrich
                    <input name="Submit" type="submit" class="formbtn" value="Save"> <input type="button" value="Cancel" onclick="history.back()">
161 5b237745 Scott Ullrich
                    <?php if (isset($id) && $a_vlans[$id]): ?>
162
                    <input name="id" type="hidden" value="<?=$id;?>">
163
                    <?php endif; ?>
164
                  </td>
165
                </tr>
166
              </table>
167
</form>
168
<?php include("fend.inc"); ?>
169
</body>
170
</html>