mirror of
https://github.com/karl0ss/homepage.git
synced 2025-05-02 13:33:40 +01:00
Add authentik
This commit is contained in:
parent
d876ba30d4
commit
1840e9a57a
@ -179,5 +179,10 @@
|
|||||||
"user_count": "Users",
|
"user_count": "Users",
|
||||||
"status_count": "Posts",
|
"status_count": "Posts",
|
||||||
"domain_count": "Domains"
|
"domain_count": "Domains"
|
||||||
|
},
|
||||||
|
"authentik": {
|
||||||
|
"users": "Users",
|
||||||
|
"loginsLast24H": "Logins (24h)",
|
||||||
|
"failedLoginsLast24H": "Failed Logins (24h)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
import getServiceWidget from "utils/service-helpers";
|
import getServiceWidget from "utils/service-helpers";
|
||||||
import { formatApiCall } from "utils/api-helpers";
|
import { formatApiCall } from "utils/api-helpers";
|
||||||
import { httpProxy } from "utils/http";
|
import { httpProxy } from "utils/http";
|
||||||
|
import createLogger from "utils/logger";
|
||||||
import widgets from "widgets/widgets";
|
import widgets from "widgets/widgets";
|
||||||
|
|
||||||
|
const logger = createLogger("credentialedProxyHandler");
|
||||||
|
|
||||||
export default async function credentialedProxyHandler(req, res) {
|
export default async function credentialedProxyHandler(req, res) {
|
||||||
const { group, service, endpoint } = req.query;
|
const { group, service, endpoint } = req.query;
|
||||||
|
|
||||||
@ -24,6 +27,8 @@ export default async function credentialedProxyHandler(req, res) {
|
|||||||
headers["X-CMC_PRO_API_KEY"] = `${widget.key}`;
|
headers["X-CMC_PRO_API_KEY"] = `${widget.key}`;
|
||||||
} else if (widget.type === "gotify") {
|
} else if (widget.type === "gotify") {
|
||||||
headers["X-gotify-Key"] = `${widget.key}`;
|
headers["X-gotify-Key"] = `${widget.key}`;
|
||||||
|
} else if (widget.type === "authentik") {
|
||||||
|
headers.Authorization = `Bearer ${widget.key}`;
|
||||||
} else {
|
} else {
|
||||||
headers["X-API-Key"] = `${widget.key}`;
|
headers["X-API-Key"] = `${widget.key}`;
|
||||||
}
|
}
|
||||||
@ -39,10 +44,15 @@ export default async function credentialedProxyHandler(req, res) {
|
|||||||
return res.status(status).end();
|
return res.status(status).end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (status >= 400) {
|
||||||
|
logger.debug("HTTP Error %d calling %s//%s%s...", status, url.protocol, url.hostname, url.pathname);
|
||||||
|
}
|
||||||
|
|
||||||
if (contentType) res.setHeader("Content-Type", contentType);
|
if (contentType) res.setHeader("Content-Type", contentType);
|
||||||
return res.status(status).send(data);
|
return res.status(status).send(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.debug("Invalid or missing proxy service type '%s' in group '%s'", service, group);
|
||||||
return res.status(400).json({ error: "Invalid proxy service type" });
|
return res.status(400).json({ error: "Invalid proxy service type" });
|
||||||
}
|
}
|
||||||
|
46
src/widgets/authentik/component.jsx
Normal file
46
src/widgets/authentik/component.jsx
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
import useSWR from "swr";
|
||||||
|
import { useTranslation } from "next-i18next";
|
||||||
|
|
||||||
|
import Widget from "components/services/widgets/widget";
|
||||||
|
import Block from "components/services/widgets/block";
|
||||||
|
import { formatProxyUrl } from "utils/api-helpers";
|
||||||
|
|
||||||
|
export default function Component({ service }) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
const config = service.widget;
|
||||||
|
|
||||||
|
const { data: usersData, error: usersError } = useSWR(formatProxyUrl(config, "users"));
|
||||||
|
const { data: loginsData, error: loginsError } = useSWR(formatProxyUrl(config, "login"));
|
||||||
|
const { data: failedLoginsData, error: failedLoginsError } = useSWR(formatProxyUrl(config, "login_failed"));
|
||||||
|
|
||||||
|
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) => current.x_cord >= yesterday ? total + current.y_cord : total
|
||||||
|
, 0);
|
||||||
|
const failedLoginsLast24H = failedLoginsData.reduce(
|
||||||
|
(total, current) => 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>
|
||||||
|
);
|
||||||
|
}
|
20
src/widgets/authentik/widget.js
Normal file
20
src/widgets/authentik/widget.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import credentialedProxyHandler from "utils/proxies/credentialed";
|
||||||
|
|
||||||
|
const widget = {
|
||||||
|
api: "{url}/api/v3/{endpoint}",
|
||||||
|
proxyHandler: credentialedProxyHandler,
|
||||||
|
|
||||||
|
mappings: {
|
||||||
|
"users": {
|
||||||
|
endpoint: "core/users?page_size=1"
|
||||||
|
},
|
||||||
|
"login": {
|
||||||
|
endpoint: "events/events/per_month/?action=login&query={}"
|
||||||
|
},
|
||||||
|
"login_failed": {
|
||||||
|
endpoint: "events/events/per_month/?action=login_failed&query={}"
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default widget;
|
@ -2,6 +2,7 @@ import dynamic from "next/dynamic";
|
|||||||
|
|
||||||
const components = {
|
const components = {
|
||||||
adguard: dynamic(() => import("./adguard/component")),
|
adguard: dynamic(() => import("./adguard/component")),
|
||||||
|
authentik: dynamic(() => import("./authentik/component")),
|
||||||
bazarr: dynamic(() => import("./bazarr/component")),
|
bazarr: dynamic(() => import("./bazarr/component")),
|
||||||
coinmarketcap: dynamic(() => import("./coinmarketcap/component")),
|
coinmarketcap: dynamic(() => import("./coinmarketcap/component")),
|
||||||
docker: dynamic(() => import("./docker/component")),
|
docker: dynamic(() => import("./docker/component")),
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import adguard from "./adguard/widget";
|
import adguard from "./adguard/widget";
|
||||||
|
import authentik from "./authentik/widget";
|
||||||
import bazarr from "./bazarr/widget";
|
import bazarr from "./bazarr/widget";
|
||||||
import coinmarketcap from "./coinmarketcap/widget";
|
import coinmarketcap from "./coinmarketcap/widget";
|
||||||
import emby from "./emby/widget";
|
import emby from "./emby/widget";
|
||||||
@ -27,6 +28,7 @@ import transmission from "./transmission/widget";
|
|||||||
|
|
||||||
const widgets = {
|
const widgets = {
|
||||||
adguard,
|
adguard,
|
||||||
|
authentik,
|
||||||
bazarr,
|
bazarr,
|
||||||
coinmarketcap,
|
coinmarketcap,
|
||||||
emby,
|
emby,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user