Project

General

Profile

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

    
340
	write_config();
341

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

    
344
}
345

    
346
include("head.inc");
347

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

    
354
?>
355

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

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

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

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

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