diff --git a/controllers/dns.go b/controllers/dns.go index f15d62877..cc1d70abf 100644 --- a/controllers/dns.go +++ b/controllers/dns.go @@ -150,6 +150,7 @@ func createDNS(w http.ResponseWriter, r *http.Request) { var entry models.DNSEntry var params = mux.Vars(r) + netID := params["network"] _ = json.NewDecoder(r.Body).Decode(&entry) entry.Network = params["network"] @@ -179,6 +180,10 @@ func createDNS(w http.ResponseWriter, r *http.Request) { } } + if servercfg.GetManageDNS() { + mq.SendDNSSyncByNetwork(netID) + } + logger.Log(1, "new DNS record added:", entry.Name) logger.Log(2, r.Header.Get("user"), fmt.Sprintf("DNS entry is set: %+v", entry)) @@ -200,6 +205,7 @@ func deleteDNS(w http.ResponseWriter, r *http.Request) { // get params var params = mux.Vars(r) + netID := params["network"] entrytext := params["domain"] + "." + params["network"] err := logic.DeleteDNS(params["domain"], params["network"]) @@ -219,6 +225,10 @@ func deleteDNS(w http.ResponseWriter, r *http.Request) { } } + if servercfg.GetManageDNS() { + mq.SendDNSSyncByNetwork(netID) + } + json.NewEncoder(w).Encode(entrytext + " deleted.") } diff --git a/mq/publishers.go b/mq/publishers.go index 6935cfea8..3b47390a8 100644 --- a/mq/publishers.go +++ b/mq/publishers.go @@ -254,6 +254,19 @@ func sendPeers() { } } +func SendDNSSyncByNetwork(network string) error { + + k, err := logic.GetDNS(network) + if err == nil && len(k) > 0 { + err = PushSyncDNS(k) + if err != nil { + slog.Warn("error publishing dns entry data for network ", network, err.Error()) + } + } + + return err +} + func sendDNSSync() error { networks, err := logic.GetNetworks()