Project

General

Profile

Download (17 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(gettext("Interfaces"),gettext("Assign network ports"));
44
$statusurl = "status_interfaces.php";
45

    
46
require("guiconfig.inc");
47
require("functions.inc");
48
require("filter.inc");
49
require("shaper.inc");
50
require("ipsec.inc");
51
require("vpn.inc");
52
require("captiveportal.inc");
53
require("rrd.inc");
54

    
55
/*
56
	In this file, "port" refers to the physical port name,
57
	while "interface" refers to LAN, WAN, or OPTn.
58
*/
59

    
60
/* get list without VLAN interfaces */
61
$portlist = get_interface_list();
62

    
63
/* add wireless clone interfaces */
64
if (is_array($config['wireless']['clone']) && count($config['wireless']['clone'])) {
65
	foreach ($config['wireless']['clone'] as $clone) {
66
		$portlist[$clone['cloneif']] = $clone;
67
		$portlist[$clone['cloneif']]['iswlclone'] = true;
68
	}
69
}
70

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

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

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

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

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

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

    
130
/* add PPP interfaces */
131
if (is_array($config['ppps']['ppp']) && count($config['ppps']['ppp'])) {
132
	foreach ($config['ppps']['ppp'] as $pppid => $ppp) {
133
		$portname = $ppp['if'];
134
		$portlist[$portname] = $ppp;
135
		$portlist[$portname]['isppp'] = true;
136
		$ports_base = basename($ppp['ports']);
137
		if (isset($ppp['descr']))
138
			$portlist[$portname]['descr'] = strtoupper($ppp['if']). "({$ports_base}) - {$ppp['descr']}";
139
		else if (isset($ppp['username']))
140
			$portlist[$portname]['descr'] = strtoupper($ppp['if']). "({$ports_base}) - {$ppp['username']}";
141
		else
142
			$portlist[$portname]['descr'] = strtoupper($ppp['if']). "({$ports_base})";
143
	}
144
}
145

    
146
if ($_POST['apply']) {
147
	if (file_exists("/var/run/interface_mismatch_reboot_needed"))
148
		system_reboot();
149
	else {
150
		write_config();
151

    
152
		$retval = 0;
153
		$retval = filter_configure();
154
		$savemsg = get_std_save_message($retval);
155

    
156
		if (stristr($retval, "error") <> true)
157
			$savemsg = get_std_save_message($retval);
158
		else
159
			$savemsg = $retval;
160
	}
161

    
162
} else if ($_POST) {
163

    
164
	unset($input_errors);
165

    
166
	/* input validation */
167

    
168
	/* Build a list of the port names so we can see how the interfaces map */
169
	$portifmap = array();
170
	foreach ($portlist as $portname => $portinfo)
171
		$portifmap[$portname] = array();
172

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

    
180
	/* Deliver error message for any port with more than one assignment */
181
	foreach ($portifmap as $portname => $ifnames) {
182
		if (count($ifnames) > 1) {
183
			$errstr = sprintf(gettext('Port %1$s '.
184
				' was assigned to %2$s' .
185
				' interfaces:'), $portname, count($ifnames));
186
				
187
			foreach ($portifmap[$portname] as $ifn)
188
				$errstr .= " " . $ifn;
189
			
190
			$input_errors[] = $errstr;
191
		}
192
	}
193

    
194

    
195
	if (!$input_errors) {
196
		/* No errors detected, so update the config */
197
		foreach ($_POST as $ifname => $ifport) {
198
		
199
			if (($ifname == 'lan') || ($ifname == 'wan') ||
200
				(substr($ifname, 0, 3) == 'opt')) {
201
				
202
				if (!is_array($ifport)) {
203
					$reloadif = false;
204
					if (!empty($config['interfaces'][$ifname]['if']) && $config['interfaces'][$ifname]['if'] <> $ifport) {
205
						interface_bring_down($ifname);
206
						/* Mark this to be reconfigured in any case. */
207
						$reloadif = true;
208
					}
209
					$config['interfaces'][$ifname]['if'] = $ifport;
210
					if (isset($portlist[$ifport]['isppp']))
211
						$config['interfaces'][$ifname]['ipaddr'] = $portlist[$ifport]['type'];
212
					
213
					/* check for wireless interfaces, set or clear ['wireless'] */
214
					if (preg_match($g['wireless_regex'], $ifport)) {
215
						if (!is_array($config['interfaces'][$ifname]['wireless']))
216
							$config['interfaces'][$ifname]['wireless'] = array();
217
					} else {
218
						unset($config['interfaces'][$ifname]['wireless']);
219
					}
220
					
221
					/* make sure there is a descr for all interfaces */
222
					if (!isset($config['interfaces'][$ifname]['descr']))
223
						$config['interfaces'][$ifname]['descr'] = strtoupper($ifname);
224
						
225
					if ($reloadif == true) {
226
						if (preg_match($g['wireless_regex'], $ifport))
227
							interface_sync_wireless_clones($config['interfaces'][$ifname], false);
228
						/* Reload all for the interface. */
229
						interface_configure($ifname, true);
230
					}
231
				}
232
			}
233
		}
234
	
235
		write_config();
236
		
237
		enable_rrd_graphing();
238
	}
239
}
240

    
241
if ($_GET['act'] == "del") {
242
	$id = $_GET['id'];
243

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

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

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

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

    
297
		link_interface_to_vlans($realid, "update");
298
	
299
		$savemsg = gettext("Interface has been deleted.");
300
	}
301
}
302

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

    
321
	uksort($config['interfaces'], "compare_interface_names");
322

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

    
345
	write_config();
346

    
347
	$savemsg = gettext("Interface has been added.");
348

    
349
}
350

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

    
363
	return strnatcmp($a, $b);
364
}
365

    
366
include("head.inc");
367

    
368
if(file_exists("/var/run/interface_mismatch_reboot_needed")) 
369
	if ($_POST)
370
		$savemsg = gettext("Reboot is needed. Please apply the settings in order to reboot.");
371
	else
372
		$savemsg = gettext("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(gettext("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(gettext("Interface assignments"), true, "interfaces_assign.php");
394
	$tab_array[1] = array(gettext("Interface Groups"), false, "interfaces_groups.php");
395
	$tab_array[2] = array(gettext("Wireless"), false, "interfaces_wireless.php");
396
	$tab_array[3] = array(gettext("VLANs"), false, "interfaces_vlan.php");
397
	$tab_array[4] = array(gettext("QinQs"), false, "interfaces_qinq.php");
398
	$tab_array[5] = array(gettext("PPPs"), false, "interfaces_ppps.php");
399
	$tab_array[7] = array(gettext("GRE"), false, "interfaces_gre.php");
400
	$tab_array[8] = array(gettext("GIF"), false, "interfaces_gif.php");
401
	$tab_array[9] = array(gettext("Bridges"), false, "interfaces_bridge.php");
402
	$tab_array[10] = array(gettext("LAGG"), false, "interfaces_lagg.php");
403
	display_top_tabs($tab_array);
404
?>  
405
  </td></tr>
406
  <tr> 
407
    <td>
408
	<div id="mainarea">
409
        <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
410
       <tr> 
411
	<td class="listhdrr"><?=gettext("Interface"); ?></td>
412
	<td class="listhdr"><?=gettext("Network port"); ?></td>
413
	<td class="list">&nbsp;</td>
414
  </tr>
415
  <?php foreach ($config['interfaces'] as $ifname => $iface):
416
  	if ($iface['descr'])
417
		$ifdescr = $iface['descr'];
418
	else
419
		$ifdescr = strtoupper($ifname);
420
	?>
421
  <tr> 
422
	<td class="listlr" valign="middle"><strong><?=$ifdescr;?></strong></td>
423
	  <td valign="middle" class="listr">
424
		<select onChange="javascript:\$('savediv').appear();" name="<?=$ifname;?>" id="<?=$ifname;?>">
425
		  <?php foreach ($portlist as $portname => $portinfo): ?>
426
			<option  value="<?=$portname;?>"  <?php if ($portname == $iface['if']) echo " selected";?>>
427
				<?php if ($portinfo['isvlan']) {
428
					$descr = sprintf(gettext('VLAN %1$s on %2$s'),$portinfo['tag'],$portinfo['if']);
429
				if ($portinfo['descr'])
430
					$descr .= " (" . $portinfo['descr'] . ")";
431
					echo htmlspecialchars($descr);
432
				} elseif ($portinfo['iswlclone']) {
433
					$descr = $portinfo['cloneif'];
434
					if ($portinfo['descr'])
435
						$descr .= " (" . $portinfo['descr'] . ")";
436
					echo htmlspecialchars($descr);
437
				} elseif ($portinfo['isppp']) {
438
					echo htmlspecialchars($portinfo['descr']);
439
				} elseif ($portinfo['isbridge']) {
440
					$descr = strtoupper($portinfo['bridgeif']);
441
					if ($portinfo['descr'])
442
						$descr .= " (" . $portinfo['descr'] . ")";
443
					echo htmlspecialchars($descr);
444
				} elseif ($portinfo['isgre']) {
445
					$descr = "GRE {$portinfo['remote-addr']}";
446
					if ($portinfo['descr'])
447
						$descr .= " (" . $portinfo['descr'] . ")";
448
					echo htmlspecialchars($descr);
449
				} elseif ($portinfo['isgif']) {
450
					$descr = "GRE {$portinfo['remote-addr']}";
451
					if ($portinfo['descr'])
452
						$descr .= " (" . $portinfo['descr'] . ")";
453
					echo htmlspecialchars($descr);
454
				} elseif ($portinfo['islagg']) {
455
					$descr = strtoupper($portinfo['laggif']);
456
					if ($portinfo['descr'])
457
						$descr .= " (" . $portinfo['descr'] . ")";
458
					echo htmlspecialchars($descr);
459
				} elseif ($portinfo['isqinq']) {
460
					echo htmlspecialchars($portinfo['descr']);
461
				} else
462
					echo htmlspecialchars($portname . " (" . $portinfo['mac'] . ")");
463
			?></option>
464
		<?php endforeach; ?>
465
	</select>
466
	</td>
467
	<td valign="middle" class="list">
468
		  <?php if ($ifname != 'wan'): ?>
469
		  <a href="interfaces_assign.php?act=del&id=<?=$ifname;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" title=<?=gettext("delete interface"); ?> width="17" height="17" border="0"></a> 
470
		  <?php endif; ?>
471
		</td>
472
  </tr>
473
  <?php endforeach; ?>
474
  <?php if (count($config['interfaces']) < count($portlist)): ?>
475
  <tr>
476
	<td class="list" colspan="2"></td>
477
	<td class="list" nowrap>
478
	<a href="interfaces_assign.php?act=add"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title=<?=gettext("add interface"); ?> width="17" height="17" border="0"></a>
479
	</td>
480
  </tr>
481
  <?php else: ?>
482
  <tr>
483
	<td class="list" colspan="3" height="10"></td>
484
  </tr>
485
  <?php endif; ?>
486
</table>
487
</div>
488
<br/>
489
<div name='savediv' id='savediv' style='display:none;'>
490
	<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>"><br><br>
491
	<p>
492
</div>
493
</p>
494
<ul>
495
  <li><span class="vexpl"><?=gettext("change the IP address of your computer"); ?></span></li>
496
  <li><span class="vexpl"><?=gettext("renew its DHCP lease"); ?></span></li>
497
  <li><span class="vexpl"><?=gettext("access the webConfigurator with the new IP address"); ?></span></li>
498
  <li><span class="vexpl"><?=gettext("interfaces that are configured as members of a lagg(4) interface will not be shown."); ?></span></li>
499
</ul></td>
500
	</tr>
501
</table>
502
</form>
503
<?php include("fend.inc"); ?>
504
</body>
505
</html>
(83-83/222)