Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
96bb33299e | ||
|
|
39a1a3695e | ||
|
|
fbac0c8752 | ||
|
|
26c83d8853 | ||
|
|
4ff2c9a7fb | ||
|
|
a55dc98487 |
No files matched your search
@@ -163,65 +163,3 @@ jobs:
|
|||||||
run: cp .env.example .env
|
run: cp .env.example .env
|
||||||
- name: Build
|
- name: Build
|
||||||
run: pnpm turbo build --affected
|
run: pnpm turbo build --affected
|
||||||
|
|
||||||
memory-regression:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
timeout-minutes: 15
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v6
|
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v4
|
|
||||||
- name: Build Docker image
|
|
||||||
uses: docker/build-push-action@v7
|
|
||||||
with:
|
|
||||||
platforms: linux/amd64
|
|
||||||
context: .
|
|
||||||
push: false
|
|
||||||
load: true
|
|
||||||
tags: homarr-memory-test
|
|
||||||
network: host
|
|
||||||
cache-from: type=gha
|
|
||||||
cache-to: type=gha,mode=max
|
|
||||||
env:
|
|
||||||
SKIP_ENV_VALIDATION: true
|
|
||||||
- name: Start container and measure memory
|
|
||||||
run: |
|
|
||||||
docker run -d --name homarr-mem-test -p 17575:7575 homarr-memory-test
|
|
||||||
# Wait for container to be healthy (up to 60s)
|
|
||||||
healthy=false
|
|
||||||
for i in $(seq 1 30); do
|
|
||||||
if curl -sf http://localhost:17575/api/health 2>/dev/null; then
|
|
||||||
echo "Container healthy after $((i * 2))s"
|
|
||||||
healthy=true
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
sleep 2
|
|
||||||
done
|
|
||||||
if [ "$healthy" != "true" ]; then
|
|
||||||
echo "ERROR: Container never became healthy"
|
|
||||||
docker logs homarr-mem-test --tail 50
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
# Warm up: hit the dashboard page a few times
|
|
||||||
for i in $(seq 1 5); do
|
|
||||||
curl -sf http://localhost:17575/ > /dev/null 2>&1 || true
|
|
||||||
sleep 2
|
|
||||||
done
|
|
||||||
# Measure RSS after warmup
|
|
||||||
MEM_KB=$(docker stats --no-stream --format '{{.MemUsage}}' homarr-mem-test | sed 's| /.*||')
|
|
||||||
echo "Raw memory: $MEM_KB"
|
|
||||||
# Convert to numeric MB (handles GiB and MiB suffixes)
|
|
||||||
MEM_NUM=$(echo "$MEM_KB" | awk '{
|
|
||||||
if ($0 ~ /GiB/) { gsub(/GiB/,""); print $1 * 1024 }
|
|
||||||
else if ($0 ~ /MiB/) { gsub(/MiB/,""); print $1 }
|
|
||||||
else if ($0 ~ /KiB/) { gsub(/KiB/,""); print $1 / 1024 }
|
|
||||||
else { print $1 / 1048576 }
|
|
||||||
}')
|
|
||||||
echo "Memory usage: ${MEM_NUM} MB"
|
|
||||||
MAX_MB=700
|
|
||||||
if awk "BEGIN {exit !($MEM_NUM > $MAX_MB)}"; then
|
|
||||||
echo "ERROR: Memory usage ${MEM_NUM} MB exceeds ${MAX_MB} MB threshold"
|
|
||||||
docker logs homarr-mem-test --tail 50
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
echo "Memory check passed: ${MEM_NUM} MB <= ${MAX_MB} MB"
|
|
||||||
@@ -1,48 +1,40 @@
|
|||||||
---
|
---
|
||||||
title: "Unifi Controller"
|
title: 'Unifi Controller'
|
||||||
description: "Unifi Controller is a network management platform for Unifi devices."
|
description: "Unifi Controller is a network management platform for Unifi devices."
|
||||||
hide_title: true
|
hide_title: true
|
||||||
---
|
---
|
||||||
|
|
||||||
import { IntegrationHeader } from "@site/src/components/integrations/header";
|
import { IntegrationHeader } from '@site/src/components/integrations/header';
|
||||||
import { IntegrationCapabilites } from "@site/src/components/integrations/widgets";
|
import { IntegrationCapabilites } from '@site/src/components/integrations/widgets';
|
||||||
import { AddingIntegration } from "@site/src/components/integrations/adding";
|
import { AddingIntegration } from '@site/src/components/integrations/adding';
|
||||||
import { IntegrationSecrets } from "@site/src/components/integrations/secrets";
|
import {IntegrationSecrets} from '@site/src/components/integrations/secrets';
|
||||||
import { IconTopologyFull } from "@tabler/icons-react";
|
import { IconTopologyFull } from "@tabler/icons-react";
|
||||||
import { unifiControllerIntegration } from ".";
|
import { unifiControllerIntegration } from '.';
|
||||||
import { networkControllerSummaryWidget } from "@site/docs/widgets/network-controller-summary";
|
import { networkControllerSummaryWidget } from '@site/docs/widgets/network-controller-summary';
|
||||||
import { networkControllerStatusWidget } from "@site/docs/widgets/network-controller-status";
|
import { networkControllerStatusWidget } from '@site/docs/widgets/network-controller-status';
|
||||||
|
|
||||||
<IntegrationHeader integration={unifiControllerIntegration} categories={["Network controller"]} />
|
|
||||||
|
<IntegrationHeader
|
||||||
|
integration={unifiControllerIntegration}
|
||||||
|
categories={['Network controller']}
|
||||||
|
/>
|
||||||
|
|
||||||
This integration is using the [node-unifi](https://www.npmjs.com/package/node-unifi) library under the hood to connect to the Unifi Controller.
|
This integration is using the [node-unifi](https://www.npmjs.com/package/node-unifi) library under the hood to connect to the Unifi Controller.
|
||||||
Therfore it should support CloudKey Gen1, CloudKey Gen2, UnifiOS-based UDM-Pro controllers as well as self-hosted UniFi controllers.
|
Therfore it should support CloudKey Gen1, CloudKey Gen2, UnifiOS-based UDM-Pro controllers as well as self-hosted UniFi controllers.
|
||||||
|
|
||||||
### Widgets & Capabilities
|
### Widgets & Capabilities
|
||||||
|
|
||||||
<IntegrationCapabilites
|
<IntegrationCapabilites
|
||||||
items={[{ widget: networkControllerSummaryWidget }, { widget: networkControllerStatusWidget }]}
|
items={[
|
||||||
|
{ widget: networkControllerSummaryWidget },
|
||||||
|
{ widget: networkControllerStatusWidget}
|
||||||
|
]}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
### Adding the integration
|
### Adding the integration
|
||||||
|
|
||||||
<AddingIntegration />
|
<AddingIntegration />
|
||||||
|
|
||||||
Use the local HTTPS address of your controller:
|
|
||||||
|
|
||||||
- UniFi OS consoles such as Dream Router, Dream Machine, Cloud Gateway, and CloudKey use `https://<host>` (port 443).
|
|
||||||
- Self-hosted UniFi Network Servers normally use `https://<host>:8443`.
|
|
||||||
- If you omit the port, Homarr tries port 443 first and then port 8443 when the first port cannot be reached.
|
|
||||||
|
|
||||||
Use a local administrator account. Cloud-only accounts and accounts with multi-factor authentication are not supported by the underlying client.
|
|
||||||
|
|
||||||
### Secrets
|
### Secrets
|
||||||
|
<IntegrationSecrets secrets={[{
|
||||||
<IntegrationSecrets
|
credentials: ['username', 'password'],
|
||||||
secrets={[
|
steps: []
|
||||||
{
|
}]} />
|
||||||
credentials: ["username", "password"],
|
|
||||||
steps: [],
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
/>
|
|
||||||
+90
@@ -0,0 +1,90 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useTransition } from "react";
|
||||||
|
import { Button, Tooltip } from "@mantine/core";
|
||||||
|
|
||||||
|
import type { RouterOutputs } from "@homarr/api";
|
||||||
|
import { clientApi } from "@homarr/api/client";
|
||||||
|
import { showErrorNotification, showSuccessNotification } from "@homarr/notifications";
|
||||||
|
import { useI18n } from "@homarr/translation/client";
|
||||||
|
|
||||||
|
interface DisableUserButtonProps {
|
||||||
|
user: RouterOutputs["user"]["getById"];
|
||||||
|
isSelf?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const DisableUserButton = ({ user, isSelf = false }: DisableUserButtonProps) => {
|
||||||
|
const t = useI18n();
|
||||||
|
const [isPending, startTransition] = useTransition();
|
||||||
|
const changeDisabledMutation = clientApi.user.changeDisabled.useMutation();
|
||||||
|
const isDisabled = user.disabled;
|
||||||
|
|
||||||
|
const getSuccessMessage = () => {
|
||||||
|
if (isDisabled) {
|
||||||
|
return {
|
||||||
|
title: t("user.action.enable.success", { defaultValue: "User enabled" }),
|
||||||
|
message: t("user.action.enable.successDescription", { defaultValue: "User has been enabled" }),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
title: t("user.action.disable.success", { defaultValue: "User disabled" }),
|
||||||
|
message: t("user.action.disable.successDescription", { defaultValue: "User has been disabled" }),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleToggle = () => {
|
||||||
|
if (isSelf) return;
|
||||||
|
|
||||||
|
startTransition(async () => {
|
||||||
|
try {
|
||||||
|
await changeDisabledMutation.mutateAsync({
|
||||||
|
userId: user.id,
|
||||||
|
disabled: !isDisabled,
|
||||||
|
});
|
||||||
|
showSuccessNotification(getSuccessMessage());
|
||||||
|
} catch {
|
||||||
|
showErrorNotification({
|
||||||
|
title: t("common.notification.update.error"),
|
||||||
|
message: t("common.notification.update.error"),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const getTooltipLabel = () => {
|
||||||
|
if (isDisabled) {
|
||||||
|
return t("user.action.enable.description", { defaultValue: "Enable this user" });
|
||||||
|
}
|
||||||
|
return t("user.action.disable.description", { defaultValue: "Disable this user" });
|
||||||
|
};
|
||||||
|
|
||||||
|
const getButtonLabel = () => {
|
||||||
|
if (isDisabled) {
|
||||||
|
return t("user.action.enable.label", { defaultValue: "Enable user" });
|
||||||
|
}
|
||||||
|
return t("user.action.disable.label", { defaultValue: "Disable user" });
|
||||||
|
};
|
||||||
|
|
||||||
|
const getButtonColor = () => (isDisabled ? "green" : "yellow");
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Tooltip
|
||||||
|
label={
|
||||||
|
isSelf
|
||||||
|
? t("user.action.disableSelf.disabled", { defaultValue: "Cannot disable your own account" })
|
||||||
|
: getTooltipLabel()
|
||||||
|
}
|
||||||
|
position="top"
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
onClick={handleToggle}
|
||||||
|
loading={isPending || changeDisabledMutation.isPending}
|
||||||
|
color={getButtonColor()}
|
||||||
|
variant="light"
|
||||||
|
disabled={isSelf}
|
||||||
|
>
|
||||||
|
{getButtonLabel()}
|
||||||
|
</Button>
|
||||||
|
</Tooltip>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -11,6 +11,7 @@ import { catchTrpcNotFound } from "~/errors/trpc-catch-error";
|
|||||||
import { createMetaTitle } from "~/metadata";
|
import { createMetaTitle } from "~/metadata";
|
||||||
import { canAccessUserEditPage } from "../access";
|
import { canAccessUserEditPage } from "../access";
|
||||||
import { DeleteUserButton } from "./_components/_delete-user-button";
|
import { DeleteUserButton } from "./_components/_delete-user-button";
|
||||||
|
import { DisableUserButton } from "./_components/_disable-user-button";
|
||||||
import { UserGeneralSettingsForm } from "./_components/_general-settings-form";
|
import { UserGeneralSettingsForm } from "./_components/_general-settings-form";
|
||||||
import { UserProfileAvatarForm } from "./_components/_profile-avatar-form";
|
import { UserProfileAvatarForm } from "./_components/_profile-avatar-form";
|
||||||
import { ResetTours } from "./_components/_reset-tours";
|
import { ResetTours } from "./_components/_reset-tours";
|
||||||
@@ -61,6 +62,19 @@ export default async function EditUserPage(props: Props) {
|
|||||||
const searchEngines = await api.searchEngine.getSelectable();
|
const searchEngines = await api.searchEngine.getSelectable();
|
||||||
const isSelf = session?.user.id === user.id;
|
const isSelf = session?.user.id === user.id;
|
||||||
const isCredentialsUser = user.provider === "credentials";
|
const isCredentialsUser = user.provider === "credentials";
|
||||||
|
const isDisabled = user.disabled;
|
||||||
|
|
||||||
|
const getDisableItemLabel = () => {
|
||||||
|
if (isDisabled) return t("user.action.enable.label");
|
||||||
|
return t("user.action.disable.label");
|
||||||
|
};
|
||||||
|
|
||||||
|
const getDisableItemDescription = () => {
|
||||||
|
if (isDisabled) {
|
||||||
|
return t("management.page.user.action.enable.description", { defaultValue: "Re-enable access for this user" });
|
||||||
|
}
|
||||||
|
return t("management.page.user.action.disable.description", { defaultValue: "Prevent this user from logging in" });
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack>
|
<Stack>
|
||||||
@@ -96,6 +110,13 @@ export default async function EditUserPage(props: Props) {
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
<DangerZoneRoot>
|
<DangerZoneRoot>
|
||||||
|
{!isSelf && (
|
||||||
|
<DangerZoneItem
|
||||||
|
label={getDisableItemLabel()}
|
||||||
|
description={getDisableItemDescription()}
|
||||||
|
action={<DisableUserButton user={user} isSelf={isSelf} />}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
<DangerZoneItem
|
<DangerZoneItem
|
||||||
label={t("user.action.delete.label")}
|
label={t("user.action.delete.label")}
|
||||||
description={t("user.action.delete.description")}
|
description={t("user.action.delete.description")}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
import { Anchor, Group, Text, Tooltip } from "@mantine/core";
|
import { Anchor, Badge, Group, Text, Tooltip } from "@mantine/core";
|
||||||
import { IconCheck } from "@tabler/icons-react";
|
import { IconCheck } from "@tabler/icons-react";
|
||||||
import type { MRT_ColumnDef } from "mantine-react-table";
|
import type { MRT_ColumnDef } from "mantine-react-table";
|
||||||
import { MantineReactTable } from "mantine-react-table";
|
import { MantineReactTable } from "mantine-react-table";
|
||||||
@@ -52,6 +52,15 @@ export const UserListComponent = ({ initialUserList }: UserListComponentProps) =
|
|||||||
</Group>
|
</Group>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "disabled",
|
||||||
|
header: t("user.field.status.label", { defaultValue: "Status" }),
|
||||||
|
size: 100,
|
||||||
|
Cell: ({ row }) => {
|
||||||
|
if (!row.original.disabled) return null;
|
||||||
|
return <Badge color="red">{t("user.field.status.disabled", { defaultValue: "Disabled" })}</Badge>;
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
[t],
|
[t],
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -232,6 +232,7 @@ export const userRouter = createTRPCRouter({
|
|||||||
email: true,
|
email: true,
|
||||||
emailVerified: true,
|
emailVerified: true,
|
||||||
image: true,
|
image: true,
|
||||||
|
disabled: true,
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@@ -252,6 +253,7 @@ export const userRouter = createTRPCRouter({
|
|||||||
email: true,
|
email: true,
|
||||||
emailVerified: true,
|
emailVerified: true,
|
||||||
image: true,
|
image: true,
|
||||||
|
disabled: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
@@ -341,6 +343,7 @@ export const userRouter = createTRPCRouter({
|
|||||||
emailVerified: true,
|
emailVerified: true,
|
||||||
image: true,
|
image: true,
|
||||||
provider: true,
|
provider: true,
|
||||||
|
disabled: true,
|
||||||
homeBoardId: true,
|
homeBoardId: true,
|
||||||
mobileHomeBoardId: true,
|
mobileHomeBoardId: true,
|
||||||
firstDayOfWeek: true,
|
firstDayOfWeek: true,
|
||||||
@@ -377,6 +380,7 @@ export const userRouter = createTRPCRouter({
|
|||||||
emailVerified: true,
|
emailVerified: true,
|
||||||
image: true,
|
image: true,
|
||||||
provider: true,
|
provider: true,
|
||||||
|
disabled: true,
|
||||||
homeBoardId: true,
|
homeBoardId: true,
|
||||||
mobileHomeBoardId: true,
|
mobileHomeBoardId: true,
|
||||||
firstDayOfWeek: true,
|
firstDayOfWeek: true,
|
||||||
@@ -777,6 +781,45 @@ export const userRouter = createTRPCRouter({
|
|||||||
completedBoardTour: user?.completedBoardTour ?? false,
|
completedBoardTour: user?.completedBoardTour ?? false,
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
|
changeDisabled: permissionRequiredProcedure
|
||||||
|
.requiresPermission("admin")
|
||||||
|
.input(
|
||||||
|
z.object({
|
||||||
|
userId: z.string(),
|
||||||
|
disabled: z.boolean(),
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.output(z.void())
|
||||||
|
.meta({
|
||||||
|
openapi: {
|
||||||
|
method: "PATCH",
|
||||||
|
path: "/api/users/disabled",
|
||||||
|
tags: ["users"],
|
||||||
|
protect: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.mutation(async ({ input, ctx }) => {
|
||||||
|
const dbUser = await ctx.db.query.users.findFirst({
|
||||||
|
columns: {
|
||||||
|
id: true,
|
||||||
|
},
|
||||||
|
where: eq(users.id, input.userId),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!dbUser) {
|
||||||
|
throw new TRPCError({
|
||||||
|
code: "NOT_FOUND",
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
await ctx.db
|
||||||
|
.update(users)
|
||||||
|
.set({
|
||||||
|
disabled: input.disabled,
|
||||||
|
})
|
||||||
|
.where(eq(users.id, input.userId));
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
const createUserAsync = async (db: Database, input: Omit<z.infer<typeof userBaseCreateSchema>, "groupIds">) => {
|
const createUserAsync = async (db: Database, input: Omit<z.infer<typeof userBaseCreateSchema>, "groupIds">) => {
|
||||||
|
|||||||
@@ -23,6 +23,11 @@ export const authorizeWithBasicCredentialsAsync = async (
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (user.disabled) {
|
||||||
|
logger.warn("User is disabled", { userName: user.name });
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
logger.info("User is trying to log in. Checking password...", { userName: user.name });
|
logger.info("User is trying to log in. Checking password...", { userName: user.name });
|
||||||
const isValidPassword = await comparePasswordsAsync(credentials.password, user.password);
|
const isValidPassword = await comparePasswordsAsync(credentials.password, user.password);
|
||||||
|
|
||||||
|
|||||||
@@ -107,6 +107,7 @@ export const authorizeWithLdapCredentialsAsync = async (
|
|||||||
email: true,
|
email: true,
|
||||||
emailVerified: true,
|
emailVerified: true,
|
||||||
provider: true,
|
provider: true,
|
||||||
|
disabled: true,
|
||||||
},
|
},
|
||||||
where: and(eq(users.email, mailResult.data), eq(users.provider, "ldap")),
|
where: and(eq(users.email, mailResult.data), eq(users.provider, "ldap")),
|
||||||
});
|
});
|
||||||
@@ -130,6 +131,11 @@ export const authorizeWithLdapCredentialsAsync = async (
|
|||||||
logger.info("User created successfully", { userName: credentials.name });
|
logger.info("User created successfully", { userName: credentials.name });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (user.disabled) {
|
||||||
|
logger.warn("User is disabled", { userName: credentials.name });
|
||||||
|
throw new CredentialsSignin("User is disabled");
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: user.id,
|
id: user.id,
|
||||||
name: credentials.name,
|
name: credentials.name,
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE `user` ADD `disabled` boolean DEFAULT false NOT NULL;
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE "user" ADD COLUMN "disabled" boolean DEFAULT false NOT NULL;
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE "user" ADD COLUMN "disabled" integer DEFAULT 0 NOT NULL;
|
||||||
@@ -72,6 +72,7 @@ export const users = mysqlTable("user", {
|
|||||||
image: text(),
|
image: text(),
|
||||||
password: text(),
|
password: text(),
|
||||||
provider: varchar({ length: 64 }).$type<SupportedAuthProvider>().default("credentials").notNull(),
|
provider: varchar({ length: 64 }).$type<SupportedAuthProvider>().default("credentials").notNull(),
|
||||||
|
disabled: boolean().default(false).notNull(),
|
||||||
homeBoardId: varchar({ length: 64 }).references((): AnyMySqlColumn => boards.id, {
|
homeBoardId: varchar({ length: 64 }).references((): AnyMySqlColumn => boards.id, {
|
||||||
onDelete: "set null",
|
onDelete: "set null",
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ export const users = pgTable("user", {
|
|||||||
image: text(),
|
image: text(),
|
||||||
password: text(),
|
password: text(),
|
||||||
provider: varchar({ length: 64 }).$type<SupportedAuthProvider>().default("credentials").notNull(),
|
provider: varchar({ length: 64 }).$type<SupportedAuthProvider>().default("credentials").notNull(),
|
||||||
|
disabled: boolean().default(false).notNull(),
|
||||||
homeBoardId: varchar({ length: 64 }).references((): AnyPgColumn => boards.id, {
|
homeBoardId: varchar({ length: 64 }).references((): AnyPgColumn => boards.id, {
|
||||||
onDelete: "set null",
|
onDelete: "set null",
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ export const users = sqliteTable("user", {
|
|||||||
image: text(),
|
image: text(),
|
||||||
password: text(),
|
password: text(),
|
||||||
provider: text().$type<SupportedAuthProvider>().default("credentials").notNull(),
|
provider: text().$type<SupportedAuthProvider>().default("credentials").notNull(),
|
||||||
|
disabled: int({ mode: "boolean" }).default(false).notNull(),
|
||||||
homeBoardId: text().references((): AnySQLiteColumn => boards.id, {
|
homeBoardId: text().references((): AnySQLiteColumn => boards.id, {
|
||||||
onDelete: "set null",
|
onDelete: "set null",
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -60,8 +60,8 @@ export type HomarrDocumentationPath =
|
|||||||
| "/docs/tags/connections"
|
| "/docs/tags/connections"
|
||||||
| "/docs/tags/custom-widgets"
|
| "/docs/tags/custom-widgets"
|
||||||
| "/docs/tags/customization"
|
| "/docs/tags/customization"
|
||||||
| "/docs/tags/data"
|
|
||||||
| "/docs/tags/data-sources"
|
| "/docs/tags/data-sources"
|
||||||
|
| "/docs/tags/data"
|
||||||
| "/docs/tags/database"
|
| "/docs/tags/database"
|
||||||
| "/docs/tags/developer"
|
| "/docs/tags/developer"
|
||||||
| "/docs/tags/development"
|
| "/docs/tags/development"
|
||||||
@@ -99,8 +99,8 @@ export type HomarrDocumentationPath =
|
|||||||
| "/docs/tags/redis"
|
| "/docs/tags/redis"
|
||||||
| "/docs/tags/responsive"
|
| "/docs/tags/responsive"
|
||||||
| "/docs/tags/roles"
|
| "/docs/tags/roles"
|
||||||
| "/docs/tags/search"
|
|
||||||
| "/docs/tags/search-engines"
|
| "/docs/tags/search-engines"
|
||||||
|
| "/docs/tags/search"
|
||||||
| "/docs/tags/secrets"
|
| "/docs/tags/secrets"
|
||||||
| "/docs/tags/security"
|
| "/docs/tags/security"
|
||||||
| "/docs/tags/self-signed"
|
| "/docs/tags/self-signed"
|
||||||
@@ -132,6 +132,15 @@ export type HomarrDocumentationPath =
|
|||||||
| "/docs/advanced/running-as-different-user"
|
| "/docs/advanced/running-as-different-user"
|
||||||
| "/docs/advanced/single-sign-on"
|
| "/docs/advanced/single-sign-on"
|
||||||
| "/docs/advanced/styling"
|
| "/docs/advanced/styling"
|
||||||
|
| "/docs/category/advanced"
|
||||||
|
| "/docs/category/community"
|
||||||
|
| "/docs/category/developer-guides"
|
||||||
|
| "/docs/category/getting-started"
|
||||||
|
| "/docs/category/installation-1"
|
||||||
|
| "/docs/category/installation"
|
||||||
|
| "/docs/category/integrations"
|
||||||
|
| "/docs/category/management"
|
||||||
|
| "/docs/category/widgets"
|
||||||
| "/docs/community/donate"
|
| "/docs/community/donate"
|
||||||
| "/docs/community/faq"
|
| "/docs/community/faq"
|
||||||
| "/docs/community/get-in-touch"
|
| "/docs/community/get-in-touch"
|
||||||
@@ -159,7 +168,6 @@ export type HomarrDocumentationPath =
|
|||||||
| "/docs/integrations/archiveteam-warrior"
|
| "/docs/integrations/archiveteam-warrior"
|
||||||
| "/docs/integrations/aria2"
|
| "/docs/integrations/aria2"
|
||||||
| "/docs/integrations/audiobookshelf"
|
| "/docs/integrations/audiobookshelf"
|
||||||
| "/docs/integrations/bazarr"
|
|
||||||
| "/docs/integrations/beszel"
|
| "/docs/integrations/beszel"
|
||||||
| "/docs/integrations/coolify"
|
| "/docs/integrations/coolify"
|
||||||
| "/docs/integrations/dash-dot"
|
| "/docs/integrations/dash-dot"
|
||||||
@@ -184,7 +192,6 @@ export type HomarrDocumentationPath =
|
|||||||
| "/docs/integrations/opnsense"
|
| "/docs/integrations/opnsense"
|
||||||
| "/docs/integrations/overseerr"
|
| "/docs/integrations/overseerr"
|
||||||
| "/docs/integrations/paperless-ngx"
|
| "/docs/integrations/paperless-ngx"
|
||||||
| "/docs/integrations/patchmon"
|
|
||||||
| "/docs/integrations/peanut"
|
| "/docs/integrations/peanut"
|
||||||
| "/docs/integrations/pi-hole"
|
| "/docs/integrations/pi-hole"
|
||||||
| "/docs/integrations/plex"
|
| "/docs/integrations/plex"
|
||||||
@@ -198,11 +205,9 @@ export type HomarrDocumentationPath =
|
|||||||
| "/docs/integrations/slskd"
|
| "/docs/integrations/slskd"
|
||||||
| "/docs/integrations/sonarr"
|
| "/docs/integrations/sonarr"
|
||||||
| "/docs/integrations/speedtest-tracker"
|
| "/docs/integrations/speedtest-tracker"
|
||||||
| "/docs/integrations/synology"
|
|
||||||
| "/docs/integrations/tdarr"
|
| "/docs/integrations/tdarr"
|
||||||
| "/docs/integrations/technitium-dns"
|
| "/docs/integrations/technitium-dns"
|
||||||
| "/docs/integrations/tracearr"
|
| "/docs/integrations/tracearr"
|
||||||
| "/docs/integrations/traefik"
|
|
||||||
| "/docs/integrations/transmission"
|
| "/docs/integrations/transmission"
|
||||||
| "/docs/integrations/truenas"
|
| "/docs/integrations/truenas"
|
||||||
| "/docs/integrations/umami"
|
| "/docs/integrations/umami"
|
||||||
@@ -225,7 +230,6 @@ export type HomarrDocumentationPath =
|
|||||||
| "/docs/widgets/anchor-note"
|
| "/docs/widgets/anchor-note"
|
||||||
| "/docs/widgets/app"
|
| "/docs/widgets/app"
|
||||||
| "/docs/widgets/audio-stats"
|
| "/docs/widgets/audio-stats"
|
||||||
| "/docs/widgets/bazarr"
|
|
||||||
| "/docs/widgets/beszel-alerts"
|
| "/docs/widgets/beszel-alerts"
|
||||||
| "/docs/widgets/beszel-system-grid"
|
| "/docs/widgets/beszel-system-grid"
|
||||||
| "/docs/widgets/beszel-system-stats"
|
| "/docs/widgets/beszel-system-stats"
|
||||||
@@ -245,7 +249,6 @@ export type HomarrDocumentationPath =
|
|||||||
| "/docs/widgets/immich-album-carousel"
|
| "/docs/widgets/immich-album-carousel"
|
||||||
| "/docs/widgets/immich-server-stats"
|
| "/docs/widgets/immich-server-stats"
|
||||||
| "/docs/widgets/indexer-manager"
|
| "/docs/widgets/indexer-manager"
|
||||||
| "/docs/widgets/media-missing"
|
|
||||||
| "/docs/widgets/media-releases"
|
| "/docs/widgets/media-releases"
|
||||||
| "/docs/widgets/media-request-list"
|
| "/docs/widgets/media-request-list"
|
||||||
| "/docs/widgets/media-request-stats"
|
| "/docs/widgets/media-request-stats"
|
||||||
@@ -257,18 +260,15 @@ export type HomarrDocumentationPath =
|
|||||||
| "/docs/widgets/notebook"
|
| "/docs/widgets/notebook"
|
||||||
| "/docs/widgets/notifications"
|
| "/docs/widgets/notifications"
|
||||||
| "/docs/widgets/paperless-ngx"
|
| "/docs/widgets/paperless-ngx"
|
||||||
| "/docs/widgets/patchmon"
|
|
||||||
| "/docs/widgets/releases"
|
| "/docs/widgets/releases"
|
||||||
| "/docs/widgets/rss-feed"
|
| "/docs/widgets/rss-feed"
|
||||||
| "/docs/widgets/smart-home-entity-state"
|
| "/docs/widgets/smart-home-entity-state"
|
||||||
| "/docs/widgets/smart-home-execute-automation"
|
| "/docs/widgets/smart-home-execute-automation"
|
||||||
| "/docs/widgets/speedtest-tracker"
|
| "/docs/widgets/speedtest-tracker"
|
||||||
| "/docs/widgets/stock-price"
|
| "/docs/widgets/stock-price"
|
||||||
| "/docs/widgets/system-disks"
|
|
||||||
| "/docs/widgets/system-resources"
|
| "/docs/widgets/system-resources"
|
||||||
| "/docs/widgets/timetable"
|
| "/docs/widgets/timetable"
|
||||||
| "/docs/widgets/tracearr"
|
| "/docs/widgets/tracearr"
|
||||||
| "/docs/widgets/traefik"
|
|
||||||
| "/docs/widgets/umami"
|
| "/docs/widgets/umami"
|
||||||
| "/docs/widgets/ups"
|
| "/docs/widgets/ups"
|
||||||
| "/docs/widgets/uptime-kuma"
|
| "/docs/widgets/uptime-kuma"
|
||||||
|
|||||||
@@ -1,141 +0,0 @@
|
|||||||
import { describe, expect, test, vi } from "vitest";
|
|
||||||
|
|
||||||
vi.hoisted(() => {
|
|
||||||
process.env.SKIP_ENV_VALIDATION = "true";
|
|
||||||
process.env.SECRET_ENCRYPTION_KEY = "ff3f4f7ce30e870c9630de9e5d244ffa81101a24ed0dfe5f064beb53a7e684f1";
|
|
||||||
process.env.ENABLE_DNS_CACHING = "false";
|
|
||||||
});
|
|
||||||
|
|
||||||
const controllerCtor = vi.fn();
|
|
||||||
const controllerLogin = vi.fn().mockResolvedValue(true);
|
|
||||||
|
|
||||||
vi.mock("@homarr/redis", () => ({
|
|
||||||
createGetSetChannel: () => ({
|
|
||||||
getAsync: vi.fn().mockResolvedValue(null),
|
|
||||||
setAsync: vi.fn().mockResolvedValue(undefined),
|
|
||||||
removeAsync: vi.fn().mockResolvedValue(undefined),
|
|
||||||
}),
|
|
||||||
}));
|
|
||||||
|
|
||||||
vi.mock("@homarr/core/infrastructure/logs", () => ({
|
|
||||||
createLogger: () => ({ debug: vi.fn(), info: vi.fn(), warn: vi.fn(), error: vi.fn() }),
|
|
||||||
ErrorWithMetadata: class extends Error {},
|
|
||||||
}));
|
|
||||||
|
|
||||||
vi.mock("@homarr/core/infrastructure/http", () => ({
|
|
||||||
createCustomCheckServerIdentity: () => (() => undefined) as never,
|
|
||||||
fetchWithTrustedCertificatesAsync: vi.fn(),
|
|
||||||
createAxiosCertificateInstanceAsync: vi.fn().mockResolvedValue({}),
|
|
||||||
createCertificateAgentAsync: vi.fn().mockResolvedValue(undefined),
|
|
||||||
}));
|
|
||||||
|
|
||||||
vi.mock("@homarr/core/infrastructure/certificates", () => ({
|
|
||||||
getTrustedCertificateHostnamesAsync: vi.fn().mockResolvedValue([]),
|
|
||||||
getAllTrustedCertificatesAsync: vi.fn().mockResolvedValue([]),
|
|
||||||
}));
|
|
||||||
|
|
||||||
vi.mock("axios", () => ({
|
|
||||||
AxiosError: Error,
|
|
||||||
default: {
|
|
||||||
create: vi.fn().mockReturnValue({}),
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
|
|
||||||
vi.mock("http-cookie-agent/http", () => ({
|
|
||||||
HttpCookieAgent: class {},
|
|
||||||
HttpsCookieAgent: class {},
|
|
||||||
}));
|
|
||||||
|
|
||||||
vi.mock("@homarr/node-unifi", () => {
|
|
||||||
class FakeController {
|
|
||||||
public options: Record<string, unknown>;
|
|
||||||
constructor(options: Record<string, unknown>) {
|
|
||||||
this.options = options;
|
|
||||||
controllerCtor(options);
|
|
||||||
}
|
|
||||||
public async login(): Promise<true> {
|
|
||||||
return await controllerLogin(this.options.port);
|
|
||||||
}
|
|
||||||
public async getSitesStats(): Promise<unknown[]> {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return { default: { Controller: FakeController } };
|
|
||||||
});
|
|
||||||
|
|
||||||
import { UnifiControllerIntegration } from "../unifi-controller-integration";
|
|
||||||
|
|
||||||
const createIntegration = (url: string) =>
|
|
||||||
new UnifiControllerIntegration({
|
|
||||||
id: "test-unifi",
|
|
||||||
name: "Test Unifi",
|
|
||||||
url,
|
|
||||||
externalUrl: null,
|
|
||||||
decryptedSecrets: [
|
|
||||||
{ kind: "username", value: "admin" },
|
|
||||||
{ kind: "password", value: "secret" },
|
|
||||||
],
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("UnifiControllerIntegration port resolution", () => {
|
|
||||||
test("a URL without a port uses the UniFi OS port 443", async () => {
|
|
||||||
controllerCtor.mockClear();
|
|
||||||
controllerLogin.mockClear().mockResolvedValue(true);
|
|
||||||
await createIntegration("http://192.168.1.1").getNetworkSummaryAsync();
|
|
||||||
|
|
||||||
expect(controllerCtor).toHaveBeenCalledTimes(1);
|
|
||||||
expect(controllerCtor).toHaveBeenCalledWith(expect.objectContaining({ host: "192.168.1.1", port: 443 }));
|
|
||||||
});
|
|
||||||
|
|
||||||
test("a connection failure on port 443 falls back to the self-hosted controller port 8443", async () => {
|
|
||||||
controllerCtor.mockClear();
|
|
||||||
controllerLogin
|
|
||||||
.mockClear()
|
|
||||||
.mockRejectedValueOnce(Object.assign(new Error("connect ECONNREFUSED"), { isAxiosError: true }))
|
|
||||||
.mockResolvedValueOnce(true);
|
|
||||||
|
|
||||||
await createIntegration("http://controller.lan").getNetworkSummaryAsync();
|
|
||||||
|
|
||||||
expect(controllerCtor).toHaveBeenNthCalledWith(1, expect.objectContaining({ port: 443 }));
|
|
||||||
expect(controllerCtor).toHaveBeenNthCalledWith(2, expect.objectContaining({ port: 8443 }));
|
|
||||||
});
|
|
||||||
|
|
||||||
test("https://controller.lan:8443 keeps the user-specified port", async () => {
|
|
||||||
controllerCtor.mockClear();
|
|
||||||
controllerLogin.mockClear().mockResolvedValue(true);
|
|
||||||
await createIntegration("https://controller.lan:8443").getNetworkSummaryAsync();
|
|
||||||
|
|
||||||
expect(controllerCtor).toHaveBeenCalledWith(expect.objectContaining({ host: "controller.lan", port: 8443 }));
|
|
||||||
});
|
|
||||||
|
|
||||||
test("https://192.168.1.1:8443 keeps the user-specified port", async () => {
|
|
||||||
controllerCtor.mockClear();
|
|
||||||
controllerLogin.mockClear().mockResolvedValue(true);
|
|
||||||
await createIntegration("https://192.168.1.1:8443").getNetworkSummaryAsync();
|
|
||||||
|
|
||||||
expect(controllerCtor).toHaveBeenCalledWith(expect.objectContaining({ host: "192.168.1.1", port: 8443 }));
|
|
||||||
});
|
|
||||||
|
|
||||||
test("an unusual port like 10443 is honored verbatim", async () => {
|
|
||||||
controllerCtor.mockClear();
|
|
||||||
controllerLogin.mockClear().mockResolvedValue(true);
|
|
||||||
await createIntegration("https://192.168.1.1:10443").getNetworkSummaryAsync();
|
|
||||||
|
|
||||||
expect(controllerCtor).toHaveBeenCalledWith(expect.objectContaining({ host: "192.168.1.1", port: 10443 }));
|
|
||||||
});
|
|
||||||
|
|
||||||
test("an authentication failure on port 443 does not try another port", async () => {
|
|
||||||
controllerCtor.mockClear();
|
|
||||||
controllerLogin.mockClear().mockRejectedValueOnce(
|
|
||||||
Object.assign(new Error("Request failed with status code 401"), {
|
|
||||||
isAxiosError: true,
|
|
||||||
response: { status: 401 },
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
await expect(createIntegration("https://controller.lan").getNetworkSummaryAsync()).rejects.toThrow();
|
|
||||||
|
|
||||||
expect(controllerCtor).toHaveBeenCalledTimes(1);
|
|
||||||
expect(controllerCtor).toHaveBeenCalledWith(expect.objectContaining({ port: 443 }));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -2,6 +2,7 @@ import type tls from "node:tls";
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { HttpCookieAgent, HttpsCookieAgent } from "http-cookie-agent/http";
|
import { HttpCookieAgent, HttpsCookieAgent } from "http-cookie-agent/http";
|
||||||
|
|
||||||
|
import { getPortFromUrl } from "@homarr/common";
|
||||||
import {
|
import {
|
||||||
getAllTrustedCertificatesAsync,
|
getAllTrustedCertificatesAsync,
|
||||||
getTrustedCertificateHostnamesAsync,
|
getTrustedCertificateHostnamesAsync,
|
||||||
@@ -66,53 +67,26 @@ export class UnifiControllerIntegration extends Integration implements NetworkCo
|
|||||||
checkServerIdentity: createCustomCheckServerIdentity(await getTrustedCertificateHostnamesAsync()),
|
checkServerIdentity: createCustomCheckServerIdentity(await getTrustedCertificateHostnamesAsync()),
|
||||||
};
|
};
|
||||||
|
|
||||||
// ponytail: node-unifi always connects over HTTPS, regardless of the protocol in the
|
const client = new Unifi.Controller({
|
||||||
// integration URL. UniFi OS consoles use port 443 while self-hosted controllers normally
|
host: url.hostname,
|
||||||
// use 8443. If no port was provided, try both without hiding authentication errors.
|
port: getPortFromUrl(url),
|
||||||
const ports = url.port ? [Number(url.port)] : [443, 8443];
|
username: this.getSecretValue("username"),
|
||||||
const createClientForPortAsync = async (port: number) => {
|
password: this.getSecretValue("password"),
|
||||||
const client = new Unifi.Controller({
|
createAxiosInstance({ cookies }) {
|
||||||
host: url.hostname,
|
return axios.create({
|
||||||
port,
|
adapter: "http",
|
||||||
username: this.getSecretValue("username"),
|
httpAgent: new HttpCookieAgent({ cookies }),
|
||||||
password: this.getSecretValue("password"),
|
httpsAgent: new HttpsCookieAgent({
|
||||||
createAxiosInstance({ cookies }) {
|
cookies,
|
||||||
return axios.create({
|
requestCert: true,
|
||||||
adapter: "http",
|
...certificateOptions,
|
||||||
httpAgent: new HttpCookieAgent({ cookies }),
|
}),
|
||||||
httpsAgent: new HttpsCookieAgent({
|
});
|
||||||
cookies,
|
},
|
||||||
requestCert: true,
|
});
|
||||||
...certificateOptions,
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
await client.login(this.getSecretValue("username"), this.getSecretValue("password"), null);
|
await client.login(this.getSecretValue("username"), this.getSecretValue("password"), null);
|
||||||
return client;
|
return client;
|
||||||
};
|
|
||||||
|
|
||||||
for (const [index, port] of ports.entries()) {
|
|
||||||
try {
|
|
||||||
return await createClientForPortAsync(port);
|
|
||||||
} catch (error) {
|
|
||||||
const isLastPort = index === ports.length - 1;
|
|
||||||
if (isLastPort || !this.isPortFallbackError(error)) {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new Error("Unable to connect to the UniFi controller");
|
|
||||||
}
|
|
||||||
|
|
||||||
private isPortFallbackError(error: unknown) {
|
|
||||||
if (typeof error === "object" && error !== null && "isAxiosError" in error && error.isAxiosError === true) {
|
|
||||||
return !("response" in error) || error.response === undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return error instanceof Error && error.message === "failed to detect UniFiOS status";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private getStatusValueOverAllSites<S extends HealthSubsystem>(
|
private getStatusValueOverAllSites<S extends HealthSubsystem>(
|
||||||
|
|||||||
Reference in new issue
Block a user