src: unify the label printing of interfaces

This annoyed me for a long time: always print the literal description
if found, only use uppercase on the interface key if no description
is available.
This commit is contained in:
Franco Fichtner 2018-05-04 08:15:52 +00:00
parent 2bb7131d33
commit a0e3630364
5 changed files with 19 additions and 24 deletions

View File

@ -2368,7 +2368,7 @@ function interface_configure($interface = 'wan', $reloadall = false, $linkupeven
return;
}
$wandescr = !empty($wancfg['descr']) ? strtoupper($wancfg['descr']) : strtoupper($interface);
$wandescr = !empty($wancfg['descr']) ? $wancfg['descr'] : strtoupper($interface);
if ($verbose) {
echo sprintf('Configuring %s interface...', $wandescr);
@ -3603,20 +3603,20 @@ function convert_friendly_interface_to_friendly_descr($interface)
$ifdesc = "PPPoE";
break;
case "openvpn":
/*XXX practically unneeded as we are rendering virtual interfaces to the config */
$ifdesc = "OpenVPN";
break;
case "enc0":
case "ipsec":
case "IPsec":
/* XXX practically unneeded as we are rendering virtual interfaces to the config */
/* XXX it should also be noted that "enc0" is the only proper way for this lookup */
$ifdesc = "IPsec";
break;
default:
if (isset($config['interfaces'][$interface])) {
if (empty($config['interfaces'][$interface]['descr'])) {
$ifdesc = strtoupper($interface);
} else {
$ifdesc = strtoupper($config['interfaces'][$interface]['descr']);
}
$ifdesc = !empty($config['interfaces'][$interface]['descr']) ?
$config['interfaces'][$interface]['descr'] : strtoupper($interface);
break;
} elseif (stristr($interface, "_vip")) {
if (isset($config['virtualip']['vip'])) {

View File

@ -751,13 +751,12 @@ function get_configured_interface_list_by_realif ($only_opt = false, $withdisabl
return $iflist;
}
/* return the configured interfaces list with their description. */
function get_configured_interface_with_descr($only_opt = false, $withdisabled = false)
{
global $config;
$iflist = array();
/* if list */
if (isset($config['interfaces'])) {
foreach (legacy_config_get_interfaces(array("virtual" => false)) as $if => $ifdetail) {
if ($only_opt && ($if == "wan" || $if == "lan")) {
@ -765,10 +764,11 @@ function get_configured_interface_with_descr($only_opt = false, $withdisabled =
}
if (isset($ifdetail['enable']) || $withdisabled == true) {
$iflist[$if] = strtoupper($ifdetail['descr']);
$iflist[$if] = $ifdetail['descr'];
}
}
}
return $iflist;
}

View File

@ -183,11 +183,8 @@ class InterfaceField extends BaseField
}
}
if ($isMatched) {
if ($value->descr == '') {
self::$internalOptionList[$this->internalCacheKey][$key] = $key;
} else {
self::$internalOptionList[$this->internalCacheKey][$key] = (string)$value->descr;
}
self::$internalOptionList[$this->internalCacheKey][$key] =
!empty($value->descr) ? (string)$value->descr : strtoupper($key);
}
}
}

View File

@ -771,7 +771,7 @@ include("head.inc");
(!is_array($pconfig['interface']) && in_array($iface, explode(',', $pconfig['interface']))) ||
(is_array($pconfig['interface']) && in_array($iface, $pconfig['interface']))
) ? 'selected="selected"' : ''; ?>>
<?=htmlspecialchars(strtoupper($ifdetail['descr']));?>
<?= htmlspecialchars($ifdetail['descr']) ?>
</option>
<?php
endforeach; ?>

View File

@ -153,7 +153,7 @@ legacy_html_escape_form_data($pconfig);
</thead>
<tbody>
<tr>
<td><a id="help_for_ifname" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Group Name");?></td>
<td><a id="help_for_ifname" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?= gettext('Name') ?></td>
<td>
<input type="text" name="ifname" value="<?=$pconfig['ifname'];?>" />
<div class="hidden" data-for="help_for_ifname">
@ -166,13 +166,12 @@ legacy_html_escape_form_data($pconfig);
<td>
<input name="descr" type="text" value="<?=$pconfig['descr'];?>" />
<div class="hidden" data-for="help_for_descr">
<?=gettext("You may enter a description here " .
"for your reference (not parsed)."); ?>
<?= gettext('You may enter a description here for your reference.') ?>
</div>
</td>
</tr>
<tr>
<td><a id="help_for_members" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Member (s)");?></td>
<td><a id="help_for_members" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?= gettext('Members') ?></td>
<td>
<select name="members[]" multiple="multiple" class="selectpicker" data-size="5" data-live-search="true">
<?php
@ -181,15 +180,14 @@ legacy_html_escape_form_data($pconfig);
continue;
}
?>
<option value="<?=$ifn;?>" <?=in_array($ifn, $pconfig['members']) ? "selected=\"selected\"" : "";?>>
<?=strtoupper($ifdetail['descr']);?>
</option>
<option value="<?=$ifn;?>" <?=in_array($ifn, $pconfig['members']) ? "selected=\"selected\"" : "";?>>
<?= htmlspecialchars($ifdetail['descr']) ?>
</option>
<?php
endforeach;?>
</select>
<div class="hidden" data-for="help_for_members">
<strong><?= gettext('NOTE:') ?></strong>
<?= gettext('Rules for WAN type interfaces in groups do not contain the reply-to mechanism upon which Multi-WAN typically relies.') ?>
<?= gettext('Rules for WAN type interfaces in groups do not contain the reply-to mechanism upon which Multi-WAN typically relies.') ?>
</div>
</td>
</tr>