mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2025-12-12 07:06:03 +08:00
m
This commit is contained in:
parent
0315c8499b
commit
d0604a24d1
3 changed files with 29 additions and 8 deletions
|
|
@ -18,7 +18,10 @@ const (
|
||||||
|
|
||||||
// DomainConfig describes a DNS domain (technically a DNS zone).
|
// DomainConfig describes a DNS domain (technically a DNS zone).
|
||||||
type DomainConfig struct {
|
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"`
|
RegistrarName string `json:"registrar"`
|
||||||
DNSProviderNames map[string]int `json:"dnsProviders"`
|
DNSProviderNames map[string]int `json:"dnsProviders"`
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -355,15 +355,29 @@ type Warning struct {
|
||||||
// ValidateAndNormalizeConfig performs and normalization and/or validation of the IR.
|
// ValidateAndNormalizeConfig performs and normalization and/or validation of the IR.
|
||||||
func ValidateAndNormalizeConfig(config *models.DNSConfig) (errs []error) {
|
func ValidateAndNormalizeConfig(config *models.DNSConfig) (errs []error) {
|
||||||
|
|
||||||
// This is a horrible hack. We need to redo IDN processing someday.
|
// This should probably be done elsewhere (maybe where we first ingest a domain).
|
||||||
// For now, we just convert everything to punycode at the earliest point, which is here.
|
// Convert all domain names to punycode.
|
||||||
for _, domain := range config.Domains {
|
for _, domain := range config.Domains {
|
||||||
// Convert domain name to punycode.
|
|
||||||
var err error
|
// Create the .NameRaw field.
|
||||||
domain.Name, err = idna.ToASCII(domain.Name)
|
domain.NameRaw = domain.Name
|
||||||
|
idn, err := idna.ToASCII(domain.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []error{fmt.Errorf("Can not convert domain %q to IDN: %w", domain.Name, err)}
|
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)
|
err := processSplitHorizonDomains(config)
|
||||||
|
|
|
||||||
|
|
@ -89,8 +89,12 @@ type ConsolePrinter struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// StartDomain is called at the start of each domain.
|
// StartDomain is called at the start of each domain.
|
||||||
func (c ConsolePrinter) StartDomain(domain string) {
|
func (c ConsolePrinter) StartDomain(domainIDN, domainUnicode string) {
|
||||||
fmt.Fprintf(c.Writer, "******************** Domain: %s\n", domain)
|
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.
|
// PrintCorrection is called to print/format each correction.
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue