Project

General

Profile

Download (14 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
<?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 94a77286 Scott Ullrich
	Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
8 5b237745 Scott Ullrich
	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 6b07c15a Matthew Grooms
##|+PRIV
33
##|*IDENT=page-interfaces-assignnetworkports
34
##|*NAME=Interfaces: Assign network ports page
35
##|*DESCR=Allow access to the 'Interfaces: Assign network ports' page.
36
##|*MATCH=interfaces_assign.php*
37
##|-PRIV
38
39 94a77286 Scott Ullrich
$pgtitle = array("Interfaces", "Assign network ports");
40 5b237745 Scott Ullrich
require("guiconfig.inc");
41
42
/*
43
	In this file, "port" refers to the physical port name,
44
	while "interface" refers to LAN, WAN, or OPTn.
45
*/
46
47
/* get list without VLAN interfaces */
48
$portlist = get_interface_list();
49
50
/* add VLAN interfaces */
51
if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) {
52
	foreach ($config['vlans']['vlan'] as $vlan) {
53 d59557dc Ermal Luçi
		$portlist[$vlan['vlanif']] = $vlan;
54
		$portlist[$vlan['vlanif']]['isvlan'] = true;
55 5b237745 Scott Ullrich
	}
56
}
57
58 38738505 Ermal Luçi
/* add Bridge interfaces */
59 b47c94bd Ermal Luçi
if (is_array($config['bridges']['bridged']) && count($config['bridges']['bridged'])) {
60
        foreach ($config['bridges']['bridged'] as $bridge) {
61 38738505 Ermal Luçi
                $portlist[$bridge['bridgeif']] = $bridge;
62
                $portlist[$bridge['bridgeif']]['isbridge'] = true;
63
        }
64
}
65
66
/* add GIF interfaces */
67
if (is_array($config['gifs']['gif']) && count($config['gifs']['gif'])) {
68
        foreach ($config['gifs']['gif'] as $gif) {
69
                $portlist[$gif['gifif']] = $gif;
70
                $portlist[$gif['gifif']]['isgif'] = true;
71
        }
72
}
73
74
/* add GRE interfaces */
75
if (is_array($config['gres']['gre']) && count($config['gres']['gre'])) {
76
        foreach ($config['gres']['gre'] as $gre) {
77
                $portlist[$gre['greif']] = $gre;
78
                $portlist[$gre['greif']]['isgre'] = true;
79
        }
80
}
81
82 dbdd08af Ermal Luçi
/* add LAGG interfaces */
83 c720925c Ermal Luçi
if (is_array($config['laggs']['lagg']) && count($config['laggs']['lagg'])) {
84
        foreach ($config['laggs']['lagg'] as $lagg) {
85
                $portlist[$lagg['laggif']] = $lagg;
86
                $portlist[$lagg['laggif']]['islagg'] = true;
87 dbdd08af Ermal Luçi
		/* LAGG members cannot be assigned */
88
		$lagifs = explode(',', $lagg['members']);
89
		foreach ($lagifs as $lagif)
90
			if (isset($portlist[$lagif]))
91
				unset($portlist[$lagif]);
92 c720925c Ermal Luçi
        }
93
}
94
95
96 860c4e80 Chris Buechler
/* add PPP interfaces */
97
if (is_array($config['ppps']['ppp']) && count($config['ppps']['ppp'])) {
98
	$i = 0;
99
	foreach ($config['ppps']['ppp'] as $ppp) {
100
		$portname = 'ppp_' . basename($ppp['port']);
101
		$portlist[$portname] = $ppp;
102
		$portlist[$portname]['isppp'] = true;
103
		$i++;
104
	}
105
}
106
107 d59557dc Ermal Luçi
if ($_POST['apply']) {
108
	if (file_exists("/var/run/interface_mismatch_reboot_needed"))
109
		exec("/etc/rc.reboot");
110
	else {
111
		write_config();
112
113
		$retval = 0;
114
		$savemsg = get_std_save_message($retval);
115
116
		config_lock();
117
		$retval = filter_configure();
118
		config_unlock();
119
120
		if (stristr($retval, "error") <> true)
121
			$savemsg = get_std_save_message($retval);
122
		else
123
			$savemsg = $retval;
124
125 4a166751 Ermal Luçi
		unlink_if_exists("/tmp/reload_interfaces");
126 d59557dc Ermal Luçi
	}
127
128
} else if ($_POST) {
129 5b237745 Scott Ullrich
130
	unset($input_errors);
131
132
	/* input validation */
133
134
	/* Build a list of the port names so we can see how the interfaces map */
135
	$portifmap = array();
136
	foreach ($portlist as $portname => $portinfo)
137
		$portifmap[$portname] = array();
138
139
	/* Go through the list of ports selected by the user,
140
	   build a list of port-to-interface mappings in portifmap */
141
	foreach ($_POST as $ifname => $ifport) {
142
		if (($ifname == 'lan') || ($ifname == 'wan') || (substr($ifname, 0, 3) == 'opt'))
143
			$portifmap[$ifport][] = strtoupper($ifname);
144
	}
145
146
	/* Deliver error message for any port with more than one assignment */
147
	foreach ($portifmap as $portname => $ifnames) {
148
		if (count($ifnames) > 1) {
149
			$errstr = "Port " . $portname .
150
				" was assigned to " . count($ifnames) .
151
				" interfaces:";
152
				
153
			foreach ($portifmap[$portname] as $ifn)
154
				$errstr .= " " . $ifn;
155
			
156
			$input_errors[] = $errstr;
157
		}
158
	}
159
160
161
	if (!$input_errors) {
162
		/* No errors detected, so update the config */
163
		foreach ($_POST as $ifname => $ifport) {
164
		
165
			if (($ifname == 'lan') || ($ifname == 'wan') ||
166
				(substr($ifname, 0, 3) == 'opt')) {
167
				
168
				if (!is_array($ifport)) {
169
					$config['interfaces'][$ifname]['if'] = $ifport;
170 860c4e80 Chris Buechler
					if (preg_match('/^ppp_(.+)$/', $ifport, $matches)) {
171
						$config['interfaces'][$ifname]['pointtopoint'] = true;
172
						$config['interfaces'][$ifname]['serialport'] = $matches[1];
173
					}
174
175 5b237745 Scott Ullrich
					/* check for wireless interfaces, set or clear ['wireless'] */
176 94a77286 Scott Ullrich
					if (preg_match($g['wireless_regex'], $ifport)) {
177 5b237745 Scott Ullrich
						if (!is_array($config['interfaces'][$ifname]['wireless']))
178
							$config['interfaces'][$ifname]['wireless'] = array();
179
					} else {
180
						unset($config['interfaces'][$ifname]['wireless']);
181
					}
182
					
183 d59557dc Ermal Luçi
					/* make sure there is a descr for all interfaces */
184
					if (!isset($config['interfaces'][$ifname]['descr']))
185
						$config['interfaces'][$ifname]['descr'] = strtoupper($ifname);
186 5b237745 Scott Ullrich
				}
187
			}
188
		}
189
	
190
		write_config();
191 182c30de Scott Ullrich
		
192 d59557dc Ermal Luçi
		touch("/tmp/reload_interfaces");
193 5b237745 Scott Ullrich
	}
194
}
195
196
if ($_GET['act'] == "del") {
197
	$id = $_GET['id'];
198 3c43a344 Scott Ullrich
199
	unset($config['interfaces'][$id]['enable']);
200 f1f60c92 Ermal Luçi
	interface_bring_down($id);   /* down the interface */
201 3c43a344 Scott Ullrich
		
202 bda86e8f Scott Ullrich
	unset($config['interfaces'][$id]);	/* delete the specified OPTn or LAN*/
203 5b237745 Scott Ullrich
204 d59557dc Ermal Luçi
	if($id == "lan") {
205 bda86e8f Scott Ullrich
		unset($config['interfaces']['lan']);
206 3f24dd12 Ermal Luçi
		if (is_array($config['dhcpd']))
207
			unset($config['dhcpd']['lan']);
208 7385b511 Scott Ullrich
		unset($config['shaper']);
209
		unset($config['ezshaper']);
210 5bf11e36 Scott Ullrich
		unset($config['nat']);
211 f2366cc0 Scott Ullrich
		system("rm /var/dhcpd/var/db/*");
212 d59557dc Ermal Luçi
        	services_dhcpd_configure();
213 5b237745 Scott Ullrich
	}
214
215 c3bc7432 Ermal Luçi
	if ($config['filter']['rule'] > 0)
216
        foreach ($config['filter']['rule'] as $x => $rule) {
217
                        if($rule['interface'] == $id)
218
                                unset($config['filter']['rule'][$x]);
219
        }
220
	if ($config['nat']['advancedoutbound']['rule'] > 0)
221
        foreach ($config['nat']['advancedoutbound']['rule'] as $id => $rule) {
222
                        if($rule['interface'] == $x)
223
                                unset($config['nat']['advancedoutbound']['rule'][$x]['interface']);
224
        }
225
        if (count($config['nat']['rule']) > 0) 
226
        foreach ($config['nat']['rule'] as $x => $rule) {
227
                        if($rule['interface'] == $id)
228
                                unset($config['nat']['rule'][$x]['interface']);
229
        }
230
231
232 5b237745 Scott Ullrich
	write_config();
233 21eebbb0 Scott Ullrich
	
234 d59557dc Ermal Luçi
	/* XXX: What is this for?!?! */
235 bda86e8f Scott Ullrich
	if($config['interfaces']['lan']) {
236
		unset($config['dhcpd']['wan']);		
237
	}
238 98a0128c Scott Ullrich
	
239 21eebbb0 Scott Ullrich
	$savemsg = "Interface has been deleted.";
240 5b237745 Scott Ullrich
}
241
242
if ($_GET['act'] == "add") {
243
	/* find next free optional interface number */
244 bda86e8f Scott Ullrich
	if(!$config['interfaces']['lan']) {
245
		$newifname = "lan";
246 0d21552c Scott Ullrich
		$config['interfaces'][$newifname] = array();
247 d59557dc Ermal Luçi
		$config['interfaces'][$newifname]['descr'] = $descr;
248 bda86e8f Scott Ullrich
	} else {
249 8a648100 Ermal Luçi
		for ($i = 1; $i <= count($config['interfaces']); $i++) {
250
			if (!$config['interfaces']["opt{$i}"])
251
				break;
252
		}
253 bda86e8f Scott Ullrich
		$newifname = 'opt' . $i;
254 d59557dc Ermal Luçi
		$descr = "OPT{$i}";
255 0d21552c Scott Ullrich
		$config['interfaces'][$newifname] = array();
256 d59557dc Ermal Luçi
		$config['interfaces'][$newifname]['descr'] = $descr;
257
		ksort($config['interfaces']);
258 bda86e8f Scott Ullrich
	}
259 5b237745 Scott Ullrich
	
260
	/* Find an unused port for this interface */
261
	foreach ($portlist as $portname => $portinfo) {
262
		$portused = false;
263
		foreach ($config['interfaces'] as $ifname => $ifdata) {
264
			if ($ifdata['if'] == $portname) {
265
				$portused = true;
266
				break;
267
			}
268
		}
269
		if (!$portused) {
270
			$config['interfaces'][$newifname]['if'] = $portname;
271 94a77286 Scott Ullrich
			if (preg_match($g['wireless_regex'], $portname))
272 5b237745 Scott Ullrich
				$config['interfaces'][$newifname]['wireless'] = array();
273
			break;
274
		}
275
	}
276
	
277 d59557dc Ermal Luçi
        /* XXX: Do not remove this. */
278
        mwexec("rm -f /tmp/config.cache");
279
280 5b237745 Scott Ullrich
	write_config();
281 093a01b0 Scott Ullrich
282 21eebbb0 Scott Ullrich
	$savemsg = "Interface has been added.";
283
284 5b237745 Scott Ullrich
}
285
286 7f43ca88 Scott Ullrich
include("head.inc");
287
288 23be6f1b Scott Ullrich
if(file_exists("/var/run/interface_mismatch_reboot_needed")) 
289 d59557dc Ermal Luçi
	if ($_POST)
290
		$savemsg = "Reboot is needed. Please apply the settings in order to reboot.";
291 c35e12af Scott Ullrich
	else
292 00404818 Chris Buechler
		$savemsg = "Interface mismatch detected.  Please resolve the mismatch and click Save.  The firewall will reboot afterwards.";
293 23be6f1b Scott Ullrich
294 5b237745 Scott Ullrich
?>
295 6eb47218 Scott Ullrich
296
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
297 5b237745 Scott Ullrich
<?php include("fbegin.inc"); ?>
298
<?php if ($input_errors) print_input_errors($input_errors); ?>
299 2e506568 Scott Ullrich
<?php if ($savemsg) print_info_box($savemsg); ?>
300 a2dab9bc Bill Marquette
301 5b237745 Scott Ullrich
<form action="interfaces_assign.php" method="post" name="iform" id="iform">
302 d59557dc Ermal Luçi
<?php if (file_exists("/tmp/reload_interfaces")): ?><p>
303
<?php print_info_box_np("The interface configuration has been changed.<br>You must apply
304
 the changes in order for them to take effect.");?><br>
305
<?php endif; ?>
306
307 5b237745 Scott Ullrich
<table width="100%" border="0" cellpadding="0" cellspacing="0">
308 94a77286 Scott Ullrich
  <tr><td class="tabnavtbl">
309 c8b8ff69 Scott Ullrich
<?php
310
	$tab_array = array();
311 931066a8 Bill Marquette
	$tab_array[0] = array("Interface assignments", true, "interfaces_assign.php");
312
	$tab_array[1] = array("VLANs", false, "interfaces_vlan.php");
313 860c4e80 Chris Buechler
	$tab_array[2] = array("PPP", false, "interfaces_ppp.php");
314 77d129c6 Ermal Luçi
        $tab_array[3] = array("GRE", false, "interfaces_gre.php");
315
        $tab_array[4] = array("GIF", false, "interfaces_gif.php");
316 d8b93051 Ermal Luçi
	$tab_array[5] = array("Bridges", false, "interfaces_bridge.php");
317 417cba65 Ermal Luçi
	$tab_array[6] = array("LAGG", false, "interfaces_lagg.php");
318 c8b8ff69 Scott Ullrich
	display_top_tabs($tab_array);
319
?>  
320 5b237745 Scott Ullrich
  </td></tr>
321
  <tr> 
322 d732f186 Bill Marquette
    <td>
323
	<div id="mainarea">
324
        <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
325
       <tr> 
326 5b237745 Scott Ullrich
	<td class="listhdrr">Interface</td>
327
	<td class="listhdr">Network port</td>
328
	<td class="list">&nbsp;</td>
329
  </tr>
330
  <?php foreach ($config['interfaces'] as $ifname => $iface):
331
  	if ($iface['descr'])
332
		$ifdescr = $iface['descr'];
333
	else
334
		$ifdescr = strtoupper($ifname);
335
	?>
336
  <tr> 
337
	<td class="listlr" valign="middle"><strong><?=$ifdescr;?></strong></td>
338
	  <td valign="middle" class="listr">
339 34834d88 Scott Ullrich
		<select name="<?=$ifname;?>" id="<?=$ifname;?>">
340 5b237745 Scott Ullrich
		  <?php foreach ($portlist as $portname => $portinfo): ?>
341
		  <option value="<?=$portname;?>" <?php if ($portname == $iface['if']) echo "selected";?>> 
342
		  <?php if ($portinfo['isvlan']) {
343
		  			$descr = "VLAN {$portinfo['tag']} on {$portinfo['if']}";
344
					if ($portinfo['descr'])
345
						$descr .= " (" . $portinfo['descr'] . ")";
346
					echo htmlspecialchars($descr);
347 860c4e80 Chris Buechler
				} elseif ($portinfo['isppp']) {
348
					$descr = "PPP {$portinfo['port']}";
349
					if ($portinfo['descr'])
350
						$descr .= " (" . $portinfo['descr'] . ")";
351
					echo htmlspecialchars($descr);
352 38738505 Ermal Luçi
                                 } elseif ($portinfo['isbridge']) {
353
                                         $descr = strtoupper($portinfo['bridgeif']);
354
                                         if ($portinfo['descr'])
355
                                                 $descr .= " (" . $portinfo['descr'] . ")";
356
                                        echo htmlspecialchars($descr);
357
                                 } elseif ($portinfo['isgre']) {
358
                                         $descr = "GRE {$portinfo['remote-addr']}";
359
                                         if ($portinfo['descr'])
360
                                                 $descr .= " (" . $portinfo['descr'] . ")";
361
                                        echo htmlspecialchars($descr);
362
                                 } elseif ($portinfo['isgif']) {
363
                                         $descr = "GRE {$portinfo['remote-addr']}";
364
                                         if ($portinfo['descr'])
365
                                                 $descr .= " (" . $portinfo['descr'] . ")";
366
                                        echo htmlspecialchars($descr);
367 c720925c Ermal Luçi
                                 } elseif ($portinfo['islagg']) {
368
                                         $descr = strtoupper($portinfo['laggif']);
369
                                         if ($portinfo['descr'])
370
                                                 $descr .= " (" . $portinfo['descr'] . ")";
371
                                        echo htmlspecialchars($descr);
372 5b237745 Scott Ullrich
				  } else
373
					echo htmlspecialchars($portname . " (" . $portinfo['mac'] . ")");
374
		  ?>
375
		  </option>
376
		  <?php endforeach; ?>
377
		</select>
378
		</td>
379
		<td valign="middle" class="list"> 
380 b0d756ba Scott Ullrich
		  <?php if ($ifname != 'wan'): ?>
381 677c0869 Erik Kristensen
		  <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> 
382 5b237745 Scott Ullrich
		  <?php endif; ?>
383
		</td>
384
  </tr>
385
  <?php endforeach; ?>
386
  <?php if (count($config['interfaces']) < count($portlist)): ?>
387
  <tr>
388
	<td class="list" colspan="2"></td>
389
	<td class="list" nowrap>
390 677c0869 Erik Kristensen
	<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>
391 5b237745 Scott Ullrich
	</td>
392
  </tr>
393
  <?php else: ?>
394
  <tr>
395
	<td class="list" colspan="3" height="10"></td>
396
  </tr>
397
  <?php endif; ?>
398
</table>
399 d732f186 Bill Marquette
</div>
400 0d21552c Scott Ullrich
<br/>
401
<input name="Submit" type="submit" class="formbtn" value="Save"><br><br>
402 56afcab6 Scott Ullrich
<p>
403 bd705fb8 Scott Ullrich
</p>
404 94a77286 Scott Ullrich
<ul>
405
  <li><span class="vexpl">change the IP address of your computer</span></li>
406
  <li><span class="vexpl">renew its DHCP lease</span></li>
407 709cc6e0 Bill Marquette
  <li><span class="vexpl">access the webConfigurator with the new IP address</span></li>
408 30c1b51e Ermal Luçi
  <li><span class="vexpl">interfaces that are configured as members of a lagg(4) interface will not be shown.</span></li>
409 94a77286 Scott Ullrich
</ul></td>
410 5b237745 Scott Ullrich
	</tr>
411
</table>
412
</form>
413
<?php include("fend.inc"); ?>
414 c8b8ff69 Scott Ullrich
</body>
415
</html>