Project

General

Profile

Download (9.54 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php 
2
/*
3
	interfaces_assign.php
4
	part of m0n0wall (http://m0n0.ch/wall)
5
	Written by Jim McBeath based on existing m0n0wall files
6
	
7
	Copyright (C) 2003-2005 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
$pgtitle = array("Interfaces", "Assign network ports");
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($g['wireless_regex'], $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
		$savemsg = get_std_save_message($retval);
114
	
115
		write_config();
116
		
117
	}
118
}
119

    
120
if ($_GET['act'] == "del") {
121
	$id = $_GET['id'];
122

    
123
	$i = substr($id, 3); /* the number of the OPTn port being deleted */
124
	unset($config['interfaces'][$id]['enable']);
125
	interfaces_optional_configure_if($i);   /* down the interface */
126
		
127
	unset($config['interfaces'][$id]);	/* delete the specified OPTn or LAN*/
128

    
129
	if($id <> "lan") {
130
		/* shift down other OPTn interfaces to get rid of holes */
131
		$i++;
132
	
133
		/* look at the following OPTn ports */
134
		while (is_array($config['interfaces']['opt' . $i])) {
135
			$config['interfaces']['opt' . ($i - 1)] =
136
				$config['interfaces']['opt' . $i];
137
		
138
			if ($config['interfaces']['opt' . ($i - 1)]['descr'] == "OPT" . $i)
139
				$config['interfaces']['opt' . ($i - 1)]['descr'] = "OPT" . ($i - 1);
140
		
141
			unset($config['interfaces']['opt' . $i]);
142
			$i++;
143
		}
144
	} else {
145
		unset($config['interfaces']['lan']);
146
		unset($config['dhcpd']['lan']);
147
		unset($config['shaper']);
148
		unset($config['ezshaper']);
149
		unset($config['nat']);
150
		system("rm /var/dhcpd/var/db/*");
151
        services_dhcpd_configure();
152
	}
153

    
154
	write_config();
155
	
156
	if($id <> "lan") {
157
		/*   move all the interfaces up.  for example:
158
	 	*      opt1 --> opt1
159
	 	*		opt2 --> delete
160
	 	*		opt3 --> opt2
161
     	*      opt4 --> opt3
162
     	*/
163
		cleanup_opt_interfaces_after_removal($i);
164
	}
165

    
166
	parse_config(true);
167

    
168
	if($config['interfaces']['lan']) {
169
		unset($config['dhcpd']['wan']);		
170
	}
171
	
172
	$savemsg = "Interface has been deleted.";
173

    
174
}
175

    
176
if ($_GET['act'] == "add") {
177
	/* find next free optional interface number */
178
	$i = 1;
179
	if(!$config['interfaces']['lan']) {
180
		$newifname = "lan";
181
		$config['interfaces'][$newifname] = array();
182
		$config['interfaces'][$newifname]['descr'] = "{$descr}";
183
	} else {
184
		while (is_array($config['interfaces']['opt' . $i]))
185
			$i++;
186
		$newifname = 'opt' . $i;
187
		$descr = "OPT";
188
		$config['interfaces'][$newifname] = array();
189
		$config['interfaces'][$newifname]['descr'] = "{$descr}" . $i;
190
	}
191
	
192
	/* Find an unused port for this interface */
193
	foreach ($portlist as $portname => $portinfo) {
194
		$portused = false;
195
		foreach ($config['interfaces'] as $ifname => $ifdata) {
196
			if ($ifdata['if'] == $portname) {
197
				$portused = true;
198
				break;
199
			}
200
		}
201
		if (!$portused) {
202
			$config['interfaces'][$newifname]['if'] = $portname;
203
			if (preg_match($g['wireless_regex'], $portname))
204
				$config['interfaces'][$newifname]['wireless'] = array();
205
			break;
206
		}
207
	}
208
	
209
	write_config();
210

    
211
	$savemsg = "Interface has been added.";
212

    
213
}
214

    
215
include("head.inc");
216

    
217
if(file_exists("/var/run/interface_mismatch_reboot_needed")) 
218
	if ($_POST) 
219
		$savemsg = "The firewall is now rebooting.";
220
	else
221
		$savemsg = "Interface mismatch detected.  Please resolve the mismatch and click Save.  The firewall will reboot afterwards.";
222

    
223
?>
224

    
225
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
226
<?php include("fbegin.inc"); ?>
227
<?php if ($input_errors) print_input_errors($input_errors); ?>
228
<?php if ($savemsg) print_info_box($savemsg); ?>
229

    
230
<form action="interfaces_assign.php" method="post" name="iform" id="iform">
231
  <div id="save_button" style="display:none"><?php print_info_box_np("Assignment change detected, changes are not yet saved.", "save", "Save Changes"); ?></div>
232
<table width="100%" border="0" cellpadding="0" cellspacing="0">
233
  <tr><td class="tabnavtbl">
234
<?php
235
	$tab_array = array();
236
	$tab_array[0] = array("Interface assignments", true, "interfaces_assign.php");
237
	$tab_array[1] = array("VLANs", false, "interfaces_vlan.php");
238
	display_top_tabs($tab_array);
239
?>  
240
  </td></tr>
241
  <tr> 
242
    <td>
243
	<div id="mainarea">
244
        <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
245
       <tr> 
246
	<td class="listhdrr">Interface</td>
247
	<td class="listhdr">Network port</td>
248
	<td class="list">&nbsp;</td>
249
  </tr>
250
  <?php foreach ($config['interfaces'] as $ifname => $iface):
251
  	if ($iface['descr'])
252
		$ifdescr = $iface['descr'];
253
	else
254
		$ifdescr = strtoupper($ifname);
255
	?>
256
  <tr> 
257
	<td class="listlr" valign="middle"><strong><?=$ifdescr;?></strong></td>
258
	  <td valign="middle" class="listr">
259
		<select onChange="document.getElementById('save_button').style.display='inline';" name="<?=$ifname;?>" class="formfld" id="<?=$ifname;?>">
260
		  <?php foreach ($portlist as $portname => $portinfo): ?>
261
		  <option value="<?=$portname;?>" <?php if ($portname == $iface['if']) echo "selected";?>> 
262
		  <?php if ($portinfo['isvlan']) {
263
		  			$descr = "VLAN {$portinfo['tag']} on {$portinfo['if']}";
264
					if ($portinfo['descr'])
265
						$descr .= " (" . $portinfo['descr'] . ")";
266
					echo htmlspecialchars($descr);
267
				  } else
268
					echo htmlspecialchars($portname . " (" . $portinfo['mac'] . ")");
269
		  ?>
270
		  </option>
271
		  <?php endforeach; ?>
272
		</select>
273
		</td>
274
		<td valign="middle" class="list"> 
275
		  <?php if ($ifname != 'wan'): ?>
276
		  <a href="interfaces_assign.php?act=del&id=<?=$ifname;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" title="delete interface" width="17" height="17" border="0"></a> 
277
		  <?php endif; ?>
278
		</td>
279
  </tr>
280
  <?php endforeach; ?>
281
  <?php if (count($config['interfaces']) < count($portlist)): ?>
282
  <tr>
283
	<td class="list" colspan="2"></td>
284
	<td class="list" nowrap>
285
	<a href="interfaces_assign.php?act=add"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="add interface" width="17" height="17" border="0"></a>
286
	</td>
287
  </tr>
288
  <?php else: ?>
289
  <tr>
290
	<td class="list" colspan="3" height="10"></td>
291
  </tr>
292
  <?php endif; ?>
293
</table>
294
</div>
295
<br/>
296
<input name="Submit" type="submit" class="formbtn" value="Save"><br><br>
297
<p>
298
</p>
299
<ul>
300
  <li><span class="vexpl">change the IP address of your computer</span></li>
301
  <li><span class="vexpl">renew its DHCP lease</span></li>
302
  <li><span class="vexpl">access the webConfigurator with the new IP address</span></li>
303
</ul></td>
304
	</tr>
305
</table>
306
</form>
307
<?php include("fend.inc"); ?>
308
</body>
309
</html>
310

    
311
<?php
312

    
313
	if ($_POST) {
314
		if (!$input_errors)
315
			touch("/tmp/reload_interfaces");
316
		if(file_exists("/var/run/interface_mismatch_reboot_needed")) 
317
			exec("/etc/rc.reboot");
318
	}
319
	
320
?>
(74-74/187)