Add authentik Widget
- disallow proxied client calls to set HTTP verbs for generic and credentiald proxies
This commit is contained in:
parent
8a226ca473
commit
3413347660
@ -168,5 +168,10 @@
|
||||
"jackett": {
|
||||
"configured": "Configured",
|
||||
"errored": "Errored"
|
||||
},
|
||||
"authentik": {
|
||||
"users": "Users",
|
||||
"loginsLast24H": "Logins (24h)",
|
||||
"failedLoginsLast24H": "Failed Logins (24h)"
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,6 +27,7 @@ import Gotify from "./widgets/service/gotify";
|
||||
import Prowlarr from "./widgets/service/prowlarr";
|
||||
import Jackett from "./widgets/service/jackett";
|
||||
import AdGuard from "./widgets/service/adguard";
|
||||
import Authentik from "./widgets/service/authentik";
|
||||
|
||||
const widgetMappings = {
|
||||
docker: Docker,
|
||||
@ -56,6 +57,7 @@ const widgetMappings = {
|
||||
prowlarr: Prowlarr,
|
||||
jackett: Jackett,
|
||||
adguard: AdGuard,
|
||||
authentik: Authentik,
|
||||
};
|
||||
|
||||
export default function Widget({ service }) {
|
||||
|
||||
47
src/components/services/widgets/service/authentik.jsx
Normal file
47
src/components/services/widgets/service/authentik.jsx
Normal file
@ -0,0 +1,47 @@
|
||||
import useSWR from "swr";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import Widget from "../widget";
|
||||
import Block from "../block";
|
||||
|
||||
import { formatApiUrl } from "utils/api-helpers";
|
||||
|
||||
export default function Authentik({ service }) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const config = service.widget;
|
||||
|
||||
const { data: usersData, error: usersError } = useSWR(formatApiUrl(config, "core/users?page_size=1"));
|
||||
const { data: loginsData, error: loginsError } = useSWR(formatApiUrl(config, "events/events/per_month/?action=login&query={}"));
|
||||
const { data: failedLoginsData, error: failedLoginsError } = useSWR(formatApiUrl(config, "events/events/per_month/?action=login_failed&query={}"));
|
||||
|
||||
if (usersError || loginsError || failedLoginsError) {
|
||||
return <Widget error={t("widget.api_error")} />;
|
||||
}
|
||||
|
||||
if (!usersData || !loginsData || !failedLoginsData) {
|
||||
return (
|
||||
<Widget>
|
||||
<Block label={t("authentik.users")} />
|
||||
<Block label={t("authentik.loginsLast24H")} />
|
||||
<Block label={t("authentik.failedLoginsLast24H")} />
|
||||
</Widget>
|
||||
);
|
||||
}
|
||||
|
||||
const yesterday = new Date(Date.now()).setHours(-24);
|
||||
const loginsLast24H = loginsData.reduce((total, current) => {
|
||||
return current.x_cord >= yesterday ? total + current.y_cord : total;
|
||||
}, 0);
|
||||
const failedLoginsLast24H = failedLoginsData.reduce((total, current) => {
|
||||
return current.x_cord >= yesterday ? total + current.y_cord : total;
|
||||
}, 0);
|
||||
|
||||
return (
|
||||
<Widget>
|
||||
<Block label={t("authentik.users")} value={t("common.number", { value: usersData.pagination.count })} />
|
||||
<Block label={t("authentik.loginsLast24H")} value={t("common.number", { value: loginsLast24H })} />
|
||||
<Block label={t("authentik.failedLoginsLast24H")} value={t("common.number", { value: failedLoginsLast24H })} />
|
||||
</Widget>
|
||||
);
|
||||
}
|
||||
@ -89,6 +89,7 @@ const serviceProxyHandlers = {
|
||||
ombi: credentialedProxyHandler,
|
||||
coinmarketcap: credentialedProxyHandler,
|
||||
prowlarr: credentialedProxyHandler,
|
||||
authentik: credentialedProxyHandler,
|
||||
// super specific handlers
|
||||
rutorrent: rutorrentProxyHandler,
|
||||
nzbget: nzbgetProxyHandler,
|
||||
|
||||
@ -24,6 +24,7 @@ const formats = {
|
||||
prowlarr: `{url}/api/v1/{endpoint}`,
|
||||
jackett: `{url}/api/v2.0/{endpoint}?apikey={key}&configured=true`,
|
||||
adguard: `{url}/control/{endpoint}`,
|
||||
authentik: `{url}/api/v3/{endpoint}`,
|
||||
};
|
||||
|
||||
export function formatApiCall(api, args) {
|
||||
|
||||
@ -19,12 +19,14 @@ export default async function credentialedProxyHandler(req, res) {
|
||||
headers["X-CMC_PRO_API_KEY"] = `${widget.key}`;
|
||||
} else if (widget.type === "gotify") {
|
||||
headers["X-gotify-Key"] = `${widget.key}`;
|
||||
} else if (widget.type === "authentik") {
|
||||
headers["Authorization"] = `Bearer ${widget.key}`;
|
||||
} else {
|
||||
headers["X-API-Key"] = `${widget.key}`;
|
||||
}
|
||||
|
||||
const [status, contentType, data] = await httpProxy(url, {
|
||||
method: req.method,
|
||||
method: "GET", // disallow a client SWR call to set a destructive HTTP verb
|
||||
withCredentials: true,
|
||||
credentials: "include",
|
||||
headers,
|
||||
|
||||
@ -19,7 +19,7 @@ export default async function genericProxyHandler(req, res, maps) {
|
||||
}
|
||||
|
||||
const [status, contentType, data] = await httpProxy(url, {
|
||||
method: req.method,
|
||||
method: "GET", // disallow a client SWR call to set a destructive HTTP verb
|
||||
headers,
|
||||
});
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user