|
@@ -191,3 +191,48 @@ func (h *DNSHandler) ListDNSRecords(w http.ResponseWriter, r *http.Request) {
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+// GetDNSRecordID retrieves the record ID for a specific subdomain
|
|
|
+func (h *DNSHandler) GetDNSRecordID(w http.ResponseWriter, r *http.Request) {
|
|
|
+ vars := mux.Vars(r)
|
|
|
+ subdomain := vars["subdomain"]
|
|
|
+ log.Printf("Handling GET request for DNS record ID with subdomain: %s from %s", subdomain, r.RemoteAddr)
|
|
|
+
|
|
|
+ // Get all record IDs
|
|
|
+ var recordIDs []int
|
|
|
+ err := config.OVHClient.Get("/domain/zone/"+h.Zone+"/record", &recordIDs)
|
|
|
+ if err != nil {
|
|
|
+ log.Printf("Error getting DNS record IDs: %v", err)
|
|
|
+ http.Error(w, "Failed to get DNS records: "+err.Error(), http.StatusInternalServerError)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // Search through records to find matching subdomain
|
|
|
+ for _, id := range recordIDs {
|
|
|
+ var record DNSRecord
|
|
|
+ err := config.OVHClient.Get(fmt.Sprintf("/domain/zone/%s/record/%d", h.Zone, id), &record)
|
|
|
+ if err != nil {
|
|
|
+ log.Printf("Error getting DNS record %d: %v", id, err)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ if record.FieldType == "A" && record.SubDomain == subdomain {
|
|
|
+ response := struct {
|
|
|
+ ID int `json:"id"`
|
|
|
+ }{
|
|
|
+ ID: id,
|
|
|
+ }
|
|
|
+
|
|
|
+ w.Header().Set("Content-Type", "application/json")
|
|
|
+ if err := json.NewEncoder(w).Encode(response); err != nil {
|
|
|
+ log.Printf("Error encoding response: %v", err)
|
|
|
+ http.Error(w, "Failed to encode response", http.StatusInternalServerError)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // If we get here, no matching record was found
|
|
|
+ http.Error(w, "Record not found", http.StatusNotFound)
|
|
|
+}
|