headplane/app/routes/dns/overview.tsx

84 lines
2.4 KiB
TypeScript
Raw Normal View History

2024-12-31 10:31:50 +05:30
import type { ActionFunctionArgs } from 'react-router';
import { useLoaderData } from 'react-router';
2024-12-31 10:30:14 +05:30
import Code from '~/components/Code';
import Notice from '~/components/Notice';
2025-02-19 18:09:42 -05:00
import { hs_getConfig } from '~/utils/config/loader';
import ManageDomains from './components/manage-domains';
import ManageNS from './components/manage-ns';
import ManageRecords from './components/manage-records';
import RenameTailnet from './components/rename-tailnet';
import ToggleMagic from './components/toggle-magic';
import { dnsAction } from './dns-actions';
2024-03-26 17:42:45 -04:00
// We do not want to expose every config value
export async function loader() {
const { config, mode } = hs_getConfig();
if (mode === 'no') {
2024-12-31 10:30:14 +05:30
throw new Error('No configuration is available');
2024-03-30 01:48:35 -04:00
}
2024-03-26 17:42:45 -04:00
const dns = {
prefixes: config.prefixes,
magicDns: config.dns.magic_dns,
baseDomain: config.dns.base_domain,
nameservers: config.dns.nameservers.global,
splitDns: config.dns.nameservers.split,
searchDomains: config.dns.search_domains,
extraRecords: config.dns.extra_records,
2024-12-31 10:30:14 +05:30
};
2024-03-26 17:42:45 -04:00
return {
...dns,
mode,
2024-12-31 10:30:14 +05:30
};
2024-03-26 17:42:45 -04:00
}
export async function action(data: ActionFunctionArgs) {
return dnsAction(data);
2024-03-28 17:03:37 -04:00
}
2024-03-26 17:42:45 -04:00
export default function Page() {
2024-12-31 10:30:14 +05:30
const data = useLoaderData<typeof loader>();
2024-05-21 17:21:14 -04:00
2024-12-31 10:30:14 +05:30
const allNs: Record<string, string[]> = {};
2024-05-21 17:21:14 -04:00
for (const key of Object.keys(data.splitDns)) {
2024-12-31 10:30:14 +05:30
allNs[key] = data.splitDns[key];
2024-05-21 17:21:14 -04:00
}
2024-12-31 10:30:14 +05:30
allNs.global = data.nameservers;
const isDisabled = data.mode !== 'rw';
2024-03-26 17:42:45 -04:00
return (
<div className="flex flex-col gap-16 max-w-screen-lg">
{data.mode === 'rw' ? undefined : (
2024-12-31 10:30:14 +05:30
<Notice>
The Headscale configuration is read-only. You cannot make changes to
the configuration
</Notice>
)}
<RenameTailnet name={data.baseDomain} isDisabled={isDisabled} />
<ManageNS nameservers={allNs} isDisabled={isDisabled} />
<ManageRecords records={data.extraRecords} isDisabled={isDisabled} />
<ManageDomains
searchDomains={data.searchDomains}
isDisabled={isDisabled}
magic={data.magicDns ? data.baseDomain : undefined}
/>
<div className="flex flex-col w-2/3">
<h1 className="text-2xl font-medium mb-4">Magic DNS</h1>
2025-02-04 17:21:03 -05:00
<p className="mb-4">
2024-12-31 10:30:14 +05:30
Automatically register domain names for each device on the tailnet.
Devices will be accessible at{' '}
<Code>
[device].
{data.baseDomain}
2024-12-31 10:30:14 +05:30
</Code>{' '}
2024-03-28 14:20:19 -04:00
when Magic DNS is enabled.
</p>
<ToggleMagic isEnabled={data.magicDns} isDisabled={isDisabled} />
2024-03-28 14:20:19 -04:00
</div>
2024-03-26 17:42:45 -04:00
</div>
2024-12-31 10:30:14 +05:30
);
2024-03-26 17:42:45 -04:00
}