Registrar: only for zones that are a registered domain
With porkbun.domains empty the Registrar tab was offered for every zone and always failed for subdomain zones, reverse zones and private names. dnsname.RegisteredDomain (public suffix list) now decides; the others get a message naming what delegates them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
65086e314a
commit
82c282cd32
7 files changed
+106
-2
No files matched your search
@@ -11,6 +11,7 @@ import (
|
||||
|
||||
"github.com/miekg/dns"
|
||||
"golang.org/x/net/idna"
|
||||
"golang.org/x/net/publicsuffix"
|
||||
)
|
||||
|
||||
// Root is the root domain name.
|
||||
@@ -305,6 +306,28 @@ func EmailFromMailbox(rname string) string {
|
||||
return local + "@" + strings.Join(labels[1:], ".")
|
||||
}
|
||||
|
||||
// RegisteredDomain returns the domain registered at a registrar that name
|
||||
// is in, without a trailing dot: adbraun.lol for lab.adbraun.lol, from
|
||||
// the public suffix list. ok is false when no registrar is involved:
|
||||
// reverse zones and the rest of .arpa (delegated by whoever holds the
|
||||
// addresses), names under a suffix the list doesn't know (home.lan,
|
||||
// internal) and public suffixes themselves (co.uk).
|
||||
func RegisteredDomain(name string) (string, bool) {
|
||||
n := strings.ToLower(strings.TrimSuffix(name, "."))
|
||||
if n == "" || n == "arpa" || strings.HasSuffix(n, ".arpa") {
|
||||
return "", false
|
||||
}
|
||||
suffix, icann := publicsuffix.PublicSuffix(n)
|
||||
if !icann || suffix == n {
|
||||
return "", false
|
||||
}
|
||||
d, err := publicsuffix.EffectiveTLDPlusOne(n)
|
||||
if err != nil {
|
||||
return "", false
|
||||
}
|
||||
return d, true
|
||||
}
|
||||
|
||||
// IsReverse reports whether name is in in-addr.arpa or ip6.arpa.
|
||||
func IsReverse(name string) bool {
|
||||
return IsSubdomain(name, "in-addr.arpa.") || IsSubdomain(name, "ip6.arpa.") || IsSubdomain(name, "ip6.int.")
|
||||
|
||||
@@ -249,3 +249,23 @@ func TestPrefixFromReverse(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegisteredDomain(t *testing.T) {
|
||||
for name, want := range map[string]string{
|
||||
"adbraun.lol.": "adbraun.lol",
|
||||
"lab.adbraun.lol.": "adbraun.lol",
|
||||
"Example.CO.UK": "example.co.uk",
|
||||
"co.uk.": "",
|
||||
"lol.": "",
|
||||
"10.0.10.in-addr.arpa.": "",
|
||||
"d.f.ip6.arpa.": "",
|
||||
"home.arpa.": "",
|
||||
"nas.home.lan.": "",
|
||||
"": "",
|
||||
} {
|
||||
got, ok := RegisteredDomain(name)
|
||||
if got != want || ok != (want != "") {
|
||||
t.Errorf("RegisteredDomain(%q) = %q, %v; want %q", name, got, ok, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user