Project

General

Profile

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