Project

General

Profile

Download (8.6 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php 
3
/*
4
	interfaces_assign.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6
	Written by Jim McBeath based on existing m0n0wall files
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
/*
36
	In this file, "port" refers to the physical port name,
37
	while "interface" refers to LAN, WAN, or OPTn.
38
*/
39

    
40
/* get list without VLAN interfaces */
41
$portlist = get_interface_list();
42

    
43
/* add VLAN interfaces */
44
if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) {
45
	$i = 0;
46
	foreach ($config['vlans']['vlan'] as $vlan) {
47
		$portlist['vlan' . $i] = $vlan;
48
		$portlist['vlan' . $i]['isvlan'] = true;
49
		$i++;
50
	}
51
}
52

    
53
if ($_POST) {
54

    
55
	unset($input_errors);
56

    
57
	/* input validation */
58

    
59
	/* Build a list of the port names so we can see how the interfaces map */
60
	$portifmap = array();
61
	foreach ($portlist as $portname => $portinfo)
62
		$portifmap[$portname] = array();
63

    
64
	/* Go through the list of ports selected by the user,
65
	   build a list of port-to-interface mappings in portifmap */
66
	foreach ($_POST as $ifname => $ifport) {
67
		if (($ifname == 'lan') || ($ifname == 'wan') || (substr($ifname, 0, 3) == 'opt'))
68
			$portifmap[$ifport][] = strtoupper($ifname);
69
	}
70

    
71
	/* Deliver error message for any port with more than one assignment */
72
	foreach ($portifmap as $portname => $ifnames) {
73
		if (count($ifnames) > 1) {
74
			$errstr = "Port " . $portname .
75
				" was assigned to " . count($ifnames) .
76
				" interfaces:";
77
				
78
			foreach ($portifmap[$portname] as $ifn)
79
				$errstr .= " " . $ifn;
80
			
81
			$input_errors[] = $errstr;
82
		}
83
	}
84

    
85

    
86
	if (!$input_errors) {
87
		/* No errors detected, so update the config */
88
		foreach ($_POST as $ifname => $ifport) {
89
		
90
			if (($ifname == 'lan') || ($ifname == 'wan') ||
91
				(substr($ifname, 0, 3) == 'opt')) {
92
				
93
				if (!is_array($ifport)) {
94
					$config['interfaces'][$ifname]['if'] = $ifport;
95
					
96
					/* check for wireless interfaces, set or clear ['wireless'] */
97
					if (preg_match("/^(wi|awi|an)/", $ifport)) {
98
						if (!is_array($config['interfaces'][$ifname]['wireless']))
99
							$config['interfaces'][$ifname]['wireless'] = array();
100
					} else {
101
						unset($config['interfaces'][$ifname]['wireless']);
102
					}
103
					
104
					/* make sure there is a name for OPTn */
105
					if (substr($ifname, 0, 3) == 'opt') {
106
						if (!isset($config['interfaces'][$ifname]['descr']))
107
							$config['interfaces'][$ifname]['descr'] = strtoupper($ifname);
108
					}
109
				}
110
			}
111
		}
112
	
113
		write_config();
114
		touch($d_sysrebootreqd_path);
115
	}
116
}
117

    
118
if ($_GET['act'] == "del") {
119
	$id = $_GET['id'];
120
	
121
	unset($config['interfaces'][$id]);	/* delete the specified OPTn */
122

    
123
	/* shift down other OPTn interfaces to get rid of holes */
124
	$i = substr($id, 3); /* the number of the OPTn port being deleted */
125
	$i++;
126
	
127
	/* look at the following OPTn ports */
128
	while (is_array($config['interfaces']['opt' . $i])) {
129
		$config['interfaces']['opt' . ($i - 1)] =
130
			$config['interfaces']['opt' . $i];
131
		
132
		if ($config['interfaces']['opt' . ($i - 1)]['descr'] == "OPT" . $i)
133
			$config['interfaces']['opt' . ($i - 1)]['descr'] = "OPT" . ($i - 1);
134
		
135
		unset($config['interfaces']['opt' . $i]);
136
		$i++;
137
	}
138

    
139
	write_config();
140
	touch($d_sysrebootreqd_path);
141
	header("Location: interfaces_assign.php");
142
	exit;
143
}
144

    
145
if ($_GET['act'] == "add") {
146
	/* find next free optional interface number */
147
	$i = 1;
148
	while (is_array($config['interfaces']['opt' . $i]))
149
		$i++;
150
	
151
	$newifname = 'opt' . $i;
152
	$config['interfaces'][$newifname] = array();
153
	$config['interfaces'][$newifname]['descr'] = "OPT" . $i;
154
	
155
	/* Find an unused port for this interface */
156
	foreach ($portlist as $portname => $portinfo) {
157
		$portused = false;
158
		foreach ($config['interfaces'] as $ifname => $ifdata) {
159
			if ($ifdata['if'] == $portname) {
160
				$portused = true;
161
				break;
162
			}
163
		}
164
		if (!$portused) {
165
			$config['interfaces'][$newifname]['if'] = $portname;
166
			if (preg_match("/^(wi|awi|an)/", $portname))
167
				$config['interfaces'][$newifname]['wireless'] = array();
168
			break;
169
		}
170
	}
171
	
172
	write_config();
173
	touch($d_sysrebootreqd_path);
174
	header("Location: interfaces_assign.php");
175
	exit;
176
}
177

    
178
?>
179
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
180
<html>
181
<head>
182
<title><?=gentitle("Interfaces: Assign network ports");?></title>
183
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
184
<link href="gui.css" rel="stylesheet" type="text/css">
185
</head>
186

    
187
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
188
<?php include("fbegin.inc"); ?>
189
<p class="pgtitle">Interfaces: Assign network ports</p>
190
<?php if ($input_errors) print_input_errors($input_errors); ?>
191
<?php if (file_exists($d_sysrebootreqd_path)) print_info_box(get_std_save_message(0)); ?>
192
<form action="interfaces_assign.php" method="post" name="iform" id="iform">
193
<table width="100%" border="0" cellpadding="0" cellspacing="0">
194
  <tr><td>
195
  <ul id="tabnav">
196
    <li class="tabact">Interface assignments</li>
197
    <li class="tabinact"><a href="interfaces_vlan.php">VLANs</a></li>
198
  </ul>
199
  </td></tr>
200
  <tr> 
201
    <td class="tabcont">
202
                    <table border="0" cellpadding="0" cellspacing="0">
203
                      <tr> 
204
	<td class="listhdrr">Interface</td>
205
	<td class="listhdr">Network port</td>
206
	<td class="list">&nbsp;</td>
207
  </tr>
208
  <?php foreach ($config['interfaces'] as $ifname => $iface):
209
  	if ($iface['descr'])
210
		$ifdescr = $iface['descr'];
211
	else
212
		$ifdescr = strtoupper($ifname);
213
	?>
214
  <tr> 
215
	<td class="listlr" valign="middle"><strong><?=$ifdescr;?></strong></td>
216
	  <td valign="middle" class="listr">
217
		<select name="<?=$ifname;?>" class="formfld" id="<?=$ifname;?>">
218
		  <?php foreach ($portlist as $portname => $portinfo): ?>
219
		  <option value="<?=$portname;?>" <?php if ($portname == $iface['if']) echo "selected";?>> 
220
		  <?php if ($portinfo['isvlan']) {
221
		  			$descr = "VLAN {$portinfo['tag']} on {$portinfo['if']}";
222
					if ($portinfo['descr'])
223
						$descr .= " (" . $portinfo['descr'] . ")";
224
					echo htmlspecialchars($descr);
225
				  } else
226
					echo htmlspecialchars($portname . " (" . $portinfo['mac'] . ")");
227
		  ?>
228
		  </option>
229
		  <?php endforeach; ?>
230
		</select>
231
		</td>
232
		<td valign="middle" class="list"> 
233
		  <?php if (($ifname != 'lan') && ($ifname != 'wan')): ?>
234
		  <a href="interfaces_assign.php?act=del&id=<?=$ifname;?>"><img src="x.gif" title="delete interface" width="17" height="17" border="0"></a> 
235
		  <?php endif; ?>
236
		</td>
237
  </tr>
238
  <?php endforeach; ?>
239
  <?php if (count($config['interfaces']) < count($portlist)): ?>
240
  <tr>
241
	<td class="list" colspan="2"></td>
242
	<td class="list" nowrap>
243
	<a href="interfaces_assign.php?act=add"><img src="plus.gif" title="add interface" width="17" height="17" border="0"></a>
244
	</td>
245
  </tr>
246
  <?php else: ?>
247
  <tr>
248
	<td class="list" colspan="3" height="10"></td>
249
  </tr>
250
  <?php endif; ?>
251
</table>
252
                      <input name="Submit" type="submit" class="formbtn" value="Save">
253
                    <p><span class="vexpl"><strong><span class="red">Warning:</span><br>
254
                    </strong>After you click &quot;Save&quot;, you must reboot the firewall to make the changes take effect. You may also have to do one or more of the following steps before you can access your firewall again: </span></p>
255
                    <ul>
256
                      <li><span class="vexpl">change the IP address of your computer</span></li>
257
                      <li><span class="vexpl">renew its DHCP lease</span></li>
258
                      <li><span class="vexpl">access the webGUI with the new IP address</span></li>
259
                    </ul></td>
260
	</tr>
261
</table>
262
</form>
263
<?php include("fend.inc"); ?>
264
</body>
265
</html>
(46-46/106)