2024-12-31 10:31:50 +05:30
|
|
|
import type { ActionFunctionArgs } from 'react-router';
|
2025-02-13 12:29:16 -05:00
|
|
|
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';
|
2025-02-13 12:29:16 -05:00
|
|
|
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() {
|
2025-02-13 12:29:16 -05:00
|
|
|
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,
|
2024-08-22 16:55:05 -04:00
|
|
|
magicDns: config.dns.magic_dns,
|
2025-01-18 13:22:43 +00:00
|
|
|
baseDomain: config.dns.base_domain,
|
2024-08-22 16:55:05 -04:00
|
|
|
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
|
|
|
|
2024-03-29 21:46:21 -04:00
|
|
|
return {
|
|
|
|
|
...dns,
|
2025-02-13 12:29:16 -05:00
|
|
|
mode,
|
2024-12-31 10:30:14 +05:30
|
|
|
};
|
2024-03-26 17:42:45 -04:00
|
|
|
}
|
|
|
|
|
|
2025-02-13 12:29:16 -05: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;
|
2025-02-13 12:29:16 -05:00
|
|
|
const isDisabled = data.mode !== 'rw';
|
2024-03-26 17:42:45 -04:00
|
|
|
|
|
|
|
|
return (
|
2024-05-20 14:05:09 -04:00
|
|
|
<div className="flex flex-col gap-16 max-w-screen-lg">
|
2025-02-13 12:29:16 -05:00
|
|
|
{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>
|
|
|
|
|
)}
|
2025-02-13 12:29:16 -05:00
|
|
|
<RenameTailnet name={data.baseDomain} isDisabled={isDisabled} />
|
|
|
|
|
<ManageNS nameservers={allNs} isDisabled={isDisabled} />
|
|
|
|
|
<ManageRecords records={data.extraRecords} isDisabled={isDisabled} />
|
|
|
|
|
<ManageDomains
|
2024-03-28 18:47:28 -04:00
|
|
|
searchDomains={data.searchDomains}
|
2025-02-13 12:29:16 -05:00
|
|
|
isDisabled={isDisabled}
|
|
|
|
|
magic={data.magicDns ? data.baseDomain : undefined}
|
2024-03-28 18:47:28 -04:00
|
|
|
/>
|
|
|
|
|
|
2024-05-20 14:05:09 -04:00
|
|
|
<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{' '}
|
2024-03-29 15:41:10 -04:00
|
|
|
<Code>
|
2024-09-25 16:22:00 -04:00
|
|
|
[device].
|
2024-05-20 14:05:09 -04:00
|
|
|
{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>
|
2025-02-13 12:29:16 -05:00
|
|
|
<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
|
|
|
}
|