Project

General

Profile

Download (8.37 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-2005 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
$pgtitle = array("Interfaces", "Assign network ports");
34
require("guiconfig.inc");
35

    
36
/*
37
	In this file, "port" refers to the physical port name,
38
	while "interface" refers to LAN, WAN, or OPTn.
39
*/
40

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

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

    
54
if ($_POST) {
55

    
56
	unset($input_errors);
57

    
58
	/* input validation */
59

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

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

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

    
86

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

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

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

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

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

    
179

    
180
$pgtitle = "Interfaces: Assign";
181
include("head.inc");
182

    
183
?>
184

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