Project

General

Profile

Download (5.32 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php 
3
/* $Id$ */
4
/*
5
	interfaces_vlan_edit.php
6
	part of m0n0wall (http://m0n0.ch/wall)
7
	
8
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
9
	All rights reserved.
10
	
11
	Redistribution and use in source and binary forms, with or without
12
	modification, are permitted provided that the following conditions are met:
13
	
14
	1. Redistributions of source code must retain the above copyright notice,
15
	   this list of conditions and the following disclaimer.
16
	
17
	2. Redistributions in binary form must reproduce the above copyright
18
	   notice, this list of conditions and the following disclaimer in the
19
	   documentation and/or other materials provided with the distribution.
20
	
21
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
22
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
23
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
25
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
	POSSIBILITY OF SUCH DAMAGE.
31
*/
32

    
33
require("guiconfig.inc");
34

    
35
if (!is_array($config['vlans']['vlan']))
36
	$config['vlans']['vlan'] = array();
37

    
38
$a_vlans = &$config['vlans']['vlan'];
39

    
40
$portlist = get_interface_list();
41

    
42
$id = $_GET['id'];
43
if (isset($_POST['id']))
44
	$id = $_POST['id'];
45

    
46
if (isset($id) && $a_vlans[$id]) {
47
	$pconfig['if'] = $a_vlans[$id]['if'];
48
	$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
	
61
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
62
	
63
	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
		
71
		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
		}	
75
	}
76

    
77
	if (!$input_errors) {
78
		$vlan = array();
79
		$vlan['if'] = $_POST['if'];
80
		$vlan['tag'] = $_POST['tag'];
81
		$vlan['descr'] = $_POST['descr'];
82

    
83
		if (isset($id) && $a_vlans[$id])
84
			$a_vlans[$id] = $vlan;
85
		else
86
			$a_vlans[] = $vlan;
87
		
88
		write_config();		
89
		
90
		reload_interfaces();
91
		
92
		header("Location: interfaces_vlan.php");
93
		exit;
94
	}
95
}
96

    
97
$pgtitle = "Firewall: VLAN: Edit";
98
include("head.inc");
99

    
100
?>
101

    
102
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
103
<?php include("fbegin.inc"); ?>
104
<p class="pgtitle"><?=$pgtitle?></p>
105
<?php if ($input_errors) print_input_errors($input_errors); ?>
106
            <form action="interfaces_vlan_edit.php" method="post" name="iform" id="iform">
107
              <?display_topbar()?>
108
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
109
				<tr>
110
                  <td width="22%" valign="top" class="vncellreq">Parent interface</td>
111
                  <td width="78%" class="vtable"> 
112
                    <select name="if" class="formfld">
113
                      <?php
114
					  foreach ($portlist as $ifn => $ifinfo) 
115
						if (is_jumbo_capable($ifn)) {
116
							echo "<option value=\"{$ifn}\"";
117
							if ($ifn == $pconfig['if'])
118
								echo "selected";
119
							echo ">";
120
                      				        echo htmlspecialchars($ifn . " (" . $ifinfo['mac'] . ")");
121
                      					echo "</option>";
122
						}
123
		      ?>
124
                    </select>
125
			<br/>
126
			<span class="vexpl">Only VLAN capable interfaces will be shown.</span></td>
127
                </tr>
128
				<tr>
129
                  <td valign="top" class="vncellreq">VLAN tag </td>
130
                  <td class="vtable">
131
                    <input name="tag" type="text" class="formfld" id="tag" size="6" value="<?=htmlspecialchars($pconfig['tag']);?>">
132
                    <br>
133
                    <span class="vexpl">802.1Q VLAN tag (between 1 and 4094) </span></td>
134
			    </tr>
135
				<tr>
136
                  <td width="22%" valign="top" class="vncell">Description</td>
137
                  <td width="78%" class="vtable"> 
138
                    <input name="descr" type="text" class="formfld" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
139
                    <br> <span class="vexpl">You may enter a description here
140
                    for your reference (not parsed).</span></td>
141
                </tr>
142
                <tr>
143
                  <td width="22%" valign="top">&nbsp;</td>
144
                  <td width="78%"> 
145
                    <input name="Submit" type="submit" class="formbtn" value="Save"> <input type="button" value="Cancel" onclick="history.back()">
146
                    <?php if (isset($id) && $a_vlans[$id]): ?>
147
                    <input name="id" type="hidden" value="<?=$id;?>">
148
                    <?php endif; ?>
149
                  </td>
150
                </tr>
151
              </table>
152
</form>
153
<?php include("fend.inc"); ?>
154
</body>
155
</html>
(64-64/147)