Project

General

Profile

Download (16.4 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
		exec("/etc/rc.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
		interface_bring_down($id);   /* down the interface */
250
		
251
		unset($config['interfaces'][$id]);	/* delete the specified OPTn or LAN*/
252

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

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

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

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

    
299
if ($_GET['act'] == "add") {
300
	/* find next free optional interface number */
301
	if(!$config['interfaces']['lan']) {
302
		$newifname = "lan";
303
		$config['interfaces'][$newifname] = array();
304
		$config['interfaces'][$newifname]['descr'] = $descr;
305
	} else {
306
		for ($i = 1; $i <= count($config['interfaces']); $i++) {
307
			if (!$config['interfaces']["opt{$i}"])
308
				break;
309
		}
310
		$newifname = 'opt' . $i;
311
		$descr = "OPT{$i}";
312
		$config['interfaces'][$newifname] = array();
313
		$config['interfaces'][$newifname]['descr'] = $descr;
314
		uksort($config['interfaces'], "strnatcmp");
315
	}
316
	
317
	/* Find an unused port for this interface */
318
	foreach ($portlist as $portname => $portinfo) {
319
		$portused = false;
320
		foreach ($config['interfaces'] as $ifname => $ifdata) {
321
			if ($ifdata['if'] == $portname) {
322
				$portused = true;
323
				break;
324
			}
325
		}
326
		if (!$portused) {
327
			$config['interfaces'][$newifname]['if'] = $portname;
328
			if (preg_match($g['wireless_regex'], $portname)) {
329
				$config['interfaces'][$newifname]['wireless'] = array();
330
				interface_sync_wireless_clones($config['interfaces'][$newifname], false);
331
			}
332
			break;
333
		}
334
	}
335
	
336
        /* XXX: Do not remove this. */
337
        mwexec("/bin/rm -f /tmp/config.cache");
338

    
339
	write_config();
340

    
341
	$savemsg = "Interface has been added.";
342

    
343
}
344

    
345
include("head.inc");
346

    
347
if(file_exists("/var/run/interface_mismatch_reboot_needed")) 
348
	if ($_POST)
349
		$savemsg = "Reboot is needed. Please apply the settings in order to reboot.";
350
	else
351
		$savemsg = "Interface mismatch detected.  Please resolve the mismatch and click Save.  The firewall will reboot afterwards.";
352

    
353
?>
354

    
355
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
356
<?php include("fbegin.inc"); ?>
357

    
358
<form action="interfaces_assign.php" method="post" name="iform" id="iform">
359

    
360
<?php if (file_exists("/tmp/reload_interfaces")): ?><p>
361
	<?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>
362
<?php elseif($savemsg): ?>
363
	<?php print_info_box($savemsg); ?>
364
<?php endif; ?>
365

    
366
<?php if ($input_errors) print_input_errors($input_errors); ?>
367

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