diff --git a/app/routes/machines/components/machine.tsx b/app/routes/machines/components/machine.tsx index f804cac..e78932a 100644 --- a/app/routes/machines/components/machine.tsx +++ b/app/routes/machines/components/machine.tsx @@ -15,6 +15,7 @@ interface Props { machine: Machine; routes: Route[]; users: User[]; + isAgent?: boolean; magic?: string; stats?: HostInfo; } @@ -22,8 +23,9 @@ interface Props { export default function MachineRow({ machine, routes, - magic, users, + isAgent, + magic, stats, }: Props) { const expired = @@ -79,6 +81,10 @@ export default function MachineRow({ tags.unshift('Subnets'); } + if (isAgent) { + tags.unshift('Headplane Agent'); + } + const ipOptions = useMemo(() => { if (magic) { return [...machine.ipAddresses, `${machine.givenName}.${prefix}`]; diff --git a/app/routes/machines/machine.tsx b/app/routes/machines/machine.tsx index ebba6e7..eab1198 100644 --- a/app/routes/machines/machine.tsx +++ b/app/routes/machines/machine.tsx @@ -14,11 +14,16 @@ import cn from '~/utils/cn'; import { hs_getConfig } from '~/utils/config/loader'; import { pull } from '~/utils/headscale'; import { getSession } from '~/utils/sessions.server'; +import type { AppContext } from '~server/context/app'; import { menuAction } from './action'; import MenuOptions from './components/menu'; import Routes from './dialogs/routes'; -export async function loader({ request, params }: LoaderFunctionArgs) { +export async function loader({ + request, + params, + context, +}: LoaderFunctionArgs) { const session = await getSession(request.headers.get('Cookie')); if (!params.id) { throw new Error('No machine ID provided'); @@ -44,6 +49,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) { routes: routes.routes.filter((route) => route.node.id === params.id), users: users.users, magic, + agent: context?.agents.includes(machine.node.id), }; } @@ -52,8 +58,10 @@ export async function action({ request }: ActionFunctionArgs) { } export default function Page() { - const { machine, magic, routes, users } = useLoaderData(); + const { machine, magic, routes, users, agent } = + useLoaderData(); const [showRouting, setShowRouting] = useState(false); + console.log(machine.expiry); const expired = machine.expiry === '0001-01-01 00:00:00' || @@ -68,6 +76,10 @@ export default function Page() { tags.unshift('Expired'); } + if (agent) { + tags.unshift('Headplane Agent'); + } + // This is much easier with Object.groupBy but it's too new for us const { exit, subnet, subnetApproved } = routes.reduce<{ exit: Route[]; diff --git a/app/routes/machines/overview.tsx b/app/routes/machines/overview.tsx index 1944584..5786183 100644 --- a/app/routes/machines/overview.tsx +++ b/app/routes/machines/overview.tsx @@ -51,6 +51,7 @@ export async function loader({ magic, server: ctx.headscale.url, publicServer: ctx.headscale.public_url, + agents: context.agents, }; } @@ -124,6 +125,7 @@ export default function Page() { users={data.users} magic={data.magic} stats={stats?.[machine.nodeKey]} + isAgent={data.agents.includes(machine.id)} /> ))}