Split long TXT values in 255 strings

This commit is contained in:
William Bouzourène 2025-04-12 14:22:28 +02:00
parent 63442acdb2
commit b1881f90d4
Signed by: bouzoure
SSH key fingerprint: SHA256:19MbXpLua4rUtk8tunMesD8KUKb91LXLHg8E/qTooww

View file

@ -58,6 +58,30 @@ func GetTomlZones() ([]TomlZone, error) {
zone.DefaultTTL = 3600 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) zones = append(zones, zone)
} }
@ -77,5 +101,16 @@ func CreateTomlZone(zone TomlZone) error {
return err 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) return toml.NewEncoder(file).Encode(&zone)
} }