Project

General

Profile

Download (16.7 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
	pfSense_BUILDER_BINARIES:	/bin/rm
33
	pfSense_MODULE:	interfaces
34
*/
35

    
36
##|+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
$pgtitle = array("Interfaces", "Assign network ports");
44
require("guiconfig.inc");
45
require("functions.inc");
46
require("filter.inc");
47
require("shaper.inc");
48
require("ipsec.inc");
49
require("vpn.inc");
50
require("captiveportal.inc");
51
require("rrd.inc");
52

    
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 wireless clone interfaces */
62
if (is_array($config['wireless']['clone']) && count($config['wireless']['clone'])) {
63
	foreach ($config['wireless']['clone'] as $clone) {
64
		$portlist[$clone['cloneif']] = $clone;
65
		$portlist[$clone['cloneif']]['iswlclone'] = true;
66
	}
67
}
68

    
69
/* add VLAN interfaces */
70
if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) {
71
	foreach ($config['vlans']['vlan'] as $vlan) {
72
		$portlist[$vlan['vlanif']] = $vlan;
73
		$portlist[$vlan['vlanif']]['isvlan'] = true;
74
	}
75
}
76

    
77
/* add Bridge interfaces */
78
if (is_array($config['bridges']['bridged']) && count($config['bridges']['bridged'])) {
79
        foreach ($config['bridges']['bridged'] as $bridge) {
80
                $portlist[$bridge['bridgeif']] = $bridge;
81
                $portlist[$bridge['bridgeif']]['isbridge'] = true;
82
        }
83
}
84

    
85
/* add GIF interfaces */
86
if (is_array($config['gifs']['gif']) && count($config['gifs']['gif'])) {
87
        foreach ($config['gifs']['gif'] as $gif) {
88
                $portlist[$gif['gifif']] = $gif;
89
                $portlist[$gif['gifif']]['isgif'] = true;
90
        }
91
}
92

    
93
/* add GRE interfaces */
94
if (is_array($config['gres']['gre']) && count($config['gres']['gre'])) {
95
        foreach ($config['gres']['gre'] as $gre) {
96
                $portlist[$gre['greif']] = $gre;
97
                $portlist[$gre['greif']]['isgre'] = true;
98
        }
99
}
100

    
101
/* add LAGG interfaces */
102
if (is_array($config['laggs']['lagg']) && count($config['laggs']['lagg'])) {
103
        foreach ($config['laggs']['lagg'] as $lagg) {
104
                $portlist[$lagg['laggif']] = $lagg;
105
                $portlist[$lagg['laggif']]['islagg'] = true;
106
		/* LAGG members cannot be assigned */
107
		$lagifs = explode(',', $lagg['members']);
108
		foreach ($lagifs as $lagif)
109
			if (isset($portlist[$lagif]))
110
				unset($portlist[$lagif]);
111
        }
112
}
113

    
114
/* add QinQ interfaces */
115
if (is_array($config['qinqs']['qinqentry']) && count($config['qinqs']['qinqentry'])) {
116
        foreach ($config['qinqs']['qinqentry'] as $qinq) {
117
                $portlist["vlan{$qinq['tag']}"]['descr'] = "VLAN {$qinq['tag']}";
118
                $portlist["vlan{$qinq['tag']}"]['isqinq'] = true;
119
                /* QinQ members */
120
                $qinqifs = explode(' ', $qinq['members']);
121
                foreach ($qinqifs as $qinqif) {
122
			$portlist["vlan{$qinq['tag']}_{$qinqif}"]['descr'] = "QinQ {$qinqif}";
123
			$portlist["vlan{$qinq['tag']}_{$qinqif}"]['isqinq'] = true;
124
		}
125
        }
126
}
127

    
128
/* add PPP interfaces */
129
if (is_array($config['ppps']['ppp']) && count($config['ppps']['ppp'])) {
130
	foreach ($config['ppps']['ppp'] as $pppid => $ppp) {
131
		$portname = basename($ppp['port']);
132
		$portlist[$portname] = $ppp;
133
		$portlist[$portname]['isppp'] = true;
134
		$portlist[$portname]['descr'] = "PPP " . basename($ppp['port']);
135
	}
136
}
137

    
138
if ($_POST['apply']) {
139
	if (file_exists("/var/run/interface_mismatch_reboot_needed"))
140
		system_reboot();
141
	else {
142
		write_config();
143

    
144
		$retval = 0;
145
		$retval = filter_configure();
146
		$savemsg = get_std_save_message($retval);
147

    
148
		if (stristr($retval, "error") <> true)
149
			$savemsg = get_std_save_message($retval);
150
		else
151
			$savemsg = $retval;
152

    
153
		unlink_if_exists("/tmp/reload_interfaces");
154
	}
155

    
156
} else if ($_POST) {
157

    
158
	unset($input_errors);
159

    
160
	/* input validation */
161

    
162
	/* Build a list of the port names so we can see how the interfaces map */
163
	$portifmap = array();
164
	foreach ($portlist as $portname => $portinfo)
165
		$portifmap[$portname] = array();
166

    
167
	/* Go through the list of ports selected by the user,
168
	   build a list of port-to-interface mappings in portifmap */
169
	foreach ($_POST as $ifname => $ifport) {
170
		if (($ifname == 'lan') || ($ifname == 'wan') || (substr($ifname, 0, 3) == 'opt'))
171
			$portifmap[$ifport][] = strtoupper($ifname);
172
	}
173

    
174
	/* Deliver error message for any port with more than one assignment */
175
	foreach ($portifmap as $portname => $ifnames) {
176
		if (count($ifnames) > 1) {
177
			$errstr = "Port " . $portname .
178
				" was assigned to " . count($ifnames) .
179
				" interfaces:";
180
				
181
			foreach ($portifmap[$portname] as $ifn)
182
				$errstr .= " " . $ifn;
183
			
184
			$input_errors[] = $errstr;
185
		}
186
	}
187

    
188

    
189
	if (!$input_errors) {
190
		/* No errors detected, so update the config */
191
		foreach ($_POST as $ifname => $ifport) {
192
		
193
			if (($ifname == 'lan') || ($ifname == 'wan') ||
194
				(substr($ifname, 0, 3) == 'opt')) {
195
				
196
				if (!is_array($ifport)) {
197
					$reloadif = false;
198
					if (!empty($config['interfaces'][$ifname]['if']) && $config['interfaces'][$ifname]['if'] <> $ifport) {
199
						interface_bring_down($ifname);
200
						/* Mark this to be reconfigured in any case. */
201
						$reloadif = true;
202
					}
203
					$config['interfaces'][$ifname]['if'] = $ifport;
204
					if (file_exists("/dev/{$ifport}")) {
205
						$config['interfaces'][$ifname]['if'] =  basename($portlist[$ifport]['port']);
206
						$config['interfaces'][$ifname]['ipaddr'] = "ppp";
207
					}
208

    
209
					/* check for wireless interfaces, set or clear ['wireless'] */
210
					if (preg_match($g['wireless_regex'], $ifport)) {
211
						if (!is_array($config['interfaces'][$ifname]['wireless']))
212
							$config['interfaces'][$ifname]['wireless'] = array();
213
					} else {
214
						unset($config['interfaces'][$ifname]['wireless']);
215
					}
216
					
217
					/* make sure there is a descr for all interfaces */
218
					if (!isset($config['interfaces'][$ifname]['descr']))
219
						$config['interfaces'][$ifname]['descr'] = strtoupper($ifname);
220
					if ($reloadif == true) {
221
						if (preg_match($g['wireless_regex'], $ifport))
222
							interface_sync_wireless_clones($config['interfaces'][$ifname], false);
223
						/* Reload all for the interface. */
224
						interface_configure($ifname, true);
225
					}
226
				}
227

    
228
				touch("/tmp/reload_interfaces");
229
			}
230
		}
231
	
232
		write_config();
233
		
234
		enable_rrd_graphing();
235
	}
236
}
237

    
238
if ($_GET['act'] == "del") {
239
	$id = $_GET['id'];
240

    
241
	if (link_interface_to_bridge($id))
242
		$input_errors[] = "The interface is part of a bridge. Please remove it from the bridge to continue";
243
	else if (link_interface_to_gre($id))
244
		$input_errors[] = "The interface is part of a gre tunnel. Please delete the tunnel to continue";
245
	else if (link_interface_to_gif($id))
246
		$input_errors[] = "The interface is part of a gif tunnel. Please delete the tunnel to continue";
247
	else {
248
		unset($config['interfaces'][$id]['enable']);
249
		$realid = get_real_interface($id);
250
		interface_bring_down($id);   /* down the interface */
251
		
252
		unset($config['interfaces'][$id]);	/* delete the specified OPTn or LAN*/
253

    
254
		if($id == "lan") {
255
			unset($config['interfaces']['lan']);
256
			if (is_array($config['dhcpd']))
257
				unset($config['dhcpd']['lan']);
258
				unset($config['shaper']);
259
				unset($config['ezshaper']);
260
				unset($config['nat']);
261
				system("rm /var/dhcpd/var/db/*");
262
        			services_dhcpd_configure();
263
		}
264

    
265
		if (count($config['filter']['rule']) > 0) {
266
       	 		foreach ($config['filter']['rule'] as $x => $rule) {
267
                	        if($rule['interface'] == $id)
268
               		                 unset($config['filter']['rule'][$x]);
269
			}
270
        	}
271
		if (is_array($config['nat']['advancedoutbound']) && count($config['nat']['advancedoutbound']['rule']) > 0) {
272
        		foreach ($config['nat']['advancedoutbound']['rule'] as $x => $rule) {
273
                	        if($rule['interface'] == $id)
274
           	    	                 unset($config['nat']['advancedoutbound']['rule'][$x]['interface']);
275
        		}
276
		}
277
        	if (is_array($config['nat']['rule']) && count($config['nat']['rule']) > 0) {
278
        		foreach ($config['nat']['rule'] as $x => $rule) {
279
                        	if($rule['interface'] == $id)
280
                	                unset($config['nat']['rule'][$x]['interface']);
281
			}
282
        	}
283

    
284
		write_config();
285
	
286
		/* If we are in firewall/routing mode (not single interface)
287
		 * then ensure that we are not running DHCP on the wan which
288
		 * will make a lot of ISP's unhappy.
289
		 */
290
		if($config['interfaces']['lan']) {
291
			unset($config['dhcpd']['wan']);		
292
		}
293

    
294
		link_interface_to_vlans($realid, "update");
295
	
296
		$savemsg = "Interface has been deleted.";
297
	}
298
}
299

    
300
if ($_GET['act'] == "add") {
301
	/* find next free optional interface number */
302
	if(!$config['interfaces']['lan']) {
303
		$newifname = "lan";
304
		$descr = "LAN";
305
		$config['interfaces'][$newifname] = array();
306
		$config['interfaces'][$newifname]['descr'] = $descr;
307
	} else {
308
		for ($i = 1; $i <= count($config['interfaces']); $i++) {
309
			if (!$config['interfaces']["opt{$i}"])
310
				break;
311
		}
312
		$newifname = 'opt' . $i;
313
		$descr = "OPT{$i}";
314
		$config['interfaces'][$newifname] = array();
315
		$config['interfaces'][$newifname]['descr'] = $descr;
316
	}
317

    
318
	uksort($config['interfaces'], "compare_interface_names");
319

    
320
	/* Find an unused port for this interface */
321
	foreach ($portlist as $portname => $portinfo) {
322
		$portused = false;
323
		foreach ($config['interfaces'] as $ifname => $ifdata) {
324
			if ($ifdata['if'] == $portname) {
325
				$portused = true;
326
				break;
327
			}
328
		}
329
		if (!$portused) {
330
			$config['interfaces'][$newifname]['if'] = $portname;
331
			if (preg_match($g['wireless_regex'], $portname)) {
332
				$config['interfaces'][$newifname]['wireless'] = array();
333
				interface_sync_wireless_clones($config['interfaces'][$newifname], false);
334
			}
335
			break;
336
		}
337
	}
338
	
339
        /* XXX: Do not remove this. */
340
        mwexec("/bin/rm -f /tmp/config.cache");
341

    
342
	write_config();
343

    
344
	$savemsg = "Interface has been added.";
345

    
346
}
347

    
348
function compare_interface_names($a, $b) {
349
	if ($a == $b)
350
		return 0;
351
	else if ($a == 'wan')
352
		return -1;
353
	else if ($b == 'wan')
354
		return 1;
355
	else if ($a == 'lan')
356
		return -1;
357
	else if ($b == 'lan')
358
		return 1;
359

    
360
	return strnatcmp($a, $b);
361
}
362

    
363
include("head.inc");
364

    
365
if(file_exists("/var/run/interface_mismatch_reboot_needed")) 
366
	if ($_POST)
367
		$savemsg = "Reboot is needed. Please apply the settings in order to reboot.";
368
	else
369
		$savemsg = "Interface mismatch detected.  Please resolve the mismatch and click Save.  The firewall will reboot afterwards.";
370

    
371
?>
372

    
373
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
374
<?php include("fbegin.inc"); ?>
375

    
376
<form action="interfaces_assign.php" method="post" name="iform" id="iform">
377

    
378
<?php if (file_exists("/tmp/reload_interfaces")): ?><p>
379
	<?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>
380
<?php elseif($savemsg): ?>
381
	<?php print_info_box($savemsg); ?>
382
<?php endif; ?>
383

    
384
<?php if ($input_errors) print_input_errors($input_errors); ?>
385

    
386
<table width="100%" border="0" cellpadding="0" cellspacing="0">
387
  <tr><td class="tabnavtbl">
388
<?php
389
	$tab_array = array();
390
	$tab_array[0] = array("Interface assignments", true, "interfaces_assign.php");
391
	$tab_array[1] = array("Interface Groups", false, "interfaces_groups.php");
392
	$tab_array[2] = array("Wireless", false, "interfaces_wireless.php");
393
	$tab_array[3] = array("VLANs", false, "interfaces_vlan.php");
394
	$tab_array[4] = array("QinQs", false, "interfaces_qinq.php");
395
	$tab_array[5] = array("PPP", false, "interfaces_ppp.php");
396
        $tab_array[6] = array("GRE", false, "interfaces_gre.php");
397
        $tab_array[7] = array("GIF", false, "interfaces_gif.php");
398
	$tab_array[8] = array("Bridges", false, "interfaces_bridge.php");
399
	$tab_array[9] = array("LAGG", false, "interfaces_lagg.php");
400
	display_top_tabs($tab_array);
401
?>  
402
  </td></tr>
403
  <tr> 
404
    <td>
405
	<div id="mainarea">
406
        <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
407
       <tr> 
408
	<td class="listhdrr">Interface</td>
409
	<td class="listhdr">Network port</td>
410
	<td class="list">&nbsp;</td>
411
  </tr>
412
  <?php foreach ($config['interfaces'] as $ifname => $iface):
413
  	if ($iface['descr'])
414
		$ifdescr = $iface['descr'];
415
	else
416
		$ifdescr = strtoupper($ifname);
417
	?>
418
  <tr> 
419
	<td class="listlr" valign="middle"><strong><?=$ifdescr;?></strong></td>
420
	  <td valign="middle" class="listr">
421
		<select name="<?=$ifname;?>" id="<?=$ifname;?>">
422
		  <?php foreach ($portlist as $portname => $portinfo): ?>
423
		  <option value="<?=$portname;?>" <?php if ($portname == $iface['if']) echo "selected";?>> 
424
		  <?php if ($portinfo['isvlan']) {
425
			$descr = "VLAN {$portinfo['tag']} on {$portinfo['if']}";
426
		if ($portinfo['descr'])
427
			$descr .= " (" . $portinfo['descr'] . ")";
428
			echo htmlspecialchars($descr);
429
                } elseif ($portinfo['iswlclone']) {
430
                        $descr = $portinfo['cloneif'];
431
                        if ($portinfo['descr'])
432
				$descr .= " (" . $portinfo['descr'] . ")";
433
                        echo htmlspecialchars($descr);
434
		} elseif ($portinfo['isppp']) {
435
			echo htmlspecialchars($portinfo['descr']);
436
                } elseif ($portinfo['isbridge']) {
437
                        $descr = strtoupper($portinfo['bridgeif']);
438
                        if ($portinfo['descr'])
439
				$descr .= " (" . $portinfo['descr'] . ")";
440
                        echo htmlspecialchars($descr);
441
                } elseif ($portinfo['isgre']) {
442
                        $descr = "GRE {$portinfo['remote-addr']}";
443
                        if ($portinfo['descr'])
444
				$descr .= " (" . $portinfo['descr'] . ")";
445
                        echo htmlspecialchars($descr);
446
                } elseif ($portinfo['isgif']) {
447
                        $descr = "GRE {$portinfo['remote-addr']}";
448
                        if ($portinfo['descr'])
449
				$descr .= " (" . $portinfo['descr'] . ")";
450
                        echo htmlspecialchars($descr);
451
                } elseif ($portinfo['islagg']) {
452
                        $descr = strtoupper($portinfo['laggif']);
453
                        if ($portinfo['descr'])
454
				$descr .= " (" . $portinfo['descr'] . ")";
455
                        echo htmlspecialchars($descr);
456
		} elseif ($portinfo['isqinq']) {
457
			echo htmlspecialchars($portinfo['descr']);
458
		} else
459
			echo htmlspecialchars($portname . " (" . $portinfo['mac'] . ")");
460
		?>
461
		</option>
462
		<?php endforeach; ?>
463
	</select>
464
	</td>
465
	<td valign="middle" class="list">
466
		  <?php if ($ifname != 'wan'): ?>
467
		  <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> 
468
		  <?php endif; ?>
469
		</td>
470
  </tr>
471
  <?php endforeach; ?>
472
  <?php if (count($config['interfaces']) < count($portlist)): ?>
473
  <tr>
474
	<td class="list" colspan="2"></td>
475
	<td class="list" nowrap>
476
	<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>
477
	</td>
478
  </tr>
479
  <?php else: ?>
480
  <tr>
481
	<td class="list" colspan="3" height="10"></td>
482
  </tr>
483
  <?php endif; ?>
484
</table>
485
</div>
486
<br/>
487
<input name="Submit" type="submit" class="formbtn" value="Save"><br><br>
488
<p>
489
</p>
490
<ul>
491
  <li><span class="vexpl">change the IP address of your computer</span></li>
492
  <li><span class="vexpl">renew its DHCP lease</span></li>
493
  <li><span class="vexpl">access the webConfigurator with the new IP address</span></li>
494
  <li><span class="vexpl">interfaces that are configured as members of a lagg(4) interface will not be shown.</span></li>
495
</ul></td>
496
	</tr>
497
</table>
498
</form>
499
<?php include("fend.inc"); ?>
500
</body>
501
</html>
(80-80/218)