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
	$i = 0;
131
	foreach ($config['ppps']['ppp'] as $ppp) {
132
		$portname = 'ppp_' . basename($ppp['port']);
133
		$portlist[$portname] = $ppp;
134
		$portlist[$portname]['isppp'] = true;
135
		$i++;
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
		/* No errors detected, so update the config */
192
		foreach ($_POST as $ifname => $ifport) {
193
		
194
			if (($ifname == 'lan') || ($ifname == 'wan') ||
195
				(substr($ifname, 0, 3) == 'opt')) {
196
				
197
				if (!is_array($ifport)) {
198
					$reloadif = false;
199
					if (!empty($config['interfaces'][$ifname]['if']) && $config['interfaces'][$ifname]['if'] <> $ifport) {
200
						interface_bring_down($ifname);
201
						/* Mark this to be reconfigured in any case. */
202
						$reloadif = true;
203
					}
204
					$config['interfaces'][$ifname]['if'] = $ifport;
205
					if (preg_match('/^ppp_(.+)$/', $ifport, $matches)) {
206
						$config['interfaces'][$ifname]['pointtopoint'] = true;
207
						$config['interfaces'][$ifname]['serialport'] = $matches[1];
208
					} else {
209
						unset($config['interfaces'][$ifname]['pointtopoint']);
210
						unset($config['interfaces'][$ifname]['serialport']);
211
					}
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
					if ($reloadif == true)
225
						/* Reload all for the interface. */
226
						interface_configure($ifname, true);
227
				}
228

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

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

    
242
	if (link_interface_to_bridge($id))
243
		$input_errors[] = "The interface is part of a bridge. Please remove it from the bridge to continue";
244
	else if (link_interface_to_gre($id))
245
		$input_errors[] = "The interface is part of a gre tunnel. Please delete the tunnel to continue";
246
	else if (link_interface_to_gif($id))
247
		$input_errors[] = "The interface is part of a gif tunnel. Please delete the tunnel to continue";
248
	else {
249
		unset($config['interfaces'][$id]['enable']);
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 ($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
		if ($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
        	if (count($config['nat']['rule']) > 0) 
276
        	foreach ($config['nat']['rule'] as $x => $rule) {
277
                        	if($rule['interface'] == $id)
278
                	                unset($config['nat']['rule'][$x]['interface']);
279
        	}
280

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

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

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

    
337
	write_config();
338

    
339
	$savemsg = "Interface has been added.";
340

    
341
}
342

    
343
include("head.inc");
344

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

    
351
?>
352

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

    
356
<form action="interfaces_assign.php" method="post" name="iform" id="iform">
357

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

    
364
<?php if ($input_errors) print_input_errors($input_errors); ?>
365

    
366
<table width="100%" border="0" cellpadding="0" cellspacing="0">
367
  <tr><td class="tabnavtbl">
368
<?php
369
	$tab_array = array();
370
	$tab_array[0] = array("Interface assignments", true, "interfaces_assign.php");
371
	$tab_array[1] = array("Interface Groups", false, "interfaces_groups.php");
372
	$tab_array[2] = array("Wireless", false, "interfaces_wireless.php");
373
	$tab_array[3] = array("VLANs", false, "interfaces_vlan.php");
374
	$tab_array[4] = array("QinQs", false, "interfaces_qinq.php");
375
	$tab_array[5] = array("PPP", false, "interfaces_ppp.php");
376
        $tab_array[6] = array("GRE", false, "interfaces_gre.php");
377
        $tab_array[7] = array("GIF", false, "interfaces_gif.php");
378
	$tab_array[8] = array("Bridges", false, "interfaces_bridge.php");
379
	$tab_array[9] = array("LAGG", false, "interfaces_lagg.php");
380
	display_top_tabs($tab_array);
381
?>  
382
  </td></tr>
383
  <tr> 
384
    <td>
385
	<div id="mainarea">
386
        <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
387
       <tr> 
388
	<td class="listhdrr">Interface</td>
389
	<td class="listhdr">Network port</td>
390
	<td class="list">&nbsp;</td>
391
  </tr>
392
  <?php foreach ($config['interfaces'] as $ifname => $iface):
393
  	if ($iface['descr'])
394
		$ifdescr = $iface['descr'];
395
	else
396
		$ifdescr = strtoupper($ifname);
397
	?>
398
  <tr> 
399
	<td class="listlr" valign="middle"><strong><?=$ifdescr;?></strong></td>
400
	  <td valign="middle" class="listr">
401
		<select name="<?=$ifname;?>" id="<?=$ifname;?>">
402
		  <?php foreach ($portlist as $portname => $portinfo): ?>
403
		  <option value="<?=$portname;?>" <?php if ($portname == $iface['if']) echo "selected";?>> 
404
		  <?php if ($portinfo['isvlan']) {
405
			$descr = "VLAN {$portinfo['tag']} on {$portinfo['if']}";
406
		if ($portinfo['descr'])
407
			$descr .= " (" . $portinfo['descr'] . ")";
408
			echo htmlspecialchars($descr);
409
                } elseif ($portinfo['iswlclone']) {
410
                        $descr = $portinfo['cloneif'];
411
                        if ($portinfo['descr'])
412
				$descr .= " (" . $portinfo['descr'] . ")";
413
                        echo htmlspecialchars($descr);
414
		} elseif ($portinfo['isppp']) {
415
			$descr = "PPP {$portinfo['port']}";
416
			if ($portinfo['descr'])
417
				$descr .= " (" . $portinfo['descr'] . ")";
418
			echo htmlspecialchars($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>
(81-81/218)