Project

General

Profile

« Previous | Next » 

Revision 87489e5c

Added by Peter Schofield over 7 years ago

re-adding changes made to fix bug#6400, includes fixes for bug#8222 and bug#8223 that were introduced with the initial commit of this code.

original pull request was #3868

View differences:

src/usr/local/www/interfaces_assign.php
3 3
 * interfaces_assign.php
4 4
 *
5 5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2018 Rubicon Communications, LLC (Netgate)
6
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
7 7
 * All rights reserved.
8 8
 *
9 9
 * originally based on m0n0wall (http://m0n0.ch/wall)
......
31 31
##|*MATCH=interfaces_assign.php*
32 32
##|-PRIV
33 33

  
34
//$timealla = microtime(true);
35

  
34 36
$pgtitle = array(gettext("Interfaces"), gettext("Interface Assignments"));
35 37
$shortcut_section = "interfaces";
36 38

  
......
42 44
require_once("vpn.inc");
43 45
require_once("captiveportal.inc");
44 46
require_once("rrd.inc");
47
require_once("interfaces_fast.inc");
45 48

  
46
function interface_assign_description($portinfo, $portname) {
47
	global $ovpn_descrs;
48
	if ($portinfo['isvlan']) {
49
		$descr = sprintf(gettext('VLAN %1$s on %2$s'), $portinfo['tag'], $portinfo['if']);
50
		$iface = convert_real_interface_to_friendly_interface_name($portinfo['if']);
51
		if (isset($iface) && strlen($iface) > 0) {
52
			$descr .= " - $iface";
53
		}
54
		if ($portinfo['descr']) {
55
			$descr .= " (" . $portinfo['descr'] . ")";
56
		}
57
	} elseif ($portinfo['iswlclone']) {
58
		$descr = $portinfo['cloneif'];
59
		if ($portinfo['descr']) {
60
			$descr .= " (" . $portinfo['descr'] . ")";
61
		}
62
	} elseif ($portinfo['isppp']) {
63
		$descr = $portinfo['descr'];
64
	} elseif ($portinfo['isbridge']) {
65
		$descr = strtoupper($portinfo['bridgeif']);
66
		if ($portinfo['descr']) {
67
			$descr .= " (" . $portinfo['descr'] . ")";
68
		}
69
	} elseif ($portinfo['isgre']) {
70
		$descr = "GRE {$portinfo['remote-addr']}";
71
		if ($portinfo['descr']) {
72
			$descr .= " (" . $portinfo['descr'] . ")";
73
		}
74
	} elseif ($portinfo['isgif']) {
75
		$descr = "GIF {$portinfo['remote-addr']}";
76
		if ($portinfo['descr']) {
77
			$descr .= " (" . $portinfo['descr'] . ")";
78
		}
79
	} elseif ($portinfo['islagg']) {
80
		$descr = strtoupper($portinfo['laggif']);
81
		$descr .= " (" . $portinfo['mac'] . ")";
82
		if ($portinfo['descr']) {
83
			$descr .= " - " . $portinfo['descr'];
84
		}
85
	} elseif ($portinfo['isqinq']) {
86
		$descr = $portinfo['descr'];
87
	} elseif (substr($portname, 0, 4) == 'ovpn') {
88
		$descr = $portname . " (" . $ovpn_descrs[substr($portname, 5)] . ")";
89
	} else {
90
		$descr = $portname . " (" . $portinfo['mac'] . ")";
91
	}
49
global $friendlyifnames;
92 50

  
93
	return htmlspecialchars($descr);
94
}
51
/*moved most gettext calls to here, we really don't want to be repeatedly calling gettext() within loops if it can be avoided.*/
52
$gettextArray = array('add'=>gettext('Add'),'addif'=>gettext('Add interface'),'delete'=>gettext('Delete'),'deleteif'=>gettext('Delete interface'),'edit'=>gettext('Edit'),'on'=>gettext('on'));
95 53

  
96 54
/*
97 55
	In this file, "port" refers to the physical port name,
......
101 59
/* get list without VLAN interfaces */
102 60
$portlist = get_interface_list();
103 61

  
62
/*another *_fast function from interfaces_fast.inc. These functions are basically the same as the 
63
ones they're named after, except they (usually) take an array and (always) return an array. This means that they only
64
need to be called once per script run, the returned array contains all the data necessary for repeated use */
65
$friendlyifnames = convert_real_interface_to_friendly_interface_name_fast();
66

  
104 67
/* add wireless clone interfaces */
105 68
if (is_array($config['wireless']['clone']) && count($config['wireless']['clone'])) {
106 69
	foreach ($config['wireless']['clone'] as $clone) {
......
111 74

  
112 75
/* add VLAN interfaces */
113 76
if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) {
77
	//$timea = microtime(true);
114 78
	foreach ($config['vlans']['vlan'] as $vlan) {
115 79
		$portlist[$vlan['vlanif']] = $vlan;
116 80
		$portlist[$vlan['vlanif']]['isvlan'] = true;
......
142 106
}
143 107

  
144 108
/* add LAGG interfaces */
145
$lagglist = get_lagg_interface_list();
146
$portlist = array_merge($portlist, $lagglist);
147
foreach ($lagglist as $laggif => $lagg) {
148
	/* LAGG members cannot be assigned */
149
	$laggmembers = explode(',', $lagg['members']);
150
	foreach ($laggmembers as $lagm) {
151
		if (isset($portlist[$lagm])) {
152
			unset($portlist[$lagm]);
109
if (is_array($config['laggs']['lagg']) && count($config['laggs']['lagg'])) {
110
	foreach ($config['laggs']['lagg'] as $lagg) {
111
		$portlist[$lagg['laggif']] = $lagg;
112
		$portlist[$lagg['laggif']]['islagg'] = true;
113
		/* LAGG members cannot be assigned */
114
		$lagifs = explode(',', $lagg['members']);
115
		foreach ($lagifs as $lagif) {
116
			if (isset($portlist[$lagif])) {
117
				unset($portlist[$lagif]);
118
			}
153 119
		}
154 120
	}
155 121
}
......
162 128
		/* QinQ members */
163 129
		$qinqifs = explode(' ', $qinq['members']);
164 130
		foreach ($qinqifs as $qinqif) {
165
			$portlist["{$qinq['vlanif']}.{$qinqif}"]['descr'] = "QinQ {$qinqif} on VLAN {$qinq['tag']} on {$qinq['if']}";
166
			$portlist["{$qinq['vlanif']}.{$qinqif}"]['isqinq'] = true;
131
			$portlist["{$qinq['vlanif']}_{$qinqif}"]['descr'] = "QinQ {$qinqif} on VLAN {$qinq['tag']} on {$qinq['if']}";
132
			$portlist["{$qinq['vlanif']}_{$qinqif}"]['isqinq'] = true;
167 133
		}
168 134
	}
169 135
}
......
203 169
	}
204 170
}
205 171

  
172

  
173
$ifdescrs = interface_assign_description_fast($portlist,$friendlyifnames);
174

  
206 175
if (isset($_REQUEST['add']) && isset($_REQUEST['if_add'])) {
207 176
	/* Be sure this port is not being used */
208 177
	$portused = false;
......
227 196
			$newifname = 'opt' . $i;
228 197
			$descr = "OPT" . $i;
229 198
		}
230

  
199
		
231 200
		$config['interfaces'][$newifname] = array();
232 201
		$config['interfaces'][$newifname]['descr'] = $descr;
233 202
		$config['interfaces'][$newifname]['if'] = $_POST['if_add'];
......
236 205
			interface_sync_wireless_clones($config['interfaces'][$newifname], false);
237 206
		}
238 207

  
208
		
239 209
		uksort($config['interfaces'], "compare_interface_friendly_names");
240 210

  
241 211
		/* XXX: Do not remove this. */
......
365 335
				}
366 336
			}
367 337
		}
368

  
369 338
		write_config();
370 339

  
371 340
		enable_rrd_graphing();
......
441 410

  
442 411
/* Create a list of unused ports */
443 412
$unused_portlist = array();
444
foreach ($portlist as $portname => $portinfo) {
445
	$portused = false;
446
	foreach ($config['interfaces'] as $ifname => $ifdata) {
447
		if ($ifdata['if'] == $portname) {
448
			$portused = true;
449
			break;
450
		}
451
	}
452
	if ($portused === false) {
453
		$unused_portlist[$portname] = $portinfo;
454
	}
455
}
413
$portArray = array_keys($portlist);
414

  
415
$ifaceArray = array_column($config['interfaces'],'if');
416
$unused = array_diff($portArray,$ifaceArray);
417
$unused = array_flip($unused);
418
$unused_portlist = array_intersect_key($portlist,$unused);//*/
419
unset($unused,$portArray,$ifaceArray);
456 420

  
457 421
include("head.inc");
458 422

  
......
501 465
$tab_array[] = array(gettext("Bridges"), false, "interfaces_bridge.php");
502 466
$tab_array[] = array(gettext("LAGGs"), false, "interfaces_lagg.php");
503 467
display_top_tabs($tab_array);
468

  
469
/*Generate the port select box only once. 
470
Not indenting the HTML to produce smaller code
471
and faster page load times */
472

  
473
$portselect='';
474
foreach ($portlist as $portname => $portinfo) {
475
	$portselect.='<option value="'.$portname.'"'; 
476
	$portselect.=">".$ifdescrs[$portname]."</option>\n";
477
}
478

  
504 479
?>
505 480
<form action="interfaces_assign.php" method="post">
506 481
	<div class="table-responsive">
......
514 489
	</thead>
515 490
	<tbody>
516 491
<?php
492
	$i=0;
517 493
	foreach ($config['interfaces'] as $ifname => $iface):
518 494
		if ($iface['descr']) {
519 495
			$ifdescr = $iface['descr'];
......
525 501
			<td><a href="/interfaces.php?if=<?=$ifname?>"><?=$ifdescr?></a></td>
526 502
			<td>
527 503
				<select name="<?=$ifname?>" id="<?=$ifname?>" class="form-control">
528
<?php foreach ($portlist as $portname => $portinfo):?>
529
					<option value="<?=$portname?>" <?=($portname == $iface['if']) ? ' selected': ''?>>
530
						<?=interface_assign_description($portinfo, $portname)?>
531
					</option>
532
<?php endforeach;?>
504
<?php 
505
/*port select menu generation loop replaced with pre-prepared select menu to reduce page generation time */
506
echo str_replace('value="'.$iface['if'].'">','value="'.$iface['if'].'" selected>',$portselect);
507
?>
533 508
				</select>
534 509
			</td>
535 510
			<td>
536 511
<?php if ($ifname != 'wan'):?>
537
				<button type="submit" name="del[<?=$ifname?>]" class="btn btn-danger btn-sm" title="<?=gettext("Delete interface")?>">
512
				<button type="submit" name="del[<?=$ifname?>]" class="btn btn-danger btn-sm" title="<?=$gettextArray['deleteif']?>">
538 513
					<i class="fa fa-trash icon-embed-btn"></i>
539
					<?=gettext("Delete")?>
514
					<?=$gettextArray["delete"]?>
540 515
				</button>
541 516
<?php endif;?>
542 517
			</td>
543 518
		</tr>
544
<?php endforeach;
519
<?php $i++; 
520
endforeach;
545 521
	if (count($config['interfaces']) < count($portlist)):
546 522
?>
547 523
		<tr>
......
550 526
			</th>
551 527
			<td>
552 528
				<select name="if_add" id="if_add" class="form-control">
553
<?php foreach ($unused_portlist as $portname => $portinfo):?>
554
					<option value="<?=$portname?>" <?=($portname == $iface['if']) ? ' selected': ''?>>
555
						<?=interface_assign_description($portinfo, $portname)?>
556
					</option>
557
<?php endforeach;?>
529
<?php
530
/* HTML not indented to save on transmission/render time */
531
foreach ($unused_portlist as $portname => $portinfo):?>
532
<option value="<?=$portname?>" <?=($portname == $iface['if']) ? ' selected': ''?>><?=$ifdescrs[$portname]?></option>
533
<?php endforeach;
534
?>
558 535
				</select>
559 536
			</td>
560 537
			<td>
561 538
				<button type="submit" name="add" title="<?=gettext("Add selected interface")?>" value="add interface" class="btn btn-success btn-sm" >
562 539
					<i class="fa fa-plus icon-embed-btn"></i>
563
					<?=gettext("Add")?>
540
					<?=$gettextArray["add"]?>
564 541
				</button>
565 542
			</td>
566 543
		</tr>

Also available in: Unified diff