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