mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
AXFRDDNS provider - adds update/transfer connection modes support (#1143)
* Adds update/transfer connection modes support * Fixes typo * gofmt all (#1144) * go generate (#1145) * go generate * gofmt Co-authored-by: Tom Limoncelli <tlimoncelli@stackoverflow.com>
This commit is contained in:
@ -18,6 +18,17 @@ and [Yadifa](https://www.yadifa.eu/home).
|
|||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
|
### Connection modes
|
||||||
|
|
||||||
|
Zone transfers default to TCP, DDNS updates default to UDP when
|
||||||
|
using this provider.
|
||||||
|
|
||||||
|
The following two parameters in `creds.json` allow switching
|
||||||
|
to TCP or TCP over TLS.
|
||||||
|
|
||||||
|
* `update-mode`: May contain `udp` (the default), `tcp`, or `tcp-tls`.
|
||||||
|
* `transfer-mode`: May contain `tcp` (the default), or `tcp-tls`.
|
||||||
|
|
||||||
### Authentication
|
### Authentication
|
||||||
|
|
||||||
Authentication information is included in the `creds.json` entry for
|
Authentication information is included in the `creds.json` entry for
|
||||||
|
@ -13,11 +13,13 @@ axfrddns -
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"crypto/tls"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -52,11 +54,13 @@ var features = providers.DocumentationNotes{
|
|||||||
|
|
||||||
// axfrddnsProvider stores the client info for the provider.
|
// axfrddnsProvider stores the client info for the provider.
|
||||||
type axfrddnsProvider struct {
|
type axfrddnsProvider struct {
|
||||||
rand *rand.Rand
|
rand *rand.Rand
|
||||||
master string
|
master string
|
||||||
nameservers []*models.Nameserver
|
updateMode string
|
||||||
transferKey *Key
|
transferMode string
|
||||||
updateKey *Key
|
nameservers []*models.Nameserver
|
||||||
|
transferKey *Key
|
||||||
|
updateKey *Key
|
||||||
}
|
}
|
||||||
|
|
||||||
func initAxfrDdns(config map[string]string, providermeta json.RawMessage) (providers.DNSServiceProvider, error) {
|
func initAxfrDdns(config map[string]string, providermeta json.RawMessage) (providers.DNSServiceProvider, error) {
|
||||||
@ -84,6 +88,30 @@ func initAxfrDdns(config map[string]string, providermeta json.RawMessage) (provi
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if config["update-mode"] != "" {
|
||||||
|
switch config["update-mode"] {
|
||||||
|
case "tcp",
|
||||||
|
"tcp-tls":
|
||||||
|
api.updateMode = config["update-mode"]
|
||||||
|
case "udp":
|
||||||
|
api.updateMode = ""
|
||||||
|
default:
|
||||||
|
fmt.Printf("[Warning] AXFRDDNS: Unknown update-mode in `creds.json` (%s)\n", config["update-mode"])
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
api.updateMode = ""
|
||||||
|
}
|
||||||
|
if config["transfer-mode"] != "" {
|
||||||
|
switch config["transfer-mode"] {
|
||||||
|
case "tcp",
|
||||||
|
"tcp-tls":
|
||||||
|
api.transferMode = config["transfer-mode"]
|
||||||
|
default:
|
||||||
|
fmt.Printf("[Warning] AXFRDDNS: Unknown transfer-mode in `creds.json` (%s)\n", config["transfer-mode"])
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
api.transferMode = "tcp"
|
||||||
|
}
|
||||||
if config["master"] != "" {
|
if config["master"] != "" {
|
||||||
api.master = config["master"]
|
api.master = config["master"]
|
||||||
if !strings.Contains(api.master, ":") {
|
if !strings.Contains(api.master, ":") {
|
||||||
@ -107,7 +135,9 @@ func initAxfrDdns(config map[string]string, providermeta json.RawMessage) (provi
|
|||||||
case "master",
|
case "master",
|
||||||
"nameservers",
|
"nameservers",
|
||||||
"update-key",
|
"update-key",
|
||||||
"transfer-key":
|
"transfer-key",
|
||||||
|
"update-mode",
|
||||||
|
"transfer-mode":
|
||||||
continue
|
continue
|
||||||
default:
|
default:
|
||||||
fmt.Printf("[Warning] AXFRDDNS: unknown key in `creds.json` (%s)\n", key)
|
fmt.Printf("[Warning] AXFRDDNS: unknown key in `creds.json` (%s)\n", key)
|
||||||
@ -169,10 +199,28 @@ func (c *axfrddnsProvider) GetNameservers(domain string) ([]*models.Nameserver,
|
|||||||
return c.nameservers, nil
|
return c.nameservers, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *axfrddnsProvider) getAxfrConnection() (*dns.Transfer, error) {
|
||||||
|
var con net.Conn = nil
|
||||||
|
var err error = nil
|
||||||
|
if c.transferMode == "tcp-tls" {
|
||||||
|
con, err = tls.Dial("tcp", c.master, &tls.Config{})
|
||||||
|
} else {
|
||||||
|
con, err = net.Dial("tcp", c.master)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
dnscon := &dns.Conn{Conn: con}
|
||||||
|
transfer := &dns.Transfer{Conn: dnscon}
|
||||||
|
return transfer, nil
|
||||||
|
}
|
||||||
|
|
||||||
// FetchZoneRecords gets the records of a zone and returns them in dns.RR format.
|
// FetchZoneRecords gets the records of a zone and returns them in dns.RR format.
|
||||||
func (c *axfrddnsProvider) FetchZoneRecords(domain string) ([]dns.RR, error) {
|
func (c *axfrddnsProvider) FetchZoneRecords(domain string) ([]dns.RR, error) {
|
||||||
|
transfer, err := c.getAxfrConnection()
|
||||||
transfer := new(dns.Transfer)
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
transfer.DialTimeout = dnsTimeout
|
transfer.DialTimeout = dnsTimeout
|
||||||
transfer.ReadTimeout = dnsTimeout
|
transfer.ReadTimeout = dnsTimeout
|
||||||
|
|
||||||
@ -368,6 +416,7 @@ func (c *axfrddnsProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*mod
|
|||||||
}
|
}
|
||||||
|
|
||||||
client := new(dns.Client)
|
client := new(dns.Client)
|
||||||
|
client.Net = c.updateMode
|
||||||
client.Timeout = dnsTimeout
|
client.Timeout = dnsTimeout
|
||||||
if c.updateKey != nil {
|
if c.updateKey != nil {
|
||||||
client.TsigSecret =
|
client.TsigSecret =
|
||||||
|
Reference in New Issue
Block a user