switch away from net.LookUpTxt
This commit is contained in:
parent
b7c2beb01c
commit
9cfc330971
@ -3,7 +3,6 @@ package nsupdate
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@ -32,22 +31,27 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (c NsUpdateStruct) UpdateTXT(record, recordType, value string) error {
|
func (c NsUpdateStruct) UpdateTXT(record, recordType, value string) error {
|
||||||
|
var (
|
||||||
|
stdout bytes.Buffer
|
||||||
|
stderr bytes.Buffer
|
||||||
|
)
|
||||||
|
|
||||||
for _, v := range specialChars {
|
for _, v := range specialChars {
|
||||||
value = strings.ReplaceAll(value, v, fmt.Sprintf("\\%s", v))
|
value = strings.ReplaceAll(value, v, fmt.Sprintf("\\%s", v))
|
||||||
}
|
}
|
||||||
|
|
||||||
value = sanitizeTXT(value)
|
value = sanitizeTXT(value)
|
||||||
|
|
||||||
r, err := net.LookupTXT(record)
|
command := fmt.Sprintf("dig +shord TXT %s", record)
|
||||||
if err != nil {
|
cmd := exec.Command("/usr/bin/env", "sh", "-c", command)
|
||||||
config.Cfg.Log.Info("unable to get existing record", "record", record, "error", err)
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var oldTXT string
|
oldTXT := stdout.String()
|
||||||
for _, v := range r {
|
|
||||||
oldTXT += v
|
|
||||||
}
|
|
||||||
|
|
||||||
if strings.ReplaceAll(oldTXT, `" "`, ``) != strings.ReplaceAll(value, `" "`, ``) {
|
if strings.ReplaceAll(oldTXT, `" "`, ``) != strings.ReplaceAll(value, `" "`, ``) {
|
||||||
config.Cfg.Log.Debug("deleting record", "record", record)
|
config.Cfg.Log.Debug("deleting record", "record", record)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user