added wildcard option

This commit is contained in:
Malte
2022-04-06 10:58:41 +02:00
parent 217cb2a575
commit 47cb9e742a
4 changed files with 29 additions and 12 deletions
+11 -2
View File
@@ -11,7 +11,7 @@ import (
)
// UpdateRecord builds a nsupdate file and updates a record by executing it with nsupdate.
func UpdateRecord(hostname string, target string, addrType string, zone string, ttl int) error {
func UpdateRecord(hostname string, target string, addrType string, zone string, ttl int, enableWildcard bool) error {
log.Info(fmt.Sprintf("%s record update request: %s -> %s", addrType, hostname, target))
f, err := ioutil.TempFile(os.TempDir(), "dyndns")
@@ -25,7 +25,13 @@ func UpdateRecord(hostname string, target string, addrType string, zone string,
w.WriteString(fmt.Sprintf("server %s\n", "localhost"))
w.WriteString(fmt.Sprintf("zone %s\n", zone))
w.WriteString(fmt.Sprintf("update delete %s.%s %s\n", hostname, zone, addrType))
if enableWildcard {
w.WriteString(fmt.Sprintf("update delete %s.%s %s\n", "*."+hostname, zone, addrType))
}
w.WriteString(fmt.Sprintf("update add %s.%s %v %s %s\n", hostname, zone, ttl, addrType, target))
if enableWildcard {
w.WriteString(fmt.Sprintf("update add %s.%s %v %s %s\n", "*."+hostname, zone, ttl, addrType, target))
}
w.WriteString("send\n")
w.Flush()
@@ -49,7 +55,7 @@ func UpdateRecord(hostname string, target string, addrType string, zone string,
}
// DeleteRecord builds a nsupdate file and deletes a record by executing it with nsupdate.
func DeleteRecord(hostname string, zone string) error {
func DeleteRecord(hostname string, zone string, enableWildcard bool) error {
fmt.Printf("record delete request: %s\n", hostname)
f, err := ioutil.TempFile(os.TempDir(), "dyndns")
@@ -63,6 +69,9 @@ func DeleteRecord(hostname string, zone string) error {
w.WriteString(fmt.Sprintf("server %s\n", "localhost"))
w.WriteString(fmt.Sprintf("zone %s\n", zone))
w.WriteString(fmt.Sprintf("update delete %s.%s\n", hostname, zone))
if enableWildcard {
w.WriteString(fmt.Sprintf("update delete %s.%s\n", "*."+hostname, zone))
}
w.WriteString("send\n")
w.Flush()