From 3211f8e6f9096f952f0144ec07083bbd201d84c7 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Thu, 8 Feb 2024 12:52:05 +0100 Subject: [PATCH] Include intermediate subdomains without service in list Closes: https://github.com/happyDomain/happydomain/issues/26 --- .../components/domains/SubdomainItem.svelte | 38 ++++++++++++++++- .../components/domains/SubdomainList.svelte | 3 +- .../domains/SubdomainListTiny.svelte | 41 +++++++++++++++++++ ui/src/lib/stores/thiszone.ts | 31 ++++++++++++++ ui/src/routes/domains/[dn]/+layout.svelte | 30 +++++++------- .../domains/[dn]/[[historyid]]/+page.svelte | 3 +- 6 files changed, 129 insertions(+), 17 deletions(-) create mode 100644 ui/src/lib/components/domains/SubdomainListTiny.svelte diff --git a/ui/src/lib/components/domains/SubdomainItem.svelte b/ui/src/lib/components/domains/SubdomainItem.svelte index 176d51a..a5d1fc3 100644 --- a/ui/src/lib/components/domains/SubdomainItem.svelte +++ b/ui/src/lib/components/domains/SubdomainItem.svelte @@ -82,7 +82,43 @@ } -{#if isCNAME(services) || isPTR(services)} +{#if services.length === 0} +
+ {#if !reverseZone} +

+ + + + {#if reverseZone} + {unreverseDomain(fqdn(dn, origin.domain))} + {:else} + {fqdn(dn, origin.domain)} + {/if} + + + +

+ {/if} +
+{:else if isCNAME(services) || isPTR(services)}

; + export let sortedDomainsWithIntermediate: Array; export let zone: Zone; let aliases: Record>; @@ -69,7 +70,7 @@ } -{#each sortedDomains as dn} +{#each sortedDomainsWithIntermediate as dn} . + + For AGPL licensing: + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +--> + + + +{#each domains as dn} + + {fqdn(dn, origin.domain)} + +{/each} diff --git a/ui/src/lib/stores/thiszone.ts b/ui/src/lib/stores/thiszone.ts index d901ce5..5f2b936 100644 --- a/ui/src/lib/stores/thiszone.ts +++ b/ui/src/lib/stores/thiszone.ts @@ -31,6 +31,7 @@ import { refreshDomains } from '$lib/stores/domains'; export const thisZone: Writable = writable(null); +// sortedDomains returns all subdomains, sorted export const sortedDomains = derived( thisZone, ($thisZone: null|Zone) => { @@ -46,6 +47,36 @@ export const sortedDomains = derived( }, ); +// sortedDomainsWithIntermediate returns all subdomains, sorted, with intermediate subdomains +export const sortedDomainsWithIntermediate = derived( + sortedDomains, + ($sortedDomains: null|Array) => { + if (!$sortedDomains || $sortedDomains.length <= 1) { + return $sortedDomains; + } + const domains: Array = [$sortedDomains[0]]; + + let previous = domains[0].split('.'); + for (let i = 1; i < $sortedDomains.length; i++) { + const cur = $sortedDomains[i].split('.'); + + if (previous.length < cur.length && previous[0] !== cur[cur.length - previous.length]) { + domains.push(cur.slice(cur.length - previous.length).join('.')); + } + + while (previous.length + 1 < cur.length) { + previous = cur.slice(cur.length - previous.length - 1); + domains.push(previous.join('.')); + } + + domains.push(cur.join('.')); + previous = cur; + } + + return domains; + }, +); + export async function getZone(domain: DomainInList | Domain, zoneId: string) { thisZone.set(null); diff --git a/ui/src/routes/domains/[dn]/+layout.svelte b/ui/src/routes/domains/[dn]/+layout.svelte index fcc8112..1512865 100644 --- a/ui/src/routes/domains/[dn]/+layout.svelte +++ b/ui/src/routes/domains/[dn]/+layout.svelte @@ -57,11 +57,12 @@ import ModalViewZone, { controls as ctrlViewZone } from '$lib/components/ModalViewZone.svelte'; import NewSubdomainPath, { controls as ctrlNewSubdomain } from '$lib/components/NewSubdomainPath.svelte'; import NewSubdomainModal from '$lib/components/domains/NewSubdomainModal.svelte'; - import { fqdn } from '$lib/dns'; + import SubdomainListTiny from '$lib/components/domains/SubdomainListTiny.svelte'; + import { fqdn, isReverseZone } from '$lib/dns'; import type { Domain, DomainInList } from '$lib/model/domain'; import type { ZoneMeta } from '$lib/model/zone'; import { domains, domains_by_groups, domains_idx, refreshDomains } from '$lib/stores/domains'; - import { retrieveZone as StoreRetrieveZone, sortedDomains, thisZone } from '$lib/stores/thiszone'; + import { retrieveZone as StoreRetrieveZone, sortedDomains, sortedDomainsWithIntermediate, thisZone } from '$lib/stores/thiszone'; import { t } from '$lib/translations'; export let data: {domain: DomainInList;}; @@ -175,7 +176,7 @@ Retour à la zone - {:else if $page.data.streamed && $sortedDomains} + {:else if $page.data.streamed && $sortedDomainsWithIntermediate}