import { CheckCircle, CircleSlash, Info, UserCircle } from 'lucide-react'; import { useMemo, useState } from 'react'; import type { ActionFunctionArgs, LoaderFunctionArgs } from 'react-router'; import { Link as RemixLink, useLoaderData } from 'react-router'; import Attribute from '~/components/Attribute'; import Button from '~/components/Button'; import Card from '~/components/Card'; import Chip from '~/components/Chip'; import Link from '~/components/Link'; import StatusCircle from '~/components/StatusCircle'; import Tooltip from '~/components/Tooltip'; import type { LoadContext } from '~/server'; import type { Machine, Route, User } from '~/types'; import cn from '~/utils/cn'; import MenuOptions from './components/menu'; import Routes from './dialogs/routes'; import { machineAction } from './machine-actions'; export async function loader({ request, params, context, }: LoaderFunctionArgs) { const session = await context.sessions.auth(request); if (!params.id) { throw new Error('No machine ID provided'); } let magic: string | undefined; if (context.hs.readable()) { if (context.hs.c?.dns.magic_dns) { magic = context.hs.c.dns.base_domain; } } const [machine, routes, users] = await Promise.all([ context.client.get<{ node: Machine }>( `v1/node/${params.id}`, session.get('api_key')!, ), context.client.get<{ routes: Route[] }>( 'v1/routes', session.get('api_key')!, ), context.client.get<{ users: User[] }>('v1/user', session.get('api_key')!), ]); return { machine: machine.node, routes: routes.routes.filter((route) => route.node.id === params.id), users: users.users, magic, // TODO: Fix agent agent: false, // agent: [...(hp_getSingletonUnsafe('ws_agents') ?? []).keys()].includes( // machine.node.id, // ), }; } export async function action(request: ActionFunctionArgs) { return machineAction(request); } export default function Page() { const { machine, magic, routes, users, agent } = useLoaderData(); const [showRouting, setShowRouting] = useState(false); const expired = machine.expiry === '0001-01-01 00:00:00' || machine.expiry === '0001-01-01T00:00:00Z' || machine.expiry === null ? false : new Date(machine.expiry).getTime() < Date.now(); const tags = [...new Set([...machine.forcedTags, ...machine.validTags])]; if (expired) { 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[]; subnet: Route[]; subnetApproved: Route[]; }>( (acc, route) => { if (route.prefix === '::/0' || route.prefix === '0.0.0.0/0') { acc.exit.push(route); return acc; } if (route.enabled) { acc.subnetApproved.push(route); return acc; } acc.subnet.push(route); return acc; }, { exit: [], subnetApproved: [], subnet: [] }, ); const exitEnabled = useMemo(() => { if (exit.length !== 2) return false; return exit[0].enabled && exit[1].enabled; }, [exit]); if (exitEnabled) { tags.unshift('Exit Node'); } if (subnetApproved.length > 0) { tags.unshift('Subnets'); } return (

All Machines / {machine.givenName}

{machine.givenName}

Managed by By default, a machine’s permissions match its creator’s.
{machine.user.name}
{tags.length > 0 ? (

Status

{tags.map((tag) => ( ))}
) : undefined}

Subnets & Routing

Subnets let you expose physical network routes onto Tailscale.{' '} Learn More

Approved Traffic to these routes are being routed through this machine.
{subnetApproved.length === 0 ? ( ) : (
    {subnetApproved.map((route) => (
  • {route.prefix}
  • ))}
)}
Awaiting Approval This machine is advertising these routes, but they must be approved before traffic will be routed to them.
{subnet.length === 0 ? ( ) : (
    {subnet.map((route) => (
  • {route.prefix}
  • ))}
)}
Exit Node Whether this machine can act as an exit node for your tailnet.
{exit.length === 0 ? ( ) : exitEnabled ? ( Allowed ) : ( Awaiting Approval )}

Machine Details

{magic ? ( ) : undefined}
); }