Project

General

Profile

Download (15.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 VLAN interfaces */
62
if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) {
63
	foreach ($config['vlans']['vlan'] as $vlan) {
64
		$portlist[$vlan['vlanif']] = $vlan;
65
		$portlist[$vlan['vlanif']]['isvlan'] = true;
66
	}
67
}
68

    
69
/* add Bridge interfaces */
70
if (is_array($config['bridges']['bridged']) && count($config['bridges']['bridged'])) {
71
        foreach ($config['bridges']['bridged'] as $bridge) {
72
                $portlist[$bridge['bridgeif']] = $bridge;
73
                $portlist[$bridge['bridgeif']]['isbridge'] = true;
74
        }
75
}
76

    
77
/* add GIF interfaces */
78
if (is_array($config['gifs']['gif']) && count($config['gifs']['gif'])) {
79
        foreach ($config['gifs']['gif'] as $gif) {
80
                $portlist[$gif['gifif']] = $gif;
81
                $portlist[$gif['gifif']]['isgif'] = true;
82
        }
83
}
84

    
85
/* add GRE interfaces */
86
if (is_array($config['gres']['gre']) && count($config['gres']['gre'])) {
87
        foreach ($config['gres']['gre'] as $gre) {
88
                $portlist[$gre['greif']] = $gre;
89
                $portlist[$gre['greif']]['isgre'] = true;
90
        }
91
}
92

    
93
/* add LAGG interfaces */
94
if (is_array($config['laggs']['lagg']) && count($config['laggs']['lagg'])) {
95
        foreach ($config['laggs']['lagg'] as $lagg) {
96
                $portlist[$lagg['laggif']] = $lagg;
97
                $portlist[$lagg['laggif']]['islagg'] = true;
98
		/* LAGG members cannot be assigned */
99
		$lagifs = explode(',', $lagg['members']);
100
		foreach ($lagifs as $lagif)
101
			if (isset($portlist[$lagif]))
102
				unset($portlist[$lagif]);
103
        }
104
}
105

    
106
/* add QinQ interfaces */
107
if (is_array($config['qinqs']['qinqentry']) && count($config['qinqs']['qinqentry'])) {
108
        foreach ($config['qinqs']['qinqentry'] as $qinq) {
109
                $portlist["vlan{$qinq['tag']}"]['descr'] = "VLAN {$qinq['tag']}";
110
                $portlist["vlan{$qinq['tag']}"]['isqinq'] = true;
111
                /* QinQ members */
112
                $qinqifs = explode(' ', $qinq['members']);
113
                foreach ($qinqifs as $qinqif) {
114
			$portlist["vlan{$qinq['tag']}_{$qinqif}"]['descr'] = "QinQ {$qinqif}";
115
			$portlist["vlan{$qinq['tag']}_{$qinqif}"]['isqinq'] = true;
116
		}
117
        }
118
}
119

    
120
/* add PPP interfaces */
121
if (is_array($config['ppps']['ppp']) && count($config['ppps']['ppp'])) {
122
	$i = 0;
123
	foreach ($config['ppps']['ppp'] as $ppp) {
124
		$portname = 'ppp_' . basename($ppp['port']);
125
		$portlist[$portname] = $ppp;
126
		$portlist[$portname]['isppp'] = true;
127
		$i++;
128
	}
129
}
130

    
131
if ($_POST['apply']) {
132
	if (file_exists("/var/run/interface_mismatch_reboot_needed"))
133
		exec("/etc/rc.reboot");
134
	else {
135
		write_config();
136

    
137
		$retval = 0;
138
		$retval = filter_configure();
139
		$savemsg = get_std_save_message($retval);
140

    
141
		if (stristr($retval, "error") <> true)
142
			$savemsg = get_std_save_message($retval);
143
		else
144
			$savemsg = $retval;
145

    
146
		unlink_if_exists("/tmp/reload_interfaces");
147
	}
148

    
149
} else if ($_POST) {
150

    
151
	unset($input_errors);
152

    
153
	/* input validation */
154

    
155
	/* Build a list of the port names so we can see how the interfaces map */
156
	$portifmap = array();
157
	foreach ($portlist as $portname => $portinfo)
158
		$portifmap[$portname] = array();
159

    
160
	/* Go through the list of ports selected by the user,
161
	   build a list of port-to-interface mappings in portifmap */
162
	foreach ($_POST as $ifname => $ifport) {
163
		if (($ifname == 'lan') || ($ifname == 'wan') || (substr($ifname, 0, 3) == 'opt'))
164
			$portifmap[$ifport][] = strtoupper($ifname);
165
	}
166

    
167
	/* Deliver error message for any port with more than one assignment */
168
	foreach ($portifmap as $portname => $ifnames) {
169
		if (count($ifnames) > 1) {
170
			$errstr = "Port " . $portname .
171
				" was assigned to " . count($ifnames) .
172
				" interfaces:";
173
				
174
			foreach ($portifmap[$portname] as $ifn)
175
				$errstr .= " " . $ifn;
176
			
177
			$input_errors[] = $errstr;
178
		}
179
	}
180

    
181

    
182
	if (!$input_errors) {
183
		/* No errors detected, so update the config */
184
		foreach ($_POST as $ifname => $ifport) {
185
		
186
			if (($ifname == 'lan') || ($ifname == 'wan') ||
187
				(substr($ifname, 0, 3) == 'opt')) {
188
				
189
				if (!is_array($ifport)) {
190
					$reloadif = false;
191
					if (!empty($config['interfaces'][$ifname]['if']) && $config['interfaces'][$ifname]['if'] <> $ifport)
192
						/* Mark this to be reconfigured in any case. */
193
						$reloadif = true;
194
					$config['interfaces'][$ifname]['if'] = $ifport;
195
					if (preg_match('/^ppp_(.+)$/', $ifport, $matches)) {
196
						$config['interfaces'][$ifname]['pointtopoint'] = true;
197
						$config['interfaces'][$ifname]['serialport'] = $matches[1];
198
					}
199

    
200
					/* check for wireless interfaces, set or clear ['wireless'] */
201
					if (preg_match($g['wireless_regex'], $ifport)) {
202
						if (!is_array($config['interfaces'][$ifname]['wireless']))
203
							$config['interfaces'][$ifname]['wireless'] = array();
204
					} else {
205
						unset($config['interfaces'][$ifname]['wireless']);
206
					}
207
					
208
					/* make sure there is a descr for all interfaces */
209
					if (!isset($config['interfaces'][$ifname]['descr']))
210
						$config['interfaces'][$ifname]['descr'] = strtoupper($ifname);
211
					if ($reloadif == true)
212
						/* Reload all for the interface. */
213
						interface_configure($ifname, true);
214
				}
215

    
216
				touch("/tmp/reload_interfaces");
217
			}
218
		}
219
	
220
		write_config();
221
		
222
		enable_rrd_graphing();
223
	}
224
}
225

    
226
if ($_GET['act'] == "del") {
227
	$id = $_GET['id'];
228

    
229
	if (link_interface_to_bridge($id))
230
		$input_errors[] = "The interface is part of a bridge. Please remove it from the bridge to continue";
231
	else if (link_interface_to_gre($id))
232
		$input_errors[] = "The interface is part of a gre tunnel. Please delete the tunnel to continue";
233
	else if (link_interface_to_gif($id))
234
		$input_errors[] = "The interface is part of a gif tunnel. Please delete the tunnel to continue";
235
	else {
236
		unset($config['interfaces'][$id]['enable']);
237
		interface_bring_down($id);   /* down the interface */
238
		
239
		unset($config['interfaces'][$id]);	/* delete the specified OPTn or LAN*/
240

    
241
		if($id == "lan") {
242
			unset($config['interfaces']['lan']);
243
			if (is_array($config['dhcpd']))
244
				unset($config['dhcpd']['lan']);
245
				unset($config['shaper']);
246
				unset($config['ezshaper']);
247
				unset($config['nat']);
248
				system("rm /var/dhcpd/var/db/*");
249
        			services_dhcpd_configure();
250
		}
251

    
252
		if ($config['filter']['rule'] > 0)
253
       	 	foreach ($config['filter']['rule'] as $x => $rule) {
254
                	        if($rule['interface'] == $id)
255
               		                 unset($config['filter']['rule'][$x]);
256
        	}
257
		if ($config['nat']['advancedoutbound']['rule'] > 0)
258
        	foreach ($config['nat']['advancedoutbound']['rule'] as $x => $rule) {
259
                	        if($rule['interface'] == $id)
260
           	    	                 unset($config['nat']['advancedoutbound']['rule'][$x]['interface']);
261
        	}
262
        	if (count($config['nat']['rule']) > 0) 
263
        	foreach ($config['nat']['rule'] as $x => $rule) {
264
                        	if($rule['interface'] == $id)
265
                	                unset($config['nat']['rule'][$x]['interface']);
266
        	}
267

    
268
		write_config();
269
	
270
		/* If we are in firewall/routing mode (not single interface)
271
		 * then ensure that we are not running DHCP on the wan which
272
		 * will make a lot of ISP's unhappy.
273
		 */
274
		if($config['interfaces']['lan']) {
275
			unset($config['dhcpd']['wan']);		
276
		}
277

    
278
		link_interface_to_vlans($id, "update");
279
	
280
		$savemsg = "Interface has been deleted.";
281
	}
282
}
283

    
284
if ($_GET['act'] == "add") {
285
	/* find next free optional interface number */
286
	if(!$config['interfaces']['lan']) {
287
		$newifname = "lan";
288
		$config['interfaces'][$newifname] = array();
289
		$config['interfaces'][$newifname]['descr'] = $descr;
290
	} else {
291
		for ($i = 1; $i <= count($config['interfaces']); $i++) {
292
			if (!$config['interfaces']["opt{$i}"])
293
				break;
294
		}
295
		$newifname = 'opt' . $i;
296
		$descr = "OPT{$i}";
297
		$config['interfaces'][$newifname] = array();
298
		$config['interfaces'][$newifname]['descr'] = $descr;
299
		ksort($config['interfaces']);
300
	}
301
	
302
	/* Find an unused port for this interface */
303
	foreach ($portlist as $portname => $portinfo) {
304
		$portused = false;
305
		foreach ($config['interfaces'] as $ifname => $ifdata) {
306
			if ($ifdata['if'] == $portname) {
307
				$portused = true;
308
				break;
309
			}
310
		}
311
		if (!$portused) {
312
			$config['interfaces'][$newifname]['if'] = $portname;
313
			if (preg_match($g['wireless_regex'], $portname))
314
				$config['interfaces'][$newifname]['wireless'] = array();
315
			break;
316
		}
317
	}
318
	
319
        /* XXX: Do not remove this. */
320
        mwexec("/bin/rm -f /tmp/config.cache");
321

    
322
	write_config();
323

    
324
	$savemsg = "Interface has been added.";
325

    
326
}
327

    
328
include("head.inc");
329

    
330
if(file_exists("/var/run/interface_mismatch_reboot_needed")) 
331
	if ($_POST)
332
		$savemsg = "Reboot is needed. Please apply the settings in order to reboot.";
333
	else
334
		$savemsg = "Interface mismatch detected.  Please resolve the mismatch and click Save.  The firewall will reboot afterwards.";
335

    
336
?>
337

    
338
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
339
<?php include("fbegin.inc"); ?>
340

    
341
<form action="interfaces_assign.php" method="post" name="iform" id="iform">
342

    
343
<?php if (file_exists("/tmp/reload_interfaces")): ?><p>
344
	<?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>
345
<?php elseif($savemsg): ?>
346
	<?php print_info_box($savemsg); ?>
347
<?php endif; ?>
348

    
349
<?php if ($input_errors) print_input_errors($input_errors); ?>
350

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