Enhancement: improve fritzbox proxy perfomance (#2429)

---------

Co-authored-by: Thorben Grove <thorben.grove@tui.de>
Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
pull/2435/head
Thorben 12 months ago committed by GitHub
parent 77ed445da1
commit 0f3fc77ddf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -11,12 +11,12 @@ Home Network > Network > Network Settings > Access Settings in the Home Network
[x] Transmit status information over UPnP
```
You don't need to provide any credentials.
Credentials are not needed and, as such, you may want to consider using `http` instead of `https` as those requests are significantly faster.
Allowed fields (limited to a max of 4): `["connectionStatus", "upTime", "maxDown", "maxUp", "down", "up", "received", "sent", "externalIPAddress"]`.
```yaml
widget:
type: fritzbox
url: https://192.168.178.1
url: http://192.168.178.1
```

@ -127,7 +127,7 @@
"connectionStatusUnconfigured": "Unconfigured",
"connectionStatusConnecting": "Connecting",
"connectionStatusAuthenticating": "Authenticating",
"connectionStatusPendingDisconnect": "PendingDisconnect",
"connectionStatusPendingDisconnect": "Pending Disconnect",
"connectionStatusDisconnecting": "Disconnecting",
"connectionStatusDisconnected": "Disconnected",
"connectionStatusConnected": "Connected",

@ -4,6 +4,8 @@ import Container from "components/services/widget/container";
import Block from "components/services/widget/block";
import useWidgetAPI from "utils/proxy/use-widget-api";
export const fritzboxDefaultFields = ["connectionStatus", "uptime", "maxDown", "maxUp"];
const formatUptime = (timestamp) => {
const hours = Math.floor(timestamp / 3600);
const minutes = Math.floor((timestamp % 3600) / 60);
@ -27,7 +29,7 @@ export default function Component({ service }) {
// Default fields
if (!widget.fields?.length > 0) {
widget.fields = ["connectionStatus", "uptime", "maxDown", "maxUp"];
widget.fields = fritzboxDefaultFields;
}
const MAX_ALLOWED_FIELDS = 4;
// Limits max number of displayed fields

@ -1,5 +1,7 @@
import { xml2json } from "xml-js";
import { fritzboxDefaultFields } from "./component";
import { httpProxy } from "utils/proxy/http";
import getServiceWidget from "utils/config/service-helpers";
import createLogger from "utils/logger";
@ -46,10 +48,12 @@ async function requestEndpoint(apiBaseUrl, service, action) {
export default async function fritzboxProxyHandler(req, res) {
const { group, service } = req.query;
const serviceWidget = await getServiceWidget(group, service);
if (!serviceWidget) {
res.status(500).json({ error: "Service widget not found" });
return;
}
if (!serviceWidget.url) {
res.status(500).json({ error: "Service widget url not configured" });
return;
@ -59,23 +63,31 @@ export default async function fritzboxProxyHandler(req, res) {
const port = serviceWidgetUrl.protocol === "https:" ? 49443 : 49000;
const apiBaseUrl = `${serviceWidgetUrl.protocol}//${serviceWidgetUrl.hostname}:${port}`;
if (!serviceWidget.fields?.length > 0) {
serviceWidget.fields = fritzboxDefaultFields;
}
const requestStatusInfo = ["connectionStatus", "uptime"].some((field) => serviceWidget.fields.includes(field));
const requestLinkProperties = ["maxDown", "maxUp"].some((field) => serviceWidget.fields.includes(field));
const requestAddonInfos = ["down", "up", "received", "sent"].some((field) => serviceWidget.fields.includes(field));
const requestExternalIPAddress = ["externalIPAddress"].some((field) => serviceWidget.fields.includes(field));
await Promise.all([
requestEndpoint(apiBaseUrl, "WANIPConnection", "GetStatusInfo"),
requestEndpoint(apiBaseUrl, "WANIPConnection", "GetExternalIPAddress"),
requestEndpoint(apiBaseUrl, "WANCommonInterfaceConfig", "GetCommonLinkProperties"),
requestEndpoint(apiBaseUrl, "WANCommonInterfaceConfig", "GetAddonInfos"),
requestStatusInfo ? requestEndpoint(apiBaseUrl, "WANIPConnection", "GetStatusInfo") : null,
requestLinkProperties ? requestEndpoint(apiBaseUrl, "WANCommonInterfaceConfig", "GetCommonLinkProperties") : null,
requestAddonInfos ? requestEndpoint(apiBaseUrl, "WANCommonInterfaceConfig", "GetAddonInfos") : null,
requestExternalIPAddress ? requestEndpoint(apiBaseUrl, "WANIPConnection", "GetExternalIPAddress") : null,
])
.then(([statusInfo, externalIPAddress, linkProperties, addonInfos]) => {
.then(([statusInfo, linkProperties, addonInfos, externalIPAddress]) => {
res.status(200).json({
connectionStatus: statusInfo.NewConnectionStatus,
uptime: statusInfo.NewUptime,
maxDown: linkProperties.NewLayer1DownstreamMaxBitRate,
maxUp: linkProperties.NewLayer1UpstreamMaxBitRate,
down: addonInfos.NewByteReceiveRate,
up: addonInfos.NewByteSendRate,
received: addonInfos.NewX_AVM_DE_TotalBytesReceived64,
sent: addonInfos.NewX_AVM_DE_TotalBytesSent64,
externalIPAddress: externalIPAddress.NewExternalIPAddress,
connectionStatus: statusInfo?.NewConnectionStatus || "Unconfigured",
uptime: statusInfo?.NewUptime || 0,
maxDown: linkProperties?.NewLayer1DownstreamMaxBitRate || 0,
maxUp: linkProperties?.NewLayer1UpstreamMaxBitRate || 0,
down: addonInfos?.NewByteReceiveRate || 0,
up: addonInfos?.NewByteSendRate || 0,
received: addonInfos?.NewX_AVM_DE_TotalBytesReceived64 || 0,
sent: addonInfos?.NewX_AVM_DE_TotalBytesSent64 || 0,
externalIPAddress: externalIPAddress?.NewExternalIPAddress || null,
});
})
.catch((error) => {

Loading…
Cancel
Save