diff --git a/internal/nsupdate/nsupdate.go b/internal/nsupdate/nsupdate.go index 1fdbbb5..f503bf8 100644 --- a/internal/nsupdate/nsupdate.go +++ b/internal/nsupdate/nsupdate.go @@ -3,7 +3,6 @@ package nsupdate import ( "bytes" "fmt" - "net" "strings" "os/exec" @@ -32,22 +31,27 @@ var ( ) func (c NsUpdateStruct) UpdateTXT(record, recordType, value string) error { + var ( + stdout bytes.Buffer + stderr bytes.Buffer + ) + for _, v := range specialChars { value = strings.ReplaceAll(value, v, fmt.Sprintf("\\%s", v)) } value = sanitizeTXT(value) - r, err := net.LookupTXT(record) - if err != nil { - config.Cfg.Log.Info("unable to get existing record", "record", record, "error", err) + command := fmt.Sprintf("dig +shord TXT %s", record) + cmd := exec.Command("/usr/bin/env", "sh", "-c", command) + cmd.Stdout = &stdout + cmd.Stderr = &stderr + if err := cmd.Run(); err != nil { + config.Cfg.Log.Error("error adding record", "error", err, "stderr", stderr.String(), "stdout", stdout.String()) return err } - var oldTXT string - for _, v := range r { - oldTXT += v - } + oldTXT := stdout.String() if strings.ReplaceAll(oldTXT, `" "`, ``) != strings.ReplaceAll(value, `" "`, ``) { config.Cfg.Log.Debug("deleting record", "record", record)