Skip to content

Commit

Permalink
sync up dns when custom dns add/delete
Browse files Browse the repository at this point in the history
  • Loading branch information
yabinma committed Oct 18, 2024
1 parent d7c1171 commit 4de0fc1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
10 changes: 10 additions & 0 deletions controllers/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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))
Expand All @@ -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"])

Expand All @@ -219,6 +225,10 @@ func deleteDNS(w http.ResponseWriter, r *http.Request) {
}
}

if servercfg.GetManageDNS() {
mq.SendDNSSyncByNetwork(netID)
}

json.NewEncoder(w).Encode(entrytext + " deleted.")

}
Expand Down
13 changes: 13 additions & 0 deletions mq/publishers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 4de0fc1

Please sign in to comment.