Project

General

Profile

Download (5.79 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 a3f9082f Ermal Luçi
	$pconfig['vlanif'] = $a_vlans[$id]['vlanif'];
48 5b237745 Scott Ullrich
	$pconfig['tag'] = $a_vlans[$id]['tag'];
49
	$pconfig['descr'] = $a_vlans[$id]['descr'];
50
}
51
52
if ($_POST) {
53
54
	unset($input_errors);
55
	$pconfig = $_POST;
56
57
	/* input validation */
58
	$reqdfields = explode(" ", "if tag");
59
	$reqdfieldsn = explode(",", "Parent interface,VLAN tag");
60 de068d0b Scott Ullrich
61 5b237745 Scott Ullrich
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
62 de068d0b Scott Ullrich
63 5b237745 Scott Ullrich
	if ($_POST['tag'] && (!is_numericint($_POST['tag']) || ($_POST['tag'] < '1') || ($_POST['tag'] > '4094'))) {
64
		$input_errors[] = "The VLAN tag must be an integer between 1 and 4094.";
65
	}
66
67
	foreach ($a_vlans as $vlan) {
68
		if (isset($id) && ($a_vlans[$id]) && ($a_vlans[$id] === $vlan))
69
			continue;
70 de068d0b Scott Ullrich
71 5b237745 Scott Ullrich
		if (($vlan['if'] == $_POST['if']) && ($vlan['tag'] == $_POST['tag'])) {
72
			$input_errors[] = "A VLAN with the tag {$vlan['tag']} is already defined on this interface.";
73
			break;
74 de068d0b Scott Ullrich
		}
75 5b237745 Scott Ullrich
	}
76
77
	if (!$input_errors) {
78
		$vlan = array();
79
		$vlan['if'] = $_POST['if'];
80
		$vlan['tag'] = $_POST['tag'];
81
		$vlan['descr'] = $_POST['descr'];
82 28115e32 Ermal Luçi
		$vlan['vlanif'] = $_POST['vlanif'];
83 5b237745 Scott Ullrich
84 28115e32 Ermal Luçi
                $vlan['vlanif'] = interface_vlan_configure($vlan['if'], $vlan['tag'], $vlan['vlanif']);
85 a3f9082f Ermal Luçi
                if ($vlan['vlanif'] == "" || !stristr($vlan['vlanif'], "vlan"))
86
                        $input_errors[] = "Error occured creating interface, please retry.";
87
                else {
88
                        if (isset($id) && $a_vlans[$id])
89
                                $a_vlans[$id] = $vlan;
90
                        else
91
                                $a_vlans[] = $vlan;
92 de068d0b Scott Ullrich
93 a3f9082f Ermal Luçi
                        write_config();
94 de068d0b Scott Ullrich
95 a3f9082f Ermal Luçi
			header("Location: interfaces_vlan.php");
96
			exit;
97
		}
98 5b237745 Scott Ullrich
	}
99
}
100 7f43ca88 Scott Ullrich
101 d88c6a9f Scott Ullrich
$pgtitle = array("Firewall","VLAN","Edit");
102 7f43ca88 Scott Ullrich
include("head.inc");
103
104 5b237745 Scott Ullrich
?>
105
106
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
107
<?php include("fbegin.inc"); ?>
108
<?php if ($input_errors) print_input_errors($input_errors); ?>
109
            <form action="interfaces_vlan_edit.php" method="post" name="iform" id="iform">
110
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
111
				<tr>
112
                  <td width="22%" valign="top" class="vncellreq">Parent interface</td>
113 de068d0b Scott Ullrich
                  <td width="78%" class="vtable">
114 b5c78501 Seth Mos
                    <select name="if" class="formselect">
115 5b237745 Scott Ullrich
                      <?php
116 de068d0b Scott Ullrich
					  foreach ($portlist as $ifn => $ifinfo)
117 bc0caea7 Bill Marquette
						if (is_jumbo_capable($ifn)) {
118
							echo "<option value=\"{$ifn}\"";
119
							if ($ifn == $pconfig['if'])
120
								echo "selected";
121
							echo ">";
122
                      				        echo htmlspecialchars($ifn . " (" . $ifinfo['mac'] . ")");
123
                      					echo "</option>";
124
						}
125
		      ?>
126
                    </select>
127
			<br/>
128
			<span class="vexpl">Only VLAN capable interfaces will be shown.</span></td>
129 5b237745 Scott Ullrich
                </tr>
130
				<tr>
131
                  <td valign="top" class="vncellreq">VLAN tag </td>
132
                  <td class="vtable">
133 b5c78501 Seth Mos
                    <input name="tag" type="text" class="formfld unknown" id="tag" size="6" value="<?=htmlspecialchars($pconfig['tag']);?>">
134 5b237745 Scott Ullrich
                    <br>
135
                    <span class="vexpl">802.1Q VLAN tag (between 1 and 4094) </span></td>
136
			    </tr>
137
				<tr>
138
                  <td width="22%" valign="top" class="vncell">Description</td>
139 de068d0b Scott Ullrich
                  <td width="78%" class="vtable">
140 b5c78501 Seth Mos
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
141 5b237745 Scott Ullrich
                    <br> <span class="vexpl">You may enter a description here
142
                    for your reference (not parsed).</span></td>
143
                </tr>
144
                <tr>
145
                  <td width="22%" valign="top">&nbsp;</td>
146 de068d0b Scott Ullrich
                  <td width="78%">
147 28115e32 Ermal Luçi
		    <input type="hidden" name="vlanif" value="<?=$pconfig['vlanif']; ?>">
148 28b86d64 Scott Ullrich
                    <input name="Submit" type="submit" class="formbtn" value="Save"> <input type="button" value="Cancel" onclick="history.back()">
149 5b237745 Scott Ullrich
                    <?php if (isset($id) && $a_vlans[$id]): ?>
150
                    <input name="id" type="hidden" value="<?=$id;?>">
151
                    <?php endif; ?>
152
                  </td>
153
                </tr>
154
              </table>
155
</form>
156
<?php include("fend.inc"); ?>
157
</body>
158
</html>