2020-12-29 05:07:33 +08:00
|
|
|
package msdns
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
|
2023-05-21 01:21:45 +08:00
|
|
|
"github.com/StackExchange/dnscontrol/v4/models"
|
2020-12-29 05:07:33 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// DNSAccessor describes a system that can access Microsoft DNS.
|
|
|
|
type DNSAccessor interface {
|
|
|
|
Exit()
|
|
|
|
GetDNSServerZoneAll(dnsserver string) ([]string, error)
|
|
|
|
GetDNSZoneRecords(dnsserver, domain string) ([]nativeRecord, error)
|
|
|
|
RecordCreate(dnsserver, domain string, rec *models.RecordConfig) error
|
|
|
|
RecordDelete(dnsserver, domain string, rec *models.RecordConfig) error
|
|
|
|
RecordModify(dnsserver, domain string, old, rec *models.RecordConfig) error
|
2023-03-31 21:08:26 +08:00
|
|
|
RecordModifyTTL(dnsserver, domain string, old *models.RecordConfig, newTTL uint32) error
|
2020-12-29 05:07:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// nativeRecord the JSON received from PowerShell when listing all DNS
|
|
|
|
// records in a zone.
|
|
|
|
type nativeRecord struct {
|
|
|
|
//CimClass interface{} `json:"CimClass"`
|
|
|
|
//CimInstanceProperties interface{} `json:"CimInstanceProperties"`
|
|
|
|
//CimSystemProperties interface{} `json:"CimSystemProperties"`
|
|
|
|
//DistinguishedName string `json:"DistinguishedName"`
|
|
|
|
//RecordClass string `json:"RecordClass"`
|
|
|
|
RecordType string `json:"RecordType"`
|
|
|
|
HostName string `json:"HostName"`
|
|
|
|
RecordData struct {
|
|
|
|
CimInstanceProperties []ciProperty `json:"CimInstanceProperties"`
|
|
|
|
} `json:"RecordData"`
|
|
|
|
TimeToLive struct {
|
|
|
|
TotalSeconds float64 `json:"TotalSeconds"`
|
|
|
|
} `json:"TimeToLive"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type ciProperty struct {
|
|
|
|
Name string `json:"Name"`
|
|
|
|
Value json.RawMessage `json:"Value,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type ciValueDuration struct {
|
|
|
|
TotalSeconds float64 `json:"TotalSeconds"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// NB(tlim): The above structs were created using the help of:
|
|
|
|
// Get-DnsServerResourceRecord -ZoneName example.com | where { $_.RecordType -eq "SOA" } | select $_.RecordData | ConvertTo-Json -depth 10
|
|
|
|
// and pass it to https://mholt.github.io/json-to-go/
|