Project

General

Profile

Download (6.2 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
$id = $_GET['id'];
50
if (isset($_POST['id']))
51
	$id = $_POST['id'];
52

    
53
if (isset($id) && $a_vlans[$id]) {
54
	$pconfig['if'] = $a_vlans[$id]['if'];
55
	$pconfig['vlanif'] = $a_vlans[$id]['vlanif'];
56
	$pconfig['tag'] = $a_vlans[$id]['tag'];
57
	$pconfig['descr'] = $a_vlans[$id]['descr'];
58
}
59

    
60
if ($_POST) {
61

    
62
	unset($input_errors);
63
	$pconfig = $_POST;
64

    
65
	/* input validation */
66
	$reqdfields = explode(" ", "if tag");
67
	$reqdfieldsn = explode(",", "Parent interface,VLAN tag");
68

    
69
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
70

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

    
75
	foreach ($a_vlans as $vlan) {
76
		if (isset($id) && ($a_vlans[$id]) && ($a_vlans[$id] === $vlan))
77
			continue;
78

    
79
		if (($vlan['if'] == $_POST['if']) && ($vlan['tag'] == $_POST['tag'])) {
80
			$input_errors[] = "A VLAN with the tag {$vlan['tag']} is already defined on this interface.";
81
			break;
82
		}
83
	}
84

    
85
	if (!$input_errors) {
86
		$vlan = array();
87
		$vlan['if'] = $_POST['if'];
88
		$vlan['tag'] = $_POST['tag'];
89
		$vlan['descr'] = $_POST['descr'];
90
		$vlan['vlanif'] = $_POST['vlanif'];
91

    
92
                $vlan['vlanif'] = interface_vlan_configure($vlan['if'], $vlan['tag'], $vlan['vlanif']);
93
                if ($vlan['vlanif'] == "" || !stristr($vlan['vlanif'], "vlan"))
94
                        $input_errors[] = "Error occured creating interface, please retry.";
95
                else {
96
                        if (isset($id) && $a_vlans[$id])
97
                                $a_vlans[$id] = $vlan;
98
                        else
99
                                $a_vlans[] = $vlan;
100

    
101
                        write_config();
102

    
103
			$confif = convert_real_interface_to_friendly_interface_name($vlan['vlanif']);
104
			if ($confif <> "")
105
				interface_configure($confif);
106
				
107
			header("Location: interfaces_vlan.php");
108
			exit;
109
		}
110
	}
111
}
112

    
113
$pgtitle = array("Firewall","VLAN","Edit");
114
include("head.inc");
115

    
116
?>
117

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