mirror of
https://codeberg.org/lauralani/ipam.git
synced 2024-11-27 14:00:00 +01:00
fix detection of correct zone
This commit is contained in:
parent
29ddaf84d5
commit
f88d93f6f0
2 changed files with 368 additions and 370 deletions
|
@ -78,7 +78,7 @@ var ipaddCmd = &cobra.Command{
|
|||
fmt.Printf("added ip:\nip: %v\nhostname: %v\n", ipaddress, hostname)
|
||||
dnserr := AddDNSFqdn(hostname, ip)
|
||||
if dnserr != nil {
|
||||
fmt.Println("[ERROR]", writeerr)
|
||||
fmt.Println("[ERROR]", dnserr)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -109,11 +109,7 @@ func (z DNSZone) SendPATCH(record string, value string, recordtype string, chang
|
|||
req.Header.Add("Content-Type", "application/json")
|
||||
|
||||
client := &http.Client{}
|
||||
resp, resperr := client.Do(req)
|
||||
if resperr != nil {
|
||||
return resperr
|
||||
}
|
||||
|
||||
resp, _ := client.Do(req)
|
||||
if resp.StatusCode != 204 {
|
||||
defer resp.Body.Close()
|
||||
|
||||
|
@ -121,7 +117,7 @@ func (z DNSZone) SendPATCH(record string, value string, recordtype string, chang
|
|||
if readerr != nil {
|
||||
fmt.Println(readerr)
|
||||
}
|
||||
return errors.New("HTTP Error: " + resp.Status + "\n" + string(body))
|
||||
return fmt.Errorf("[HTTP ERROR] %v: %q", resp.Status, string(body))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -236,7 +232,7 @@ func GetBestDNSZone(fqdn string) (DNSZone, error) {
|
|||
var matchfound bool = false
|
||||
|
||||
for _, zone := range zones {
|
||||
if strings.HasSuffix(fqdn, zone.Name) {
|
||||
if strings.HasSuffix(fqdn, "."+zone.Name) {
|
||||
if !matchfound {
|
||||
matchfound = true
|
||||
bestmatch = zone
|
||||
|
@ -292,7 +288,9 @@ func AddDNSFqdn(fqdn string, addr netip.Addr) error {
|
|||
if frecordexists {
|
||||
fmt.Printf("[DNS] DNS Record for %v already exists, no need to change DNS.\n", fqdn)
|
||||
} else {
|
||||
fpatcherr := fzone.SendPATCH(strings.Replace(fqdn+".", "."+fzone.Name, "", 1), addr.String(), recordtype, "REPLACE")
|
||||
var dotfqdn, dotfzone string = fqdn + ".", "." + fzone.Name
|
||||
record := strings.Replace(dotfqdn, dotfzone, "", 1)
|
||||
fpatcherr := fzone.SendPATCH(record, addr.String(), recordtype, "REPLACE")
|
||||
if fpatcherr != nil {
|
||||
return fpatcherr
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue