Project

General

Profile

Download (17.1 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 = $ppp['type'].$pppid;
132
		$portlist[$portname] = $ppp;
133
		$portlist[$portname]['isppp'] = true;
134
		$portlist[$portname]['pppid'] = $pppid;
135
		$portlist[$portname]['descr'] = strtoupper($ppp['type']) . $pppid ." - ".$ppp['descr'];
136
	}
137
}
138

    
139
if ($_POST['apply']) {
140
	if (file_exists("/var/run/interface_mismatch_reboot_needed"))
141
		exec("/etc/rc.reboot");
142
	else {
143
		write_config();
144

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

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

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

    
157
} else if ($_POST) {
158

    
159
	unset($input_errors);
160

    
161
	/* input validation */
162

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

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

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

    
189

    
190
	if (!$input_errors) {
191
		/* The 'ifname' must be unset for all PPPs before continuing or we can get legacy data
192
		left in the ppps config sections */
193
		if (is_array($config['ppps']['ppp']) && count($config['ppps']['ppp'])){
194
			foreach ($config['ppps']['ppp'] as $pppid => $ppp) {
195
				unset($config['ppps']['ppp'][$pppid]['ifname']);
196
			}
197
		}
198
		/* No errors detected, so update the config */
199
		foreach ($_POST as $ifname => $ifport) {
200
		
201
			if (($ifname == 'lan') || ($ifname == 'wan') ||
202
				(substr($ifname, 0, 3) == 'opt')) {
203
				
204
				if (!is_array($ifport)) {
205
					$reloadif = false;
206
					if (!empty($config['interfaces'][$ifname]['if']) && $config['interfaces'][$ifname]['if'] <> $ifport) {
207
						interface_bring_down($ifname);
208
						/* Mark this to be reconfigured in any case. */
209
						$reloadif = true;
210
					}
211
					$config['interfaces'][$ifname]['if'] = $ifport;
212
					
213
					/*For PPP interfaces, write link type to IP address field to signal that IP 
214
					addr is dynamic and comes from PPP, PPPoE, or PPTP */
215
					if (isset($portlist[$ifport]['isppp'])){
216
						$config['interfaces'][$ifname]['ipaddr'] = $portlist[$ifport]['type'];
217
						foreach ($config['ppps']['ppp'] as $pppid => $ppp) {
218
							if ($portlist[$ifport]['pppid'] == $pppid)
219
								$config['ppps']['ppp'][$pppid]['ifname'] = $ifname;
220
						}
221
					}
222
					/* check for wireless interfaces, set or clear ['wireless'] */
223
					if (preg_match($g['wireless_regex'], $ifport)) {
224
						if (!is_array($config['interfaces'][$ifname]['wireless']))
225
							$config['interfaces'][$ifname]['wireless'] = array();
226
					} else {
227
						unset($config['interfaces'][$ifname]['wireless']);
228
					}
229
					
230
					/* make sure there is a descr for all interfaces */
231
					if (!isset($config['interfaces'][$ifname]['descr']))
232
						$config['interfaces'][$ifname]['descr'] = strtoupper($ifname);
233
						
234
					if ($reloadif == true) {
235
						if (preg_match($g['wireless_regex'], $ifport))
236
							interface_sync_wireless_clones($config['interfaces'][$ifname], false);
237
						/* Reload all for the interface. */
238
						interface_configure($ifname, true);
239
					}
240
				}
241

    
242
				touch("/tmp/reload_interfaces");
243
			}
244
		}
245
	
246
		write_config();
247
		
248
		enable_rrd_graphing();
249
	}
250
}
251

    
252
if ($_GET['act'] == "del") {
253
	$id = $_GET['id'];
254

    
255
	if (link_interface_to_bridge($id))
256
		$input_errors[] = "The interface is part of a bridge. Please remove it from the bridge to continue";
257
	else if (link_interface_to_gre($id))
258
		$input_errors[] = "The interface is part of a gre tunnel. Please delete the tunnel to continue";
259
	else if (link_interface_to_gif($id))
260
		$input_errors[] = "The interface is part of a gif tunnel. Please delete the tunnel to continue";
261
	else {
262
		unset($config['interfaces'][$id]['enable']);
263
		interface_bring_down($id);   /* down the interface */
264
		
265
		unset($config['interfaces'][$id]);	/* delete the specified OPTn or LAN*/
266

    
267
		if($id == "lan") {
268
			unset($config['interfaces']['lan']);
269
			if (is_array($config['dhcpd']))
270
				unset($config['dhcpd']['lan']);
271
				unset($config['shaper']);
272
				unset($config['ezshaper']);
273
				unset($config['nat']);
274
				system("rm /var/dhcpd/var/db/*");
275
        			services_dhcpd_configure();
276
		}
277

    
278
		if (count($config['filter']['rule']) > 0) {
279
			foreach ($config['filter']['rule'] as $x => $rule) {
280
				if($rule['interface'] == $id)
281
					unset($config['filter']['rule'][$x]);
282
			}
283
        	}
284
		if (is_array($config['nat']['advancedoutbound']) && count($config['nat']['advancedoutbound']['rule']) > 0) {
285
        	foreach ($config['nat']['advancedoutbound']['rule'] as $x => $rule) {
286
				if($rule['interface'] == $id)
287
					unset($config['nat']['advancedoutbound']['rule'][$x]['interface']);
288
        		}
289
		}
290
		if (is_array($config['nat']['rule']) && count($config['nat']['rule']) > 0) {
291
			foreach ($config['nat']['rule'] as $x => $rule) {
292
				if($rule['interface'] == $id)
293
					unset($config['nat']['rule'][$x]['interface']);
294
			}
295
        }
296
        /* Clean up association with deleted interface in PPPs config section */
297
        if (is_array($config['ppps']['ppp']) && count($config['ppps']['ppp'])){
298
        	foreach ($config['ppps']['ppp'] as $pppid => $ppp) {
299
        		if ($ppp['ifname'] == $id)
300
        			unset($config['ppps']['ppp'][$pppid]['ifname']);
301
        	}
302
        }
303

    
304
		write_config();
305
	
306
		/* If we are in firewall/routing mode (not single interface)
307
		 * then ensure that we are not running DHCP on the wan which
308
		 * will make a lot of ISP's unhappy.
309
		 */
310
		if($config['interfaces']['lan']) {
311
			unset($config['dhcpd']['wan']);		
312
		}
313

    
314
		link_interface_to_vlans($id, "update");
315
	
316
		$savemsg = "Interface has been deleted.";
317
	}
318
}
319

    
320
if ($_GET['act'] == "add") {
321
	/* find next free optional interface number */
322
	if(!$config['interfaces']['lan']) {
323
		$newifname = "lan";
324
		$config['interfaces'][$newifname] = array();
325
		$config['interfaces'][$newifname]['descr'] = $descr;
326
	} else {
327
		for ($i = 1; $i <= count($config['interfaces']); $i++) {
328
			if (!$config['interfaces']["opt{$i}"])
329
				break;
330
		}
331
		$newifname = 'opt' . $i;
332
		$descr = "OPT{$i}";
333
		$config['interfaces'][$newifname] = array();
334
		$config['interfaces'][$newifname]['descr'] = $descr;
335
		uksort($config['interfaces'], "strnatcmp");
336
	}
337
	
338
	/* Find an unused port for this interface */
339
	foreach ($portlist as $portname => $portinfo) {
340
		$portused = false;
341
		foreach ($config['interfaces'] as $ifname => $ifdata) {
342
			if ($ifdata['if'] == $portname) {
343
				$portused = true;
344
				break;
345
			}
346
		}
347
		if (!$portused) {
348
			$config['interfaces'][$newifname]['if'] = $portname;
349
			if (preg_match($g['wireless_regex'], $portname)) {
350
				$config['interfaces'][$newifname]['wireless'] = array();
351
				interface_sync_wireless_clones($config['interfaces'][$newifname], false);
352
			}
353
			break;
354
		}
355
	}
356
	
357
        /* XXX: Do not remove this. */
358
        mwexec("/bin/rm -f /tmp/config.cache");
359

    
360
	write_config();
361

    
362
	$savemsg = "Interface has been added.";
363

    
364
}
365

    
366
include("head.inc");
367

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

    
374
?>
375

    
376
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
377
<?php include("fbegin.inc"); ?>
378

    
379
<form action="interfaces_assign.php" method="post" name="iform" id="iform">
380

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

    
387
<?php if ($input_errors) print_input_errors($input_errors); ?>
388

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