Projet

Général

Profil

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

univnautes / usr / local / www / interfaces_assign.php @ 1c4b1636

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
function interface_assign_description($portinfo, $portname) {
56
	if ($portinfo['isvlan']) {
57
		$descr = sprintf(gettext('VLAN %1$s on %2$s'),$portinfo['tag'],$portinfo['if']);
58
		if ($portinfo['descr'])
59
			$descr .= " (" . $portinfo['descr'] . ")";
60
	} elseif ($portinfo['iswlclone']) {
61
		$descr = $portinfo['cloneif'];
62
		if ($portinfo['descr'])
63
			$descr .= " (" . $portinfo['descr'] . ")";
64
	} elseif ($portinfo['isppp']) {
65
		$descr = $portinfo['descr'];
66
	} elseif ($portinfo['isbridge']) {
67
		$descr = strtoupper($portinfo['bridgeif']);
68
		if ($portinfo['descr'])
69
			$descr .= " (" . $portinfo['descr'] . ")";
70
	} elseif ($portinfo['isgre']) {
71
		$descr = "GRE {$portinfo['remote-addr']}";
72
		if ($portinfo['descr'])
73
			$descr .= " (" . $portinfo['descr'] . ")";
74
	} elseif ($portinfo['isgif']) {
75
		$descr = "GIF {$portinfo['remote-addr']}";
76
		if ($portinfo['descr'])
77
			$descr .= " (" . $portinfo['descr'] . ")";
78
	} elseif ($portinfo['islagg']) {
79
		$descr = strtoupper($portinfo['laggif']);
80
		if ($portinfo['descr'])
81
			$descr .= " (" . $portinfo['descr'] . ")";
82
	} elseif ($portinfo['isqinq']) {
83
		$descr =  $portinfo['descr'];
84
	} elseif (substr($portname, 0, 4) == 'ovpn') {
85
		$descr = $portname . " (" . $ovpn_descrs[substr($portname, 5)] . ")";
86
	} else
87
		$descr = $portname . " (" . $portinfo['mac'] . ")";
88

    
89
	return htmlspecialchars($descr);
90
}
91

    
92
/*
93
	In this file, "port" refers to the physical port name,
94
	while "interface" refers to LAN, WAN, or OPTn.
95
*/
96

    
97
/* get list without VLAN interfaces */
98
$portlist = get_interface_list();
99

    
100
/* add wireless clone interfaces */
101
if (is_array($config['wireless']['clone']) && count($config['wireless']['clone'])) {
102
	foreach ($config['wireless']['clone'] as $clone) {
103
		$portlist[$clone['cloneif']] = $clone;
104
		$portlist[$clone['cloneif']]['iswlclone'] = true;
105
	}
106
}
107

    
108
/* add VLAN interfaces */
109
if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) {
110
	foreach ($config['vlans']['vlan'] as $vlan) {
111
		$portlist[$vlan['vlanif']] = $vlan;
112
		$portlist[$vlan['vlanif']]['isvlan'] = true;
113
	}
114
}
115

    
116
/* add Bridge interfaces */
117
if (is_array($config['bridges']['bridged']) && count($config['bridges']['bridged'])) {
118
	foreach ($config['bridges']['bridged'] as $bridge) {
119
		$portlist[$bridge['bridgeif']] = $bridge;
120
		$portlist[$bridge['bridgeif']]['isbridge'] = true;
121
	}
122
}
123

    
124
/* add GIF interfaces */
125
if (is_array($config['gifs']['gif']) && count($config['gifs']['gif'])) {
126
	foreach ($config['gifs']['gif'] as $gif) {
127
		$portlist[$gif['gifif']] = $gif;
128
		$portlist[$gif['gifif']]['isgif'] = true;
129
	}
130
}
131

    
132
/* add GRE interfaces */
133
if (is_array($config['gres']['gre']) && count($config['gres']['gre'])) {
134
	foreach ($config['gres']['gre'] as $gre) {
135
		$portlist[$gre['greif']] = $gre;
136
		$portlist[$gre['greif']]['isgre'] = true;
137
	}
138
}
139

    
140
/* add LAGG interfaces */
141
if (is_array($config['laggs']['lagg']) && count($config['laggs']['lagg'])) {
142
	foreach ($config['laggs']['lagg'] as $lagg) {
143
		$portlist[$lagg['laggif']] = $lagg;
144
		$portlist[$lagg['laggif']]['islagg'] = true;
145
		/* LAGG members cannot be assigned */
146
		$lagifs = explode(',', $lagg['members']);
147
		foreach ($lagifs as $lagif)
148
			if (isset($portlist[$lagif]))
149
				unset($portlist[$lagif]);
150
	}
151
}
152

    
153
/* add QinQ interfaces */
154
if (is_array($config['qinqs']['qinqentry']) && count($config['qinqs']['qinqentry'])) {
155
	foreach ($config['qinqs']['qinqentry'] as $qinq) {
156
		$portlist["vlan{$qinq['tag']}"]['descr'] = "VLAN {$qinq['tag']}";
157
		$portlist["vlan{$qinq['tag']}"]['isqinq'] = true;
158
		/* QinQ members */
159
		$qinqifs = explode(' ', $qinq['members']);
160
		foreach ($qinqifs as $qinqif) {
161
			$portlist["vlan{$qinq['tag']}_{$qinqif}"]['descr'] = "QinQ {$qinqif}";
162
			$portlist["vlan{$qinq['tag']}_{$qinqif}"]['isqinq'] = true;
163
		}
164
	}
165
}
166

    
167
/* add PPP interfaces */
168
if (is_array($config['ppps']['ppp']) && count($config['ppps']['ppp'])) {
169
	foreach ($config['ppps']['ppp'] as $pppid => $ppp) {
170
		$portname = $ppp['if'];
171
		$portlist[$portname] = $ppp;
172
		$portlist[$portname]['isppp'] = true;
173
		$ports_base = basename($ppp['ports']);
174
		if (isset($ppp['descr']))
175
			$portlist[$portname]['descr'] = strtoupper($ppp['if']). "({$ports_base}) - {$ppp['descr']}";
176
		else if (isset($ppp['username']))
177
			$portlist[$portname]['descr'] = strtoupper($ppp['if']). "({$ports_base}) - {$ppp['username']}";
178
		else
179
			$portlist[$portname]['descr'] = strtoupper($ppp['if']). "({$ports_base})";
180
	}
181
}
182

    
183
$ovpn_descrs = array();
184
if (is_array($config['openvpn'])) {
185
	if (is_array($config['openvpn']['openvpn-server']))
186
		foreach ($config['openvpn']['openvpn-server'] as $s)
187
			$ovpn_descrs[$s['vpnid']] = $s['description'];
188
	if (is_array($config['openvpn']['openvpn-client']))
189
		foreach ($config['openvpn']['openvpn-client'] as $c)
190
			$ovpn_descrs[$c['vpnid']] = $c['description'];
191
}
192

    
193
if ($_POST['apply']) {
194
	if (file_exists("/var/run/interface_mismatch_reboot_needed")) {
195
		system_reboot();
196
		$rebootingnow = true;
197
	} else {
198
		write_config();
199

    
200
		$retval = filter_configure();
201
		$savemsg = get_std_save_message($retval);
202

    
203
		if (stristr($retval, "error") <> true)
204
			$savemsg = get_std_save_message($retval);
205
		else
206
			$savemsg = $retval;
207
	}
208

    
209
} else if ($_POST) {
210

    
211
	unset($input_errors);
212

    
213
	/* input validation */
214

    
215
	/* Build a list of the port names so we can see how the interfaces map */
216
	$portifmap = array();
217
	foreach ($portlist as $portname => $portinfo)
218
		$portifmap[$portname] = array();
219

    
220
	/* Go through the list of ports selected by the user,
221
	build a list of port-to-interface mappings in portifmap */
222
	foreach ($_POST as $ifname => $ifport) {
223
		if (($ifname == 'lan') || ($ifname == 'wan') || (substr($ifname, 0, 3) == 'opt'))
224
			$portifmap[$ifport][] = strtoupper($ifname);
225
	}
226

    
227
	/* Deliver error message for any port with more than one assignment */
228
	foreach ($portifmap as $portname => $ifnames) {
229
		if (count($ifnames) > 1) {
230
			$errstr = sprintf(gettext('Port %1$s '.
231
				' was assigned to %2$s' .
232
				' interfaces:'), $portname, count($ifnames));
233

    
234
			foreach ($portifmap[$portname] as $ifn)
235
				$errstr .= " " . $ifn;
236

    
237
			$input_errors[] = $errstr;
238
		} else if (count($ifnames) == 1 && preg_match('/^bridge[0-9]/', $portname) && is_array($config['bridges']['bridged']) && count($config['bridges']['bridged'])) {
239
			foreach ($config['bridges']['bridged'] as $bridge) {
240
				if ($bridge['bridgeif'] != $portname)
241
					continue;
242

    
243
				$members = explode(",", strtoupper($bridge['members']));
244
				foreach ($members as $member) {
245
					if ($member == $ifnames[0]) {
246
						$input_errors[] = sprintf(gettext("You cannot set port %s to interface %s because this interface is a member of %s."), $portname, $member, $portname);
247
						break;
248
					}
249
				}
250
			}
251
		}
252
	}
253

    
254
	if (is_array($config['vlans']['vlan'])) {
255
		foreach ($config['vlans']['vlan'] as $vlan) {
256
			if (does_interface_exist($vlan['if']) == false)
257
				$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.";
258
		}
259
	}
260

    
261
	if (!$input_errors) {
262
		/* No errors detected, so update the config */
263
		foreach ($_POST as $ifname => $ifport) {
264

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

    
267
				if (!is_array($ifport)) {
268
					$reloadif = false;
269
					if (!empty($config['interfaces'][$ifname]['if']) && $config['interfaces'][$ifname]['if'] <> $ifport) {
270
						interface_bring_down($ifname);
271
						/* Mark this to be reconfigured in any case. */
272
						$reloadif = true;
273
					}
274
					$config['interfaces'][$ifname]['if'] = $ifport;
275
					if (isset($portlist[$ifport]['isppp']))
276
						$config['interfaces'][$ifname]['ipaddr'] = $portlist[$ifport]['type'];
277

    
278
					if (substr($ifport, 0, 3) == 'gre' || substr($ifport, 0, 3) == 'gif') {
279
						unset($config['interfaces'][$ifname]['ipaddr']);
280
						unset($config['interfaces'][$ifname]['subnet']);
281
						unset($config['interfaces'][$ifname]['ipaddrv6']);
282
						unset($config['interfaces'][$ifname]['subnetv6']);
283
					}
284

    
285
					/* check for wireless interfaces, set or clear ['wireless'] */
286
					if (preg_match($g['wireless_regex'], $ifport)) {
287
						if (!is_array($config['interfaces'][$ifname]['wireless']))
288
							$config['interfaces'][$ifname]['wireless'] = array();
289
					} else {
290
						unset($config['interfaces'][$ifname]['wireless']);
291
					}
292

    
293
					/* make sure there is a descr for all interfaces */
294
					if (!isset($config['interfaces'][$ifname]['descr']))
295
						$config['interfaces'][$ifname]['descr'] = strtoupper($ifname);
296

    
297
					if ($reloadif == true) {
298
						if (preg_match($g['wireless_regex'], $ifport))
299
							interface_sync_wireless_clones($config['interfaces'][$ifname], false);
300
						/* Reload all for the interface. */
301
						interface_configure($ifname, true);
302
					}
303
				}
304
			}
305
		}
306

    
307
		write_config();
308

    
309
		enable_rrd_graphing();
310
	}
311
}
312

    
313
if ($_GET['act'] == "del") {
314
	$id = $_GET['id'];
315

    
316
	if (link_interface_to_group($id))
317
		$input_errors[] = gettext("The interface is part of a group. Please remove it from the group to continue");
318
	else if (link_interface_to_bridge($id))
319
		$input_errors[] = gettext("The interface is part of a bridge. Please remove it from the bridge to continue");
320
	else if (link_interface_to_gre($id))
321
		$input_errors[] = gettext("The interface is part of a gre tunnel. Please delete the tunnel to continue");
322
	else if (link_interface_to_gif($id))
323
		$input_errors[] = gettext("The interface is part of a gif tunnel. Please delete the tunnel to continue");
324
	else {
325
		unset($config['interfaces'][$id]['enable']);
326
		$realid = get_real_interface($id);
327
		interface_bring_down($id);   /* down the interface */
328

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

    
331
		if (is_array($config['dhcpd']) && is_array($config['dhcpd'][$id])) {
332
			unset($config['dhcpd'][$id]);
333
			services_dhcpd_configure();
334
		}
335

    
336
		if (count($config['filter']['rule']) > 0) {
337
			foreach ($config['filter']['rule'] as $x => $rule) {
338
				if($rule['interface'] == $id)
339
					unset($config['filter']['rule'][$x]);
340
			}
341
		}
342
		if (is_array($config['nat']['rule']) && count($config['nat']['rule']) > 0) {
343
			foreach ($config['nat']['rule'] as $x => $rule) {
344
				if($rule['interface'] == $id)
345
					unset($config['nat']['rule'][$x]['interface']);
346
			}
347
		}
348

    
349
		write_config();
350

    
351
		/* If we are in firewall/routing mode (not single interface)
352
		 * then ensure that we are not running DHCP on the wan which
353
		 * will make a lot of ISP's unhappy.
354
		 */
355
		if($config['interfaces']['lan'] && $config['dhcpd']['wan']) {
356
			unset($config['dhcpd']['wan']);
357
		}
358

    
359
		link_interface_to_vlans($realid, "update");
360

    
361
		$savemsg = gettext("Interface has been deleted.");
362
	}
363
}
364

    
365
if ($_GET['act'] == "add" && (count($config['interfaces']) < count($portlist))) {
366
	/* find next free optional interface number */
367
	if(!$config['interfaces']['lan']) {
368
		$newifname = gettext("lan");
369
		$descr = gettext("LAN");
370
		$config['interfaces'][$newifname] = array();
371
		$config['interfaces'][$newifname]['descr'] = $descr;
372
	} else {
373
		for ($i = 1; $i <= count($config['interfaces']); $i++) {
374
			if (!$config['interfaces']["opt{$i}"])
375
				break;
376
		}
377
		$newifname = 'opt' . $i;
378
		$descr = "OPT" . $i;
379
		$config['interfaces'][$newifname] = array();
380
		$config['interfaces'][$newifname]['descr'] = $descr;
381
	}
382

    
383
	uksort($config['interfaces'], "compare_interface_friendly_names");
384

    
385
	/* Find an unused port for this interface */
386
	foreach ($portlist as $portname => $portinfo) {
387
		$portused = false;
388
		foreach ($config['interfaces'] as $ifname => $ifdata) {
389
			if ($ifdata['if'] == $portname) {
390
				$portused = true;
391
				break;
392
			}
393
		}
394
		if (!$portused) {
395
			$config['interfaces'][$newifname]['if'] = $portname;
396
			if (preg_match($g['wireless_regex'], $portname)) {
397
				$config['interfaces'][$newifname]['wireless'] = array();
398
				interface_sync_wireless_clones($config['interfaces'][$newifname], false);
399
			}
400
			break;
401
		}
402
	}
403

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

    
407
	write_config();
408

    
409
	$savemsg = gettext("Interface has been added.");
410

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

    
414
include("head.inc");
415

    
416
if(file_exists("/var/run/interface_mismatch_reboot_needed"))
417
	if ($_POST) {
418
		if($rebootingnow)
419
			$savemsg = gettext("The system is now rebooting.  Please wait.");
420
		else
421
			$savemsg = gettext("Reboot is needed. Please apply the settings in order to reboot.");
422
	} else {
423
		$savemsg = gettext("Interface mismatch detected.  Please resolve the mismatch and click 'Apply changes'.  The firewall will reboot afterwards.");
424
	}
425
?>
426

    
427
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
428
<?php include("fbegin.inc"); ?>
429

    
430
<form action="interfaces_assign.php" method="post" name="iform" id="iform">
431

    
432
<?php
433
if (file_exists("/tmp/reload_interfaces")) {
434
	echo "<p>\n";
435
	print_info_box_np(gettext("The interface configuration has been changed.<br />You must apply the changes in order for them to take effect."));
436
	echo "<br /></p>\n";
437
} elseif($savemsg)
438
	print_info_box($savemsg);
439

    
440
pfSense_handle_custom_code("/usr/local/pkg/interfaces_assign/pre_input_errors");
441
if ($input_errors)
442
	print_input_errors($input_errors);
443
?>
444

    
445
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="interfaces assign">
446
	<tr><td class="tabnavtbl">
447
<?php
448
	$tab_array = array();
449
	$tab_array[0] = array(gettext("Interface assignments"), true, "interfaces_assign.php");
450
	$tab_array[1] = array(gettext("Interface Groups"), false, "interfaces_groups.php");
451
	$tab_array[2] = array(gettext("Wireless"), false, "interfaces_wireless.php");
452
	$tab_array[3] = array(gettext("VLANs"), false, "interfaces_vlan.php");
453
	$tab_array[4] = array(gettext("QinQs"), false, "interfaces_qinq.php");
454
	$tab_array[5] = array(gettext("PPPs"), false, "interfaces_ppps.php");
455
	$tab_array[7] = array(gettext("GRE"), false, "interfaces_gre.php");
456
	$tab_array[8] = array(gettext("GIF"), false, "interfaces_gif.php");
457
	$tab_array[9] = array(gettext("Bridges"), false, "interfaces_bridge.php");
458
	$tab_array[10] = array(gettext("LAGG"), false, "interfaces_lagg.php");
459
	display_top_tabs($tab_array);
460
?>
461
	</td></tr>
462
	<tr><td>
463
		<div id="mainarea">
464
			<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="main area">
465
				<tr>
466
					<td class="listhdrr"><?=gettext("Interface"); ?></td>
467
					<td class="listhdr"><?=gettext("Network port"); ?></td>
468
					<td class="list">&nbsp;</td>
469
				</tr>
470
<?php
471
			foreach ($config['interfaces'] as $ifname => $iface):
472
				if ($iface['descr'])
473
					$ifdescr = $iface['descr'];
474
				else
475
					$ifdescr = strtoupper($ifname);
476
?>
477
				<tr>
478
					<td class="listlr" valign="middle"><strong><u><span onclick="location.href='/interfaces.php?if=<?=$ifname;?>'" style="cursor: pointer;"><?=$ifdescr;?></span></u></strong></td>
479
					<td valign="middle" class="listr">
480
						<select onchange="javascript:jQuery('#savediv').show();" name="<?=$ifname;?>" id="<?=$ifname;?>">
481
<?php
482
						foreach ($portlist as $portname => $portinfo):
483
?>
484
							<option  value="<?=$portname;?>"  <?php if ($portname == $iface['if']) echo " selected=\"selected\"";?>>
485
								<?=interface_assign_description($portinfo, $portname);?>
486
							</option>
487
<?php
488
						endforeach;
489
?>
490
						</select>
491
					</td>
492
					<td valign="middle" class="list">
493
<?php
494
					if ($ifname != 'wan'):
495
?>
496
						<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>
497
<?php
498
					endif;
499
?>
500
					</td>
501
				</tr>
502
<?php
503
			endforeach;
504
			if (count($config['interfaces']) < count($portlist)):
505
?>
506
				<tr>
507
					<td class="list" colspan="2"></td>
508
					<td class="list nowrap">
509
						<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>
510
					</td>
511
				</tr>
512
<?php
513
			else:
514
?>
515
				<tr>
516
					<td class="list" colspan="3" height="10"></td>
517
				</tr>
518
<?php
519
			endif;
520
?>
521
			</table>
522
		</div>
523
		<br />
524
		<div id='savediv' <?php if (empty($_GET['act'])) echo "style='display:none;'"; ?>>
525
			<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" /><br /><br />
526
		</div>
527
		<ul>
528
			<li><span class="vexpl"><?=gettext("Interfaces that are configured as members of a lagg(4) interface will not be shown."); ?></span></li>
529
		</ul>
530
	</td></tr>
531
</table>
532
</form>
533
<?php include("fend.inc"); ?>
534
</body>
535
</html>
(95-95/255)