From b1881f90d4ff039900851308a04e2d9fb2475836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20Bouzour=C3=A8ne?= Date: Sat, 12 Apr 2025 14:22:28 +0200 Subject: [PATCH] Split long TXT values in 255 strings --- dnsconfig/toml_zones.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/dnsconfig/toml_zones.go b/dnsconfig/toml_zones.go index e3fda6f..eaead34 100644 --- a/dnsconfig/toml_zones.go +++ b/dnsconfig/toml_zones.go @@ -58,6 +58,30 @@ func GetTomlZones() ([]TomlZone, error) { zone.DefaultTTL = 3600 } + for index, record := range zone.TomlRecords { + if !strings.EqualFold(record.Type, "TXT") || len(record.Value) <= 255 { + continue + } + + var newValue string + var split string + for count, char := range record.Value { + split = fmt.Sprintf("%s%c", split, char) + + if (count+1)%255 == 0 || (count+1) == len(record.Value) { + if newValue == "" { + newValue = fmt.Sprintf("\"%s\"", split) + } else { + newValue = fmt.Sprintf("%s \"%s\"", newValue, split) + } + + split = "" + } + } + + zone.TomlRecords[index].Value = newValue + } + zones = append(zones, zone) } @@ -77,5 +101,16 @@ func CreateTomlZone(zone TomlZone) error { return err } + for index, record := range zone.TomlRecords { + if !strings.EqualFold(record.Type, "TXT") || len(record.Value) <= 255 { + continue + } + + newValue := strings.ReplaceAll(record.Value, "\" \"", "") + newValue = strings.ReplaceAll(newValue, "\"", "") + + zone.TomlRecords[index].Value = newValue + } + return toml.NewEncoder(file).Encode(&zone) }