Project

General

Profile

Download (22.9 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * interfaces_assign.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
7
 * All rights reserved.
8
 *
9
 * originally based on m0n0wall (http://m0n0.ch/wall)
10
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
11
 * Written by Jim McBeath based on existing m0n0wall files
12
 * All rights reserved.
13
 *
14
 * Licensed under the Apache License, Version 2.0 (the "License");
15
 * you may not use this file except in compliance with the License.
16
 * You may obtain a copy of the License at
17
 *
18
 * http://www.apache.org/licenses/LICENSE-2.0
19
 *
20
 * Unless required by applicable law or agreed to in writing, software
21
 * distributed under the License is distributed on an "AS IS" BASIS,
22
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23
 * See the License for the specific language governing permissions and
24
 * limitations under the License.
25
 */
26

    
27
##|+PRIV
28
##|*IDENT=page-interfaces-assignnetworkports
29
##|*NAME=Interfaces: Interface Assignments
30
##|*DESCR=Allow access to the 'Interfaces: Interface Assignments' page.
31
##|*MATCH=interfaces_assign.php*
32
##|-PRIV
33

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

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

    
39
require_once("guiconfig.inc");
40
require_once("functions.inc");
41
require_once("filter.inc");
42
require_once("shaper.inc");
43
require_once("ipsec.inc");
44
require_once("vpn.inc");
45
require_once("captiveportal.inc");
46
require_once("rrd.inc");
47
require_once("interfaces_fast.inc");
48

    
49
global $friendlyifnames;
50
//global $profile;
51

    
52
/*moved most gettext calls to here, we really don't want to be repeatedly calling gettext() within loops if it can be avoided.*/
53
$gettextArray = array('add'=>gettext('Add'),'addif'=>gettext('Add interface'),'delete'=>gettext('Delete'),'deleteif'=>gettext('Delete interface'),'edit'=>gettext('Edit'),'on'=>gettext('on'));
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
/*another *_fast function from interfaces_fast.inc. These functions are basically the same as the 
64
ones they're named after, except they (usually) take an array and (always) return an array. This means that they only
65
need to be called once per script run, the returned array contains all the data necessary for repeated use */
66
$friendlyifnames = convert_real_interface_to_friendly_interface_name_fast(array_keys($portlist));
67

    
68
/* add wireless clone interfaces */
69
if (is_array($config['wireless']['clone']) && count($config['wireless']['clone'])) {
70
	foreach ($config['wireless']['clone'] as $clone) {
71
		$portlist[$clone['cloneif']] = $clone;
72
		$portlist[$clone['cloneif']]['iswlclone'] = true;
73
	}
74
}
75

    
76
/* add VLAN interfaces */
77
if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) {
78
	//$timea = microtime(true);
79
	foreach ($config['vlans']['vlan'] as $vlan) {
80
		$portlist[$vlan['vlanif']] = $vlan;
81
		$portlist[$vlan['vlanif']]['isvlan'] = true;
82
	}
83
	/*$timeb = microtime(true);
84
	$profile['add_vlan_if'] = $timeb-$timea;*/
85
}
86

    
87
/* add Bridge interfaces */
88
if (is_array($config['bridges']['bridged']) && count($config['bridges']['bridged'])) {
89
	foreach ($config['bridges']['bridged'] as $bridge) {
90
		$portlist[$bridge['bridgeif']] = $bridge;
91
		$portlist[$bridge['bridgeif']]['isbridge'] = true;
92
	}
93
}
94

    
95
/* add GIF interfaces */
96
if (is_array($config['gifs']['gif']) && count($config['gifs']['gif'])) {
97
	foreach ($config['gifs']['gif'] as $gif) {
98
		$portlist[$gif['gifif']] = $gif;
99
		$portlist[$gif['gifif']]['isgif'] = true;
100
	}
101
}
102

    
103
/* add GRE interfaces */
104
if (is_array($config['gres']['gre']) && count($config['gres']['gre'])) {
105
	foreach ($config['gres']['gre'] as $gre) {
106
		$portlist[$gre['greif']] = $gre;
107
		$portlist[$gre['greif']]['isgre'] = true;
108
	}
109
}
110

    
111
/* add LAGG interfaces */
112
if (is_array($config['laggs']['lagg']) && count($config['laggs']['lagg'])) {
113
	foreach ($config['laggs']['lagg'] as $lagg) {
114
		$portlist[$lagg['laggif']] = $lagg;
115
		$portlist[$lagg['laggif']]['islagg'] = true;
116
		/* LAGG members cannot be assigned */
117
		$lagifs = explode(',', $lagg['members']);
118
		foreach ($lagifs as $lagif) {
119
			if (isset($portlist[$lagif])) {
120
				unset($portlist[$lagif]);
121
			}
122
		}
123
	}
124
}
125

    
126
/* add QinQ interfaces */
127
if (is_array($config['qinqs']['qinqentry']) && count($config['qinqs']['qinqentry'])) {
128
	foreach ($config['qinqs']['qinqentry'] as $qinq) {
129
		$portlist["{$qinq['vlanif']}"]['descr'] = "VLAN {$qinq['tag']} on {$qinq['if']}";
130
		$portlist["{$qinq['vlanif']}"]['isqinq'] = true;
131
		/* QinQ members */
132
		$qinqifs = explode(' ', $qinq['members']);
133
		foreach ($qinqifs as $qinqif) {
134
			$portlist["{$qinq['vlanif']}_{$qinqif}"]['descr'] = "QinQ {$qinqif} on VLAN {$qinq['tag']} on {$qinq['if']}";
135
			$portlist["{$qinq['vlanif']}_{$qinqif}"]['isqinq'] = true;
136
		}
137
	}
138
}
139

    
140
/* add PPP interfaces */
141
if (is_array($config['ppps']['ppp']) && count($config['ppps']['ppp'])) {
142
	foreach ($config['ppps']['ppp'] as $pppid => $ppp) {
143
		$portname = $ppp['if'];
144
		$portlist[$portname] = $ppp;
145
		$portlist[$portname]['isppp'] = true;
146
		$ports_base = basename($ppp['ports']);
147
		if (isset($ppp['descr'])) {
148
			$portlist[$portname]['descr'] = strtoupper($ppp['if']). "({$ports_base}) - {$ppp['descr']}";
149
		} else if (isset($ppp['username'])) {
150
			$portlist[$portname]['descr'] = strtoupper($ppp['if']). "({$ports_base}) - {$ppp['username']}";
151
		} else {
152
			$portlist[$portname]['descr'] = strtoupper($ppp['if']). "({$ports_base})";
153
		}
154
	}
155
}
156

    
157
$ovpn_descrs = array();
158
if (is_array($config['openvpn'])) {
159
	if (is_array($config['openvpn']['openvpn-server'])) {
160
		foreach ($config['openvpn']['openvpn-server'] as $s) {
161
			$portname = "ovpns{$s['vpnid']}";
162
			$portlist[$portname] = $s;
163
			$ovpn_descrs[$s['vpnid']] = $s['description'];
164
		}
165
	}
166
	if (is_array($config['openvpn']['openvpn-client'])) {
167
		foreach ($config['openvpn']['openvpn-client'] as $c) {
168
			$portname = "ovpnc{$c['vpnid']}";
169
			$portlist[$portname] = $c;
170
			$ovpn_descrs[$c['vpnid']] = $c['description'];
171
		}
172
	}
173
}
174

    
175
//$timea = microtime(true);
176
$ifdescrs = interface_assign_description_fast($portlist,$friendlyifnames);
177
/*$timeb = microtime(true);
178
$profile['build_if_descrs'] = $timeb - $timea;*/
179

    
180
if (isset($_REQUEST['add']) && isset($_REQUEST['if_add'])) {
181
	/* Be sure this port is not being used */
182
	$portused = false;
183
	//$timea = microtime(true);
184
	foreach ($config['interfaces'] as $ifname => $ifdata) {
185
		if ($ifdata['if'] == $_REQUEST['if_add']) {
186
			$portused = true;
187
			break;
188
		}
189
	}
190
	/*$timeb = microtime(true);
191
	$profile['if_add_portused'] = $timeb-$timea;*/
192

    
193
	if ($portused === false) {
194
		/* find next free optional interface number */
195
		if (!$config['interfaces']['lan']) {
196
			$newifname = gettext("lan");
197
			$descr = gettext("LAN");
198
		} else {
199
			/*get first available OPT interface number. This code scales better than the foreach it replaces. 
200
			* might not work if theres ifs other than 'wan','lan' and 'optx';
201
			* The performance increase isn't substantial over the foreach; however as the number of OPT interfaces
202
			* increases, so does the performance gain; from ~0.0003s improvement with 100 VLANs to ~0.0009s with 400.
203
			* It is, however, marginally slower (~0.000036s at 50 VLANS) than the foreach with less than 100 VLANs, and 
204
			* therefore may not be worth the loss of code readability or performance for the majority of use cases. */
205
			//$timea = microtime(true);
206
			$step1 = array_keys($config['interfaces']);
207
			unset($step1['lan'],$step1['wan']);
208
			$step2 = str_replace("opt","",$step1);
209
			$step3 = array_fill(0,end($step2),'x');
210
			$step4 = array_flip($step2);
211
			$step5 = array_replace($step3,$step2);
212
			$step6 = array_unique($step5);
213
			$step7 = array_flip($step6);
214
			if (isset($step7['x']))
215
				$i = $step7['x'];
216
			else
217
				$i = count($config['interfaces'])-1;
218

    
219
			$newifname = 'opt' . $i;
220
			$descr = "OPT" . $i;
221
		}
222
		/*$timeb = microtime(true);
223
		$profile['if_add_get_free_opt'] = $timeb-$timea;*/
224

    
225
		$config['interfaces'][$newifname] = array();
226
		$config['interfaces'][$newifname]['descr'] = $descr;
227
		$config['interfaces'][$newifname]['if'] = $_POST['if_add'];
228
		if (preg_match($g['wireless_regex'], $_POST['if_add'])) {
229
			$config['interfaces'][$newifname]['wireless'] = array();
230
			interface_sync_wireless_clones($config['interfaces'][$newifname], false);
231
		}
232

    
233
		//$timea = microtime(true);
234
		uksort($config['interfaces'], "compare_interface_friendly_names");
235
		/*$timeb = microtime(true);
236
		$profile['if_add_uksort'] = $timeb-$timea;*/
237

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

    
241
		//$timea = microtime(true);
242
		write_config();
243
		/*$timeb = microtime(true);
244
		$profile['if_add_write_config'] = $timeb-$timea;*/
245

    
246
		$action_msg = gettext("Interface has been added.");
247
		$class = "success";
248
	}
249

    
250
} else if (isset($_POST['apply'])) {
251
	if (file_exists("/var/run/interface_mismatch_reboot_needed")) {
252
		system_reboot();
253
		$rebootingnow = true;
254
	} else {
255
		write_config();
256

    
257
		$changes_applied = true;
258
		$retval = 0;
259
		$retval |= filter_configure();
260
	}
261

    
262
} else if (isset($_POST['Submit'])) {
263

    
264
	unset($input_errors);
265

    
266
	/* input validation */
267

    
268
	/* Build a list of the port names so we can see how the interfaces map */
269
	$portifmap = array();
270
	//$timea = microtime(true);
271
	foreach ($portlist as $portname => $portinfo) {
272
		$portifmap[$portname] = array();
273
	}
274
	/*$timeb = microtime(true);
275
	$profile['post_list_port_names'] = $timeb - $timea;*/
276

    
277
	/* Go through the list of ports selected by the user,
278
	build a list of port-to-interface mappings in portifmap */
279
	//$timea = microtime(true);
280
	foreach ($_POST as $ifname => $ifport) {
281
		if (($ifname == 'lan') || ($ifname == 'wan') || (substr($ifname, 0, 3) == 'opt')) {
282
			$portifmap[$ifport][] = strtoupper($ifname);
283
		}
284
	}
285
	/*$timeb = microtime(true);
286
	$profile['post_build_port_if_map']=$timeb-$timea;*/
287

    
288
	/* Deliver error message for any port with more than one assignment */
289
	//$timea = microtime(true);
290
	foreach ($portifmap as $portname => $ifnames) {
291
		if (count($ifnames) > 1) {
292
			$errstr = sprintf(gettext('Port %1$s '.
293
				' was assigned to %2$s' .
294
				' interfaces:'), $portname, count($ifnames));
295

    
296
			//$timea2 = microtime(true);
297
			foreach ($portifmap[$portname] as $ifn) {
298
				$errstr .= " " . convert_friendly_interface_to_friendly_descr(strtolower($ifn)) . " (" . $ifn . ")";
299
			}
300
			/*$timeb2 = microtime(true);
301
			if ($timeb2-$timea2 > $profile['post_error_multiple_assign_convert_friendly_if_friendly_desc'])
302
				$profile['post_error_multiple_assign_convert_friendly_if_friendly_desc'] = $timeb2 - $timea2;*/
303

    
304
			$input_errors[] = $errstr;
305
		} else if (count($ifnames) == 1 && preg_match('/^bridge[0-9]/', $portname) && is_array($config['bridges']['bridged']) && count($config['bridges']['bridged'])) {
306
			foreach ($config['bridges']['bridged'] as $bridge) {
307
				if ($bridge['bridgeif'] != $portname) {
308
					continue;
309
				}
310

    
311
				$members = explode(",", strtoupper($bridge['members']));
312
				foreach ($members as $member) {
313
					if ($member == $ifnames[0]) {
314
						$input_errors[] = sprintf(gettext('Cannot set port %1$s to interface %2$s because this interface is a member of %3$s.'), $portname, $member, $portname);
315
						break;
316
					}
317
				}
318
			}
319
		}
320
	}
321
	/*$timeb = $microtime(true);
322
	$profile['post_error_multiple_assign'] = $timeb-$timea;*/
323

    
324
	if (is_array($config['vlans']['vlan'])) {
325
		//$timea = microtime(true);
326
		foreach ($config['vlans']['vlan'] as $vlan) {
327
			if (does_interface_exist($vlan['if']) == false) {
328
				$input_errors[] = sprintf(gettext('Vlan parent interface %1$s does not exist anymore so vlan id %2$s cannot be created please fix the issue before continuing.'), $vlan['if'], $vlan['tag']);
329
			}
330
		}
331
		/*$timeb = microtime(true);
332
		$profile['post_error_vlan_parent_not_exist'] = $timeb - $timea;*/
333
	}
334

    
335
	if (!$input_errors) {
336
		/* No errors detected, so update the config */
337
		//$timea = microtime(true);
338
		foreach ($_POST as $ifname => $ifport) {
339

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

    
342
				if (!is_array($ifport)) {
343
					$reloadif = false;
344
					if (!empty($config['interfaces'][$ifname]['if']) && $config['interfaces'][$ifname]['if'] <> $ifport) {
345
						interface_bring_down($ifname);
346
						/* Mark this to be reconfigured in any case. */
347
						$reloadif = true;
348
					}
349
					$config['interfaces'][$ifname]['if'] = $ifport;
350
					if (isset($portlist[$ifport]['isppp'])) {
351
						$config['interfaces'][$ifname]['ipaddr'] = $portlist[$ifport]['type'];
352
					}
353

    
354
					if (substr($ifport, 0, 3) == 'gre' || substr($ifport, 0, 3) == 'gif') {
355
						unset($config['interfaces'][$ifname]['ipaddr']);
356
						unset($config['interfaces'][$ifname]['subnet']);
357
						unset($config['interfaces'][$ifname]['ipaddrv6']);
358
						unset($config['interfaces'][$ifname]['subnetv6']);
359
					}
360

    
361
					/* check for wireless interfaces, set or clear ['wireless'] */
362
					if (preg_match($g['wireless_regex'], $ifport)) {
363
						if (!is_array($config['interfaces'][$ifname]['wireless'])) {
364
							$config['interfaces'][$ifname]['wireless'] = array();
365
						}
366
					} else {
367
						unset($config['interfaces'][$ifname]['wireless']);
368
					}
369

    
370
					/* make sure there is a descr for all interfaces */
371
					if (!isset($config['interfaces'][$ifname]['descr'])) {
372
						$config['interfaces'][$ifname]['descr'] = strtoupper($ifname);
373
					}
374

    
375
					if ($reloadif == true) {
376
						if (preg_match($g['wireless_regex'], $ifport)) {
377
							interface_sync_wireless_clones($config['interfaces'][$ifname], false);
378
						}
379
						/* Reload all for the interface. */
380
						interface_configure($ifname, true);
381
					}
382
				}
383
			}
384
		}
385
		/*$timeb = microtime(true);
386
		$profile['post_build_config'] = $timeb-$timea;
387

    
388
		$timea = microtime(true);*/
389
		write_config();
390
		/*$timeb = microtime(true);
391
		$profile['post_write_config']=$timeb-$timea;*/
392

    
393
		enable_rrd_graphing();
394
	}
395
} else {
396
	unset($delbtn);
397
	if (!empty($_POST['del'])) {
398
		$delbtn = key($_POST['del']);
399
	}
400

    
401
	if (isset($delbtn)) {
402
		$id = $delbtn;
403

    
404
		if (link_interface_to_group($id)) {
405
			$input_errors[] = gettext("The interface is part of a group. Please remove it from the group to continue");
406
		} else if (link_interface_to_bridge($id)) {
407
			$input_errors[] = gettext("The interface is part of a bridge. Please remove it from the bridge to continue");
408
		} else if (link_interface_to_gre($id)) {
409
			$input_errors[] = gettext("The interface is part of a gre tunnel. Please delete the tunnel to continue");
410
		} else if (link_interface_to_gif($id)) {
411
			$input_errors[] = gettext("The interface is part of a gif tunnel. Please delete the tunnel to continue");
412
		} else if (interface_has_queue($id)) {
413
			$input_errors[] = gettext("The interface has a traffic shaper queue configured.\nPlease remove all queues on the interface to continue.");
414
		} else {
415
			unset($config['interfaces'][$id]['enable']);
416
			//$timea = microtime(true);
417
			$realid = get_real_interface($id);
418
			/*$timeb = microtime(true);
419
			$profile['del_if_get_real_if'] = $timeb-$timea;*/
420
			interface_bring_down($id);   /* down the interface */
421

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

    
424
			if (is_array($config['dhcpd']) && is_array($config['dhcpd'][$id])) {
425
				unset($config['dhcpd'][$id]);
426
				services_dhcpd_configure('inet');
427
			}
428

    
429
			if (is_array($config['dhcpdv6']) && is_array($config['dhcpdv6'][$id])) {
430
				unset($config['dhcpdv6'][$id]);
431
				services_dhcpd_configure('inet6');
432
			}
433

    
434
			if (count($config['filter']['rule']) > 0) {
435
				foreach ($config['filter']['rule'] as $x => $rule) {
436
					if ($rule['interface'] == $id) {
437
						unset($config['filter']['rule'][$x]);
438
					}
439
				}
440
			}
441
			if (is_array($config['nat']['rule']) && count($config['nat']['rule']) > 0) {
442
				foreach ($config['nat']['rule'] as $x => $rule) {
443
					if ($rule['interface'] == $id) {
444
						unset($config['nat']['rule'][$x]['interface']);
445
					}
446
				}
447
			}
448

    
449
			//$timea = microtime(true);
450
			write_config();
451
			/*$timeb = microtime(true);
452
			$profile['del_if_write_config']=$timeb-$timea;
453

    
454
			/* If we are in firewall/routing mode (not single interface)
455
			 * then ensure that we are not running DHCP on the wan which
456
			 * will make a lot of ISP's unhappy.
457
			 */
458
			if ($config['interfaces']['lan'] && $config['dhcpd']['wan']) {
459
				unset($config['dhcpd']['wan']);
460
			}
461

    
462
			//$timea = microtime(true);
463
			link_interface_to_vlans($realid, "update");
464
			/*$timeb = microtime(true);
465
			$profile['del_if_link_if_vlans'] = $timeb-$timea;*/
466

    
467
			$action_msg = gettext("Interface has been deleted.");
468
			$class = "success";
469
		}
470
	}
471
}
472

    
473
/* Create a list of unused ports */
474
$unused_portlist = array();
475
//$timea = microtime(true);
476
$portArray = array_keys($portlist);
477

    
478
/*  this code scales much much better 
479
0.0065770149230957 seconds
480
vs
481
0.49271988868713 seconds with 400 vlans*/
482

    
483
	$ifaceArray = array_column($config['interfaces'],'if');
484
	$unused = array_diff($portArray,$ifaceArray);
485
	$unused = array_flip($unused);
486
	$unused_portlist = array_intersect_key($portlist,$unused);//*/
487
	unset($unused,$portArray,$ifaceArray);
488

    
489
/*$timeb = microtime(true);
490
$profile['build_unused_port_list'] = $timeb-$timea;*/
491

    
492
include("head.inc");
493

    
494
if (file_exists("/var/run/interface_mismatch_reboot_needed")) {
495
	if ($_POST) {
496
		if ($rebootingnow) {
497
			$action_msg = gettext("The system is now rebooting. Please wait.");
498
			$class = "success";
499
		} else {
500
			$applymsg = gettext("Reboot is needed. Please apply the settings in order to reboot.");
501
			$class = "warning";
502
		}
503
	} else {
504
		$action_msg = gettext("Interface mismatch detected. Please resolve the mismatch, save and then click 'Apply Changes'. The firewall will reboot afterwards.");
505
		$class = "warning";
506
	}
507
}
508

    
509
if (file_exists("/tmp/reload_interfaces")) {
510
	echo "<p>\n";
511
	print_apply_box(gettext("The interface configuration has been changed.") . "<br />" . gettext("The changes must be applied for them to take effect."));
512
	echo "<br /></p>\n";
513
} elseif ($applymsg) {
514
	print_apply_box($applymsg);
515
} elseif ($action_msg) {
516
	print_info_box($action_msg, $class);
517
} elseif ($changes_applied) {
518
	print_apply_result_box($retval);
519
}
520

    
521
pfSense_handle_custom_code("/usr/local/pkg/interfaces_assign/pre_input_errors");
522

    
523
if ($input_errors) {
524
	print_input_errors($input_errors);
525
}
526

    
527
$tab_array = array();
528
$tab_array[] = array(gettext("Interface Assignments"), true, "interfaces_assign.php");
529
$tab_array[] = array(gettext("Interface Groups"), false, "interfaces_groups.php");
530
$tab_array[] = array(gettext("Wireless"), false, "interfaces_wireless.php");
531
$tab_array[] = array(gettext("VLANs"), false, "interfaces_vlan.php");
532
$tab_array[] = array(gettext("QinQs"), false, "interfaces_qinq.php");
533
$tab_array[] = array(gettext("PPPs"), false, "interfaces_ppps.php");
534
$tab_array[] = array(gettext("GREs"), false, "interfaces_gre.php");
535
$tab_array[] = array(gettext("GIFs"), false, "interfaces_gif.php");
536
$tab_array[] = array(gettext("Bridges"), false, "interfaces_bridge.php");
537
$tab_array[] = array(gettext("LAGGs"), false, "interfaces_lagg.php");
538
display_top_tabs($tab_array);
539
//$timea = microtime(true);
540

    
541
/*generate the port select box only once. 
542
Not indenting the HTML and keeping each option to one line in
543
this function results in HTML code that is 8.9KB smaller with 500
544
VLANS than the original code structure. Multiplied by 500 VLANs 
545
this means the page is ~4.5MB smaller and takes over 1s less to 
546
transmit and also renders significantly faster in the browser.
547
This is too much of an improvement to ignore. Tested with 500
548
VLANS, total page output is 17,197.33KB with 8456ms spent 
549
waiting for page generation and transmission, compared to 
550
21,697.89KB with a wait of 9734ms*/
551

    
552
//$timea2 = microtime();
553
$portselect='';
554
foreach ($portlist as $portname => $portinfo) {
555
	$portselect.='<option value="'.$portname.'"'; 
556
	/*if($portname == $iface['if']) {
557
		$portselect.=' selected';
558
	}*/
559
	$portselect.=">".$ifdescrs[$portname]."</option>\n";
560
}
561
/*$timeb2 = microtime();
562
$profile['html_generate_port_select'];
563
$profile['html_generated_port_select'] = strlen($portselect);*/
564

    
565
?>
566
<form action="interfaces_assign.php" method="post">
567
	<div class="table-responsive">
568
	<table class="table table-striped table-hover">
569
	<thead>
570
		<tr>
571
			<th><?=gettext("Interface")?></th>
572
			<th><?=gettext("Network port")?></th>
573
			<th>&nbsp;</th>
574
		</tr>
575
	</thead>
576
	<tbody>
577
<?php
578
	//$timea2 = microtime(true);
579
	$i=0;
580
	foreach ($config['interfaces'] as $ifname => $iface):
581
		if ($iface['descr']) {
582
			$ifdescr = $iface['descr'];
583
		} else {
584
			$ifdescr = strtoupper($ifname);
585
		}
586
?>
587
		<tr>
588
			<td><a href="/interfaces.php?if=<?=$ifname?>"><?=$ifdescr?></a></td>
589
			<td>
590
				<select name="<?=$ifname?>" id="<?=$ifname?>" class="form-control">
591
<?php //$timea3 = microtime(true);
592
/* replacing the port select menu generation loop that has count(interfaces) iterations 
593
and is run count(interfaces) times with a pre-prepared select menu generated outside of
594
this loop has produced a significant improvement in page generation and load time */
595
//foreach ($portlist as $portname => $portinfo):
596
echo str_replace('value="'.$iface['if'].'">','value="'.$iface['if'].'" selected>',$portselect);
597
 //endforeach;
598
/*$timeb3 = microtime(true);
599
$profile['html_if_assign_desc'] = $timeb3-$timea3;*/
600
?>
601
				</select>
602
			</td>
603
			<td>
604
<?php if ($ifname != 'wan'):?>
605
				<button type="submit" name="del[<?=$ifname?>]" class="btn btn-danger btn-sm" title="<?=$gettextArray['deleteif']?>">
606
					<i class="fa fa-trash icon-embed-btn"></i>
607
					<?=$gettextArray["delete"]?>
608
				</button>
609
<?php endif;?>
610
			</td>
611
		</tr>
612
<?php $i++; 
613
endforeach;
614
/*$timeb2 = microtime(true);
615
$profile['html_display_ifs'] = $timeb2-$timea2;*/
616
	if (count($config['interfaces']) < count($portlist)):
617
?>
618
		<tr>
619
			<th>
620
				<?=gettext("Available network ports:")?>
621
			</th>
622
			<td>
623
				<select name="if_add" id="if_add" class="form-control">
624
<?php //$timea2 = microtime(true);
625
/* As with the gettext() calls, I've removed the interface_assign_description() calls and
626
replaced them with my own interface_assign_description_fast() function that's called once
627
outside of the loop. Also like the gettext() edits, this change keeps paying for itself.
628
 Also, removing the indents and newlines saves potentially ~9KB of HTML with 500 unassigned VLANs */
629
foreach ($unused_portlist as $portname => $portinfo):?>
630
<option value="<?=$portname?>" <?=($portname == $iface['if']) ? ' selected': ''?>><?=$ifdescrs[$portname]?></option>
631
<?php endforeach;
632
/*$timeb2 = microtime(true);
633
$profile['html_available_ports_list'] = $timeb2-$timea2;*/
634
?>
635
				</select>
636
			</td>
637
			<td>
638
				<button type="submit" name="add" title="<?=gettext("Add selected interface")?>" value="add interface" class="btn btn-success btn-sm" >
639
					<i class="fa fa-plus icon-embed-btn"></i>
640
					<?=$gettextArray["add"]?>
641
				</button>
642
			</td>
643
		</tr>
644
<?php endif;?>
645
		</tbody>
646
	</table>
647
	</div>
648

    
649
	<button name="Submit" type="submit" class="btn btn-primary" value="<?=gettext('Save')?>"><i class="fa fa-save icon-embed-btn"></i><?=gettext('Save')?></button>
650
</form>
651
<br />
652

    
653
<?php
654
/*$timeb = microtime(true);
655
$profile['html'] = $timeb-$timea;*/
656
print_info_box(gettext("Interfaces that are configured as members of a lagg(4) interface will not be shown.") .
657
    '<br/><br/>' .
658
    gettext("Wireless interfaces must be created on the Wireless tab before they can be assigned."), 'info', false);
659
/*$timeallb = microtime(true);
660
$profile['total'] = $timeallb - $timealla;
661
print_r($profile);*/
662
?>
663

    
664
<?php include("foot.inc")?>
(72-72/230)