Project

General

Profile

Download (14.8 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

    
46
/*
47
	In this file, "port" refers to the physical port name,
48
	while "interface" refers to LAN, WAN, or OPTn.
49
*/
50

    
51
/* get list without VLAN interfaces */
52
$portlist = get_interface_list();
53

    
54
/* add VLAN interfaces */
55
if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) {
56
	foreach ($config['vlans']['vlan'] as $vlan) {
57
		$portlist[$vlan['vlanif']] = $vlan;
58
		$portlist[$vlan['vlanif']]['isvlan'] = true;
59
	}
60
}
61

    
62
/* add Bridge interfaces */
63
if (is_array($config['bridges']['bridged']) && count($config['bridges']['bridged'])) {
64
        foreach ($config['bridges']['bridged'] as $bridge) {
65
                $portlist[$bridge['bridgeif']] = $bridge;
66
                $portlist[$bridge['bridgeif']]['isbridge'] = true;
67
        }
68
}
69

    
70
/* add GIF interfaces */
71
if (is_array($config['gifs']['gif']) && count($config['gifs']['gif'])) {
72
        foreach ($config['gifs']['gif'] as $gif) {
73
                $portlist[$gif['gifif']] = $gif;
74
                $portlist[$gif['gifif']]['isgif'] = true;
75
        }
76
}
77

    
78
/* add GRE interfaces */
79
if (is_array($config['gres']['gre']) && count($config['gres']['gre'])) {
80
        foreach ($config['gres']['gre'] as $gre) {
81
                $portlist[$gre['greif']] = $gre;
82
                $portlist[$gre['greif']]['isgre'] = true;
83
        }
84
}
85

    
86
/* add LAGG interfaces */
87
if (is_array($config['laggs']['lagg']) && count($config['laggs']['lagg'])) {
88
        foreach ($config['laggs']['lagg'] as $lagg) {
89
                $portlist[$lagg['laggif']] = $lagg;
90
                $portlist[$lagg['laggif']]['islagg'] = true;
91
		/* LAGG members cannot be assigned */
92
		$lagifs = explode(',', $lagg['members']);
93
		foreach ($lagifs as $lagif)
94
			if (isset($portlist[$lagif]))
95
				unset($portlist[$lagif]);
96
        }
97
}
98

    
99
/* add QinQ interfaces */
100
if (is_array($config['qinqs']['qinqentry']) && count($config['qinqs']['qinqentry'])) {
101
        foreach ($config['qinqs']['qinqentry'] as $qinq) {
102
                $portlist["vlan{$qinq['tag']}"]['descr'] = "VLAN {$qinq['tag']}";
103
                $portlist["vlan{$qinq['tag']}"]['isqinq'] = true;
104
                /* QinQ members */
105
                $qinqifs = explode(' ', $qinq['members']);
106
                foreach ($qinqifs as $qinqif) {
107
			$portlist["vlan{$qinq['tag']}_{$qinqif}"]['descr'] = "QinQ {$qinqif}";
108
			$portlist["vlan{$qinq['tag']}_{$qinqif}"]['isqinq'] = true;
109
		}
110
        }
111
}
112

    
113
/* add PPP interfaces */
114
if (is_array($config['ppps']['ppp']) && count($config['ppps']['ppp'])) {
115
	$i = 0;
116
	foreach ($config['ppps']['ppp'] as $ppp) {
117
		$portname = 'ppp_' . basename($ppp['port']);
118
		$portlist[$portname] = $ppp;
119
		$portlist[$portname]['isppp'] = true;
120
		$i++;
121
	}
122
}
123

    
124
if ($_POST['apply']) {
125
	if (file_exists("/var/run/interface_mismatch_reboot_needed"))
126
		exec("/etc/rc.reboot");
127
	else {
128
		write_config();
129

    
130
		$retval = 0;
131
		$retval = filter_configure();
132
		$savemsg = get_std_save_message($retval);
133

    
134
		if (stristr($retval, "error") <> true)
135
			$savemsg = get_std_save_message($retval);
136
		else
137
			$savemsg = $retval;
138

    
139
		unlink_if_exists("/tmp/reload_interfaces");
140
	}
141

    
142
} else if ($_POST) {
143

    
144
	unset($input_errors);
145

    
146
	/* input validation */
147

    
148
	/* Build a list of the port names so we can see how the interfaces map */
149
	$portifmap = array();
150
	foreach ($portlist as $portname => $portinfo)
151
		$portifmap[$portname] = array();
152

    
153
	/* Go through the list of ports selected by the user,
154
	   build a list of port-to-interface mappings in portifmap */
155
	foreach ($_POST as $ifname => $ifport) {
156
		if (($ifname == 'lan') || ($ifname == 'wan') || (substr($ifname, 0, 3) == 'opt'))
157
			$portifmap[$ifport][] = strtoupper($ifname);
158
	}
159

    
160
	/* Deliver error message for any port with more than one assignment */
161
	foreach ($portifmap as $portname => $ifnames) {
162
		if (count($ifnames) > 1) {
163
			$errstr = "Port " . $portname .
164
				" was assigned to " . count($ifnames) .
165
				" interfaces:";
166
				
167
			foreach ($portifmap[$portname] as $ifn)
168
				$errstr .= " " . $ifn;
169
			
170
			$input_errors[] = $errstr;
171
		}
172
	}
173

    
174

    
175
	if (!$input_errors) {
176
		/* No errors detected, so update the config */
177
		foreach ($_POST as $ifname => $ifport) {
178
		
179
			if (($ifname == 'lan') || ($ifname == 'wan') ||
180
				(substr($ifname, 0, 3) == 'opt')) {
181
				
182
				if (!is_array($ifport)) {
183
					$config['interfaces'][$ifname]['if'] = $ifport;
184
					if (preg_match('/^ppp_(.+)$/', $ifport, $matches)) {
185
						$config['interfaces'][$ifname]['pointtopoint'] = true;
186
						$config['interfaces'][$ifname]['serialport'] = $matches[1];
187
					}
188

    
189
					/* check for wireless interfaces, set or clear ['wireless'] */
190
					if (preg_match($g['wireless_regex'], $ifport)) {
191
						if (!is_array($config['interfaces'][$ifname]['wireless']))
192
							$config['interfaces'][$ifname]['wireless'] = array();
193
					} else {
194
						unset($config['interfaces'][$ifname]['wireless']);
195
					}
196
					
197
					/* make sure there is a descr for all interfaces */
198
					if (!isset($config['interfaces'][$ifname]['descr']))
199
						$config['interfaces'][$ifname]['descr'] = strtoupper($ifname);
200
				}
201
			}
202
		}
203
	
204
		write_config();
205
		
206
		touch("/tmp/reload_interfaces");
207
	}
208
}
209

    
210
if ($_GET['act'] == "del") {
211
	$id = $_GET['id'];
212

    
213
	if (link_interface_to_bridge($id))
214
		$input_errors[] = "The interface is part of a bridge. Please remove it from the bridge to continue";
215
	else if (link_interface_to_gre($id))
216
		$input_errors[] = "The interface is part of a gre tunnel. Please delete the tunnel to continue";
217
	else if (link_interface_to_gif($id))
218
		$input_errors[] = "The interface is part of a gif tunnel. Please delete the tunnel to continue";
219
	else {
220
		unset($config['interfaces'][$id]['enable']);
221
		interface_bring_down($id);   /* down the interface */
222
		
223
		unset($config['interfaces'][$id]);	/* delete the specified OPTn or LAN*/
224

    
225
		if($id == "lan") {
226
			unset($config['interfaces']['lan']);
227
			if (is_array($config['dhcpd']))
228
				unset($config['dhcpd']['lan']);
229
				unset($config['shaper']);
230
				unset($config['ezshaper']);
231
				unset($config['nat']);
232
				system("rm /var/dhcpd/var/db/*");
233
        			services_dhcpd_configure();
234
		}
235

    
236
		if ($config['filter']['rule'] > 0)
237
       	 	foreach ($config['filter']['rule'] as $x => $rule) {
238
                	        if($rule['interface'] == $id)
239
               		                 unset($config['filter']['rule'][$x]);
240
        	}
241
		if ($config['nat']['advancedoutbound']['rule'] > 0)
242
        	foreach ($config['nat']['advancedoutbound']['rule'] as $x => $rule) {
243
                	        if($rule['interface'] == $id)
244
           	    	                 unset($config['nat']['advancedoutbound']['rule'][$x]['interface']);
245
        	}
246
        	if (count($config['nat']['rule']) > 0) 
247
        	foreach ($config['nat']['rule'] as $x => $rule) {
248
                        	if($rule['interface'] == $id)
249
                	                unset($config['nat']['rule'][$x]['interface']);
250
        	}
251

    
252
		write_config();
253
	
254
		/* XXX: What is this for?!?! */
255
		if($config['interfaces']['lan']) {
256
			unset($config['dhcpd']['wan']);		
257
		}
258
	
259
		$savemsg = "Interface has been deleted.";
260
	}
261
}
262

    
263
if ($_GET['act'] == "add") {
264
	/* find next free optional interface number */
265
	if(!$config['interfaces']['lan']) {
266
		$newifname = "lan";
267
		$config['interfaces'][$newifname] = array();
268
		$config['interfaces'][$newifname]['descr'] = $descr;
269
	} else {
270
		for ($i = 1; $i <= count($config['interfaces']); $i++) {
271
			if (!$config['interfaces']["opt{$i}"])
272
				break;
273
		}
274
		$newifname = 'opt' . $i;
275
		$descr = "OPT{$i}";
276
		$config['interfaces'][$newifname] = array();
277
		$config['interfaces'][$newifname]['descr'] = $descr;
278
		ksort($config['interfaces']);
279
	}
280
	
281
	/* Find an unused port for this interface */
282
	foreach ($portlist as $portname => $portinfo) {
283
		$portused = false;
284
		foreach ($config['interfaces'] as $ifname => $ifdata) {
285
			if ($ifdata['if'] == $portname) {
286
				$portused = true;
287
				break;
288
			}
289
		}
290
		if (!$portused) {
291
			$config['interfaces'][$newifname]['if'] = $portname;
292
			if (preg_match($g['wireless_regex'], $portname))
293
				$config['interfaces'][$newifname]['wireless'] = array();
294
			break;
295
		}
296
	}
297
	
298
        /* XXX: Do not remove this. */
299
        mwexec("/bin/rm -f /tmp/config.cache");
300

    
301
	write_config();
302

    
303
	$savemsg = "Interface has been added.";
304

    
305
}
306

    
307
include("head.inc");
308

    
309
if(file_exists("/var/run/interface_mismatch_reboot_needed")) 
310
	if ($_POST)
311
		$savemsg = "Reboot is needed. Please apply the settings in order to reboot.";
312
	else
313
		$savemsg = "Interface mismatch detected.  Please resolve the mismatch and click Save.  The firewall will reboot afterwards.";
314

    
315
?>
316

    
317
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
318
<?php include("fbegin.inc"); ?>
319

    
320
<form action="interfaces_assign.php" method="post" name="iform" id="iform">
321

    
322
<?php if (file_exists("/tmp/reload_interfaces")): ?><p>
323
	<?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>
324
<?php elseif($savemsg): ?>
325
	<?php print_info_box($savemsg); ?>
326
<?php endif; ?>
327

    
328
<?php if ($input_errors) print_input_errors($input_errors); ?>
329

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