Display External IP Address in status bar

This change displays the last detected IPv4 and/or IPv6 address(es) in the GUI and WebUI's status bar. This does not yet handle systems with multiple addresses of the same type (e.g. multiple IPv6 addresses).

PR #21383.

---------

Co-authored-by: Odin Vex <44311901+OdinVex@users.noreply.github.com>
This commit is contained in:
Thomas Piccirello
2024-11-09 04:58:13 -03:00
committed by GitHub
parent fb9b3c0f34
commit f89c4c32ed
15 changed files with 155 additions and 13 deletions

View File

@@ -278,8 +278,10 @@
<tbody>
<tr>
<td id="freeSpaceOnDisk"></td>
<td class="statusBarSeparator"></td>
<td id="DHTNodes"></td>
<td class="statusBarSeparator invisible"></td>
<td id="externalIPs" class="invisible"></td>
<td class="statusBarSeparator invisible"></td>
<td id="DHTNodes" class="invisible"></td>
<td class="statusBarSeparator"></td>
<td><img id="connectionStatus" alt="QBT_TR(Connection status: Firewalled)QBT_TR[CONTEXT=MainWindow]" title="QBT_TR(Connection status: Firewalled)QBT_TR[CONTEXT=MainWindow]" src="images/firewalled.svg" style="height: 1.5em;"></td>
<td class="statusBarSeparator"></td>

View File

@@ -956,6 +956,28 @@ window.addEventListener("DOMContentLoaded", () => {
$("freeSpaceOnDisk").textContent = "QBT_TR(Free space: %1)QBT_TR[CONTEXT=HttpServer]".replace("%1", window.qBittorrent.Misc.friendlyUnit(serverState.free_space_on_disk));
const externalIPsElement = document.getElementById("externalIPs");
if (window.qBittorrent.Cache.preferences.get().status_bar_external_ip) {
const lastExternalAddressV4 = serverState.last_external_address_v4;
const lastExternalAddressV6 = serverState.last_external_address_v6;
const hasIPv4Address = lastExternalAddressV4 !== "";
const hasIPv6Address = lastExternalAddressV6 !== "";
let lastExternalAddressLabel = "QBT_TR(External IP: N/A)QBT_TR[CONTEXT=HttpServer]";
if (hasIPv4Address && hasIPv6Address)
lastExternalAddressLabel = "QBT_TR(External IPs: %1, %2)QBT_TR[CONTEXT=HttpServer]";
else if (hasIPv4Address || hasIPv6Address)
lastExternalAddressLabel = "QBT_TR(External IP: %1%2)QBT_TR[CONTEXT=HttpServer]";
// replace in reverse order ('%2' before '%1') in case address contains a % character.
// for example, see https://en.wikipedia.org/wiki/IPv6_address#Scoped_literal_IPv6_addresses_(with_zone_index)
externalIPsElement.textContent = lastExternalAddressLabel.replace("%2", lastExternalAddressV6).replace("%1", lastExternalAddressV4);
externalIPsElement.classList.remove("invisible");
externalIPsElement.previousElementSibling.classList.remove("invisible");
}
else {
externalIPsElement.classList.add("invisible");
externalIPsElement.previousElementSibling.classList.add("invisible");
}
const dhtElement = document.getElementById("DHTNodes");
if (window.qBittorrent.Cache.preferences.get().dht) {
dhtElement.textContent = "QBT_TR(DHT: %1 nodes)QBT_TR[CONTEXT=StatusBar]".replace("%1", serverState.dht_nodes);

View File

@@ -90,6 +90,11 @@
</table>
</fieldset>
<div class="formRow" style="margin-bottom: 3px;">
<input type="checkbox" id="statusBarExternalIP">
<label for="statusBarExternalIP">QBT_TR(Show external IP in status bar)QBT_TR[CONTEXT=OptionsDialog]</label>
</div>
<div class="formRow" style="margin-bottom: 5px;">
<input type="checkbox" id="performanceWarning">
<label for="performanceWarning">QBT_TR(Log performance warnings)QBT_TR[CONTEXT=OptionsDialog]</label>
@@ -2157,6 +2162,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
// Language
updateWebuiLocaleSelect(pref.locale);
updateColoSchemeSelect();
$("statusBarExternalIP").checked = pref.status_bar_external_ip;
$("performanceWarning").checked = pref.performance_warning;
document.getElementById("displayFullURLTrackerColumn").checked = (LocalPreferences.get("full_url_tracker_column", "false") === "true");
document.getElementById("hideZeroFiltersCheckbox").checked = (LocalPreferences.get("hide_zero_status_filters", "false") === "true");
@@ -2582,6 +2588,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
LocalPreferences.set("color_scheme", "light");
else
LocalPreferences.set("color_scheme", "dark");
settings["status_bar_external_ip"] = $("statusBarExternalIP").checked;
settings["performance_warning"] = $("performanceWarning").checked;
LocalPreferences.set("full_url_tracker_column", document.getElementById("displayFullURLTrackerColumn").checked.toString());
LocalPreferences.set("hide_zero_status_filters", document.getElementById("hideZeroFiltersCheckbox").checked.toString());