Feature: Twingate service widget
This commit is contained in:
parent
e6c7692677
commit
721b2c4b2f
@ -953,5 +953,13 @@
|
||||
"reminders": "Reminders",
|
||||
"nextReminder": "Next Reminder",
|
||||
"none": "None"
|
||||
},
|
||||
"twingate": {
|
||||
"networks": "Networks",
|
||||
"connectors": "Connectors",
|
||||
"resources": "Resources",
|
||||
"devices": "Devices",
|
||||
"users": "Users",
|
||||
"groups": "Groups"
|
||||
}
|
||||
}
|
||||
|
||||
@ -90,6 +90,9 @@ export default async function credentialedProxyHandler(req, res, map) {
|
||||
}
|
||||
} else if (widget.type === "wgeasy") {
|
||||
headers.Authorization = widget.password;
|
||||
} else if (widget.type == "twingate") {
|
||||
headers["Content-Type"] = "application/x-www-form-urlencoded";
|
||||
headers["X-API-Key"] = `${widget.key}`;
|
||||
} else {
|
||||
headers["X-API-Key"] = `${widget.key}`;
|
||||
}
|
||||
|
||||
@ -120,6 +120,7 @@ const components = {
|
||||
transmission: dynamic(() => import("./transmission/component")),
|
||||
tubearchivist: dynamic(() => import("./tubearchivist/component")),
|
||||
truenas: dynamic(() => import("./truenas/component")),
|
||||
twingate: dynamic(() => import("./twingate/component")),
|
||||
unifi: dynamic(() => import("./unifi/component")),
|
||||
unmanic: dynamic(() => import("./unmanic/component")),
|
||||
uptimekuma: dynamic(() => import("./uptimekuma/component")),
|
||||
|
||||
63
src/widgets/twingate/component.jsx
Normal file
63
src/widgets/twingate/component.jsx
Normal file
@ -0,0 +1,63 @@
|
||||
import { useTranslation } from "next-i18next";
|
||||
import Container from "components/services/widget/container";
|
||||
import Block from "components/services/widget/block";
|
||||
import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||
|
||||
export default function Component({ service }) {
|
||||
|
||||
const { widget } = service;
|
||||
|
||||
const { data: statsData, error: statsError } = useWidgetAPI(widget, "stats", {
|
||||
query:
|
||||
"{ connectors { totalCount states: edges { node { state } } } groups { totalCount states: edges { node { state: isActive } } } users { totalCount states: edges { node { state } } } remoteNetworks { totalCount states: edges { node { state: isActive } } } devices { totalCount states: edges { node { state: activeState } } } resources { totalCount states: edges { node { state: isActive } } } }",
|
||||
});
|
||||
|
||||
console.log(statsData);
|
||||
|
||||
if (statsError) {
|
||||
return <Container service={service} error={statsError} />;
|
||||
}
|
||||
|
||||
const { connectors, groups, users, remoteNetworks, devices, resources } = statsData || {};
|
||||
|
||||
const activeConnectors = connectors?.states?.filter(({ node }) => node.state === "ALIVE").length;
|
||||
const activeGroups = groups?.states?.filter(({ node }) => node.state).length;
|
||||
const activeUsers = users?.states?.filter(({ node }) => node.state === "ACTIVE").length;
|
||||
const activeNetworks = remoteNetworks?.states?.filter(({ node }) => node.state).length;
|
||||
const activeDevices = devices?.states?.filter(({ node }) => node.state === "ACTIVE").length;
|
||||
const activeResources = resources?.states?.filter(({ node }) => node.state).length;
|
||||
|
||||
// Provide a default if not set in the config
|
||||
if (!widget.fields) {
|
||||
widget.fields = ["networks", "connectors", "resources"];
|
||||
}
|
||||
|
||||
// Limit to a maximum of 4 at a time
|
||||
if (widget.fields.length > 4) {
|
||||
widget.fields = widget.fields.slice(0, 4);
|
||||
}
|
||||
|
||||
if (!statsData) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="twingate.networks" />
|
||||
<Block label="twingate.connectors" />
|
||||
<Block label="twingate.resources" />
|
||||
<Block label="twingate.devices" />
|
||||
<Block label="twingate.users" />
|
||||
<Block label="twingate.groups" />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="twingate.networks" value={`${activeNetworks}/${remoteNetworks?.totalCount}`} />
|
||||
<Block label="twingate.connectors" value={`${activeConnectors}/${connectors?.totalCount}`} />
|
||||
<Block label="twingate.resources" value={`${activeResources}/${resources?.totalCount}`} />
|
||||
<Block label="twingate.devices" value={`${activeDevices}/${devices?.totalCount}`} />
|
||||
<Block label="twingate.users" value={`${activeUsers}/${users?.totalCount}`} />
|
||||
<Block label="twingate.groups" value={`${activeGroups}/${groups?.totalCount}`} />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
20
src/widgets/twingate/widget.js
Normal file
20
src/widgets/twingate/widget.js
Normal file
@ -0,0 +1,20 @@
|
||||
import { asJson } from "utils/proxy/api-helpers";
|
||||
import credentialedProxyHandler from "utils/proxy/handlers/credentialed";
|
||||
|
||||
const widget = {
|
||||
api: "{url}/api/{endpoint}",
|
||||
proxyHandler: credentialedProxyHandler,
|
||||
|
||||
mappings: {
|
||||
stats: {
|
||||
method: "GET",
|
||||
endpoint: "graphql",
|
||||
map: (data) => asJson(data).data,
|
||||
params:[
|
||||
"query"
|
||||
]
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default widget;
|
||||
@ -111,6 +111,7 @@ import traefik from "./traefik/widget";
|
||||
import transmission from "./transmission/widget";
|
||||
import tubearchivist from "./tubearchivist/widget";
|
||||
import truenas from "./truenas/widget";
|
||||
import twingate from "./twingate/widget";
|
||||
import unifi from "./unifi/widget";
|
||||
import unmanic from "./unmanic/widget";
|
||||
import uptimekuma from "./uptimekuma/widget";
|
||||
@ -240,6 +241,7 @@ const widgets = {
|
||||
transmission,
|
||||
tubearchivist,
|
||||
truenas,
|
||||
twingate,
|
||||
unifi,
|
||||
unifi_console: unifi,
|
||||
unmanic,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user