Projet

Général

Profil

Télécharger (18,4 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / interfaces_assign.php @ 19498fbf

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(gettext("Interfaces"),gettext("Assign network ports"));
44
$shortcut_section = "interfaces";
45

    
46
require("guiconfig.inc");
47
require("functions.inc");
48
require_once("filter.inc");
49
require("shaper.inc");
50
require("ipsec.inc");
51
require("vpn.inc");
52
require("captiveportal.inc");
53
require_once("rrd.inc");
54

    
55
/*
56
	In this file, "port" refers to the physical port name,
57
	while "interface" refers to LAN, WAN, or OPTn.
58
*/
59

    
60
/* get list without VLAN interfaces */
61
$portlist = get_interface_list();
62

    
63
/* add wireless clone interfaces */
64
if (is_array($config['wireless']['clone']) && count($config['wireless']['clone'])) {
65
	foreach ($config['wireless']['clone'] as $clone) {
66
		$portlist[$clone['cloneif']] = $clone;
67
		$portlist[$clone['cloneif']]['iswlclone'] = true;
68
	}
69
}
70

    
71
/* add VLAN interfaces */
72
if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) {
73
	foreach ($config['vlans']['vlan'] as $vlan) {
74
		$portlist[$vlan['vlanif']] = $vlan;
75
		$portlist[$vlan['vlanif']]['isvlan'] = true;
76
	}
77
}
78

    
79
/* add Bridge interfaces */
80
if (is_array($config['bridges']['bridged']) && count($config['bridges']['bridged'])) {
81
	foreach ($config['bridges']['bridged'] as $bridge) {
82
		$portlist[$bridge['bridgeif']] = $bridge;
83
		$portlist[$bridge['bridgeif']]['isbridge'] = true;
84
	}
85
}
86

    
87
/* add GIF interfaces */
88
if (is_array($config['gifs']['gif']) && count($config['gifs']['gif'])) {
89
	foreach ($config['gifs']['gif'] as $gif) {
90
		$portlist[$gif['gifif']] = $gif;
91
		$portlist[$gif['gifif']]['isgif'] = true;
92
	}
93
}
94

    
95
/* add GRE interfaces */
96
if (is_array($config['gres']['gre']) && count($config['gres']['gre'])) {
97
	foreach ($config['gres']['gre'] as $gre) {
98
		$portlist[$gre['greif']] = $gre;
99
		$portlist[$gre['greif']]['isgre'] = true;
100
	}
101
}
102

    
103
/* add LAGG interfaces */
104
if (is_array($config['laggs']['lagg']) && count($config['laggs']['lagg'])) {
105
	foreach ($config['laggs']['lagg'] as $lagg) {
106
		$portlist[$lagg['laggif']] = $lagg;
107
		$portlist[$lagg['laggif']]['islagg'] = true;
108
		/* LAGG members cannot be assigned */
109
		$lagifs = explode(',', $lagg['members']);
110
		foreach ($lagifs as $lagif)
111
			if (isset($portlist[$lagif]))
112
				unset($portlist[$lagif]);
113
	}
114
}
115

    
116
/* add QinQ interfaces */
117
if (is_array($config['qinqs']['qinqentry']) && count($config['qinqs']['qinqentry'])) {
118
	foreach ($config['qinqs']['qinqentry'] as $qinq) {
119
		$portlist["vlan{$qinq['tag']}"]['descr'] = "VLAN {$qinq['tag']}";
120
		$portlist["vlan{$qinq['tag']}"]['isqinq'] = true;
121
		/* QinQ members */
122
		$qinqifs = explode(' ', $qinq['members']);
123
		foreach ($qinqifs as $qinqif) {
124
			$portlist["vlan{$qinq['tag']}_{$qinqif}"]['descr'] = "QinQ {$qinqif}";
125
			$portlist["vlan{$qinq['tag']}_{$qinqif}"]['isqinq'] = true;
126
		}
127
	}
128
}
129

    
130
/* add PPP interfaces */
131
if (is_array($config['ppps']['ppp']) && count($config['ppps']['ppp'])) {
132
	foreach ($config['ppps']['ppp'] as $pppid => $ppp) {
133
		$portname = $ppp['if'];
134
		$portlist[$portname] = $ppp;
135
		$portlist[$portname]['isppp'] = true;
136
		$ports_base = basename($ppp['ports']);
137
		if (isset($ppp['descr']))
138
			$portlist[$portname]['descr'] = strtoupper($ppp['if']). "({$ports_base}) - {$ppp['descr']}";
139
		else if (isset($ppp['username']))
140
			$portlist[$portname]['descr'] = strtoupper($ppp['if']). "({$ports_base}) - {$ppp['username']}";
141
		else
142
			$portlist[$portname]['descr'] = strtoupper($ppp['if']). "({$ports_base})";
143
	}
144
}
145

    
146
$ovpn_descrs = array();
147
if (is_array($config['openvpn'])) {
148
	if (is_array($config['openvpn']['openvpn-server']))
149
		foreach ($config['openvpn']['openvpn-server'] as $s)
150
			$ovpn_descrs[$s['vpnid']] = $s['description'];
151
	if (is_array($config['openvpn']['openvpn-client']))
152
		foreach ($config['openvpn']['openvpn-client'] as $c)
153
			$ovpn_descrs[$c['vpnid']] = $c['description'];
154
}
155

    
156
if ($_POST['apply']) {
157
	if (file_exists("/var/run/interface_mismatch_reboot_needed")) {
158
		system_reboot();
159
		$rebootingnow = true;
160
	} else {
161
		write_config();
162

    
163
		$retval = 0;
164
		$retval = filter_configure();
165
		$savemsg = get_std_save_message($retval);
166

    
167
		if (stristr($retval, "error") <> true)
168
			$savemsg = get_std_save_message($retval);
169
		else
170
			$savemsg = $retval;
171
	}
172

    
173
} else if ($_POST) {
174

    
175
	unset($input_errors);
176

    
177
	/* input validation */
178

    
179
	/* Build a list of the port names so we can see how the interfaces map */
180
	$portifmap = array();
181
	foreach ($portlist as $portname => $portinfo)
182
		$portifmap[$portname] = array();
183

    
184
	/* Go through the list of ports selected by the user,
185
	build a list of port-to-interface mappings in portifmap */
186
	foreach ($_POST as $ifname => $ifport) {
187
		if (($ifname == 'lan') || ($ifname == 'wan') || (substr($ifname, 0, 3) == 'opt'))
188
			$portifmap[$ifport][] = strtoupper($ifname);
189
	}
190

    
191
	/* Deliver error message for any port with more than one assignment */
192
	foreach ($portifmap as $portname => $ifnames) {
193
		if (count($ifnames) > 1) {
194
			$errstr = sprintf(gettext('Port %1$s '.
195
				' was assigned to %2$s' .
196
				' interfaces:'), $portname, count($ifnames));
197

    
198
			foreach ($portifmap[$portname] as $ifn)
199
				$errstr .= " " . $ifn;
200

    
201
			$input_errors[] = $errstr;
202
		} else if (count($ifnames) == 1 && preg_match('/^bridge[0-9]/', $portname) && is_array($config['bridges']['bridged']) && count($config['bridges']['bridged'])) {
203
			foreach ($config['bridges']['bridged'] as $bridge) {
204
				if ($bridge['bridgeif'] != $portname)
205
					continue;
206

    
207
				$members = explode(",", strtoupper($bridge['members']));
208
				foreach ($members as $member) {
209
					if ($member == $ifnames[0]) {
210
						$input_errors[] = sprintf(gettext("You cannot set port %s to interface %s because this interface is a member of %s."), $portname, $member, $portname);
211
						break;
212
					}
213
				}
214
			}
215
		}
216
	}
217

    
218
	if (is_array($config['vlans']['vlan'])) {
219
		foreach ($config['vlans']['vlan'] as $vlan) {
220
			if (does_interface_exist($vlan['if']) == false)
221
				$input_errors[] = "Vlan parent interface {$vlan['if']} does not exist anymore so vlan id {$vlan['tag']} cannot be created please fix the issue before continuing.";
222
		}
223
	}
224

    
225
	if (!$input_errors) {
226
		/* No errors detected, so update the config */
227
		foreach ($_POST as $ifname => $ifport) {
228

    
229
			if (($ifname == 'lan') || ($ifname == 'wan') || (substr($ifname, 0, 3) == 'opt')) {
230

    
231
				if (!is_array($ifport)) {
232
					$reloadif = false;
233
					if (!empty($config['interfaces'][$ifname]['if']) && $config['interfaces'][$ifname]['if'] <> $ifport) {
234
						interface_bring_down($ifname);
235
						/* Mark this to be reconfigured in any case. */
236
						$reloadif = true;
237
					}
238
					$config['interfaces'][$ifname]['if'] = $ifport;
239
					if (isset($portlist[$ifport]['isppp']))
240
						$config['interfaces'][$ifname]['ipaddr'] = $portlist[$ifport]['type'];
241

    
242
					if (substr($ifport, 0, 3) == 'gre' || substr($ifport, 0, 3) == 'gif') {
243
						unset($config['interfaces'][$ifname]['ipaddr']);
244
						unset($config['interfaces'][$ifname]['subnet']);
245
						unset($config['interfaces'][$ifname]['ipaddrv6']);
246
						unset($config['interfaces'][$ifname]['subnetv6']);
247
					}
248

    
249
					/* check for wireless interfaces, set or clear ['wireless'] */
250
					if (preg_match($g['wireless_regex'], $ifport)) {
251
						if (!is_array($config['interfaces'][$ifname]['wireless']))
252
							$config['interfaces'][$ifname]['wireless'] = array();
253
					} else {
254
						unset($config['interfaces'][$ifname]['wireless']);
255
					}
256

    
257
					/* make sure there is a descr for all interfaces */
258
					if (!isset($config['interfaces'][$ifname]['descr']))
259
						$config['interfaces'][$ifname]['descr'] = strtoupper($ifname);
260

    
261
					if ($reloadif == true) {
262
						if (preg_match($g['wireless_regex'], $ifport))
263
							interface_sync_wireless_clones($config['interfaces'][$ifname], false);
264
						/* Reload all for the interface. */
265
						interface_configure($ifname, true);
266
					}
267
				}
268
			}
269
		}
270

    
271
		write_config();
272

    
273
		enable_rrd_graphing();
274
	}
275
}
276

    
277
if ($_GET['act'] == "del") {
278
	$id = $_GET['id'];
279

    
280
	if (link_interface_to_group($id))
281
		$input_errors[] = gettext("The interface is part of a group. Please remove it from the group to continue");
282
	else if (link_interface_to_bridge($id))
283
		$input_errors[] = gettext("The interface is part of a bridge. Please remove it from the bridge to continue");
284
	else if (link_interface_to_gre($id))
285
		$input_errors[] = gettext("The interface is part of a gre tunnel. Please delete the tunnel to continue");
286
	else if (link_interface_to_gif($id))
287
		$input_errors[] = gettext("The interface is part of a gif tunnel. Please delete the tunnel to continue");
288
	else {
289
		unset($config['interfaces'][$id]['enable']);
290
		$realid = get_real_interface($id);
291
		interface_bring_down($id);   /* down the interface */
292

    
293
		unset($config['interfaces'][$id]);	/* delete the specified OPTn or LAN*/
294

    
295
		if (is_array($config['dhcpd']) && is_array($config['dhcpd'][$id])) {
296
			unset($config['dhcpd'][$id]);
297
			services_dhcpd_configure();
298
		}
299

    
300
		if (count($config['filter']['rule']) > 0) {
301
			foreach ($config['filter']['rule'] as $x => $rule) {
302
				if($rule['interface'] == $id)
303
					unset($config['filter']['rule'][$x]);
304
			}
305
		}
306
		if (is_array($config['nat']['rule']) && count($config['nat']['rule']) > 0) {
307
			foreach ($config['nat']['rule'] as $x => $rule) {
308
				if($rule['interface'] == $id)
309
					unset($config['nat']['rule'][$x]['interface']);
310
			}
311
		}
312

    
313
		write_config();
314

    
315
		/* If we are in firewall/routing mode (not single interface)
316
		 * then ensure that we are not running DHCP on the wan which
317
		 * will make a lot of ISP's unhappy.
318
		 */
319
		if($config['interfaces']['lan'] && $config['dhcpd']['wan']) {
320
			unset($config['dhcpd']['wan']);
321
		}
322

    
323
		link_interface_to_vlans($realid, "update");
324

    
325
		$savemsg = gettext("Interface has been deleted.");
326
	}
327
}
328

    
329
if ($_GET['act'] == "add" && (count($config['interfaces']) < count($portlist))) {
330
	/* find next free optional interface number */
331
	if(!$config['interfaces']['lan']) {
332
		$newifname = gettext("lan");
333
		$descr = gettext("LAN");
334
		$config['interfaces'][$newifname] = array();
335
		$config['interfaces'][$newifname]['descr'] = $descr;
336
	} else {
337
		for ($i = 1; $i <= count($config['interfaces']); $i++) {
338
			if (!$config['interfaces']["opt{$i}"])
339
				break;
340
		}
341
		$newifname = 'opt' . $i;
342
		$descr = "OPT" . $i;
343
		$config['interfaces'][$newifname] = array();
344
		$config['interfaces'][$newifname]['descr'] = $descr;
345
	}
346

    
347
	uksort($config['interfaces'], "compare_interface_friendly_names");
348

    
349
	/* Find an unused port for this interface */
350
	foreach ($portlist as $portname => $portinfo) {
351
		$portused = false;
352
		foreach ($config['interfaces'] as $ifname => $ifdata) {
353
			if ($ifdata['if'] == $portname) {
354
				$portused = true;
355
				break;
356
			}
357
		}
358
		if (!$portused) {
359
			$config['interfaces'][$newifname]['if'] = $portname;
360
			if (preg_match($g['wireless_regex'], $portname)) {
361
				$config['interfaces'][$newifname]['wireless'] = array();
362
				interface_sync_wireless_clones($config['interfaces'][$newifname], false);
363
			}
364
			break;
365
		}
366
	}
367

    
368
	/* XXX: Do not remove this. */
369
	unlink_if_exists("{$g['tmp_path']}/config.cache");
370

    
371
	write_config();
372

    
373
	$savemsg = gettext("Interface has been added.");
374

    
375
} else if ($_GET['act'] == "add")
376
	$input_errors[] = "No more interfaces available to be assigned.";
377

    
378
include("head.inc");
379

    
380
if(file_exists("/var/run/interface_mismatch_reboot_needed"))
381
	if ($_POST) {
382
		if($rebootingnow)
383
			$savemsg = gettext("The system is now rebooting.  Please wait.");
384
		else
385
			$savemsg = gettext("Reboot is needed. Please apply the settings in order to reboot.");
386
	} else {
387
		$savemsg = gettext("Interface mismatch detected.  Please resolve the mismatch and click 'Apply changes'.  The firewall will reboot afterwards.");
388
	}
389
?>
390

    
391
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
392
<?php include("fbegin.inc"); ?>
393

    
394
<form action="interfaces_assign.php" method="post" name="iform" id="iform">
395

    
396
<?php
397
if (file_exists("/tmp/reload_interfaces")) {
398
	echo "<p>\n";
399
	print_info_box_np(gettext("The interface configuration has been changed.<br />You must apply the changes in order for them to take effect."));
400
	echo "<br /></p>\n";
401
} elseif($savemsg)
402
	print_info_box($savemsg);
403

    
404
pfSense_handle_custom_code("/usr/local/pkg/interfaces_assign/pre_input_errors");
405
if ($input_errors)
406
	print_input_errors($input_errors);
407
?>
408

    
409
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="interfaces assign">
410
	<tr><td class="tabnavtbl">
411
<?php
412
	$tab_array = array();
413
	$tab_array[0] = array(gettext("Interface assignments"), true, "interfaces_assign.php");
414
	$tab_array[1] = array(gettext("Interface Groups"), false, "interfaces_groups.php");
415
	$tab_array[2] = array(gettext("Wireless"), false, "interfaces_wireless.php");
416
	$tab_array[3] = array(gettext("VLANs"), false, "interfaces_vlan.php");
417
	$tab_array[4] = array(gettext("QinQs"), false, "interfaces_qinq.php");
418
	$tab_array[5] = array(gettext("PPPs"), false, "interfaces_ppps.php");
419
	$tab_array[7] = array(gettext("GRE"), false, "interfaces_gre.php");
420
	$tab_array[8] = array(gettext("GIF"), false, "interfaces_gif.php");
421
	$tab_array[9] = array(gettext("Bridges"), false, "interfaces_bridge.php");
422
	$tab_array[10] = array(gettext("LAGG"), false, "interfaces_lagg.php");
423
	display_top_tabs($tab_array);
424
?>
425
	</td></tr>
426
	<tr><td>
427
		<div id="mainarea">
428
			<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="main area">
429
				<tr>
430
					<td class="listhdrr"><?=gettext("Interface"); ?></td>
431
					<td class="listhdr"><?=gettext("Network port"); ?></td>
432
					<td class="list">&nbsp;</td>
433
				</tr>
434
<?php
435
			foreach ($config['interfaces'] as $ifname => $iface):
436
				if ($iface['descr'])
437
					$ifdescr = $iface['descr'];
438
				else
439
					$ifdescr = strtoupper($ifname);
440
?>
441
				<tr>
442
					<td class="listlr" valign="middle"><strong><u><span onclick="location.href='/interfaces.php?if=<?=$ifname;?>'" style="cursor: pointer;"><?=$ifdescr;?></span></u></strong></td>
443
					<td valign="middle" class="listr">
444
						<select onchange="javascript:jQuery('#savediv').show();" name="<?=$ifname;?>" id="<?=$ifname;?>">
445
<?php
446
						foreach ($portlist as $portname => $portinfo):
447
?>
448
							<option  value="<?=$portname;?>"  <?php if ($portname == $iface['if']) echo " selected=\"selected\"";?>>
449
<?php
450
							if ($portinfo['isvlan']) {
451
								$descr = sprintf(gettext('VLAN %1$s on %2$s'),$portinfo['tag'],$portinfo['if']);
452
							if ($portinfo['descr'])
453
								$descr .= " (" . $portinfo['descr'] . ")";
454
								echo htmlspecialchars($descr);
455
							} elseif ($portinfo['iswlclone']) {
456
								$descr = $portinfo['cloneif'];
457
								if ($portinfo['descr'])
458
									$descr .= " (" . $portinfo['descr'] . ")";
459
								echo htmlspecialchars($descr);
460
							} elseif ($portinfo['isppp']) {
461
								echo htmlspecialchars($portinfo['descr']);
462
							} elseif ($portinfo['isbridge']) {
463
								$descr = strtoupper($portinfo['bridgeif']);
464
								if ($portinfo['descr'])
465
									$descr .= " (" . $portinfo['descr'] . ")";
466
								echo htmlspecialchars($descr);
467
							} elseif ($portinfo['isgre']) {
468
								$descr = "GRE {$portinfo['remote-addr']}";
469
								if ($portinfo['descr'])
470
									$descr .= " (" . $portinfo['descr'] . ")";
471
								echo htmlspecialchars($descr);
472
							} elseif ($portinfo['isgif']) {
473
								$descr = "GIF {$portinfo['remote-addr']}";
474
								if ($portinfo['descr'])
475
									$descr .= " (" . $portinfo['descr'] . ")";
476
								echo htmlspecialchars($descr);
477
							} elseif ($portinfo['islagg']) {
478
								$descr = strtoupper($portinfo['laggif']);
479
								if ($portinfo['descr'])
480
									$descr .= " (" . $portinfo['descr'] . ")";
481
								echo htmlspecialchars($descr);
482
							} elseif ($portinfo['isqinq']) {
483
								echo htmlspecialchars($portinfo['descr']);
484
							} elseif (substr($portname, 0, 4) == 'ovpn') {
485
								echo htmlspecialchars($portname . " (" . $ovpn_descrs[substr($portname, 5)] . ")");
486
							} else
487
								echo htmlspecialchars($portname . " (" . $portinfo['mac'] . ")");
488
?>
489
							</option>
490
<?php
491
						endforeach;
492
?>
493
						</select>
494
					</td>
495
					<td valign="middle" class="list">
496
<?php
497
					if ($ifname != 'wan'):
498
?>
499
						<a href="interfaces_assign.php?act=del&amp;id=<?=$ifname;?>" onclick="return confirm('<?=gettext("Do you really want to delete this interface?");?>')"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" title="<?=gettext("delete interface"); ?>" width="17" height="17" border="0" alt="delete" /></a>
500
<?php
501
					endif;
502
?>
503
					</td>
504
				</tr>
505
<?php
506
			endforeach;
507
			if (count($config['interfaces']) < count($portlist)):
508
?>
509
				<tr>
510
					<td class="list" colspan="2"></td>
511
					<td class="list nowrap">
512
						<a href="interfaces_assign.php?act=add"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("add interface"); ?>" width="17" height="17" border="0" alt="add" /></a>
513
					</td>
514
				</tr>
515
<?php
516
			else:
517
?>
518
				<tr>
519
					<td class="list" colspan="3" height="10"></td>
520
				</tr>
521
<?php
522
			endif;
523
?>
524
			</table>
525
		</div>
526
		<br />
527
		<div id='savediv' <?php if (empty($_GET['act'])) echo "style='display:none;'"; ?>>
528
			<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" /><br /><br />
529
		</div>
530
		<ul>
531
			<li><span class="vexpl"><?=gettext("Interfaces that are configured as members of a lagg(4) interface will not be shown."); ?></span></li>
532
		</ul>
533
	</td></tr>
534
</table>
535
</form>
536
<?php include("fend.inc"); ?>
537
</body>
538
</html>
(95-95/255)