This commit is contained in:
Thomas Limoncelli 2025-11-24 11:39:09 -05:00
parent 0315c8499b
commit d0604a24d1
No known key found for this signature in database
3 changed files with 29 additions and 8 deletions

View file

@ -18,7 +18,10 @@ const (
// DomainConfig describes a DNS domain (technically a DNS zone).
type DomainConfig struct {
Name string `json:"name"` // NO trailing "."
Name string `json:"name"` // NO trailing "." Converted to IDN (punycode) early in the pipeline.
NameRaw string `json:"-"` // name as entered by user in dnsconfig.js
NameUnicode string `json:"-"` // name in Unicode format
RegistrarName string `json:"registrar"`
DNSProviderNames map[string]int `json:"dnsProviders"`

View file

@ -355,15 +355,29 @@ type Warning struct {
// ValidateAndNormalizeConfig performs and normalization and/or validation of the IR.
func ValidateAndNormalizeConfig(config *models.DNSConfig) (errs []error) {
// This is a horrible hack. We need to redo IDN processing someday.
// For now, we just convert everything to punycode at the earliest point, which is here.
// This should probably be done elsewhere (maybe where we first ingest a domain).
// Convert all domain names to punycode.
for _, domain := range config.Domains {
// Convert domain name to punycode.
var err error
domain.Name, err = idna.ToASCII(domain.Name)
// Create the .NameRaw field.
domain.NameRaw = domain.Name
idn, err := idna.ToASCII(domain.Name)
if err != nil {
return []error{fmt.Errorf("Can not convert domain %q to IDN: %w", domain.Name, err)}
}
if idn != domain.NameRaw {
domain.Name = idn
}
// Create the .NameUnicode field.
domain.NameUnicode = domain.Name
uni, err := idna.ToUnicode(domain.Name)
if err != nil {
return []error{fmt.Errorf("Can not convert domain %q to Unicode: %w", domain.Name, err)}
}
if uni != domain.NameUnicode {
domain.NameUnicode = idn
}
}
err := processSplitHorizonDomains(config)

View file

@ -89,8 +89,12 @@ type ConsolePrinter struct {
}
// StartDomain is called at the start of each domain.
func (c ConsolePrinter) StartDomain(domain string) {
fmt.Fprintf(c.Writer, "******************** Domain: %s\n", domain)
func (c ConsolePrinter) StartDomain(domainIDN, domainUnicode string) {
if domainIDN == domainUnicode {
fmt.Fprintf(c.Writer, "******************** Domain: %s\n", domainIDN)
} else {
fmt.Fprintf(c.Writer, "******************** Domain: %s (%s)\n", domainIDN, domainUnicode)
}
}
// PrintCorrection is called to print/format each correction.