feat!: release v2 (#6545)

Co-authored-by: Artur <145776561+arturict@users.noreply.github.com>
Co-authored-by: arturict <arturict@users.noreply.github.com>
Co-authored-by: Thomas <thomas@ajnart.fr>
Co-authored-by: Afonso Jorge Ramos <afonsojorgeramos@gmail.com>
Co-authored-by: Danura30082 <danura30082+github@gmail.com>
Co-authored-by: Kushie <122986913+kushiemoon-dev@users.noreply.github.com>
Co-authored-by: ajnart <thomas@ajnart.fr>
Co-authored-by: ajnart <thomas@ajnart.dev>
Co-authored-by: chenjun <chenjun@foxmail.com>
Co-authored-by: Wikibear <wikibear@users.noreply.github.com>
Co-authored-by: Bergasha <bergasha@gmail.com>
Co-authored-by: leafyelin <43306196+leafyelin@users.noreply.github.com>
Co-authored-by: Lucas Araujo <lucas.lra@gmail.com>
Co-authored-by: GreenMonito <86085570+GreenMonito@users.noreply.github.com>
Co-authored-by: Nerdy-Technician <roffo@nerdy-technician.social>
Co-authored-by: Jun <34545896+jcstrong@users.noreply.github.com>
Co-authored-by: Edmond Abraham <54119952+gitedmond@users.noreply.github.com>
Co-authored-by: thrawnx <tight.bulb9384@fastmail.com>
Co-authored-by: Chris <58918656+nordada@users.noreply.github.com>
Co-authored-by: yi111 <153097222+Yi-111-a@users.noreply.github.com>
Co-authored-by: Yanis <naamaneyanis@gmail.com>
Co-authored-by: Wikibear <me@sej.de>
Co-authored-by: alessiottavo <93441886+alessiottavo@users.noreply.github.com>
This commit is contained in:
3286 files changed
+284386 -139176

No files matched your search

@@ -0,0 +1,48 @@
"use client";
import { Tooltip } from "@mantine/core";
import { useI18n } from "@homarr/translation/client";
import { getWazuhLevelColor, getWazuhSeverityForLevel } from "./severity";
import classes from "./wazuh.module.css";
export const WazuhLevelBadge = ({ level }: { level: number }) => {
const t = useI18n("widget.wazuh");
return (
<Tooltip
label={t("levelTooltip", { level: String(level), severity: t(`severity.${getWazuhSeverityForLevel(level)}`) })}
withArrow
openDelay={300}
>
<span className={classes.levelBadge} data-color={getWazuhLevelColor(level)}>
{level}
</span>
</Tooltip>
);
};
export const WazuhChip = ({
children,
color,
title,
}: {
children: string;
color?: "violet" | "cyan" | "red";
title?: string;
}) => (
<span className={classes.chip} data-color={color} title={title ?? children}>
{children}
</span>
);
const privateRanges = [
/^10\./,
/^192\.168\./,
/^172\.(1[6-9]|2\d|3[01])\./,
/^127\./,
/^169\.254\./,
/^fc|^fd|^fe80|^::1$/i,
];
export const isPrivateIp = (ip: string) => privateRanges.some((range) => range.test(ip));
@@ -0,0 +1,48 @@
"use client";
import { Center, Stack, Text } from "@mantine/core";
import {
IconCertificateOff,
IconClockExclamation,
IconDatabaseOff,
IconExclamationCircle,
IconLock,
IconPlugConnectedX,
} from "@tabler/icons-react";
import type { WazuhErrorReason, WazuhPublicError } from "@homarr/integrations";
import { useI18n } from "@homarr/translation/client";
import type { TablerIcon } from "@homarr/ui";
const errorIcons: Record<WazuhErrorReason, TablerIcon> = {
unauthorized: IconLock,
certificate: IconCertificateOff,
unreachable: IconPlugConnectedX,
timeout: IconClockExclamation,
status: IconExclamationCircle,
invalidResponse: IconExclamationCircle,
indexerRequired: IconDatabaseOff,
unknown: IconExclamationCircle,
};
export const WazuhErrorState = ({ error, compact }: { error: WazuhPublicError; compact?: boolean }) => {
const t = useI18n("widget.wazuh");
const Icon = errorIcons[error.reason];
const target = error.target ? t(`target.${error.target}`) : t("target.wazuh");
return (
<Center h="100%" w="100%" p="sm">
<Stack align="center" gap={4} maw={320}>
<Icon size={compact ? 20 : 28} stroke={1.5} color="var(--mantine-color-red-5)" />
<Text size="sm" fw={600} ta="center">
{t(`error.${error.reason}.title`, { target })}
</Text>
{!compact && (
<Text size="xs" c="dimmed" ta="center">
{t(`error.${error.reason}.description`, { target, status: String(error.status ?? "") })}
</Text>
)}
</Stack>
</Center>
);
};
@@ -0,0 +1,183 @@
"use client";
import type { ReactNode } from "react";
import { Anchor, Box, Group, Stack, Text, ThemeIcon, Tooltip, UnstyledButton } from "@mantine/core";
import { IconExternalLink } from "@tabler/icons-react";
import dayjs from "dayjs";
import relativeTime from "dayjs/plugin/relativeTime";
import { useCurrentIntlLocale } from "@homarr/translation/client";
import type { TablerIcon } from "@homarr/ui";
import { WidgetQueryLoadingState } from "../../common/query-state-indicator";
import { useWidgetNow } from "../../common/use-widget-now";
import classes from "./wazuh.module.css";
dayjs.extend(relativeTime);
interface WazuhWidgetFrameProps {
icon: TablerIcon;
title: ReactNode;
/** Deep link into the Wazuh dashboard for the header. */
href?: string | null;
headerRight?: ReactNode;
footer?: ReactNode;
children: ReactNode;
/** Tighter paddings for small tiles. */
compact?: boolean;
iconColor?: string;
}
export const WazuhWidgetFrame = ({
icon: Icon,
title,
href,
headerRight,
footer,
children,
compact = false,
iconColor = "blue",
}: WazuhWidgetFrameProps) => (
<Stack h="100%" gap={compact ? 4 : 8} p={compact ? 6 : 10} className={classes.frame}>
<Group justify="space-between" gap={6} wrap="nowrap" className={classes.header}>
<Group gap={6} wrap="nowrap" miw={0} style={{ flex: 1 }}>
<ThemeIcon size={compact ? 18 : 22} radius="sm" variant="light" color={iconColor} style={{ flexShrink: 0 }}>
<Icon size={compact ? 12 : 14} stroke={1.8} />
</ThemeIcon>
{href ? (
<Anchor
href={href}
target="_blank"
rel="noopener noreferrer"
c="inherit"
underline="never"
className={classes.headerLink}
miw={0}
>
<Text size="sm" fw={600} truncate component="span">
{title}
</Text>
<IconExternalLink size={12} className={classes.headerLinkIcon} />
</Anchor>
) : (
<Text size="sm" fw={600} truncate>
{title}
</Text>
)}
</Group>
{headerRight !== undefined && (
<Group gap={4} wrap="nowrap" style={{ flexShrink: 0 }}>
{headerRight}
</Group>
)}
</Group>
<Box className={classes.body}>{children}</Box>
{footer}
</Stack>
);
export const WazuhPendingState = () => <WidgetQueryLoadingState />;
/** Relative time that re-renders every minute, with the absolute local time in a tooltip. */
export const WazuhRelativeTime = ({
value,
short = false,
size = "xs",
}: {
value: string | number | null;
short?: boolean;
size?: "xs" | "sm";
}) => {
const locale = useCurrentIntlLocale();
useWidgetNow("minute");
if (value === null)
return (
<Text size={size} c="dimmed">
-
</Text>
);
const date = dayjs(value);
return (
<Tooltip label={date.toDate().toLocaleString(locale)} withArrow openDelay={300}>
<Text size={size} c="dimmed" className={classes.nowrap}>
{date.fromNow(short)}
</Text>
</Tooltip>
);
};
interface WazuhStatTileProps {
label: string;
value: string;
color: string;
href?: string | null;
active?: boolean;
onClick?: () => void;
hint?: string;
compact?: boolean;
}
/** Small stat tile with a coloured accent, used for counts at the top of widgets. */
export const WazuhStatTile = ({ label, value, color, href, active, onClick, hint, compact }: WazuhStatTileProps) => {
const content = (
<Stack
gap={0}
className={classes.tile}
data-active={active}
style={{ "--tile-color": `var(--mantine-color-${color}-6)` }}
>
<Text fw={700} size={compact ? "sm" : "lg"} lh={1.15} className={classes.tileValue}>
{value}
</Text>
<Text size="10px" c="dimmed" tt="uppercase" fw={600} truncate lh={1.3}>
{label}
</Text>
</Stack>
);
const wrapped = onClick ? (
<UnstyledButton onClick={onClick} className={classes.tileButton}>
{content}
</UnstyledButton>
) : href ? (
<Anchor
href={href}
target="_blank"
rel="noopener noreferrer"
underline="never"
c="inherit"
className={classes.tileButton}
>
{content}
</Anchor>
) : (
content
);
return hint ? (
<Tooltip label={hint} withArrow openDelay={300}>
<Box miw={0} style={{ flex: 1 }}>
{wrapped}
</Box>
</Tooltip>
) : (
<Box miw={0} style={{ flex: 1 }}>
{wrapped}
</Box>
);
};
/** Legend chip: coloured dot, label and value. */
export const WazuhLegendChip = ({ color, label, value }: { color: string; label: string; value?: string }) => (
<Group gap={4} wrap="nowrap" className={classes.nowrap}>
<Box className={classes.dot} style={{ background: `var(--mantine-color-${color.replace(".", "-")})` }} />
{label && (
<Text size="xs" c="dimmed">
{label}
</Text>
)}
{value !== undefined && (
<Text size="xs" fw={600}>
{value}
</Text>
)}
</Group>
);
@@ -0,0 +1,60 @@
/**
* Deep links into the Wazuh dashboard (4.9+ application routes). The base URL comes from the integration's optional
* "Dashboard URL" field or its linked app.
*/
const kuery = (query: string) =>
encodeURIComponent(
`(filters:!(),query:(language:kuery,query:'${query.replaceAll("!", "!!").replaceAll("'", "!'")}'))`,
);
const timeWindow = (from: string, to: string) => encodeURIComponent(`(time:(from:'${from}',to:'${to}'))`);
const withAgent = (agentId?: string | null) => (agentId ? `&agentId=${encodeURIComponent(agentId)}` : "");
export interface WazuhDashboardLinks {
home: string;
events: (options?: { agentId?: string | null; query?: string; from?: string; to?: string }) => string;
alert: (alert: { alertId: string | null; timestamp: string; agentId?: string | null }) => string;
rule: (ruleId: string) => string;
agents: string;
agent: (agentId: string) => string;
vulnerabilities: (options?: { agentId?: string | null; cve?: string }) => string;
fim: (agentId?: string | null) => string;
mitre: string;
}
export const createWazuhDashboardLinks = (baseUrl: string | null | undefined): WazuhDashboardLinks | null => {
if (!baseUrl) return null;
const base = baseUrl.replace(/\/+$/, "");
const events: WazuhDashboardLinks["events"] = (options = {}) => {
let url = `${base}/app/threat-hunting#/overview/?tab=general&tabView=events${withAgent(options.agentId)}`;
if (options.query) url += `&_q=${kuery(options.query)}`;
url += `&_g=${timeWindow(options.from ?? "now-24h", options.to ?? "now")}`;
return url;
};
return {
home: `${base}/app/wz-home`,
events,
alert: ({ alertId, timestamp, agentId }) => {
const time = new Date(timestamp).getTime();
const window = 5 * 60 * 1000;
return events({
agentId,
query: alertId ? `id:"${alertId}"` : undefined,
from: new Date(time - window).toISOString(),
to: new Date(time + window).toISOString(),
});
},
rule: (ruleId) => events({ query: `rule.id:${ruleId}` }),
agents: `${base}/app/endpoints-summary#/agents-preview`,
agent: (agentId) => `${base}/app/endpoints-summary#/agents?tab=welcome&agent=${encodeURIComponent(agentId)}`,
vulnerabilities: ({ agentId, cve } = {}) =>
`${base}/app/vulnerability-detection#/overview/?tab=vuls&tabView=inventory${withAgent(agentId)}${
cve ? `&_q=${kuery(`vulnerability.id:${cve}`)}` : ""
}`,
fim: (agentId) => `${base}/app/fim#/overview/?tab=fim&tabView=events${withAgent(agentId)}`,
mitre: `${base}/app/mitre-attack#/overview/?tab=mitre&tabView=dashboard`,
};
};
@@ -0,0 +1,6 @@
export const wazuhTimeRangeOptions = [
{ value: "1h", label: "Last hour" },
{ value: "24h", label: "Last 24 hours" },
{ value: "7d", label: "Last 7 days" },
{ value: "30d", label: "Last 30 days" },
] as const;
@@ -0,0 +1,61 @@
import type { WazuhSeverity } from "@homarr/integrations/types";
export const wazuhSeverityColors: Record<WazuhSeverity, string> = {
low: "blue",
medium: "yellow",
high: "orange",
critical: "red",
};
/** Mantine color tokens used by charts (shade picked for contrast on the dark theme). */
export const wazuhSeverityChartColors: Record<WazuhSeverity, string> = {
low: "blue.6",
medium: "yellow.5",
high: "orange.6",
critical: "red.7",
};
/** Wazuh dashboard buckets: low 0-6, medium 7-11, high 12-14, critical 15+. */
export const getWazuhSeverityForLevel = (level: number): WazuhSeverity => {
if (level >= 15) return "critical";
if (level >= 12) return "high";
if (level >= 7) return "medium";
return "low";
};
/** Badge color for a rule level; very low levels are informational and rendered grey. */
export const getWazuhLevelColor = (level: number) =>
level < 4 ? "gray" : wazuhSeverityColors[getWazuhSeverityForLevel(level)];
export const wazuhSeverities = ["critical", "high", "medium", "low"] as const satisfies readonly WazuhSeverity[];
/** Vulnerability severities as stored in wazuh-states-vulnerabilities-* ("Critical", "High", ...). */
export const getVulnerabilitySeverityColor = (severity: string) => {
const key = severity.toLowerCase();
if (key === "critical") return "red";
if (key === "high") return "orange";
if (key === "medium") return "yellow";
if (key === "low") return "blue";
return "gray";
};
/** Compact number formatting for stat tiles (12345 -> 12.3K). */
export const formatWazuhCount = (value: number, locale: string) =>
new Intl.NumberFormat(locale, {
notation: value >= 10_000 ? "compact" : "standard",
maximumFractionDigits: 1,
}).format(value);
/** Relative change between two periods, or null when there is no baseline. */
export const getWazuhTrend = (current: number, previous: number): number | null => {
if (previous === 0) return current === 0 ? 0 : null;
return (current - previous) / previous;
};
export const formatWazuhTrend = (trend: number, locale: string) =>
new Intl.NumberFormat(locale, {
style: "percent",
maximumFractionDigits: Math.abs(trend) < 0.1 ? 1 : 0,
signDisplay: "exceptZero",
// Normalise -0 so an unchanged bucket reads "0%" instead of "-0%".
}).format(Math.abs(trend) < 0.0005 ? 0 : trend);
@@ -0,0 +1,6 @@
import { useMemo } from "react";
import { createWazuhDashboardLinks } from "./links";
export const useWazuhLinks = (dashboardUrl: string | null | undefined) =>
useMemo(() => createWazuhDashboardLinks(dashboardUrl), [dashboardUrl]);
@@ -0,0 +1,302 @@
.frame {
overflow: hidden;
container-type: inline-size;
}
.header {
min-height: 22px;
}
.body {
flex: 1;
min-height: 0;
position: relative;
}
.headerLink {
display: inline-flex;
align-items: center;
gap: 4px;
min-width: 0;
}
.headerLinkIcon {
flex-shrink: 0;
opacity: 0;
color: var(--mantine-color-dimmed);
transition: opacity 120ms ease;
}
.headerLink:hover .headerLinkIcon {
opacity: 1;
}
.nowrap {
white-space: nowrap;
flex-shrink: 0;
}
.dot {
width: 8px;
height: 8px;
border-radius: 50%;
flex-shrink: 0;
}
.tile {
position: relative;
padding: 5px 8px 5px 10px;
border-radius: var(--mantine-radius-sm);
background: light-dark(var(--mantine-color-gray-0), rgba(255, 255, 255, 0.035));
border: 1px solid light-dark(var(--mantine-color-gray-2), rgba(255, 255, 255, 0.06));
min-width: 0;
overflow: hidden;
}
.tile::before {
content: "";
position: absolute;
left: 0;
top: 6px;
bottom: 6px;
width: 3px;
border-radius: 2px;
background: var(--tile-color);
}
.tile[data-active="true"] {
border-color: var(--tile-color);
background: light-dark(var(--mantine-color-gray-1), rgba(255, 255, 255, 0.07));
}
.tileValue {
font-variant-numeric: tabular-nums;
}
.tileButton {
display: block;
width: 100%;
border-radius: var(--mantine-radius-sm);
}
.tileButton:hover .tile {
background: light-dark(var(--mantine-color-gray-1), rgba(255, 255, 255, 0.07));
}
.row {
display: flex;
align-items: center;
gap: 8px;
padding: 4px 6px;
border-radius: var(--mantine-radius-sm);
color: inherit;
text-decoration: none;
min-width: 0;
}
a.row:hover,
button.row:hover {
background: light-dark(var(--mantine-color-gray-1), rgba(255, 255, 255, 0.05));
}
.rowStriped:nth-child(even) {
background: light-dark(var(--mantine-color-gray-0), rgba(255, 255, 255, 0.018));
}
.mono {
font-family: var(--mantine-font-family-monospace);
/* Monospace glyphs look larger; scale slightly down relative to the surrounding text. */
font-size: 0.92em;
}
.numeric {
font-variant-numeric: tabular-nums;
white-space: nowrap;
flex-shrink: 0;
}
.bar {
height: 4px;
border-radius: 2px;
background: light-dark(var(--mantine-color-gray-2), rgba(255, 255, 255, 0.06));
overflow: hidden;
}
.barFill {
height: 100%;
border-radius: 2px;
}
.sectionLabel {
font-size: 10px;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.04em;
color: var(--mantine-color-dimmed);
}
.table {
width: 100%;
border-collapse: collapse;
table-layout: fixed;
font-size: var(--mantine-font-size-xs);
}
.table th {
position: sticky;
top: 0;
z-index: 1;
background: var(--mantine-color-body);
text-align: left;
font-weight: 600;
font-size: 10px;
text-transform: uppercase;
letter-spacing: 0.04em;
color: var(--mantine-color-dimmed);
padding: 4px 6px;
border-bottom: 1px solid light-dark(var(--mantine-color-gray-3), rgba(255, 255, 255, 0.08));
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.table td {
padding: 4px 6px;
border-bottom: 1px solid light-dark(var(--mantine-color-gray-1), rgba(255, 255, 255, 0.04));
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
vertical-align: middle;
}
.table tbody tr:hover td {
background: light-dark(var(--mantine-color-gray-0), rgba(255, 255, 255, 0.035));
}
.sortButton {
display: inline-flex;
align-items: center;
gap: 2px;
font: inherit;
color: inherit;
text-transform: inherit;
letter-spacing: inherit;
background: none;
border: 0;
padding: 0;
cursor: pointer;
}
.sortButton:hover {
color: var(--mantine-color-text);
}
.statusDot {
width: 8px;
height: 8px;
border-radius: 50%;
display: inline-block;
flex-shrink: 0;
}
.statusDot[data-status="active"] {
background: var(--mantine-color-green-6);
box-shadow: 0 0 0 3px rgba(64, 192, 87, 0.15);
}
.statusDot[data-status="disconnected"] {
background: var(--mantine-color-red-6);
box-shadow: 0 0 0 3px rgba(250, 82, 82, 0.15);
}
.statusDot[data-status="never_connected"],
.statusDot[data-status="unknown"] {
background: var(--mantine-color-gray-6);
}
.statusDot[data-status="pending"] {
background: var(--mantine-color-yellow-6);
}
.chip {
display: inline-flex;
align-items: center;
flex-shrink: 0;
max-width: 100%;
padding: 0 6px;
height: 16px;
border-radius: 8px;
font-size: 10px;
font-weight: 600;
line-height: 16px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
background: light-dark(var(--mantine-color-gray-1), rgba(255, 255, 255, 0.07));
color: light-dark(var(--mantine-color-gray-7), var(--mantine-color-gray-4));
}
.chip[data-color="violet"] {
background: rgba(132, 94, 247, 0.16);
color: var(--mantine-color-violet-3);
}
.chip[data-color="cyan"] {
background: rgba(34, 184, 207, 0.14);
color: var(--mantine-color-cyan-3);
}
.chip[data-color="red"] {
background: rgba(250, 82, 82, 0.16);
color: var(--mantine-color-red-3);
}
.levelBadge {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 26px;
height: 20px;
padding: 0 5px;
border-radius: var(--mantine-radius-sm);
font-size: 11px;
font-weight: 700;
font-variant-numeric: tabular-nums;
flex-shrink: 0;
color: var(--mantine-color-white);
}
.levelBadge[data-color="gray"] {
background: var(--mantine-color-gray-7);
}
.levelBadge[data-color="blue"] {
background: var(--mantine-color-blue-7);
}
.levelBadge[data-color="yellow"] {
background: var(--mantine-color-yellow-5);
color: var(--mantine-color-dark-9);
}
.levelBadge[data-color="orange"] {
background: var(--mantine-color-orange-7);
}
.levelBadge[data-color="red"] {
background: var(--mantine-color-red-8);
}
.pathStart {
direction: rtl;
text-align: left;
unicode-bidi: plaintext;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
min-width: 0;
}
.table .mono {
font-size: 11px;
}