mirror of
https://github.com/qdm12/ddns-updater.git
synced 2026-03-31 06:24:00 -04:00
chore(lint): add revive linter and fix issues
- Export returned struct types - Do not export interfaces for other packages to use
This commit is contained in:
@@ -51,6 +51,7 @@ linters:
|
||||
- nolintlint
|
||||
- prealloc
|
||||
- predeclared
|
||||
- revive
|
||||
- rowserrcheck
|
||||
- exportloopref
|
||||
- sqlclosecheck
|
||||
|
||||
@@ -6,15 +6,15 @@ import (
|
||||
"github.com/qdm12/ddns-updater/internal/records"
|
||||
)
|
||||
|
||||
type database struct {
|
||||
type Database struct {
|
||||
data []records.Record
|
||||
sync.RWMutex
|
||||
persistentDB PersistentDatabase
|
||||
}
|
||||
|
||||
// NewDatabase creates a new in memory database.
|
||||
func NewDatabase(data []records.Record, persistentDB PersistentDatabase) *database {
|
||||
return &database{
|
||||
func NewDatabase(data []records.Record, persistentDB PersistentDatabase) *Database {
|
||||
return &Database{
|
||||
data: data,
|
||||
persistentDB: persistentDB,
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"github.com/qdm12/ddns-updater/internal/records"
|
||||
)
|
||||
|
||||
func (db *database) Select(id int) (record records.Record, err error) {
|
||||
func (db *Database) Select(id int) (record records.Record, err error) {
|
||||
db.RLock()
|
||||
defer db.RUnlock()
|
||||
if id < 0 {
|
||||
@@ -18,7 +18,7 @@ func (db *database) Select(id int) (record records.Record, err error) {
|
||||
return db.data[id], nil
|
||||
}
|
||||
|
||||
func (db *database) SelectAll() (records []records.Record) {
|
||||
func (db *Database) SelectAll() (records []records.Record) {
|
||||
db.RLock()
|
||||
defer db.RUnlock()
|
||||
return db.data
|
||||
|
||||
@@ -7,11 +7,11 @@ import (
|
||||
"github.com/qdm12/ddns-updater/internal/records"
|
||||
)
|
||||
|
||||
func (db *database) GetEvents(domain, host string) (events []models.HistoryEvent, err error) {
|
||||
func (db *Database) GetEvents(domain, host string) (events []models.HistoryEvent, err error) {
|
||||
return db.persistentDB.GetEvents(domain, host)
|
||||
}
|
||||
|
||||
func (db *database) Update(id int, record records.Record) (err error) {
|
||||
func (db *Database) Update(id int, record records.Record) (err error) {
|
||||
db.Lock()
|
||||
defer db.Unlock()
|
||||
if id < 0 {
|
||||
@@ -37,7 +37,7 @@ func (db *database) Update(id int, record records.Record) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (db *database) Close() (err error) {
|
||||
func (db *Database) Close() (err error) {
|
||||
db.Lock() // ensure write operation finishes
|
||||
defer db.Unlock()
|
||||
return db.persistentDB.Close()
|
||||
|
||||
@@ -14,13 +14,13 @@ func IsClientMode(args []string) bool {
|
||||
return len(args) > 1 && args[1] == "healthcheck"
|
||||
}
|
||||
|
||||
type client struct {
|
||||
type Client struct {
|
||||
*http.Client
|
||||
}
|
||||
|
||||
func NewClient() *client {
|
||||
func NewClient() *Client {
|
||||
const timeout = 5 * time.Second
|
||||
return &client{
|
||||
return &Client{
|
||||
Client: &http.Client{Timeout: timeout},
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@ var ErrParseHealthServerAddress = errors.New("cannot parse health server address
|
||||
|
||||
// Query sends an HTTP request to the other instance of
|
||||
// the program, and to its internal healthcheck server.
|
||||
func (c *client) Query(ctx context.Context, port uint16) error {
|
||||
func (c *Client) Query(ctx context.Context, port uint16) error {
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, "http://127.0.0.1:"+strconv.Itoa(int(port)), nil)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -8,22 +8,22 @@ import (
|
||||
"github.com/qdm12/golibs/logging"
|
||||
)
|
||||
|
||||
type server struct {
|
||||
type Server struct {
|
||||
address string
|
||||
logger logging.Logger
|
||||
handler http.Handler
|
||||
}
|
||||
|
||||
func NewServer(address string, logger logging.Logger, healthcheck func() error) *server {
|
||||
func NewServer(address string, logger logging.Logger, healthcheck func() error) *Server {
|
||||
handler := newHandler(logger, healthcheck)
|
||||
return &server{
|
||||
return &Server{
|
||||
address: address,
|
||||
logger: logger,
|
||||
handler: handler,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *server) Run(ctx context.Context, done chan<- struct{}) {
|
||||
func (s *Server) Run(ctx context.Context, done chan<- struct{}) {
|
||||
defer close(done)
|
||||
server := http.Server{
|
||||
Addr: s.address,
|
||||
|
||||
@@ -29,7 +29,7 @@ type commonSettings struct {
|
||||
|
||||
// JSONSettings obtain the update settings from the JSON content, first trying from the environment variable CONFIG
|
||||
// and then from the file config.json.
|
||||
func (r *reader) JSONSettings(filePath string) (
|
||||
func (r *Reader) JSONSettings(filePath string) (
|
||||
allSettings []settings.Settings, warnings []string, err error) {
|
||||
allSettings, warnings, err = r.getSettingsFromEnv(filePath)
|
||||
if allSettings != nil || warnings != nil || err != nil {
|
||||
@@ -41,7 +41,7 @@ func (r *reader) JSONSettings(filePath string) (
|
||||
var errWriteConfigToFile = errors.New("cannot write configuration to file")
|
||||
|
||||
// getSettingsFromFile obtain the update settings from config.json.
|
||||
func (r *reader) getSettingsFromFile(filePath string) (
|
||||
func (r *Reader) getSettingsFromFile(filePath string) (
|
||||
allSettings []settings.Settings, warnings []string, err error) {
|
||||
r.logger.Info("reading JSON config from file " + filePath)
|
||||
bytes, err := r.readFile(filePath)
|
||||
@@ -67,7 +67,7 @@ func (r *reader) getSettingsFromFile(filePath string) (
|
||||
|
||||
// getSettingsFromEnv obtain the update settings from the environment variable CONFIG.
|
||||
// If the settings are valid, they are written to the filePath.
|
||||
func (r *reader) getSettingsFromEnv(filePath string) (
|
||||
func (r *Reader) getSettingsFromEnv(filePath string) (
|
||||
allSettings []settings.Settings, warnings []string, err error) {
|
||||
s, err := r.env.Get("CONFIG", params.CaseSensitiveValue())
|
||||
if err != nil {
|
||||
@@ -132,7 +132,7 @@ func extractAllSettings(jsonBytes []byte) (
|
||||
}
|
||||
|
||||
func makeSettingsFromObject(common commonSettings, rawSettings json.RawMessage,
|
||||
matcher regex.Matcher) (
|
||||
matcher *regex.Matcher) (
|
||||
settingsSlice []settings.Settings, warnings []string, err error) {
|
||||
provider := models.Provider(common.Provider)
|
||||
if provider == constants.DuckDNS { // only hosts, no domain
|
||||
|
||||
@@ -8,15 +8,15 @@ import (
|
||||
"github.com/qdm12/golibs/params"
|
||||
)
|
||||
|
||||
type reader struct {
|
||||
type Reader struct {
|
||||
logger logging.Logger
|
||||
env envInterface
|
||||
readFile func(filename string) ([]byte, error)
|
||||
writeFile func(filename string, data []byte, perm fs.FileMode) (err error)
|
||||
}
|
||||
|
||||
func NewReader(logger logging.Logger) *reader {
|
||||
return &reader{
|
||||
func NewReader(logger logging.Logger) *Reader {
|
||||
return &Reader{
|
||||
logger: logger,
|
||||
env: params.New(),
|
||||
readFile: os.ReadFile,
|
||||
|
||||
@@ -2,19 +2,7 @@ package regex
|
||||
|
||||
import "regexp"
|
||||
|
||||
type Matcher interface {
|
||||
GandiKey(s string) bool
|
||||
GodaddyKey(s string) bool
|
||||
DuckDNSToken(s string) bool
|
||||
NamecheapPassword(s string) bool
|
||||
DreamhostKey(s string) bool
|
||||
CloudflareKey(s string) bool
|
||||
CloudflareUserServiceKey(s string) bool
|
||||
DNSOMaticUsername(s string) bool
|
||||
DNSOMaticPassword(s string) bool
|
||||
}
|
||||
|
||||
type matcher struct {
|
||||
type Matcher struct {
|
||||
goDaddyKey, duckDNSToken, namecheapPassword, dreamhostKey, cloudflareKey,
|
||||
cloudflareUserServiceKey, dnsOMaticUsername, dnsOMaticPassword, gandiKey *regexp.Regexp
|
||||
}
|
||||
@@ -31,8 +19,8 @@ var (
|
||||
dnsOMaticPassword = regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9._-]{5,19}$`)
|
||||
)
|
||||
|
||||
func NewMatcher() *matcher {
|
||||
return &matcher{
|
||||
func NewMatcher() *Matcher {
|
||||
return &Matcher{
|
||||
gandiKey: gandiKey,
|
||||
goDaddyKey: goDaddyKey,
|
||||
duckDNSToken: duckDNSToken,
|
||||
@@ -45,14 +33,14 @@ func NewMatcher() *matcher {
|
||||
}
|
||||
}
|
||||
|
||||
func (m *matcher) GandiKey(s string) bool { return m.gandiKey.MatchString(s) }
|
||||
func (m *matcher) GodaddyKey(s string) bool { return m.goDaddyKey.MatchString(s) }
|
||||
func (m *matcher) DuckDNSToken(s string) bool { return m.duckDNSToken.MatchString(s) }
|
||||
func (m *matcher) NamecheapPassword(s string) bool { return m.namecheapPassword.MatchString(s) }
|
||||
func (m *matcher) DreamhostKey(s string) bool { return m.dreamhostKey.MatchString(s) }
|
||||
func (m *matcher) CloudflareKey(s string) bool { return m.cloudflareKey.MatchString(s) }
|
||||
func (m *matcher) CloudflareUserServiceKey(s string) bool {
|
||||
func (m *Matcher) GandiKey(s string) bool { return m.gandiKey.MatchString(s) }
|
||||
func (m *Matcher) GodaddyKey(s string) bool { return m.goDaddyKey.MatchString(s) }
|
||||
func (m *Matcher) DuckDNSToken(s string) bool { return m.duckDNSToken.MatchString(s) }
|
||||
func (m *Matcher) NamecheapPassword(s string) bool { return m.namecheapPassword.MatchString(s) }
|
||||
func (m *Matcher) DreamhostKey(s string) bool { return m.dreamhostKey.MatchString(s) }
|
||||
func (m *Matcher) CloudflareKey(s string) bool { return m.cloudflareKey.MatchString(s) }
|
||||
func (m *Matcher) CloudflareUserServiceKey(s string) bool {
|
||||
return m.cloudflareUserServiceKey.MatchString(s)
|
||||
}
|
||||
func (m *matcher) DNSOMaticUsername(s string) bool { return m.dnsOMaticUsername.MatchString(s) }
|
||||
func (m *matcher) DNSOMaticPassword(s string) bool { return m.dnsOMaticPassword.MatchString(s) }
|
||||
func (m *Matcher) DNSOMaticUsername(s string) bool { return m.dnsOMaticUsername.MatchString(s) }
|
||||
func (m *Matcher) DNSOMaticPassword(s string) bool { return m.dnsOMaticPassword.MatchString(s) }
|
||||
|
||||
@@ -8,23 +8,23 @@ import (
|
||||
"github.com/qdm12/golibs/logging"
|
||||
)
|
||||
|
||||
type server struct {
|
||||
type Server struct {
|
||||
address string
|
||||
logger logging.Logger
|
||||
handler http.Handler
|
||||
}
|
||||
|
||||
func New(ctx context.Context, address, rootURL string, db Database,
|
||||
logger logging.Logger, runner UpdateForcer) *server {
|
||||
logger logging.Logger, runner UpdateForcer) *Server {
|
||||
handler := newHandler(ctx, rootURL, db, runner)
|
||||
return &server{
|
||||
return &Server{
|
||||
address: address,
|
||||
logger: logger,
|
||||
handler: handler,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *server) Run(ctx context.Context, done chan<- struct{}) {
|
||||
func (s *Server) Run(ctx context.Context, done chan<- struct{}) {
|
||||
defer close(done)
|
||||
server := http.Server{
|
||||
Addr: s.address,
|
||||
|
||||
13
internal/settings/common/interfaces.go
Normal file
13
internal/settings/common/interfaces.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package common
|
||||
|
||||
type Matcher interface {
|
||||
GandiKey(s string) bool
|
||||
GodaddyKey(s string) bool
|
||||
DuckDNSToken(s string) bool
|
||||
NamecheapPassword(s string) bool
|
||||
DreamhostKey(s string) bool
|
||||
CloudflareKey(s string) bool
|
||||
CloudflareUserServiceKey(s string) bool
|
||||
DNSOMaticUsername(s string) bool
|
||||
DNSOMaticPassword(s string) bool
|
||||
}
|
||||
@@ -10,7 +10,7 @@ const (
|
||||
Dd24 models.Provider = "dd24"
|
||||
DdnssDe models.Provider = "ddnss"
|
||||
DigitalOcean models.Provider = "digitalocean"
|
||||
DnsOMatic models.Provider = "dnsomatic"
|
||||
DNSOMatic models.Provider = "dnsomatic"
|
||||
DNSPod models.Provider = "dnspod"
|
||||
DonDominio models.Provider = "dondominio"
|
||||
Dreamhost models.Provider = "dreamhost"
|
||||
@@ -47,7 +47,7 @@ func ProviderChoices() []models.Provider {
|
||||
Dd24,
|
||||
DdnssDe,
|
||||
DigitalOcean,
|
||||
DnsOMatic,
|
||||
DNSOMatic,
|
||||
DNSPod,
|
||||
DonDominio,
|
||||
Dreamhost,
|
||||
|
||||
@@ -3,17 +3,17 @@ package errors
|
||||
import "errors"
|
||||
|
||||
var (
|
||||
ErrEmptyApiKey = errors.New("empty API key")
|
||||
ErrEmptyAPIKey = errors.New("empty API key")
|
||||
ErrEmptyAppKey = errors.New("empty app key")
|
||||
ErrEmptyConsumerKey = errors.New("empty consumer key")
|
||||
ErrEmptyEmail = errors.New("empty email")
|
||||
ErrEmptyKey = errors.New("empty key")
|
||||
ErrEmptyName = errors.New("empty name")
|
||||
ErrEmptyPassword = errors.New("empty password")
|
||||
ErrEmptyApiSecret = errors.New("empty API secret")
|
||||
ErrEmptyAPISecret = errors.New("empty API secret")
|
||||
ErrEmptySecret = errors.New("empty secret")
|
||||
ErrEmptyToken = errors.New("empty token")
|
||||
ErrEmptyAccessKeyId = errors.New("empty access key id")
|
||||
ErrEmptyAccessKeyID = errors.New("empty access key id")
|
||||
ErrEmptyAccessKeySecret = errors.New("empty key secret")
|
||||
ErrEmptyTTL = errors.New("TTL is not set")
|
||||
ErrEmptyUsername = errors.New("empty username")
|
||||
|
||||
@@ -16,30 +16,30 @@ import (
|
||||
"github.com/qdm12/ddns-updater/pkg/publicip/ipversion"
|
||||
)
|
||||
|
||||
type provider struct {
|
||||
type Provider struct {
|
||||
domain string
|
||||
host string
|
||||
ipVersion ipversion.IPVersion
|
||||
accessKeyId string
|
||||
accessKeyID string
|
||||
accessSecret string
|
||||
region string
|
||||
}
|
||||
|
||||
func New(data json.RawMessage, domain, host string,
|
||||
ipVersion ipversion.IPVersion) (p *provider, err error) {
|
||||
ipVersion ipversion.IPVersion) (p *Provider, err error) {
|
||||
extraSettings := struct {
|
||||
AccessKeyId string `json:"access_key_id"`
|
||||
AccessKeyID string `json:"access_key_id"`
|
||||
AccessSecret string `json:"access_secret"`
|
||||
Region string `json:"region"`
|
||||
}{}
|
||||
if err := json.Unmarshal(data, &extraSettings); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p = &provider{
|
||||
p = &Provider{
|
||||
domain: domain,
|
||||
host: host,
|
||||
ipVersion: ipVersion,
|
||||
accessKeyId: extraSettings.AccessKeyId,
|
||||
accessKeyID: extraSettings.AccessKeyID,
|
||||
accessSecret: extraSettings.AccessSecret,
|
||||
region: "cn-hangzhou",
|
||||
}
|
||||
@@ -52,41 +52,41 @@ func New(data json.RawMessage, domain, host string,
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (p *provider) isValid() error {
|
||||
func (p *Provider) isValid() error {
|
||||
switch {
|
||||
case p.accessKeyId == "":
|
||||
return errors.ErrEmptyAccessKeyId
|
||||
case p.accessKeyID == "":
|
||||
return errors.ErrEmptyAccessKeyID
|
||||
case p.accessSecret == "":
|
||||
return errors.ErrEmptyAccessKeySecret
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *provider) String() string {
|
||||
func (p *Provider) String() string {
|
||||
return utils.ToString(p.domain, p.host, constants.Aliyun, p.ipVersion)
|
||||
}
|
||||
|
||||
func (p *provider) Domain() string {
|
||||
func (p *Provider) Domain() string {
|
||||
return p.domain
|
||||
}
|
||||
|
||||
func (p *provider) Host() string {
|
||||
func (p *Provider) Host() string {
|
||||
return p.host
|
||||
}
|
||||
|
||||
func (p *provider) IPVersion() ipversion.IPVersion {
|
||||
func (p *Provider) IPVersion() ipversion.IPVersion {
|
||||
return p.ipVersion
|
||||
}
|
||||
|
||||
func (p *provider) Proxied() bool {
|
||||
func (p *Provider) Proxied() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *provider) BuildDomainName() string {
|
||||
func (p *Provider) BuildDomainName() string {
|
||||
return utils.BuildDomainName(p.host, p.domain)
|
||||
}
|
||||
|
||||
func (p *provider) HTML() models.HTMLRow {
|
||||
func (p *Provider) HTML() models.HTMLRow {
|
||||
return models.HTMLRow{
|
||||
Domain: models.HTML(fmt.Sprintf("<a href=\"http://%s\">%s</a>", p.BuildDomainName(), p.BuildDomainName())),
|
||||
Host: models.HTML(p.Host()),
|
||||
@@ -95,13 +95,13 @@ func (p *provider) HTML() models.HTMLRow {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *provider) Update(ctx context.Context, _ *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
func (p *Provider) Update(ctx context.Context, _ *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
recordType := constants.A
|
||||
if ip.To4() == nil {
|
||||
recordType = constants.AAAA
|
||||
}
|
||||
|
||||
client, err := alidns.NewClientWithAccessKey(p.region, p.accessKeyId, p.accessSecret)
|
||||
client, err := alidns.NewClientWithAccessKey(p.region, p.accessKeyID, p.accessSecret)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ import (
|
||||
"github.com/qdm12/golibs/verification"
|
||||
)
|
||||
|
||||
type provider struct {
|
||||
type Provider struct {
|
||||
domain string
|
||||
host string
|
||||
ipVersion ipversion.IPVersion
|
||||
@@ -29,7 +29,7 @@ type provider struct {
|
||||
}
|
||||
|
||||
func New(data json.RawMessage, domain, host string,
|
||||
ipVersion ipversion.IPVersion) (p *provider, err error) {
|
||||
ipVersion ipversion.IPVersion) (p *Provider, err error) {
|
||||
extraSettings := struct {
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
@@ -38,7 +38,7 @@ func New(data json.RawMessage, domain, host string,
|
||||
if err := json.Unmarshal(data, &extraSettings); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p = &provider{
|
||||
p = &Provider{
|
||||
domain: domain,
|
||||
host: host,
|
||||
ipVersion: ipVersion,
|
||||
@@ -52,7 +52,7 @@ func New(data json.RawMessage, domain, host string,
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (p *provider) isValid() error {
|
||||
func (p *Provider) isValid() error {
|
||||
switch {
|
||||
case p.username == "":
|
||||
return errors.ErrEmptyUsername
|
||||
@@ -64,31 +64,31 @@ func (p *provider) isValid() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *provider) String() string {
|
||||
func (p *Provider) String() string {
|
||||
return utils.ToString(p.domain, p.host, constants.AllInkl, p.ipVersion)
|
||||
}
|
||||
|
||||
func (p *provider) Domain() string {
|
||||
func (p *Provider) Domain() string {
|
||||
return p.domain
|
||||
}
|
||||
|
||||
func (p *provider) Host() string {
|
||||
func (p *Provider) Host() string {
|
||||
return p.host
|
||||
}
|
||||
|
||||
func (p *provider) IPVersion() ipversion.IPVersion {
|
||||
func (p *Provider) IPVersion() ipversion.IPVersion {
|
||||
return p.ipVersion
|
||||
}
|
||||
|
||||
func (p *provider) Proxied() bool {
|
||||
func (p *Provider) Proxied() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *provider) BuildDomainName() string {
|
||||
func (p *Provider) BuildDomainName() string {
|
||||
return utils.BuildDomainName(p.host, p.domain)
|
||||
}
|
||||
|
||||
func (p *provider) HTML() models.HTMLRow {
|
||||
func (p *Provider) HTML() models.HTMLRow {
|
||||
return models.HTMLRow{
|
||||
Domain: models.HTML(fmt.Sprintf("<a href=\"http://%s\">%s</a>", p.BuildDomainName(), p.BuildDomainName())),
|
||||
Host: models.HTML(p.Host()),
|
||||
@@ -97,7 +97,7 @@ func (p *provider) HTML() models.HTMLRow {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
func (p *Provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
u := url.URL{
|
||||
Scheme: "https",
|
||||
Host: "dyndns.kasserver.com",
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/ddns-updater/internal/models"
|
||||
"github.com/qdm12/ddns-updater/internal/regex"
|
||||
"github.com/qdm12/ddns-updater/internal/settings/common"
|
||||
"github.com/qdm12/ddns-updater/internal/settings/constants"
|
||||
"github.com/qdm12/ddns-updater/internal/settings/errors"
|
||||
"github.com/qdm12/ddns-updater/internal/settings/headers"
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
"github.com/qdm12/golibs/verification"
|
||||
)
|
||||
|
||||
type provider struct {
|
||||
type Provider struct {
|
||||
domain string
|
||||
host string
|
||||
ipVersion ipversion.IPVersion
|
||||
@@ -31,11 +31,11 @@ type provider struct {
|
||||
zoneIdentifier string
|
||||
proxied bool
|
||||
ttl uint
|
||||
matcher regex.Matcher
|
||||
matcher common.Matcher
|
||||
}
|
||||
|
||||
func New(data json.RawMessage, domain, host string, ipVersion ipversion.IPVersion,
|
||||
matcher regex.Matcher) (p *provider, err error) {
|
||||
matcher common.Matcher) (p *Provider, err error) {
|
||||
extraSettings := struct {
|
||||
Key string `json:"key"`
|
||||
Token string `json:"token"`
|
||||
@@ -48,7 +48,7 @@ func New(data json.RawMessage, domain, host string, ipVersion ipversion.IPVersio
|
||||
if err := json.Unmarshal(data, &extraSettings); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p = &provider{
|
||||
p = &Provider{
|
||||
domain: domain,
|
||||
host: host,
|
||||
ipVersion: ipVersion,
|
||||
@@ -67,7 +67,7 @@ func New(data json.RawMessage, domain, host string, ipVersion ipversion.IPVersio
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (p *provider) isValid() error {
|
||||
func (p *Provider) isValid() error {
|
||||
switch {
|
||||
case len(p.key) > 0: // email and key must be provided
|
||||
switch {
|
||||
@@ -91,31 +91,31 @@ func (p *provider) isValid() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *provider) String() string {
|
||||
func (p *Provider) String() string {
|
||||
return utils.ToString(p.domain, p.host, constants.Cloudflare, p.ipVersion)
|
||||
}
|
||||
|
||||
func (p *provider) Domain() string {
|
||||
func (p *Provider) Domain() string {
|
||||
return p.domain
|
||||
}
|
||||
|
||||
func (p *provider) Host() string {
|
||||
func (p *Provider) Host() string {
|
||||
return p.host
|
||||
}
|
||||
|
||||
func (p *provider) IPVersion() ipversion.IPVersion {
|
||||
func (p *Provider) IPVersion() ipversion.IPVersion {
|
||||
return p.ipVersion
|
||||
}
|
||||
|
||||
func (p *provider) Proxied() bool {
|
||||
func (p *Provider) Proxied() bool {
|
||||
return p.proxied
|
||||
}
|
||||
|
||||
func (p *provider) BuildDomainName() string {
|
||||
func (p *Provider) BuildDomainName() string {
|
||||
return utils.BuildDomainName(p.host, p.domain)
|
||||
}
|
||||
|
||||
func (p *provider) HTML() models.HTMLRow {
|
||||
func (p *Provider) HTML() models.HTMLRow {
|
||||
return models.HTMLRow{
|
||||
Domain: models.HTML(fmt.Sprintf("<a href=\"http://%s\">%s</a>", p.BuildDomainName(), p.BuildDomainName())),
|
||||
Host: models.HTML(p.Host()),
|
||||
@@ -124,7 +124,7 @@ func (p *provider) HTML() models.HTMLRow {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *provider) setHeaders(request *http.Request) {
|
||||
func (p *Provider) setHeaders(request *http.Request) {
|
||||
headers.SetUserAgent(request)
|
||||
headers.SetContentType(request, "application/json")
|
||||
headers.SetAccept(request, "application/json")
|
||||
@@ -141,7 +141,7 @@ func (p *provider) setHeaders(request *http.Request) {
|
||||
|
||||
// Obtain domain ID.
|
||||
// See https://api.cloudflare.com/#dns-records-for-a-zone-list-dns-records.
|
||||
func (p *provider) getRecordID(ctx context.Context, client *http.Client, newIP net.IP) (
|
||||
func (p *Provider) getRecordID(ctx context.Context, client *http.Client, newIP net.IP) (
|
||||
identifier string, upToDate bool, err error) {
|
||||
recordType := constants.A
|
||||
if newIP.To4() == nil {
|
||||
@@ -207,7 +207,7 @@ func (p *provider) getRecordID(ctx context.Context, client *http.Client, newIP n
|
||||
return listRecordsResponse.Result[0].ID, false, nil
|
||||
}
|
||||
|
||||
func (p *provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
func (p *Provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
recordType := constants.A
|
||||
if ip.To4() == nil {
|
||||
recordType = constants.AAAA
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
"github.com/qdm12/ddns-updater/pkg/publicip/ipversion"
|
||||
)
|
||||
|
||||
type provider struct {
|
||||
type Provider struct {
|
||||
domain string
|
||||
host string
|
||||
ipVersion ipversion.IPVersion
|
||||
@@ -28,7 +28,7 @@ type provider struct {
|
||||
|
||||
func New(data json.RawMessage, domain, host string,
|
||||
ipVersion ipversion.IPVersion) (
|
||||
p *provider, err error) {
|
||||
p *Provider, err error) {
|
||||
extraSettings := struct {
|
||||
Password string `json:"password"`
|
||||
UseProviderIP bool `json:"provider_ip"`
|
||||
@@ -36,7 +36,7 @@ func New(data json.RawMessage, domain, host string,
|
||||
if err := json.Unmarshal(data, &extraSettings); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p = &provider{
|
||||
p = &Provider{
|
||||
domain: domain,
|
||||
host: host,
|
||||
ipVersion: ipVersion,
|
||||
@@ -49,38 +49,38 @@ func New(data json.RawMessage, domain, host string,
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (p *provider) isValid() error {
|
||||
func (p *Provider) isValid() error {
|
||||
if len(p.password) == 0 {
|
||||
return errors.ErrEmptyPassword
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *provider) String() string {
|
||||
func (p *Provider) String() string {
|
||||
return utils.ToString(p.domain, p.host, constants.Dd24, p.ipVersion)
|
||||
}
|
||||
|
||||
func (p *provider) Domain() string {
|
||||
func (p *Provider) Domain() string {
|
||||
return p.domain
|
||||
}
|
||||
|
||||
func (p *provider) Host() string {
|
||||
func (p *Provider) Host() string {
|
||||
return p.host
|
||||
}
|
||||
|
||||
func (p *provider) IPVersion() ipversion.IPVersion {
|
||||
func (p *Provider) IPVersion() ipversion.IPVersion {
|
||||
return p.ipVersion
|
||||
}
|
||||
|
||||
func (p *provider) Proxied() bool {
|
||||
func (p *Provider) Proxied() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *provider) BuildDomainName() string {
|
||||
func (p *Provider) BuildDomainName() string {
|
||||
return utils.BuildDomainName(p.host, p.domain)
|
||||
}
|
||||
|
||||
func (p *provider) HTML() models.HTMLRow {
|
||||
func (p *Provider) HTML() models.HTMLRow {
|
||||
return models.HTMLRow{
|
||||
Domain: models.HTML(fmt.Sprintf("<a href=\"http://%s\">%s</a>", p.BuildDomainName(), p.BuildDomainName())),
|
||||
Host: models.HTML(p.Host()),
|
||||
@@ -89,7 +89,7 @@ func (p *provider) HTML() models.HTMLRow {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
func (p *Provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
// see https://www.domaindiscount24.com/faq/en/dynamic-dns
|
||||
u := url.URL{
|
||||
Scheme: "https",
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
"github.com/qdm12/ddns-updater/pkg/publicip/ipversion"
|
||||
)
|
||||
|
||||
type provider struct {
|
||||
type Provider struct {
|
||||
domain string
|
||||
host string
|
||||
ipVersion ipversion.IPVersion
|
||||
@@ -28,7 +28,7 @@ type provider struct {
|
||||
}
|
||||
|
||||
func New(data json.RawMessage, domain, host string,
|
||||
ipVersion ipversion.IPVersion) (p *provider, err error) {
|
||||
ipVersion ipversion.IPVersion) (p *Provider, err error) {
|
||||
extraSettings := struct {
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
@@ -37,7 +37,7 @@ func New(data json.RawMessage, domain, host string,
|
||||
if err := json.Unmarshal(data, &extraSettings); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p = &provider{
|
||||
p = &Provider{
|
||||
domain: domain,
|
||||
host: host,
|
||||
ipVersion: ipVersion,
|
||||
@@ -51,7 +51,7 @@ func New(data json.RawMessage, domain, host string,
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (p *provider) isValid() error {
|
||||
func (p *Provider) isValid() error {
|
||||
switch {
|
||||
case len(p.username) == 0:
|
||||
return errors.ErrEmptyUsername
|
||||
@@ -63,31 +63,31 @@ func (p *provider) isValid() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *provider) String() string {
|
||||
func (p *Provider) String() string {
|
||||
return utils.ToString(p.domain, p.host, constants.DdnssDe, p.ipVersion)
|
||||
}
|
||||
|
||||
func (p *provider) Domain() string {
|
||||
func (p *Provider) Domain() string {
|
||||
return p.domain
|
||||
}
|
||||
|
||||
func (p *provider) Host() string {
|
||||
func (p *Provider) Host() string {
|
||||
return p.host
|
||||
}
|
||||
|
||||
func (p *provider) IPVersion() ipversion.IPVersion {
|
||||
func (p *Provider) IPVersion() ipversion.IPVersion {
|
||||
return p.ipVersion
|
||||
}
|
||||
|
||||
func (p *provider) Proxied() bool {
|
||||
func (p *Provider) Proxied() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *provider) BuildDomainName() string {
|
||||
func (p *Provider) BuildDomainName() string {
|
||||
return utils.BuildDomainName(p.host, p.domain)
|
||||
}
|
||||
|
||||
func (p *provider) HTML() models.HTMLRow {
|
||||
func (p *Provider) HTML() models.HTMLRow {
|
||||
return models.HTMLRow{
|
||||
Domain: models.HTML(fmt.Sprintf("<a href=\"http://%s\">%s</a>", p.BuildDomainName(), p.BuildDomainName())),
|
||||
Host: models.HTML(p.Host()),
|
||||
@@ -96,7 +96,7 @@ func (p *provider) HTML() models.HTMLRow {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
func (p *Provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
u := url.URL{
|
||||
Scheme: "https",
|
||||
Host: "www.ddnss.de",
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
"github.com/qdm12/ddns-updater/pkg/publicip/ipversion"
|
||||
)
|
||||
|
||||
type provider struct {
|
||||
type Provider struct {
|
||||
domain string
|
||||
host string
|
||||
ipVersion ipversion.IPVersion
|
||||
@@ -25,14 +25,14 @@ type provider struct {
|
||||
}
|
||||
|
||||
func New(data json.RawMessage, domain, host string,
|
||||
ipVersion ipversion.IPVersion) (p *provider, err error) {
|
||||
ipVersion ipversion.IPVersion) (p *Provider, err error) {
|
||||
extraSettings := struct {
|
||||
Token string `json:"token"`
|
||||
}{}
|
||||
if err := json.Unmarshal(data, &extraSettings); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p = &provider{
|
||||
p = &Provider{
|
||||
domain: domain,
|
||||
host: host,
|
||||
ipVersion: ipVersion,
|
||||
@@ -44,38 +44,38 @@ func New(data json.RawMessage, domain, host string,
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (p *provider) isValid() error {
|
||||
func (p *Provider) isValid() error {
|
||||
if len(p.token) == 0 {
|
||||
return errors.ErrEmptyToken
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *provider) String() string {
|
||||
func (p *Provider) String() string {
|
||||
return utils.ToString(p.domain, p.host, constants.DigitalOcean, p.ipVersion)
|
||||
}
|
||||
|
||||
func (p *provider) Domain() string {
|
||||
func (p *Provider) Domain() string {
|
||||
return p.domain
|
||||
}
|
||||
|
||||
func (p *provider) Host() string {
|
||||
func (p *Provider) Host() string {
|
||||
return p.host
|
||||
}
|
||||
|
||||
func (p *provider) IPVersion() ipversion.IPVersion {
|
||||
func (p *Provider) IPVersion() ipversion.IPVersion {
|
||||
return p.ipVersion
|
||||
}
|
||||
|
||||
func (p *provider) Proxied() bool {
|
||||
func (p *Provider) Proxied() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *provider) BuildDomainName() string {
|
||||
func (p *Provider) BuildDomainName() string {
|
||||
return utils.BuildDomainName(p.host, p.domain)
|
||||
}
|
||||
|
||||
func (p *provider) HTML() models.HTMLRow {
|
||||
func (p *Provider) HTML() models.HTMLRow {
|
||||
return models.HTMLRow{
|
||||
Domain: models.HTML(fmt.Sprintf("<a href=\"http://%s\">%s</a>", p.BuildDomainName(), p.BuildDomainName())),
|
||||
Host: models.HTML(p.Host()),
|
||||
@@ -84,14 +84,14 @@ func (p *provider) HTML() models.HTMLRow {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *provider) setHeaders(request *http.Request) {
|
||||
func (p *Provider) setHeaders(request *http.Request) {
|
||||
headers.SetUserAgent(request)
|
||||
headers.SetContentType(request, "application/json")
|
||||
headers.SetAccept(request, "application/json")
|
||||
headers.SetAuthBearer(request, p.token)
|
||||
}
|
||||
|
||||
func (p *provider) getRecordID(ctx context.Context, recordType string, client *http.Client) (
|
||||
func (p *Provider) getRecordID(ctx context.Context, recordType string, client *http.Client) (
|
||||
recordID int, err error) {
|
||||
values := url.Values{}
|
||||
values.Set("name", utils.BuildURLQueryHostname(p.host, p.domain))
|
||||
@@ -139,7 +139,7 @@ func (p *provider) getRecordID(ctx context.Context, recordType string, client *h
|
||||
return result.DomainRecords[0].ID, nil
|
||||
}
|
||||
|
||||
func (p *provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
func (p *Provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
recordType := constants.A
|
||||
if ip.To4() == nil { // IPv6
|
||||
recordType = constants.AAAA
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/ddns-updater/internal/models"
|
||||
"github.com/qdm12/ddns-updater/internal/regex"
|
||||
"github.com/qdm12/ddns-updater/internal/settings/common"
|
||||
"github.com/qdm12/ddns-updater/internal/settings/constants"
|
||||
"github.com/qdm12/ddns-updater/internal/settings/errors"
|
||||
"github.com/qdm12/ddns-updater/internal/settings/headers"
|
||||
@@ -20,18 +20,18 @@ import (
|
||||
"github.com/qdm12/golibs/verification"
|
||||
)
|
||||
|
||||
type provider struct {
|
||||
type Provider struct {
|
||||
domain string
|
||||
host string
|
||||
ipVersion ipversion.IPVersion
|
||||
username string
|
||||
password string
|
||||
useProviderIP bool
|
||||
matcher regex.Matcher
|
||||
matcher common.Matcher
|
||||
}
|
||||
|
||||
func New(data json.RawMessage, domain, host string, ipVersion ipversion.IPVersion,
|
||||
matcher regex.Matcher) (p *provider, err error) {
|
||||
matcher common.Matcher) (p *Provider, err error) {
|
||||
extraSettings := struct {
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
@@ -40,7 +40,7 @@ func New(data json.RawMessage, domain, host string, ipVersion ipversion.IPVersio
|
||||
if err := json.Unmarshal(data, &extraSettings); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p = &provider{
|
||||
p = &Provider{
|
||||
domain: domain,
|
||||
host: host,
|
||||
ipVersion: ipVersion,
|
||||
@@ -55,7 +55,7 @@ func New(data json.RawMessage, domain, host string, ipVersion ipversion.IPVersio
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (p *provider) isValid() error {
|
||||
func (p *Provider) isValid() error {
|
||||
switch {
|
||||
case !p.matcher.DNSOMaticUsername(p.username):
|
||||
return fmt.Errorf("%w: %s", errors.ErrMalformedUsername, p.username)
|
||||
@@ -69,31 +69,31 @@ func (p *provider) isValid() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *provider) String() string {
|
||||
return utils.ToString(p.domain, p.host, constants.DnsOMatic, p.ipVersion)
|
||||
func (p *Provider) String() string {
|
||||
return utils.ToString(p.domain, p.host, constants.DNSOMatic, p.ipVersion)
|
||||
}
|
||||
|
||||
func (p *provider) Domain() string {
|
||||
func (p *Provider) Domain() string {
|
||||
return p.domain
|
||||
}
|
||||
|
||||
func (p *provider) Host() string {
|
||||
func (p *Provider) Host() string {
|
||||
return p.host
|
||||
}
|
||||
|
||||
func (p *provider) IPVersion() ipversion.IPVersion {
|
||||
func (p *Provider) IPVersion() ipversion.IPVersion {
|
||||
return p.ipVersion
|
||||
}
|
||||
|
||||
func (p *provider) Proxied() bool {
|
||||
func (p *Provider) Proxied() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *provider) BuildDomainName() string {
|
||||
func (p *Provider) BuildDomainName() string {
|
||||
return utils.BuildDomainName(p.host, p.domain)
|
||||
}
|
||||
|
||||
func (p *provider) HTML() models.HTMLRow {
|
||||
func (p *Provider) HTML() models.HTMLRow {
|
||||
return models.HTMLRow{
|
||||
Domain: models.HTML(fmt.Sprintf("<a href=\"http://%s\">%s</a>", p.BuildDomainName(), p.BuildDomainName())),
|
||||
Host: models.HTML(p.Host()),
|
||||
@@ -102,7 +102,7 @@ func (p *provider) HTML() models.HTMLRow {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
func (p *Provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
// Multiple hosts can be updated in one query, see https://www.dnsomatic.com/docs/api
|
||||
u := url.URL{
|
||||
Scheme: "https",
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
"github.com/qdm12/ddns-updater/pkg/publicip/ipversion"
|
||||
)
|
||||
|
||||
type provider struct {
|
||||
type Provider struct {
|
||||
domain string
|
||||
host string
|
||||
ipVersion ipversion.IPVersion
|
||||
@@ -25,14 +25,14 @@ type provider struct {
|
||||
}
|
||||
|
||||
func New(data json.RawMessage, domain, host string,
|
||||
ipVersion ipversion.IPVersion) (p *provider, err error) {
|
||||
ipVersion ipversion.IPVersion) (p *Provider, err error) {
|
||||
extraSettings := struct {
|
||||
Token string `json:"token"`
|
||||
}{}
|
||||
if err := json.Unmarshal(data, &extraSettings); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p = &provider{
|
||||
p = &Provider{
|
||||
domain: domain,
|
||||
host: host,
|
||||
ipVersion: ipVersion,
|
||||
@@ -44,38 +44,38 @@ func New(data json.RawMessage, domain, host string,
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (p *provider) isValid() error {
|
||||
func (p *Provider) isValid() error {
|
||||
if len(p.token) == 0 {
|
||||
return errors.ErrEmptyToken
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *provider) String() string {
|
||||
func (p *Provider) String() string {
|
||||
return utils.ToString(p.domain, p.host, constants.DNSPod, p.ipVersion)
|
||||
}
|
||||
|
||||
func (p *provider) Domain() string {
|
||||
func (p *Provider) Domain() string {
|
||||
return p.domain
|
||||
}
|
||||
|
||||
func (p *provider) Host() string {
|
||||
func (p *Provider) Host() string {
|
||||
return p.host
|
||||
}
|
||||
|
||||
func (p *provider) IPVersion() ipversion.IPVersion {
|
||||
func (p *Provider) IPVersion() ipversion.IPVersion {
|
||||
return p.ipVersion
|
||||
}
|
||||
|
||||
func (p *provider) Proxied() bool {
|
||||
func (p *Provider) Proxied() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *provider) BuildDomainName() string {
|
||||
func (p *Provider) BuildDomainName() string {
|
||||
return utils.BuildDomainName(p.host, p.domain)
|
||||
}
|
||||
|
||||
func (p *provider) HTML() models.HTMLRow {
|
||||
func (p *Provider) HTML() models.HTMLRow {
|
||||
return models.HTMLRow{
|
||||
Domain: models.HTML(fmt.Sprintf("<a href=\"http://%s\">%s</a>", p.BuildDomainName(), p.BuildDomainName())),
|
||||
Host: models.HTML(p.Host()),
|
||||
@@ -84,13 +84,13 @@ func (p *provider) HTML() models.HTMLRow {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *provider) setHeaders(request *http.Request) {
|
||||
func (p *Provider) setHeaders(request *http.Request) {
|
||||
headers.SetContentType(request, "application/x-www-form-urlencoded")
|
||||
headers.SetAccept(request, "application/json")
|
||||
headers.SetUserAgent(request)
|
||||
}
|
||||
|
||||
func (p *provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
func (p *Provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
recordType := constants.A
|
||||
if ip.To4() == nil {
|
||||
recordType = constants.AAAA
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
"github.com/qdm12/ddns-updater/pkg/publicip/ipversion"
|
||||
)
|
||||
|
||||
type provider struct {
|
||||
type Provider struct {
|
||||
domain string
|
||||
host string
|
||||
ipVersion ipversion.IPVersion
|
||||
@@ -27,7 +27,7 @@ type provider struct {
|
||||
}
|
||||
|
||||
func New(data json.RawMessage, domain, host string,
|
||||
ipVersion ipversion.IPVersion) (p *provider, err error) {
|
||||
ipVersion ipversion.IPVersion) (p *Provider, err error) {
|
||||
extraSettings := struct {
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
@@ -39,7 +39,7 @@ func New(data json.RawMessage, domain, host string,
|
||||
if len(host) == 0 {
|
||||
host = "@" // default
|
||||
}
|
||||
p = &provider{
|
||||
p = &Provider{
|
||||
domain: domain,
|
||||
host: host,
|
||||
ipVersion: ipVersion,
|
||||
@@ -53,7 +53,7 @@ func New(data json.RawMessage, domain, host string,
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (p *provider) isValid() error {
|
||||
func (p *Provider) isValid() error {
|
||||
switch {
|
||||
case len(p.username) == 0:
|
||||
return errors.ErrEmptyUsername
|
||||
@@ -67,31 +67,31 @@ func (p *provider) isValid() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *provider) String() string {
|
||||
func (p *Provider) String() string {
|
||||
return utils.ToString(p.domain, p.host, constants.DonDominio, p.ipVersion)
|
||||
}
|
||||
|
||||
func (p *provider) Domain() string {
|
||||
func (p *Provider) Domain() string {
|
||||
return p.domain
|
||||
}
|
||||
|
||||
func (p *provider) Host() string {
|
||||
func (p *Provider) Host() string {
|
||||
return p.host
|
||||
}
|
||||
|
||||
func (p *provider) IPVersion() ipversion.IPVersion {
|
||||
func (p *Provider) IPVersion() ipversion.IPVersion {
|
||||
return p.ipVersion
|
||||
}
|
||||
|
||||
func (p *provider) Proxied() bool {
|
||||
func (p *Provider) Proxied() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *provider) BuildDomainName() string {
|
||||
func (p *Provider) BuildDomainName() string {
|
||||
return utils.BuildDomainName(p.host, p.domain)
|
||||
}
|
||||
|
||||
func (p *provider) HTML() models.HTMLRow {
|
||||
func (p *Provider) HTML() models.HTMLRow {
|
||||
return models.HTMLRow{
|
||||
Domain: models.HTML(fmt.Sprintf("<a href=\"http://%s\">%s</a>", p.BuildDomainName(), p.BuildDomainName())),
|
||||
Host: models.HTML(p.Host()),
|
||||
@@ -100,13 +100,13 @@ func (p *provider) HTML() models.HTMLRow {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *provider) setHeaders(request *http.Request) {
|
||||
func (p *Provider) setHeaders(request *http.Request) {
|
||||
headers.SetUserAgent(request)
|
||||
headers.SetContentType(request, "application/x-www-form-urlencoded")
|
||||
headers.SetAccept(request, "application/json")
|
||||
}
|
||||
|
||||
func (p *provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
func (p *Provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
u := url.URL{
|
||||
Scheme: "https",
|
||||
Host: "simple-api.dondominio.net",
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"net/url"
|
||||
|
||||
"github.com/qdm12/ddns-updater/internal/models"
|
||||
"github.com/qdm12/ddns-updater/internal/regex"
|
||||
"github.com/qdm12/ddns-updater/internal/settings/common"
|
||||
"github.com/qdm12/ddns-updater/internal/settings/constants"
|
||||
"github.com/qdm12/ddns-updater/internal/settings/errors"
|
||||
"github.com/qdm12/ddns-updater/internal/settings/headers"
|
||||
@@ -19,16 +19,16 @@ import (
|
||||
"github.com/qdm12/ddns-updater/pkg/publicip/ipversion"
|
||||
)
|
||||
|
||||
type provider struct {
|
||||
type Provider struct {
|
||||
domain string
|
||||
host string
|
||||
ipVersion ipversion.IPVersion
|
||||
key string
|
||||
matcher regex.Matcher
|
||||
matcher common.Matcher
|
||||
}
|
||||
|
||||
func New(data json.RawMessage, domain, host string, ipVersion ipversion.IPVersion,
|
||||
matcher regex.Matcher) (p *provider, err error) {
|
||||
matcher common.Matcher) (p *Provider, err error) {
|
||||
extraSettings := struct {
|
||||
Key string `json:"key"`
|
||||
}{}
|
||||
@@ -38,7 +38,7 @@ func New(data json.RawMessage, domain, host string, ipVersion ipversion.IPVersio
|
||||
if host == "" { // TODO-v2 remove default
|
||||
host = "@" // default
|
||||
}
|
||||
p = &provider{
|
||||
p = &Provider{
|
||||
domain: domain,
|
||||
host: host,
|
||||
ipVersion: ipVersion,
|
||||
@@ -51,38 +51,38 @@ func New(data json.RawMessage, domain, host string, ipVersion ipversion.IPVersio
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (p *provider) isValid() error {
|
||||
func (p *Provider) isValid() error {
|
||||
if !p.matcher.DreamhostKey(p.key) {
|
||||
return fmt.Errorf("invalid key format")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *provider) String() string {
|
||||
func (p *Provider) String() string {
|
||||
return utils.ToString(p.domain, p.host, constants.Dreamhost, p.ipVersion)
|
||||
}
|
||||
|
||||
func (p *provider) Domain() string {
|
||||
func (p *Provider) Domain() string {
|
||||
return p.domain
|
||||
}
|
||||
|
||||
func (p *provider) Host() string {
|
||||
func (p *Provider) Host() string {
|
||||
return p.host
|
||||
}
|
||||
|
||||
func (p *provider) IPVersion() ipversion.IPVersion {
|
||||
func (p *Provider) IPVersion() ipversion.IPVersion {
|
||||
return p.ipVersion
|
||||
}
|
||||
|
||||
func (p *provider) Proxied() bool {
|
||||
func (p *Provider) Proxied() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *provider) BuildDomainName() string {
|
||||
func (p *Provider) BuildDomainName() string {
|
||||
return utils.BuildDomainName(p.host, p.domain)
|
||||
}
|
||||
|
||||
func (p *provider) HTML() models.HTMLRow {
|
||||
func (p *Provider) HTML() models.HTMLRow {
|
||||
return models.HTMLRow{
|
||||
Domain: models.HTML(fmt.Sprintf("<a href=\"http://%s\">%s</a>", p.BuildDomainName(), p.BuildDomainName())),
|
||||
Host: models.HTML(p.Host()),
|
||||
@@ -91,7 +91,7 @@ func (p *provider) HTML() models.HTMLRow {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
func (p *Provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
recordType := constants.A
|
||||
if ip.To4() == nil {
|
||||
recordType = constants.AAAA
|
||||
@@ -146,7 +146,7 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func (p *provider) defaultURLValues() (values url.Values) {
|
||||
func (p *Provider) defaultURLValues() (values url.Values) {
|
||||
uuid := make([]byte, 16) //nolint:gomnd
|
||||
_, _ = io.ReadFull(rand.Reader, uuid)
|
||||
//nolint:gomnd
|
||||
@@ -160,7 +160,7 @@ func (p *provider) defaultURLValues() (values url.Values) {
|
||||
return values
|
||||
}
|
||||
|
||||
func (p *provider) getRecords(ctx context.Context, client *http.Client) (
|
||||
func (p *Provider) getRecords(ctx context.Context, client *http.Client) (
|
||||
records dreamHostRecords, err error) {
|
||||
u := url.URL{
|
||||
Scheme: "https",
|
||||
@@ -198,7 +198,7 @@ func (p *provider) getRecords(ctx context.Context, client *http.Client) (
|
||||
return records, nil
|
||||
}
|
||||
|
||||
func (p *provider) removeRecord(ctx context.Context, client *http.Client, ip net.IP) error { //nolint:dupl
|
||||
func (p *Provider) removeRecord(ctx context.Context, client *http.Client, ip net.IP) error { //nolint:dupl
|
||||
recordType := constants.A
|
||||
if ip.To4() == nil {
|
||||
recordType = constants.AAAA
|
||||
@@ -245,7 +245,7 @@ func (p *provider) removeRecord(ctx context.Context, client *http.Client, ip net
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *provider) createRecord(ctx context.Context, client *http.Client, ip net.IP) error { //nolint:dupl
|
||||
func (p *Provider) createRecord(ctx context.Context, client *http.Client, ip net.IP) error { //nolint:dupl
|
||||
recordType := constants.A
|
||||
if ip.To4() == nil {
|
||||
recordType = constants.AAAA
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"net/url"
|
||||
|
||||
"github.com/qdm12/ddns-updater/internal/models"
|
||||
"github.com/qdm12/ddns-updater/internal/regex"
|
||||
"github.com/qdm12/ddns-updater/internal/settings/common"
|
||||
"github.com/qdm12/ddns-updater/internal/settings/constants"
|
||||
"github.com/qdm12/ddns-updater/internal/settings/errors"
|
||||
"github.com/qdm12/ddns-updater/internal/settings/headers"
|
||||
@@ -19,16 +19,16 @@ import (
|
||||
"github.com/qdm12/golibs/verification"
|
||||
)
|
||||
|
||||
type provider struct {
|
||||
type Provider struct {
|
||||
host string
|
||||
ipVersion ipversion.IPVersion
|
||||
token string
|
||||
useProviderIP bool
|
||||
matcher regex.Matcher
|
||||
matcher common.Matcher
|
||||
}
|
||||
|
||||
func New(data json.RawMessage, domain, host string, ipVersion ipversion.IPVersion,
|
||||
matcher regex.Matcher) (p *provider, err error) {
|
||||
matcher common.Matcher) (p *Provider, err error) {
|
||||
extraSettings := struct {
|
||||
Token string `json:"token"`
|
||||
UseProviderIP bool `json:"provider_ip"`
|
||||
@@ -36,7 +36,7 @@ func New(data json.RawMessage, domain, host string, ipVersion ipversion.IPVersio
|
||||
if err := json.Unmarshal(data, &extraSettings); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p = &provider{
|
||||
p = &Provider{
|
||||
host: host,
|
||||
ipVersion: ipVersion,
|
||||
token: extraSettings.Token,
|
||||
@@ -49,7 +49,7 @@ func New(data json.RawMessage, domain, host string, ipVersion ipversion.IPVersio
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (p *provider) isValid() error {
|
||||
func (p *Provider) isValid() error {
|
||||
if !p.matcher.DuckDNSToken(p.token) {
|
||||
return errors.ErrMalformedToken
|
||||
}
|
||||
@@ -60,31 +60,31 @@ func (p *provider) isValid() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *provider) String() string {
|
||||
func (p *Provider) String() string {
|
||||
return utils.ToString("duckdns.org", p.host, constants.DuckDNS, p.ipVersion)
|
||||
}
|
||||
|
||||
func (p *provider) Domain() string {
|
||||
func (p *Provider) Domain() string {
|
||||
return "duckdns.org"
|
||||
}
|
||||
|
||||
func (p *provider) Host() string {
|
||||
func (p *Provider) Host() string {
|
||||
return p.host
|
||||
}
|
||||
|
||||
func (p *provider) IPVersion() ipversion.IPVersion {
|
||||
func (p *Provider) IPVersion() ipversion.IPVersion {
|
||||
return p.ipVersion
|
||||
}
|
||||
|
||||
func (p *provider) Proxied() bool {
|
||||
func (p *Provider) Proxied() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *provider) BuildDomainName() string {
|
||||
func (p *Provider) BuildDomainName() string {
|
||||
return utils.BuildDomainName(p.host, "duckdns.org")
|
||||
}
|
||||
|
||||
func (p *provider) HTML() models.HTMLRow {
|
||||
func (p *Provider) HTML() models.HTMLRow {
|
||||
return models.HTMLRow{
|
||||
Domain: models.HTML(fmt.Sprintf("<a href=\"http://%s\">%s</a>", p.BuildDomainName(), p.BuildDomainName())),
|
||||
Host: models.HTML(p.Host()),
|
||||
@@ -93,7 +93,7 @@ func (p *provider) HTML() models.HTMLRow {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
func (p *Provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
u := url.URL{
|
||||
Scheme: "https",
|
||||
Host: "www.duckdns.org",
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
"github.com/qdm12/ddns-updater/pkg/publicip/ipversion"
|
||||
)
|
||||
|
||||
type provider struct {
|
||||
type Provider struct {
|
||||
domain string
|
||||
host string
|
||||
ipVersion ipversion.IPVersion
|
||||
@@ -28,7 +28,7 @@ type provider struct {
|
||||
}
|
||||
|
||||
func New(data json.RawMessage, domain, host string,
|
||||
ipVersion ipversion.IPVersion) (p *provider, err error) {
|
||||
ipVersion ipversion.IPVersion) (p *Provider, err error) {
|
||||
extraSettings := struct {
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
@@ -37,7 +37,7 @@ func New(data json.RawMessage, domain, host string,
|
||||
if err := json.Unmarshal(data, &extraSettings); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p = &provider{
|
||||
p = &Provider{
|
||||
domain: domain,
|
||||
host: host,
|
||||
ipVersion: ipVersion,
|
||||
@@ -51,7 +51,7 @@ func New(data json.RawMessage, domain, host string,
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (p *provider) isValid() error {
|
||||
func (p *Provider) isValid() error {
|
||||
switch {
|
||||
case len(p.username) == 0:
|
||||
return errors.ErrEmptyUsername
|
||||
@@ -63,31 +63,31 @@ func (p *provider) isValid() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *provider) String() string {
|
||||
func (p *Provider) String() string {
|
||||
return fmt.Sprintf("[domain: %s | host: %s | provider: Dyn]", p.domain, p.host)
|
||||
}
|
||||
|
||||
func (p *provider) Domain() string {
|
||||
func (p *Provider) Domain() string {
|
||||
return p.domain
|
||||
}
|
||||
|
||||
func (p *provider) Host() string {
|
||||
func (p *Provider) Host() string {
|
||||
return p.host
|
||||
}
|
||||
|
||||
func (p *provider) IPVersion() ipversion.IPVersion {
|
||||
func (p *Provider) IPVersion() ipversion.IPVersion {
|
||||
return p.ipVersion
|
||||
}
|
||||
|
||||
func (p *provider) Proxied() bool {
|
||||
func (p *Provider) Proxied() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *provider) BuildDomainName() string {
|
||||
func (p *Provider) BuildDomainName() string {
|
||||
return utils.BuildDomainName(p.host, p.domain)
|
||||
}
|
||||
|
||||
func (p *provider) HTML() models.HTMLRow {
|
||||
func (p *Provider) HTML() models.HTMLRow {
|
||||
return models.HTMLRow{
|
||||
Domain: models.HTML(fmt.Sprintf("<a href=\"http://%s\">%s</a>", p.BuildDomainName(), p.BuildDomainName())),
|
||||
Host: models.HTML(p.Host()),
|
||||
@@ -96,7 +96,7 @@ func (p *provider) HTML() models.HTMLRow {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
func (p *Provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
u := url.URL{
|
||||
Scheme: "https",
|
||||
User: url.UserPassword(p.username, p.password),
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
"github.com/qdm12/ddns-updater/pkg/publicip/ipversion"
|
||||
)
|
||||
|
||||
type provider struct {
|
||||
type Provider struct {
|
||||
domain string
|
||||
host string
|
||||
group string
|
||||
@@ -29,7 +29,7 @@ type provider struct {
|
||||
}
|
||||
|
||||
func New(data json.RawMessage, domain, host string,
|
||||
ipVersion ipversion.IPVersion) (p *provider, err error) {
|
||||
ipVersion ipversion.IPVersion) (p *Provider, err error) {
|
||||
extraSettings := struct {
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
@@ -44,7 +44,7 @@ func New(data json.RawMessage, domain, host string,
|
||||
host = "@" // default
|
||||
}
|
||||
|
||||
p = &provider{
|
||||
p = &Provider{
|
||||
domain: domain,
|
||||
host: host,
|
||||
ipVersion: ipVersion,
|
||||
@@ -59,7 +59,7 @@ func New(data json.RawMessage, domain, host string,
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (p *provider) isValid() error {
|
||||
func (p *Provider) isValid() error {
|
||||
switch {
|
||||
case p.username == "":
|
||||
return errors.ErrEmptyUsername
|
||||
@@ -71,31 +71,31 @@ func (p *provider) isValid() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *provider) String() string {
|
||||
func (p *Provider) String() string {
|
||||
return utils.ToString(p.domain, p.host, constants.Dynu, p.ipVersion)
|
||||
}
|
||||
|
||||
func (p *provider) Domain() string {
|
||||
func (p *Provider) Domain() string {
|
||||
return p.domain
|
||||
}
|
||||
|
||||
func (p *provider) Host() string {
|
||||
func (p *Provider) Host() string {
|
||||
return p.host
|
||||
}
|
||||
|
||||
func (p *provider) IPVersion() ipversion.IPVersion {
|
||||
func (p *Provider) IPVersion() ipversion.IPVersion {
|
||||
return p.ipVersion
|
||||
}
|
||||
|
||||
func (p *provider) Proxied() bool {
|
||||
func (p *Provider) Proxied() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *provider) BuildDomainName() string {
|
||||
func (p *Provider) BuildDomainName() string {
|
||||
return utils.BuildDomainName(p.host, p.domain)
|
||||
}
|
||||
|
||||
func (p *provider) HTML() models.HTMLRow {
|
||||
func (p *Provider) HTML() models.HTMLRow {
|
||||
return models.HTMLRow{
|
||||
Domain: models.HTML(fmt.Sprintf("<a href=\"http://%s\">%s</a>", p.BuildDomainName(), p.BuildDomainName())),
|
||||
Host: models.HTML(p.Host()),
|
||||
@@ -104,7 +104,7 @@ func (p *provider) HTML() models.HTMLRow {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
func (p *Provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
u := url.URL{
|
||||
Scheme: "https",
|
||||
Host: "api.dynu.com",
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
"github.com/qdm12/ddns-updater/pkg/publicip/ipversion"
|
||||
)
|
||||
|
||||
type provider struct {
|
||||
type Provider struct {
|
||||
domain string
|
||||
host string
|
||||
ipVersion ipversion.IPVersion
|
||||
@@ -24,7 +24,7 @@ type provider struct {
|
||||
}
|
||||
|
||||
func New(data json.RawMessage, domain, host string,
|
||||
ipVersion ipversion.IPVersion) (p *provider, err error) {
|
||||
ipVersion ipversion.IPVersion) (p *Provider, err error) {
|
||||
extraSettings := struct {
|
||||
Token string `json:"token"`
|
||||
UseProviderIP bool `json:"provider_ip"`
|
||||
@@ -32,7 +32,7 @@ func New(data json.RawMessage, domain, host string,
|
||||
if err := json.Unmarshal(data, &extraSettings); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p = &provider{
|
||||
p = &Provider{
|
||||
domain: domain,
|
||||
host: host,
|
||||
ipVersion: ipVersion,
|
||||
@@ -45,7 +45,7 @@ func New(data json.RawMessage, domain, host string,
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (p *provider) isValid() error {
|
||||
func (p *Provider) isValid() error {
|
||||
switch {
|
||||
case len(p.token) == 0:
|
||||
return errors.ErrEmptyToken
|
||||
@@ -55,31 +55,31 @@ func (p *provider) isValid() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *provider) String() string {
|
||||
func (p *Provider) String() string {
|
||||
return fmt.Sprintf("[domain: %s | host: %s | provider: DynV6]", p.domain, p.host)
|
||||
}
|
||||
|
||||
func (p *provider) Domain() string {
|
||||
func (p *Provider) Domain() string {
|
||||
return p.domain
|
||||
}
|
||||
|
||||
func (p *provider) Host() string {
|
||||
func (p *Provider) Host() string {
|
||||
return p.host
|
||||
}
|
||||
|
||||
func (p *provider) IPVersion() ipversion.IPVersion {
|
||||
func (p *Provider) IPVersion() ipversion.IPVersion {
|
||||
return p.ipVersion
|
||||
}
|
||||
|
||||
func (p *provider) Proxied() bool {
|
||||
func (p *Provider) Proxied() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *provider) BuildDomainName() string {
|
||||
func (p *Provider) BuildDomainName() string {
|
||||
return utils.BuildDomainName(p.host, p.domain)
|
||||
}
|
||||
|
||||
func (p *provider) HTML() models.HTMLRow {
|
||||
func (p *Provider) HTML() models.HTMLRow {
|
||||
return models.HTMLRow{
|
||||
Domain: models.HTML(fmt.Sprintf("<a href=\"http://%s\">%s</a>", p.BuildDomainName(), p.BuildDomainName())),
|
||||
Host: models.HTML(p.Host()),
|
||||
@@ -88,7 +88,7 @@ func (p *provider) HTML() models.HTMLRow {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
func (p *Provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
isIPv4 := ip.To4() != nil
|
||||
host := "dynv6.com"
|
||||
if isIPv4 {
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
"github.com/qdm12/ddns-updater/pkg/publicip/ipversion"
|
||||
)
|
||||
|
||||
type provider struct {
|
||||
type Provider struct {
|
||||
domain string
|
||||
host string
|
||||
ipVersion ipversion.IPVersion
|
||||
@@ -26,14 +26,14 @@ type provider struct {
|
||||
}
|
||||
|
||||
func New(data json.RawMessage, domain, host string,
|
||||
ipVersion ipversion.IPVersion) (p *provider, err error) {
|
||||
ipVersion ipversion.IPVersion) (p *Provider, err error) {
|
||||
extraSettings := struct {
|
||||
Token string `json:"token"`
|
||||
}{}
|
||||
if err := json.Unmarshal(data, &extraSettings); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p = &provider{
|
||||
p = &Provider{
|
||||
domain: domain,
|
||||
host: host,
|
||||
ipVersion: ipVersion,
|
||||
@@ -45,38 +45,38 @@ func New(data json.RawMessage, domain, host string,
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (p *provider) isValid() error {
|
||||
func (p *Provider) isValid() error {
|
||||
if len(p.token) == 0 {
|
||||
return errors.ErrEmptyToken
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *provider) String() string {
|
||||
func (p *Provider) String() string {
|
||||
return utils.ToString(p.domain, p.host, constants.FreeDNS, p.ipVersion)
|
||||
}
|
||||
|
||||
func (p *provider) Domain() string {
|
||||
func (p *Provider) Domain() string {
|
||||
return p.domain
|
||||
}
|
||||
|
||||
func (p *provider) Host() string {
|
||||
func (p *Provider) Host() string {
|
||||
return p.host
|
||||
}
|
||||
|
||||
func (p *provider) Proxied() bool {
|
||||
func (p *Provider) Proxied() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *provider) IPVersion() ipversion.IPVersion {
|
||||
func (p *Provider) IPVersion() ipversion.IPVersion {
|
||||
return p.ipVersion
|
||||
}
|
||||
|
||||
func (p *provider) BuildDomainName() string {
|
||||
func (p *Provider) BuildDomainName() string {
|
||||
return utils.BuildDomainName(p.host, p.domain)
|
||||
}
|
||||
|
||||
func (p *provider) HTML() models.HTMLRow {
|
||||
func (p *Provider) HTML() models.HTMLRow {
|
||||
return models.HTMLRow{
|
||||
Domain: models.HTML(fmt.Sprintf("<a href=\"http://%s\">%s</a>", p.BuildDomainName(), p.BuildDomainName())),
|
||||
Host: models.HTML(p.Host()),
|
||||
@@ -85,7 +85,7 @@ func (p *provider) HTML() models.HTMLRow {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
func (p *Provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
var hostPrefix string
|
||||
if ip.To4() == nil {
|
||||
hostPrefix = "v6."
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
"github.com/qdm12/ddns-updater/pkg/publicip/ipversion"
|
||||
)
|
||||
|
||||
type provider struct {
|
||||
type Provider struct {
|
||||
domain string
|
||||
host string
|
||||
ttl int
|
||||
@@ -26,7 +26,7 @@ type provider struct {
|
||||
}
|
||||
|
||||
func New(data json.RawMessage, domain, host string,
|
||||
ipVersion ipversion.IPVersion) (p *provider, err error) {
|
||||
ipVersion ipversion.IPVersion) (p *Provider, err error) {
|
||||
extraSettings := struct {
|
||||
Key string `json:"key"`
|
||||
TTL int `json:"ttl"`
|
||||
@@ -34,7 +34,7 @@ func New(data json.RawMessage, domain, host string,
|
||||
if err := json.Unmarshal(data, &extraSettings); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p = &provider{
|
||||
p = &Provider{
|
||||
domain: domain,
|
||||
host: host,
|
||||
ipVersion: ipVersion,
|
||||
@@ -47,38 +47,38 @@ func New(data json.RawMessage, domain, host string,
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (p *provider) isValid() error {
|
||||
func (p *Provider) isValid() error {
|
||||
if len(p.key) == 0 {
|
||||
return errors.ErrEmptyKey
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *provider) String() string {
|
||||
func (p *Provider) String() string {
|
||||
return utils.ToString(p.domain, p.host, constants.Gandi, p.ipVersion)
|
||||
}
|
||||
|
||||
func (p *provider) Domain() string {
|
||||
func (p *Provider) Domain() string {
|
||||
return p.domain
|
||||
}
|
||||
|
||||
func (p *provider) Host() string {
|
||||
func (p *Provider) Host() string {
|
||||
return p.host
|
||||
}
|
||||
|
||||
func (p *provider) IPVersion() ipversion.IPVersion {
|
||||
func (p *Provider) IPVersion() ipversion.IPVersion {
|
||||
return p.ipVersion
|
||||
}
|
||||
|
||||
func (p *provider) Proxied() bool {
|
||||
func (p *Provider) Proxied() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *provider) BuildDomainName() string {
|
||||
func (p *Provider) BuildDomainName() string {
|
||||
return utils.BuildDomainName(p.host, p.domain)
|
||||
}
|
||||
|
||||
func (p *provider) HTML() models.HTMLRow {
|
||||
func (p *Provider) HTML() models.HTMLRow {
|
||||
return models.HTMLRow{
|
||||
Domain: models.HTML(fmt.Sprintf("<a href=\"http://%s\">%s</a>", p.BuildDomainName(), p.BuildDomainName())),
|
||||
Host: models.HTML(p.Host()),
|
||||
@@ -87,14 +87,14 @@ func (p *provider) HTML() models.HTMLRow {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *provider) setHeaders(request *http.Request) {
|
||||
func (p *Provider) setHeaders(request *http.Request) {
|
||||
headers.SetUserAgent(request)
|
||||
headers.SetContentType(request, "application/json")
|
||||
headers.SetAccept(request, "application/json")
|
||||
request.Header.Set("X-Api-Key", p.key)
|
||||
}
|
||||
|
||||
func (p *provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
func (p *Provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
recordType := constants.A
|
||||
var ipStr string
|
||||
if ip.To4() == nil { // IPv6
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"net/url"
|
||||
|
||||
"github.com/qdm12/ddns-updater/internal/models"
|
||||
"github.com/qdm12/ddns-updater/internal/regex"
|
||||
"github.com/qdm12/ddns-updater/internal/settings/common"
|
||||
"github.com/qdm12/ddns-updater/internal/settings/constants"
|
||||
"github.com/qdm12/ddns-updater/internal/settings/errors"
|
||||
"github.com/qdm12/ddns-updater/internal/settings/headers"
|
||||
@@ -19,17 +19,17 @@ import (
|
||||
"github.com/qdm12/ddns-updater/pkg/publicip/ipversion"
|
||||
)
|
||||
|
||||
type provider struct {
|
||||
type Provider struct {
|
||||
domain string
|
||||
host string
|
||||
ipVersion ipversion.IPVersion
|
||||
key string
|
||||
secret string
|
||||
matcher regex.Matcher
|
||||
matcher common.Matcher
|
||||
}
|
||||
|
||||
func New(data json.RawMessage, domain, host string, ipVersion ipversion.IPVersion,
|
||||
matcher regex.Matcher) (p *provider, err error) {
|
||||
matcher common.Matcher) (p *Provider, err error) {
|
||||
extraSettings := struct {
|
||||
Key string `json:"key"`
|
||||
Secret string `json:"secret"`
|
||||
@@ -37,7 +37,7 @@ func New(data json.RawMessage, domain, host string, ipVersion ipversion.IPVersio
|
||||
if err := json.Unmarshal(data, &extraSettings); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p = &provider{
|
||||
p = &Provider{
|
||||
domain: domain,
|
||||
host: host,
|
||||
ipVersion: ipVersion,
|
||||
@@ -51,7 +51,7 @@ func New(data json.RawMessage, domain, host string, ipVersion ipversion.IPVersio
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (p *provider) isValid() error {
|
||||
func (p *Provider) isValid() error {
|
||||
switch {
|
||||
case !p.matcher.GodaddyKey(p.key):
|
||||
return errors.ErrMalformedKey
|
||||
@@ -61,31 +61,31 @@ func (p *provider) isValid() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *provider) String() string {
|
||||
func (p *Provider) String() string {
|
||||
return utils.ToString(p.domain, p.host, constants.GoDaddy, p.ipVersion)
|
||||
}
|
||||
|
||||
func (p *provider) Domain() string {
|
||||
func (p *Provider) Domain() string {
|
||||
return p.domain
|
||||
}
|
||||
|
||||
func (p *provider) Host() string {
|
||||
func (p *Provider) Host() string {
|
||||
return p.host
|
||||
}
|
||||
|
||||
func (p *provider) IPVersion() ipversion.IPVersion {
|
||||
func (p *Provider) IPVersion() ipversion.IPVersion {
|
||||
return p.ipVersion
|
||||
}
|
||||
|
||||
func (p *provider) Proxied() bool {
|
||||
func (p *Provider) Proxied() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *provider) BuildDomainName() string {
|
||||
func (p *Provider) BuildDomainName() string {
|
||||
return utils.BuildDomainName(p.host, p.domain)
|
||||
}
|
||||
|
||||
func (p *provider) HTML() models.HTMLRow {
|
||||
func (p *Provider) HTML() models.HTMLRow {
|
||||
return models.HTMLRow{
|
||||
Domain: models.HTML(fmt.Sprintf("<a href=\"http://%s\">%s</a>", p.BuildDomainName(), p.BuildDomainName())),
|
||||
Host: models.HTML(p.Host()),
|
||||
@@ -94,14 +94,14 @@ func (p *provider) HTML() models.HTMLRow {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *provider) setHeaders(request *http.Request) {
|
||||
func (p *Provider) setHeaders(request *http.Request) {
|
||||
headers.SetUserAgent(request)
|
||||
headers.SetAuthSSOKey(request, p.key, p.secret)
|
||||
headers.SetContentType(request, "application/json")
|
||||
headers.SetAccept(request, "application/json")
|
||||
}
|
||||
|
||||
func (p *provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
func (p *Provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
recordType := constants.A
|
||||
if ip.To4() == nil {
|
||||
recordType = constants.AAAA
|
||||
|
||||
@@ -19,7 +19,7 @@ import (
|
||||
"github.com/qdm12/golibs/verification"
|
||||
)
|
||||
|
||||
type provider struct {
|
||||
type Provider struct {
|
||||
domain string
|
||||
host string
|
||||
ipVersion ipversion.IPVersion
|
||||
@@ -29,7 +29,7 @@ type provider struct {
|
||||
}
|
||||
|
||||
func New(data json.RawMessage, domain, host string,
|
||||
ipVersion ipversion.IPVersion) (p *provider, err error) {
|
||||
ipVersion ipversion.IPVersion) (p *Provider, err error) {
|
||||
extraSettings := struct {
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
@@ -38,7 +38,7 @@ func New(data json.RawMessage, domain, host string,
|
||||
if err := json.Unmarshal(data, &extraSettings); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p = &provider{
|
||||
p = &Provider{
|
||||
domain: domain,
|
||||
host: host,
|
||||
ipVersion: ipVersion,
|
||||
@@ -52,7 +52,7 @@ func New(data json.RawMessage, domain, host string,
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (p *provider) isValid() error {
|
||||
func (p *Provider) isValid() error {
|
||||
switch {
|
||||
case len(p.username) == 0:
|
||||
return errors.ErrEmptyUsername
|
||||
@@ -62,31 +62,31 @@ func (p *provider) isValid() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *provider) String() string {
|
||||
func (p *Provider) String() string {
|
||||
return utils.ToString(p.domain, p.host, constants.Google, p.ipVersion)
|
||||
}
|
||||
|
||||
func (p *provider) Domain() string {
|
||||
func (p *Provider) Domain() string {
|
||||
return p.domain
|
||||
}
|
||||
|
||||
func (p *provider) Host() string {
|
||||
func (p *Provider) Host() string {
|
||||
return p.host
|
||||
}
|
||||
|
||||
func (p *provider) IPVersion() ipversion.IPVersion {
|
||||
func (p *Provider) IPVersion() ipversion.IPVersion {
|
||||
return p.ipVersion
|
||||
}
|
||||
|
||||
func (p *provider) Proxied() bool {
|
||||
func (p *Provider) Proxied() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *provider) BuildDomainName() string {
|
||||
func (p *Provider) BuildDomainName() string {
|
||||
return utils.BuildDomainName(p.host, p.domain)
|
||||
}
|
||||
|
||||
func (p *provider) HTML() models.HTMLRow {
|
||||
func (p *Provider) HTML() models.HTMLRow {
|
||||
return models.HTMLRow{
|
||||
Domain: models.HTML(fmt.Sprintf("<a href=\"http://%s\">%s</a>", p.BuildDomainName(), p.BuildDomainName())),
|
||||
Host: models.HTML(p.Host()),
|
||||
@@ -95,7 +95,7 @@ func (p *provider) HTML() models.HTMLRow {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
func (p *Provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
u := url.URL{
|
||||
Scheme: "https",
|
||||
Host: "domains.google.com",
|
||||
|
||||
@@ -19,7 +19,7 @@ import (
|
||||
"github.com/qdm12/golibs/verification"
|
||||
)
|
||||
|
||||
type provider struct {
|
||||
type Provider struct {
|
||||
domain string
|
||||
host string
|
||||
ipVersion ipversion.IPVersion
|
||||
@@ -28,7 +28,7 @@ type provider struct {
|
||||
}
|
||||
|
||||
func New(data json.RawMessage, domain, host string,
|
||||
ipVersion ipversion.IPVersion) (p *provider, err error) {
|
||||
ipVersion ipversion.IPVersion) (p *Provider, err error) {
|
||||
extraSettings := struct {
|
||||
Password string `json:"password"`
|
||||
UseProviderIP bool `json:"provider_ip"`
|
||||
@@ -36,7 +36,7 @@ func New(data json.RawMessage, domain, host string,
|
||||
if err := json.Unmarshal(data, &extraSettings); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p = &provider{
|
||||
p = &Provider{
|
||||
domain: domain,
|
||||
host: host,
|
||||
ipVersion: ipVersion,
|
||||
@@ -49,38 +49,38 @@ func New(data json.RawMessage, domain, host string,
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (p *provider) isValid() error {
|
||||
func (p *Provider) isValid() error {
|
||||
if len(p.password) == 0 {
|
||||
return errors.ErrEmptyPassword
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *provider) String() string {
|
||||
func (p *Provider) String() string {
|
||||
return utils.ToString(p.domain, p.host, constants.HE, p.ipVersion)
|
||||
}
|
||||
|
||||
func (p *provider) Domain() string {
|
||||
func (p *Provider) Domain() string {
|
||||
return p.domain
|
||||
}
|
||||
|
||||
func (p *provider) Host() string {
|
||||
func (p *Provider) Host() string {
|
||||
return p.host
|
||||
}
|
||||
|
||||
func (p *provider) IPVersion() ipversion.IPVersion {
|
||||
func (p *Provider) IPVersion() ipversion.IPVersion {
|
||||
return p.ipVersion
|
||||
}
|
||||
|
||||
func (p *provider) Proxied() bool {
|
||||
func (p *Provider) Proxied() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *provider) BuildDomainName() string {
|
||||
func (p *Provider) BuildDomainName() string {
|
||||
return utils.BuildDomainName(p.host, p.domain)
|
||||
}
|
||||
|
||||
func (p *provider) HTML() models.HTMLRow {
|
||||
func (p *Provider) HTML() models.HTMLRow {
|
||||
return models.HTMLRow{
|
||||
Domain: models.HTML(fmt.Sprintf("<a href=\"http://%s\">%s</a>", p.BuildDomainName(), p.BuildDomainName())),
|
||||
Host: models.HTML(p.Host()),
|
||||
@@ -89,7 +89,7 @@ func (p *provider) HTML() models.HTMLRow {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
func (p *Provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
fqdn := p.BuildDomainName()
|
||||
u := url.URL{
|
||||
Scheme: "https",
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
"github.com/qdm12/ddns-updater/pkg/publicip/ipversion"
|
||||
)
|
||||
|
||||
type provider struct {
|
||||
type Provider struct {
|
||||
domain string
|
||||
host string
|
||||
ipVersion ipversion.IPVersion
|
||||
@@ -28,7 +28,7 @@ type provider struct {
|
||||
}
|
||||
|
||||
func New(data json.RawMessage, domain, host string,
|
||||
ipVersion ipversion.IPVersion) (p *provider, err error) {
|
||||
ipVersion ipversion.IPVersion) (p *Provider, err error) {
|
||||
extraSettings := struct {
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
@@ -37,7 +37,7 @@ func New(data json.RawMessage, domain, host string,
|
||||
if err := json.Unmarshal(data, &extraSettings); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p = &provider{
|
||||
p = &Provider{
|
||||
domain: domain,
|
||||
host: host,
|
||||
ipVersion: ipVersion,
|
||||
@@ -51,7 +51,7 @@ func New(data json.RawMessage, domain, host string,
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (p *provider) isValid() error {
|
||||
func (p *Provider) isValid() error {
|
||||
switch {
|
||||
case len(p.username) == 0:
|
||||
return errors.ErrEmptyUsername
|
||||
@@ -63,31 +63,31 @@ func (p *provider) isValid() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *provider) String() string {
|
||||
func (p *Provider) String() string {
|
||||
return utils.ToString(p.domain, p.host, constants.Infomaniak, p.ipVersion)
|
||||
}
|
||||
|
||||
func (p *provider) Domain() string {
|
||||
func (p *Provider) Domain() string {
|
||||
return p.domain
|
||||
}
|
||||
|
||||
func (p *provider) Host() string {
|
||||
func (p *Provider) Host() string {
|
||||
return p.host
|
||||
}
|
||||
|
||||
func (p *provider) IPVersion() ipversion.IPVersion {
|
||||
func (p *Provider) IPVersion() ipversion.IPVersion {
|
||||
return p.ipVersion
|
||||
}
|
||||
|
||||
func (p *provider) Proxied() bool {
|
||||
func (p *Provider) Proxied() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *provider) BuildDomainName() string {
|
||||
func (p *Provider) BuildDomainName() string {
|
||||
return utils.BuildDomainName(p.host, p.domain)
|
||||
}
|
||||
|
||||
func (p *provider) HTML() models.HTMLRow {
|
||||
func (p *Provider) HTML() models.HTMLRow {
|
||||
return models.HTMLRow{
|
||||
Domain: models.HTML(fmt.Sprintf("<a href=\"http://%s\">%s</a>", p.BuildDomainName(), p.BuildDomainName())),
|
||||
Host: models.HTML(p.Host()),
|
||||
@@ -96,7 +96,7 @@ func (p *provider) HTML() models.HTMLRow {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
func (p *Provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
u := url.URL{
|
||||
Scheme: "https",
|
||||
Host: "infomaniak.com",
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
"github.com/qdm12/ddns-updater/pkg/publicip/ipversion"
|
||||
)
|
||||
|
||||
type provider struct {
|
||||
type Provider struct {
|
||||
domain string
|
||||
host string
|
||||
ipVersion ipversion.IPVersion
|
||||
@@ -28,14 +28,14 @@ type provider struct {
|
||||
}
|
||||
|
||||
func New(data json.RawMessage, domain, host string,
|
||||
ipVersion ipversion.IPVersion) (p *provider, err error) {
|
||||
ipVersion ipversion.IPVersion) (p *Provider, err error) {
|
||||
extraSettings := struct {
|
||||
Token string `json:"token"`
|
||||
}{}
|
||||
if err := json.Unmarshal(data, &extraSettings); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p = &provider{
|
||||
p = &Provider{
|
||||
domain: domain,
|
||||
host: host,
|
||||
ipVersion: ipVersion,
|
||||
@@ -47,38 +47,38 @@ func New(data json.RawMessage, domain, host string,
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (p *provider) isValid() error {
|
||||
func (p *Provider) isValid() error {
|
||||
if len(p.token) == 0 {
|
||||
return errors.ErrEmptyToken
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *provider) String() string {
|
||||
func (p *Provider) String() string {
|
||||
return utils.ToString(p.domain, p.host, constants.Linode, p.ipVersion)
|
||||
}
|
||||
|
||||
func (p *provider) Domain() string {
|
||||
func (p *Provider) Domain() string {
|
||||
return p.domain
|
||||
}
|
||||
|
||||
func (p *provider) Host() string {
|
||||
func (p *Provider) Host() string {
|
||||
return p.host
|
||||
}
|
||||
|
||||
func (p *provider) IPVersion() ipversion.IPVersion {
|
||||
func (p *Provider) IPVersion() ipversion.IPVersion {
|
||||
return p.ipVersion
|
||||
}
|
||||
|
||||
func (p *provider) Proxied() bool {
|
||||
func (p *Provider) Proxied() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *provider) BuildDomainName() string {
|
||||
func (p *Provider) BuildDomainName() string {
|
||||
return utils.BuildDomainName(p.host, p.domain)
|
||||
}
|
||||
|
||||
func (p *provider) HTML() models.HTMLRow {
|
||||
func (p *Provider) HTML() models.HTMLRow {
|
||||
return models.HTMLRow{
|
||||
Domain: models.HTML(fmt.Sprintf("<a href=\"http://%s\">%s</a>", p.BuildDomainName(), p.BuildDomainName())),
|
||||
Host: models.HTML(p.Host()),
|
||||
@@ -88,7 +88,7 @@ func (p *provider) HTML() models.HTMLRow {
|
||||
}
|
||||
|
||||
// Using https://www.linode.com/docs/api/domains/
|
||||
func (p *provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
func (p *Provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
domainID, err := p.getDomainID(ctx, client)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%w: %s", errors.ErrGetDomainID, err)
|
||||
@@ -124,13 +124,13 @@ type linodeErrors struct {
|
||||
} `json:"errors"`
|
||||
}
|
||||
|
||||
func (p *provider) setHeaders(request *http.Request) {
|
||||
func (p *Provider) setHeaders(request *http.Request) {
|
||||
headers.SetUserAgent(request)
|
||||
headers.SetContentType(request, "application/json")
|
||||
headers.SetAuthBearer(request, p.token)
|
||||
}
|
||||
|
||||
func (p *provider) getDomainID(ctx context.Context, client *http.Client) (domainID int, err error) {
|
||||
func (p *Provider) getDomainID(ctx context.Context, client *http.Client) (domainID int, err error) {
|
||||
u := url.URL{
|
||||
Scheme: "https",
|
||||
Host: "api.linode.com",
|
||||
@@ -189,7 +189,7 @@ func (p *provider) getDomainID(ctx context.Context, client *http.Client) (domain
|
||||
return *domains[0].ID, nil
|
||||
}
|
||||
|
||||
func (p *provider) getRecordID(ctx context.Context, client *http.Client,
|
||||
func (p *Provider) getRecordID(ctx context.Context, client *http.Client,
|
||||
domainID int, recordType string) (recordID int, err error) {
|
||||
u := url.URL{
|
||||
Scheme: "https",
|
||||
@@ -236,7 +236,7 @@ func (p *provider) getRecordID(ctx context.Context, client *http.Client,
|
||||
return 0, errors.ErrNotFound
|
||||
}
|
||||
|
||||
func (p *provider) createRecord(ctx context.Context, client *http.Client,
|
||||
func (p *Provider) createRecord(ctx context.Context, client *http.Client,
|
||||
domainID int, recordType string, ip net.IP) (err error) {
|
||||
u := url.URL{
|
||||
Scheme: "https",
|
||||
@@ -295,7 +295,7 @@ func (p *provider) createRecord(ctx context.Context, client *http.Client,
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *provider) updateRecord(ctx context.Context, client *http.Client,
|
||||
func (p *Provider) updateRecord(ctx context.Context, client *http.Client,
|
||||
domainID, recordID int, ip net.IP) (err error) {
|
||||
u := url.URL{
|
||||
Scheme: "https",
|
||||
@@ -348,7 +348,7 @@ func (p *provider) updateRecord(ctx context.Context, client *http.Client,
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *provider) getError(body io.Reader) (err error) {
|
||||
func (p *Provider) getError(body io.Reader) (err error) {
|
||||
var errorObj linodeErrors
|
||||
b, err := io.ReadAll(body)
|
||||
if err != nil {
|
||||
|
||||
@@ -19,7 +19,7 @@ import (
|
||||
"github.com/qdm12/golibs/verification"
|
||||
)
|
||||
|
||||
type provider struct {
|
||||
type Provider struct {
|
||||
domain string
|
||||
host string
|
||||
ipVersion ipversion.IPVersion
|
||||
@@ -28,7 +28,7 @@ type provider struct {
|
||||
}
|
||||
|
||||
func New(data json.RawMessage, domain, host string,
|
||||
ipVersion ipversion.IPVersion) (p *provider, err error) {
|
||||
ipVersion ipversion.IPVersion) (p *Provider, err error) {
|
||||
extraSettings := struct {
|
||||
Email string `json:"email"`
|
||||
Token string `json:"token"`
|
||||
@@ -36,7 +36,7 @@ func New(data json.RawMessage, domain, host string,
|
||||
if err := json.Unmarshal(data, &extraSettings); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p = &provider{
|
||||
p = &Provider{
|
||||
domain: domain,
|
||||
host: host,
|
||||
ipVersion: ipVersion,
|
||||
@@ -49,7 +49,7 @@ func New(data json.RawMessage, domain, host string,
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (p *provider) isValid() error {
|
||||
func (p *Provider) isValid() error {
|
||||
switch {
|
||||
case !verification.NewRegex().MatchEmail(p.email):
|
||||
return errors.ErrMalformedEmail
|
||||
@@ -59,31 +59,31 @@ func (p *provider) isValid() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *provider) String() string {
|
||||
func (p *Provider) String() string {
|
||||
return utils.ToString(p.domain, p.host, constants.LuaDNS, p.ipVersion)
|
||||
}
|
||||
|
||||
func (p *provider) Domain() string {
|
||||
func (p *Provider) Domain() string {
|
||||
return p.domain
|
||||
}
|
||||
|
||||
func (p *provider) Host() string {
|
||||
func (p *Provider) Host() string {
|
||||
return p.host
|
||||
}
|
||||
|
||||
func (p *provider) IPVersion() ipversion.IPVersion {
|
||||
func (p *Provider) IPVersion() ipversion.IPVersion {
|
||||
return p.ipVersion
|
||||
}
|
||||
|
||||
func (p *provider) Proxied() bool {
|
||||
func (p *Provider) Proxied() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *provider) BuildDomainName() string {
|
||||
func (p *Provider) BuildDomainName() string {
|
||||
return utils.BuildDomainName(p.host, p.domain)
|
||||
}
|
||||
|
||||
func (p *provider) HTML() models.HTMLRow {
|
||||
func (p *Provider) HTML() models.HTMLRow {
|
||||
return models.HTMLRow{
|
||||
Domain: models.HTML(fmt.Sprintf("<a href=\"http://%s\">%s</a>", p.BuildDomainName(), p.BuildDomainName())),
|
||||
Host: models.HTML(p.Host()),
|
||||
@@ -92,13 +92,13 @@ func (p *provider) HTML() models.HTMLRow {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *provider) setHeaders(request *http.Request) {
|
||||
func (p *Provider) setHeaders(request *http.Request) {
|
||||
headers.SetUserAgent(request)
|
||||
headers.SetAccept(request, "application/json")
|
||||
}
|
||||
|
||||
// Using https://www.luadns.com/api.html
|
||||
func (p *provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
func (p *Provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
zoneID, err := p.getZoneID(ctx, client)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%w: %s", errors.ErrGetZoneID, err)
|
||||
@@ -130,7 +130,7 @@ type luaDNSError struct {
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
func (p *provider) getZoneID(ctx context.Context, client *http.Client) (zoneID int, err error) {
|
||||
func (p *Provider) getZoneID(ctx context.Context, client *http.Client) (zoneID int, err error) {
|
||||
u := url.URL{
|
||||
Scheme: "https",
|
||||
Host: "api.luadns.com",
|
||||
@@ -181,7 +181,7 @@ func (p *provider) getZoneID(ctx context.Context, client *http.Client) (zoneID i
|
||||
return 0, errors.ErrZoneNotFound
|
||||
}
|
||||
|
||||
func (p *provider) getRecord(ctx context.Context, client *http.Client, zoneID int, ip net.IP) (
|
||||
func (p *Provider) getRecord(ctx context.Context, client *http.Client, zoneID int, ip net.IP) (
|
||||
record luaDNSRecord, err error) {
|
||||
u := url.URL{
|
||||
Scheme: "https",
|
||||
@@ -235,7 +235,7 @@ func (p *provider) getRecord(ctx context.Context, client *http.Client, zoneID in
|
||||
errors.ErrRecordNotFound, recordType, zoneID)
|
||||
}
|
||||
|
||||
func (p *provider) updateRecord(ctx context.Context, client *http.Client,
|
||||
func (p *Provider) updateRecord(ctx context.Context, client *http.Client,
|
||||
zoneID int, newRecord luaDNSRecord) (err error) {
|
||||
u := url.URL{
|
||||
Scheme: "https",
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"net/url"
|
||||
|
||||
"github.com/qdm12/ddns-updater/internal/models"
|
||||
"github.com/qdm12/ddns-updater/internal/regex"
|
||||
"github.com/qdm12/ddns-updater/internal/settings/common"
|
||||
"github.com/qdm12/ddns-updater/internal/settings/constants"
|
||||
"github.com/qdm12/ddns-updater/internal/settings/errors"
|
||||
"github.com/qdm12/ddns-updater/internal/settings/headers"
|
||||
@@ -19,17 +19,17 @@ import (
|
||||
"github.com/qdm12/ddns-updater/pkg/publicip/ipversion"
|
||||
)
|
||||
|
||||
type provider struct {
|
||||
type Provider struct {
|
||||
domain string
|
||||
host string
|
||||
ipVersion ipversion.IPVersion
|
||||
password string
|
||||
useProviderIP bool
|
||||
matcher regex.Matcher
|
||||
matcher common.Matcher
|
||||
}
|
||||
|
||||
func New(data json.RawMessage, domain, host string, ipVersion ipversion.IPVersion,
|
||||
matcher regex.Matcher) (p *provider, err error) {
|
||||
matcher common.Matcher) (p *Provider, err error) {
|
||||
if ipVersion == ipversion.IP6 {
|
||||
return p, errors.ErrIPv6NotSupported
|
||||
}
|
||||
@@ -40,7 +40,7 @@ func New(data json.RawMessage, domain, host string, ipVersion ipversion.IPVersio
|
||||
if err := json.Unmarshal(data, &extraSettings); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p = &provider{
|
||||
p = &Provider{
|
||||
domain: domain,
|
||||
host: host,
|
||||
ipVersion: ipVersion,
|
||||
@@ -54,38 +54,38 @@ func New(data json.RawMessage, domain, host string, ipVersion ipversion.IPVersio
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (p *provider) isValid() error {
|
||||
func (p *Provider) isValid() error {
|
||||
if !p.matcher.NamecheapPassword(p.password) {
|
||||
return errors.ErrMalformedPassword
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *provider) String() string {
|
||||
func (p *Provider) String() string {
|
||||
return utils.ToString(p.domain, p.host, constants.Namecheap, p.ipVersion)
|
||||
}
|
||||
|
||||
func (p *provider) Domain() string {
|
||||
func (p *Provider) Domain() string {
|
||||
return p.domain
|
||||
}
|
||||
|
||||
func (p *provider) Host() string {
|
||||
func (p *Provider) Host() string {
|
||||
return p.host
|
||||
}
|
||||
|
||||
func (p *provider) IPVersion() ipversion.IPVersion {
|
||||
func (p *Provider) IPVersion() ipversion.IPVersion {
|
||||
return p.ipVersion
|
||||
}
|
||||
|
||||
func (p *provider) Proxied() bool {
|
||||
func (p *Provider) Proxied() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *provider) BuildDomainName() string {
|
||||
func (p *Provider) BuildDomainName() string {
|
||||
return utils.BuildDomainName(p.host, p.domain)
|
||||
}
|
||||
|
||||
func (p *provider) HTML() models.HTMLRow {
|
||||
func (p *Provider) HTML() models.HTMLRow {
|
||||
return models.HTMLRow{
|
||||
Domain: models.HTML(fmt.Sprintf("<a href=\"http://%s\">%s</a>", p.BuildDomainName(), p.BuildDomainName())),
|
||||
Host: models.HTML(p.Host()),
|
||||
@@ -94,12 +94,12 @@ func (p *provider) HTML() models.HTMLRow {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *provider) setHeaders(request *http.Request) {
|
||||
func (p *Provider) setHeaders(request *http.Request) {
|
||||
headers.SetUserAgent(request)
|
||||
headers.SetAccept(request, "application/xml")
|
||||
}
|
||||
|
||||
func (p *provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
func (p *Provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
u := url.URL{
|
||||
Scheme: "https",
|
||||
Host: "dynamicdns.park-your-domain.com",
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
"github.com/qdm12/ddns-updater/pkg/publicip/ipversion"
|
||||
)
|
||||
|
||||
type provider struct {
|
||||
type Provider struct {
|
||||
domain string
|
||||
host string
|
||||
ipVersion ipversion.IPVersion
|
||||
@@ -25,7 +25,7 @@ type provider struct {
|
||||
}
|
||||
|
||||
func New(data json.RawMessage, domain, host string,
|
||||
ipVersion ipversion.IPVersion) (p *provider, err error) {
|
||||
ipVersion ipversion.IPVersion) (p *Provider, err error) {
|
||||
extraSettings := struct {
|
||||
Key string `json:"key"`
|
||||
UseProviderIP bool `json:"provider_ip"`
|
||||
@@ -33,7 +33,7 @@ func New(data json.RawMessage, domain, host string,
|
||||
if err := json.Unmarshal(data, &extraSettings); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p = &provider{
|
||||
p = &Provider{
|
||||
domain: domain,
|
||||
host: host,
|
||||
ipVersion: ipVersion,
|
||||
@@ -46,38 +46,38 @@ func New(data json.RawMessage, domain, host string,
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (p *provider) isValid() error {
|
||||
func (p *Provider) isValid() error {
|
||||
if len(p.key) == 0 {
|
||||
return errors.ErrEmptyKey
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *provider) String() string {
|
||||
func (p *Provider) String() string {
|
||||
return utils.ToString(p.domain, p.host, constants.Njalla, p.ipVersion)
|
||||
}
|
||||
|
||||
func (p *provider) Domain() string {
|
||||
func (p *Provider) Domain() string {
|
||||
return p.domain
|
||||
}
|
||||
|
||||
func (p *provider) Host() string {
|
||||
func (p *Provider) Host() string {
|
||||
return p.host
|
||||
}
|
||||
|
||||
func (p *provider) IPVersion() ipversion.IPVersion {
|
||||
func (p *Provider) IPVersion() ipversion.IPVersion {
|
||||
return p.ipVersion
|
||||
}
|
||||
|
||||
func (p *provider) Proxied() bool {
|
||||
func (p *Provider) Proxied() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *provider) BuildDomainName() string {
|
||||
func (p *Provider) BuildDomainName() string {
|
||||
return utils.BuildDomainName(p.host, p.domain)
|
||||
}
|
||||
|
||||
func (p *provider) HTML() models.HTMLRow {
|
||||
func (p *Provider) HTML() models.HTMLRow {
|
||||
return models.HTMLRow{
|
||||
Domain: models.HTML(fmt.Sprintf("<a href=\"http://%s\">%s</a>", p.BuildDomainName(), p.BuildDomainName())),
|
||||
Host: models.HTML(p.Host()),
|
||||
@@ -86,7 +86,7 @@ func (p *provider) HTML() models.HTMLRow {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
func (p *Provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
u := url.URL{
|
||||
Scheme: "https",
|
||||
Host: "njal.la",
|
||||
|
||||
@@ -19,7 +19,7 @@ import (
|
||||
"github.com/qdm12/golibs/verification"
|
||||
)
|
||||
|
||||
type provider struct {
|
||||
type Provider struct {
|
||||
domain string
|
||||
host string
|
||||
ipVersion ipversion.IPVersion
|
||||
@@ -29,7 +29,7 @@ type provider struct {
|
||||
}
|
||||
|
||||
func New(data json.RawMessage, domain, host string,
|
||||
ipVersion ipversion.IPVersion) (p *provider, err error) {
|
||||
ipVersion ipversion.IPVersion) (p *Provider, err error) {
|
||||
extraSettings := struct {
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
@@ -38,7 +38,7 @@ func New(data json.RawMessage, domain, host string,
|
||||
if err := json.Unmarshal(data, &extraSettings); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p = &provider{
|
||||
p = &Provider{
|
||||
domain: domain,
|
||||
host: host,
|
||||
ipVersion: ipVersion,
|
||||
@@ -52,7 +52,7 @@ func New(data json.RawMessage, domain, host string,
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (p *provider) isValid() error {
|
||||
func (p *Provider) isValid() error {
|
||||
const maxUsernameLength = 50
|
||||
switch {
|
||||
case len(p.username) == 0:
|
||||
@@ -67,31 +67,31 @@ func (p *provider) isValid() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *provider) String() string {
|
||||
func (p *Provider) String() string {
|
||||
return utils.ToString(p.domain, p.host, constants.NoIP, p.ipVersion)
|
||||
}
|
||||
|
||||
func (p *provider) Domain() string {
|
||||
func (p *Provider) Domain() string {
|
||||
return p.domain
|
||||
}
|
||||
|
||||
func (p *provider) Host() string {
|
||||
func (p *Provider) Host() string {
|
||||
return p.host
|
||||
}
|
||||
|
||||
func (p *provider) IPVersion() ipversion.IPVersion {
|
||||
func (p *Provider) IPVersion() ipversion.IPVersion {
|
||||
return p.ipVersion
|
||||
}
|
||||
|
||||
func (p *provider) Proxied() bool {
|
||||
func (p *Provider) Proxied() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *provider) BuildDomainName() string {
|
||||
func (p *Provider) BuildDomainName() string {
|
||||
return utils.BuildDomainName(p.host, p.domain)
|
||||
}
|
||||
|
||||
func (p *provider) HTML() models.HTMLRow {
|
||||
func (p *Provider) HTML() models.HTMLRow {
|
||||
return models.HTMLRow{
|
||||
Domain: models.HTML(fmt.Sprintf("<a href=\"http://%s\">%s</a>", p.BuildDomainName(), p.BuildDomainName())),
|
||||
Host: models.HTML(p.Host()),
|
||||
@@ -100,7 +100,7 @@ func (p *provider) HTML() models.HTMLRow {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
func (p *Provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
u := url.URL{
|
||||
Scheme: "https",
|
||||
Host: "dynupdate.no-ip.com",
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
"github.com/qdm12/ddns-updater/pkg/publicip/ipversion"
|
||||
)
|
||||
|
||||
type provider struct {
|
||||
type Provider struct {
|
||||
domain string
|
||||
host string
|
||||
ipVersion ipversion.IPVersion
|
||||
@@ -27,7 +27,7 @@ type provider struct {
|
||||
}
|
||||
|
||||
func New(data json.RawMessage, domain, host string,
|
||||
ipVersion ipversion.IPVersion) (p *provider, err error) {
|
||||
ipVersion ipversion.IPVersion) (p *Provider, err error) {
|
||||
extraSettings := struct {
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
@@ -36,7 +36,7 @@ func New(data json.RawMessage, domain, host string,
|
||||
if err := json.Unmarshal(data, &extraSettings); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p = &provider{
|
||||
p = &Provider{
|
||||
domain: domain,
|
||||
host: host,
|
||||
ipVersion: ipVersion,
|
||||
@@ -50,7 +50,7 @@ func New(data json.RawMessage, domain, host string,
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (p *provider) isValid() error {
|
||||
func (p *Provider) isValid() error {
|
||||
switch {
|
||||
case len(p.username) == 0:
|
||||
return errors.ErrEmptyUsername
|
||||
@@ -62,31 +62,31 @@ func (p *provider) isValid() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *provider) String() string {
|
||||
func (p *Provider) String() string {
|
||||
return fmt.Sprintf("[domain: %s | host: %s | provider: Opendns]", p.domain, p.host)
|
||||
}
|
||||
|
||||
func (p *provider) Domain() string {
|
||||
func (p *Provider) Domain() string {
|
||||
return p.domain
|
||||
}
|
||||
|
||||
func (p *provider) Host() string {
|
||||
func (p *Provider) Host() string {
|
||||
return p.host
|
||||
}
|
||||
|
||||
func (p *provider) IPVersion() ipversion.IPVersion {
|
||||
func (p *Provider) IPVersion() ipversion.IPVersion {
|
||||
return p.ipVersion
|
||||
}
|
||||
|
||||
func (p *provider) Proxied() bool {
|
||||
func (p *Provider) Proxied() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *provider) BuildDomainName() string {
|
||||
func (p *Provider) BuildDomainName() string {
|
||||
return utils.BuildDomainName(p.host, p.domain)
|
||||
}
|
||||
|
||||
func (p *provider) HTML() models.HTMLRow {
|
||||
func (p *Provider) HTML() models.HTMLRow {
|
||||
return models.HTMLRow{
|
||||
Domain: models.HTML(fmt.Sprintf("<a href=\"http://%s\">%s</a>", p.BuildDomainName(), p.BuildDomainName())),
|
||||
Host: models.HTML(p.Host()),
|
||||
@@ -95,7 +95,7 @@ func (p *provider) HTML() models.HTMLRow {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
func (p *Provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
u := url.URL{
|
||||
Scheme: "https",
|
||||
User: url.UserPassword(p.username, p.password),
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/qdm12/ddns-updater/internal/settings/errors"
|
||||
)
|
||||
|
||||
func (p *provider) createRecord(ctx context.Context, client *http.Client,
|
||||
func (p *Provider) createRecord(ctx context.Context, client *http.Client,
|
||||
recordType, subdomain, ipStr string, timestamp int64) (err error) {
|
||||
u := url.URL{
|
||||
Scheme: p.apiURL.Scheme,
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"github.com/qdm12/ddns-updater/internal/settings/errors"
|
||||
)
|
||||
|
||||
func (p *provider) getRecords(ctx context.Context, client *http.Client,
|
||||
func (p *Provider) getRecords(ctx context.Context, client *http.Client,
|
||||
recordType, subdomain string, timestamp int64) (recordIDs []uint64, err error) {
|
||||
values := url.Values{}
|
||||
values.Set("fieldType", recordType)
|
||||
|
||||
@@ -9,12 +9,12 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func (p *provider) setHeaderCommon(header http.Header) {
|
||||
func (p *Provider) setHeaderCommon(header http.Header) {
|
||||
header.Add("Accept", "application/json;charset=utf-8")
|
||||
header.Add("X-Ovh-Application", p.appKey)
|
||||
}
|
||||
|
||||
func (p *provider) setHeaderAuth(header http.Header, timestamp int64,
|
||||
func (p *Provider) setHeaderAuth(header http.Header, timestamp int64,
|
||||
httpMethod string, url *url.URL, body []byte) {
|
||||
header.Add("X-Ovh-Timestamp", strconv.Itoa(int(timestamp)))
|
||||
header.Add("X-Ovh-Consumer", p.consumerKey)
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
"github.com/qdm12/ddns-updater/pkg/publicip/ipversion"
|
||||
)
|
||||
|
||||
type provider struct {
|
||||
type Provider struct {
|
||||
domain string
|
||||
host string
|
||||
ipVersion ipversion.IPVersion
|
||||
@@ -37,7 +37,7 @@ type provider struct {
|
||||
}
|
||||
|
||||
func New(data json.RawMessage, domain, host string,
|
||||
ipVersion ipversion.IPVersion) (p *provider, err error) {
|
||||
ipVersion ipversion.IPVersion) (p *Provider, err error) {
|
||||
extraSettings := struct {
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
@@ -57,7 +57,7 @@ func New(data json.RawMessage, domain, host string,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
p = &provider{
|
||||
p = &Provider{
|
||||
domain: domain,
|
||||
host: host,
|
||||
ipVersion: ipVersion,
|
||||
@@ -77,7 +77,7 @@ func New(data json.RawMessage, domain, host string,
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (p *provider) isValid() error {
|
||||
func (p *Provider) isValid() error {
|
||||
if p.mode == "api" {
|
||||
switch {
|
||||
case len(p.appKey) == 0:
|
||||
@@ -100,31 +100,31 @@ func (p *provider) isValid() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *provider) String() string {
|
||||
func (p *Provider) String() string {
|
||||
return fmt.Sprintf("[domain: %s | host: %s | provider: OVH]", p.domain, p.host)
|
||||
}
|
||||
|
||||
func (p *provider) Domain() string {
|
||||
func (p *Provider) Domain() string {
|
||||
return p.domain
|
||||
}
|
||||
|
||||
func (p *provider) Host() string {
|
||||
func (p *Provider) Host() string {
|
||||
return p.host
|
||||
}
|
||||
|
||||
func (p *provider) IPVersion() ipversion.IPVersion {
|
||||
func (p *Provider) IPVersion() ipversion.IPVersion {
|
||||
return p.ipVersion
|
||||
}
|
||||
|
||||
func (p *provider) Proxied() bool {
|
||||
func (p *Provider) Proxied() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *provider) BuildDomainName() string {
|
||||
func (p *Provider) BuildDomainName() string {
|
||||
return utils.BuildDomainName(p.host, p.domain)
|
||||
}
|
||||
|
||||
func (p *provider) HTML() models.HTMLRow {
|
||||
func (p *Provider) HTML() models.HTMLRow {
|
||||
return models.HTMLRow{
|
||||
Domain: models.HTML(fmt.Sprintf("<a href=\"http://%s\">%s</a>", p.BuildDomainName(), p.BuildDomainName())),
|
||||
Host: models.HTML(p.Host()),
|
||||
@@ -133,7 +133,7 @@ func (p *provider) HTML() models.HTMLRow {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *provider) updateWithDynHost(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
func (p *Provider) updateWithDynHost(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
u := url.URL{
|
||||
Scheme: "https",
|
||||
User: url.UserPassword(p.username, p.password),
|
||||
@@ -187,7 +187,7 @@ var (
|
||||
ErrRefresh = stderrors.New("cannot refresh records")
|
||||
)
|
||||
|
||||
func (p *provider) updateWithZoneDNS(ctx context.Context, client *http.Client, ip net.IP) (
|
||||
func (p *Provider) updateWithZoneDNS(ctx context.Context, client *http.Client, ip net.IP) (
|
||||
newIP net.IP, err error) {
|
||||
recordType := constants.A
|
||||
var ipStr string
|
||||
@@ -232,7 +232,7 @@ func (p *provider) updateWithZoneDNS(ctx context.Context, client *http.Client, i
|
||||
return ip, nil
|
||||
}
|
||||
|
||||
func (p *provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
func (p *Provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
if p.mode != "api" {
|
||||
return p.updateWithDynHost(ctx, client, ip)
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/qdm12/ddns-updater/internal/settings/errors"
|
||||
)
|
||||
|
||||
func (p *provider) refresh(ctx context.Context, client *http.Client, timestamp int64) (err error) {
|
||||
func (p *Provider) refresh(ctx context.Context, client *http.Client, timestamp int64) (err error) {
|
||||
u := url.URL{
|
||||
Scheme: p.apiURL.Scheme,
|
||||
Host: p.apiURL.Host,
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/qdm12/ddns-updater/internal/settings/errors"
|
||||
)
|
||||
|
||||
func (p *provider) getAdjustedUnixTimestamp(ctx context.Context, client *http.Client) (
|
||||
func (p *Provider) getAdjustedUnixTimestamp(ctx context.Context, client *http.Client) (
|
||||
unix int64, err error) {
|
||||
delta, err := p.getTimeDelta(ctx, client)
|
||||
if err != nil {
|
||||
@@ -26,7 +26,7 @@ func (p *provider) getAdjustedUnixTimestamp(ctx context.Context, client *http.Cl
|
||||
// getTimeDelta obtains the delta between the OVH server time and this machine time.
|
||||
// If it is the first time executing, it fetches the time from OVH servers to calculate the
|
||||
// delta. Otherwise, it uses the delta calculated previously.
|
||||
func (p *provider) getTimeDelta(ctx context.Context, client *http.Client) (delta time.Duration, err error) {
|
||||
func (p *Provider) getTimeDelta(ctx context.Context, client *http.Client) (delta time.Duration, err error) {
|
||||
if p.serverDelta > 0 {
|
||||
return p.serverDelta, nil
|
||||
}
|
||||
@@ -41,7 +41,7 @@ func (p *provider) getTimeDelta(ctx context.Context, client *http.Client) (delta
|
||||
return p.serverDelta, nil
|
||||
}
|
||||
|
||||
func (p *provider) getOVHTime(ctx context.Context, client *http.Client) (ovhTime time.Time, err error) {
|
||||
func (p *Provider) getOVHTime(ctx context.Context, client *http.Client) (ovhTime time.Time, err error) {
|
||||
u := url.URL{
|
||||
Scheme: p.apiURL.Scheme,
|
||||
Host: p.apiURL.Host,
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"github.com/qdm12/ddns-updater/internal/settings/errors"
|
||||
)
|
||||
|
||||
func (p *provider) updateRecord(ctx context.Context, client *http.Client,
|
||||
func (p *Provider) updateRecord(ctx context.Context, client *http.Client,
|
||||
recordID uint64, ipStr string, timestamp int64) (err error) {
|
||||
u := url.URL{
|
||||
Scheme: p.apiURL.Scheme,
|
||||
|
||||
@@ -17,31 +17,31 @@ import (
|
||||
"github.com/qdm12/ddns-updater/pkg/publicip/ipversion"
|
||||
)
|
||||
|
||||
type provider struct {
|
||||
type Provider struct {
|
||||
domain string
|
||||
host string
|
||||
ttl uint
|
||||
ipVersion ipversion.IPVersion
|
||||
apiKey string
|
||||
secretApiKey string
|
||||
secretAPIKey string
|
||||
}
|
||||
|
||||
func New(data json.RawMessage, domain, host string,
|
||||
ipVersion ipversion.IPVersion) (p *provider, err error) {
|
||||
ipVersion ipversion.IPVersion) (p *Provider, err error) {
|
||||
extraSettings := struct {
|
||||
SecretApiKey string `json:"secret_api_key"`
|
||||
ApiKey string `json:"api_key"`
|
||||
SecretAPIKey string `json:"secret_api_key"`
|
||||
APIKey string `json:"api_key"`
|
||||
TTL uint `json:"ttl"`
|
||||
}{}
|
||||
if err := json.Unmarshal(data, &extraSettings); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p = &provider{
|
||||
p = &Provider{
|
||||
domain: domain,
|
||||
host: host,
|
||||
ipVersion: ipVersion,
|
||||
secretApiKey: extraSettings.SecretApiKey,
|
||||
apiKey: extraSettings.ApiKey,
|
||||
secretAPIKey: extraSettings.SecretAPIKey,
|
||||
apiKey: extraSettings.APIKey,
|
||||
ttl: extraSettings.TTL,
|
||||
}
|
||||
if err := p.isValid(); err != nil {
|
||||
@@ -50,41 +50,41 @@ func New(data json.RawMessage, domain, host string,
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (p *provider) isValid() error {
|
||||
func (p *Provider) isValid() error {
|
||||
switch {
|
||||
case p.apiKey == "":
|
||||
return errors.ErrEmptyApiKey
|
||||
case p.secretApiKey == "":
|
||||
return errors.ErrEmptyApiSecret
|
||||
return errors.ErrEmptyAPIKey
|
||||
case p.secretAPIKey == "":
|
||||
return errors.ErrEmptyAPISecret
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *provider) String() string {
|
||||
func (p *Provider) String() string {
|
||||
return fmt.Sprintf("[domain: %s | host: %s | provider: Porkbun]", p.domain, p.host)
|
||||
}
|
||||
|
||||
func (p *provider) Domain() string {
|
||||
func (p *Provider) Domain() string {
|
||||
return p.domain
|
||||
}
|
||||
|
||||
func (p *provider) Host() string {
|
||||
func (p *Provider) Host() string {
|
||||
return p.host
|
||||
}
|
||||
|
||||
func (p *provider) IPVersion() ipversion.IPVersion {
|
||||
func (p *Provider) IPVersion() ipversion.IPVersion {
|
||||
return p.ipVersion
|
||||
}
|
||||
|
||||
func (p *provider) Proxied() bool {
|
||||
func (p *Provider) Proxied() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *provider) BuildDomainName() string {
|
||||
func (p *Provider) BuildDomainName() string {
|
||||
return utils.BuildDomainName(p.host, p.domain)
|
||||
}
|
||||
|
||||
func (p *provider) HTML() models.HTMLRow {
|
||||
func (p *Provider) HTML() models.HTMLRow {
|
||||
return models.HTMLRow{
|
||||
Domain: models.HTML(fmt.Sprintf("<a href=\"http://%s\">%s</a>", p.BuildDomainName(), p.BuildDomainName())),
|
||||
Host: models.HTML(p.Host()),
|
||||
@@ -93,13 +93,13 @@ func (p *provider) HTML() models.HTMLRow {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *provider) setHeaders(request *http.Request) {
|
||||
func (p *Provider) setHeaders(request *http.Request) {
|
||||
headers.SetUserAgent(request)
|
||||
headers.SetContentType(request, "application/json")
|
||||
headers.SetAccept(request, "application/json")
|
||||
}
|
||||
|
||||
func (p *provider) getRecordIDs(ctx context.Context, client *http.Client, recordType string) (
|
||||
func (p *Provider) getRecordIDs(ctx context.Context, client *http.Client, recordType string) (
|
||||
recordIDs []string, err error) {
|
||||
u := url.URL{
|
||||
Scheme: "https",
|
||||
@@ -111,11 +111,11 @@ func (p *provider) getRecordIDs(ctx context.Context, client *http.Client, record
|
||||
}
|
||||
|
||||
postRecordsParams := struct {
|
||||
SecretApiKey string `json:"secretapikey"`
|
||||
ApiKey string `json:"apikey"`
|
||||
SecretAPIKey string `json:"secretapikey"`
|
||||
APIKey string `json:"apikey"`
|
||||
}{
|
||||
SecretApiKey: p.secretApiKey,
|
||||
ApiKey: p.apiKey,
|
||||
SecretAPIKey: p.secretAPIKey,
|
||||
APIKey: p.apiKey,
|
||||
}
|
||||
buffer := bytes.NewBuffer(nil)
|
||||
encoder := json.NewEncoder(buffer)
|
||||
@@ -142,7 +142,7 @@ func (p *provider) getRecordIDs(ctx context.Context, client *http.Client, record
|
||||
|
||||
var responseData struct {
|
||||
Records []struct {
|
||||
Id string `json:"id"`
|
||||
ID string `json:"id"`
|
||||
} `json:"records"`
|
||||
}
|
||||
decoder := json.NewDecoder(response.Body)
|
||||
@@ -151,13 +151,13 @@ func (p *provider) getRecordIDs(ctx context.Context, client *http.Client, record
|
||||
}
|
||||
|
||||
for _, record := range responseData.Records {
|
||||
recordIDs = append(recordIDs, record.Id)
|
||||
recordIDs = append(recordIDs, record.ID)
|
||||
}
|
||||
|
||||
return recordIDs, nil
|
||||
}
|
||||
|
||||
func (p *provider) createRecord(ctx context.Context, client *http.Client,
|
||||
func (p *Provider) createRecord(ctx context.Context, client *http.Client,
|
||||
recordType string, ipStr string) (err error) {
|
||||
u := url.URL{
|
||||
Scheme: "https",
|
||||
@@ -165,15 +165,15 @@ func (p *provider) createRecord(ctx context.Context, client *http.Client,
|
||||
Path: "/api/json/v3/dns/create/" + p.domain,
|
||||
}
|
||||
postRecordsParams := struct {
|
||||
SecretApiKey string `json:"secretapikey"`
|
||||
ApiKey string `json:"apikey"`
|
||||
SecretAPIKey string `json:"secretapikey"`
|
||||
APIKey string `json:"apikey"`
|
||||
Content string `json:"content"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Type string `json:"type"`
|
||||
TTL string `json:"ttl"`
|
||||
}{
|
||||
SecretApiKey: p.secretApiKey,
|
||||
ApiKey: p.apiKey,
|
||||
SecretAPIKey: p.secretAPIKey,
|
||||
APIKey: p.apiKey,
|
||||
Content: ipStr,
|
||||
Type: recordType,
|
||||
Name: p.host,
|
||||
@@ -204,7 +204,7 @@ func (p *provider) createRecord(ctx context.Context, client *http.Client,
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *provider) updateRecord(ctx context.Context, client *http.Client,
|
||||
func (p *Provider) updateRecord(ctx context.Context, client *http.Client,
|
||||
recordType string, ipStr string, recordID string) (err error) {
|
||||
u := url.URL{
|
||||
Scheme: "https",
|
||||
@@ -212,15 +212,15 @@ func (p *provider) updateRecord(ctx context.Context, client *http.Client,
|
||||
Path: "/api/json/v3/dns/edit/" + p.domain + "/" + recordID,
|
||||
}
|
||||
postRecordsParams := struct {
|
||||
SecretApiKey string `json:"secretapikey"`
|
||||
ApiKey string `json:"apikey"`
|
||||
SecretAPIKey string `json:"secretapikey"`
|
||||
APIKey string `json:"apikey"`
|
||||
Content string `json:"content"`
|
||||
Type string `json:"type"`
|
||||
TTL string `json:"ttl"`
|
||||
Name string `json:"name,omitempty"`
|
||||
}{
|
||||
SecretApiKey: p.secretApiKey,
|
||||
ApiKey: p.apiKey,
|
||||
SecretAPIKey: p.secretAPIKey,
|
||||
APIKey: p.apiKey,
|
||||
Content: ipStr,
|
||||
Type: recordType,
|
||||
TTL: fmt.Sprint(p.ttl),
|
||||
@@ -251,7 +251,7 @@ func (p *provider) updateRecord(ctx context.Context, client *http.Client,
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
func (p *Provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
recordType := constants.A
|
||||
if ip.To4() == nil { // IPv6
|
||||
recordType = constants.AAAA
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
"github.com/qdm12/ddns-updater/pkg/publicip/ipversion"
|
||||
)
|
||||
|
||||
type provider struct {
|
||||
type Provider struct {
|
||||
domain string
|
||||
host string
|
||||
ipVersion ipversion.IPVersion
|
||||
@@ -28,7 +28,7 @@ type provider struct {
|
||||
}
|
||||
|
||||
func New(data json.RawMessage, domain, host string,
|
||||
ipVersion ipversion.IPVersion) (p *provider, err error) {
|
||||
ipVersion ipversion.IPVersion) (p *Provider, err error) {
|
||||
extraSettings := struct {
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
@@ -37,7 +37,7 @@ func New(data json.RawMessage, domain, host string,
|
||||
if err := json.Unmarshal(data, &extraSettings); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p = &provider{
|
||||
p = &Provider{
|
||||
domain: domain,
|
||||
host: host,
|
||||
ipVersion: ipVersion,
|
||||
@@ -51,7 +51,7 @@ func New(data json.RawMessage, domain, host string,
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (p *provider) isValid() error {
|
||||
func (p *Provider) isValid() error {
|
||||
switch {
|
||||
case len(p.username) == 0:
|
||||
return errors.ErrEmptyUsername
|
||||
@@ -63,31 +63,31 @@ func (p *provider) isValid() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *provider) String() string {
|
||||
func (p *Provider) String() string {
|
||||
return fmt.Sprintf("[domain: %s | host: %s | provider: Selfhost.de]", p.domain, p.host)
|
||||
}
|
||||
|
||||
func (p *provider) Domain() string {
|
||||
func (p *Provider) Domain() string {
|
||||
return p.domain
|
||||
}
|
||||
|
||||
func (p *provider) Host() string {
|
||||
func (p *Provider) Host() string {
|
||||
return p.host
|
||||
}
|
||||
|
||||
func (p *provider) IPVersion() ipversion.IPVersion {
|
||||
func (p *Provider) IPVersion() ipversion.IPVersion {
|
||||
return p.ipVersion
|
||||
}
|
||||
|
||||
func (p *provider) Proxied() bool {
|
||||
func (p *Provider) Proxied() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *provider) BuildDomainName() string {
|
||||
func (p *Provider) BuildDomainName() string {
|
||||
return utils.BuildDomainName(p.host, p.domain)
|
||||
}
|
||||
|
||||
func (p *provider) HTML() models.HTMLRow {
|
||||
func (p *Provider) HTML() models.HTMLRow {
|
||||
return models.HTMLRow{
|
||||
Domain: models.HTML(fmt.Sprintf("<a href=\"http://%s\">%s</a>", p.BuildDomainName(), p.BuildDomainName())),
|
||||
Host: models.HTML(p.Host()),
|
||||
@@ -96,7 +96,7 @@ func (p *provider) HTML() models.HTMLRow {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
func (p *Provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
u := url.URL{
|
||||
Scheme: "https",
|
||||
User: url.UserPassword(p.username, p.password),
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
"github.com/qdm12/ddns-updater/pkg/publicip/ipversion"
|
||||
)
|
||||
|
||||
type provider struct {
|
||||
type Provider struct {
|
||||
username string
|
||||
host string
|
||||
domain string
|
||||
@@ -29,7 +29,7 @@ type provider struct {
|
||||
}
|
||||
|
||||
func New(data json.RawMessage, domain, host string, ipVersion ipversion.IPVersion) (
|
||||
p *provider, err error) {
|
||||
p *Provider, err error) {
|
||||
extraSettings := struct {
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
@@ -41,7 +41,7 @@ func New(data json.RawMessage, domain, host string, ipVersion ipversion.IPVersio
|
||||
return nil, err
|
||||
}
|
||||
|
||||
p = &provider{
|
||||
p = &Provider{
|
||||
host: host,
|
||||
ipVersion: ipVersion,
|
||||
username: extraSettings.Username,
|
||||
@@ -56,7 +56,7 @@ func New(data json.RawMessage, domain, host string, ipVersion ipversion.IPVersio
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (p *provider) isValid() error {
|
||||
func (p *Provider) isValid() error {
|
||||
switch {
|
||||
case p.username == "":
|
||||
return errors.ErrEmptyUsername
|
||||
@@ -69,31 +69,31 @@ func (p *provider) isValid() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *provider) String() string {
|
||||
func (p *Provider) String() string {
|
||||
return utils.ToString("servercow.de", p.host, constants.Servercow, p.ipVersion)
|
||||
}
|
||||
|
||||
func (p *provider) Domain() string {
|
||||
func (p *Provider) Domain() string {
|
||||
return p.domain
|
||||
}
|
||||
|
||||
func (p *provider) Host() string {
|
||||
func (p *Provider) Host() string {
|
||||
return p.host
|
||||
}
|
||||
|
||||
func (p *provider) IPVersion() ipversion.IPVersion {
|
||||
func (p *Provider) IPVersion() ipversion.IPVersion {
|
||||
return p.ipVersion
|
||||
}
|
||||
|
||||
func (p *provider) Proxied() bool {
|
||||
func (p *Provider) Proxied() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *provider) BuildDomainName() string {
|
||||
func (p *Provider) BuildDomainName() string {
|
||||
return utils.BuildDomainName(p.host, p.domain)
|
||||
}
|
||||
|
||||
func (p *provider) HTML() models.HTMLRow {
|
||||
func (p *Provider) HTML() models.HTMLRow {
|
||||
return models.HTMLRow{
|
||||
Domain: models.HTML(fmt.Sprintf("<a href=\"http://%s\">%s</a>", p.BuildDomainName(), p.BuildDomainName())),
|
||||
Host: models.HTML(p.Host()),
|
||||
@@ -102,7 +102,7 @@ func (p *provider) HTML() models.HTMLRow {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
func (p *Provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
recordType := constants.A
|
||||
if ip.To4() == nil {
|
||||
recordType = constants.AAAA
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
"github.com/qdm12/ddns-updater/pkg/publicip/ipversion"
|
||||
)
|
||||
|
||||
type provider struct {
|
||||
type Provider struct {
|
||||
domain string
|
||||
host string
|
||||
ipVersion ipversion.IPVersion
|
||||
@@ -29,7 +29,7 @@ type provider struct {
|
||||
}
|
||||
|
||||
func New(data json.RawMessage, domain, host string,
|
||||
ipVersion ipversion.IPVersion) (p *provider, err error) {
|
||||
ipVersion ipversion.IPVersion) (p *Provider, err error) {
|
||||
extraSettings := struct {
|
||||
User string `json:"user"`
|
||||
Password string `json:"password"`
|
||||
@@ -39,7 +39,7 @@ func New(data json.RawMessage, domain, host string,
|
||||
if err := json.Unmarshal(data, &extraSettings); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p = &provider{
|
||||
p = &Provider{
|
||||
domain: domain,
|
||||
host: host,
|
||||
ipVersion: ipVersion,
|
||||
@@ -54,7 +54,7 @@ func New(data json.RawMessage, domain, host string,
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (p *provider) isValid() error {
|
||||
func (p *Provider) isValid() error {
|
||||
if len(p.token) > 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -69,31 +69,31 @@ func (p *provider) isValid() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *provider) String() string {
|
||||
func (p *Provider) String() string {
|
||||
return fmt.Sprintf("[domain: %s | host: %s | provider: Spdyn]", p.domain, p.host)
|
||||
}
|
||||
|
||||
func (p *provider) Domain() string {
|
||||
func (p *Provider) Domain() string {
|
||||
return p.domain
|
||||
}
|
||||
|
||||
func (p *provider) Host() string {
|
||||
func (p *Provider) Host() string {
|
||||
return p.host
|
||||
}
|
||||
|
||||
func (p *provider) IPVersion() ipversion.IPVersion {
|
||||
func (p *Provider) IPVersion() ipversion.IPVersion {
|
||||
return p.ipVersion
|
||||
}
|
||||
|
||||
func (p *provider) Proxied() bool {
|
||||
func (p *Provider) Proxied() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *provider) BuildDomainName() string {
|
||||
func (p *Provider) BuildDomainName() string {
|
||||
return utils.BuildDomainName(p.host, p.domain)
|
||||
}
|
||||
|
||||
func (p *provider) HTML() models.HTMLRow {
|
||||
func (p *Provider) HTML() models.HTMLRow {
|
||||
return models.HTMLRow{
|
||||
Domain: models.HTML(fmt.Sprintf("<a href=\"http://%s\">%s</a>", p.BuildDomainName(), p.BuildDomainName())),
|
||||
Host: models.HTML(p.Host()),
|
||||
@@ -102,7 +102,7 @@ func (p *provider) HTML() models.HTMLRow {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
func (p *Provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
// see https://wiki.securepoint.de/SPDyn/Variablen
|
||||
u := url.URL{
|
||||
Scheme: "https",
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
"github.com/qdm12/ddns-updater/pkg/publicip/ipversion"
|
||||
)
|
||||
|
||||
type provider struct {
|
||||
type Provider struct {
|
||||
domain string
|
||||
host string
|
||||
ipVersion ipversion.IPVersion
|
||||
@@ -27,7 +27,7 @@ type provider struct {
|
||||
}
|
||||
|
||||
func New(data json.RawMessage, domain, host string,
|
||||
ipVersion ipversion.IPVersion) (p *provider, err error) {
|
||||
ipVersion ipversion.IPVersion) (p *Provider, err error) {
|
||||
extraSettings := struct {
|
||||
Password string `json:"password"`
|
||||
UseProviderIP bool `json:"provider_ip"`
|
||||
@@ -35,7 +35,7 @@ func New(data json.RawMessage, domain, host string,
|
||||
if err := json.Unmarshal(data, &extraSettings); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p = &provider{
|
||||
p = &Provider{
|
||||
domain: domain,
|
||||
host: host,
|
||||
ipVersion: ipVersion,
|
||||
@@ -48,7 +48,7 @@ func New(data json.RawMessage, domain, host string,
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (p *provider) isValid() error {
|
||||
func (p *Provider) isValid() error {
|
||||
switch {
|
||||
case len(p.password) == 0:
|
||||
return errors.ErrEmptyPassword
|
||||
@@ -58,31 +58,31 @@ func (p *provider) isValid() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *provider) String() string {
|
||||
func (p *Provider) String() string {
|
||||
return fmt.Sprintf("[domain: %s | host: %s | provider: Strato]", p.domain, p.host)
|
||||
}
|
||||
|
||||
func (p *provider) Domain() string {
|
||||
func (p *Provider) Domain() string {
|
||||
return p.domain
|
||||
}
|
||||
|
||||
func (p *provider) Host() string {
|
||||
func (p *Provider) Host() string {
|
||||
return p.host
|
||||
}
|
||||
|
||||
func (p *provider) IPVersion() ipversion.IPVersion {
|
||||
func (p *Provider) IPVersion() ipversion.IPVersion {
|
||||
return p.ipVersion
|
||||
}
|
||||
|
||||
func (p *provider) Proxied() bool {
|
||||
func (p *Provider) Proxied() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *provider) BuildDomainName() string {
|
||||
func (p *Provider) BuildDomainName() string {
|
||||
return utils.BuildDomainName(p.host, p.domain)
|
||||
}
|
||||
|
||||
func (p *provider) HTML() models.HTMLRow {
|
||||
func (p *Provider) HTML() models.HTMLRow {
|
||||
return models.HTMLRow{
|
||||
Domain: models.HTML(fmt.Sprintf("<a href=\"http://%s\">%s</a>", p.BuildDomainName(), p.BuildDomainName())),
|
||||
Host: models.HTML(p.Host()),
|
||||
@@ -91,7 +91,7 @@ func (p *provider) HTML() models.HTMLRow {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
func (p *Provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
u := url.URL{
|
||||
Scheme: "https",
|
||||
User: url.UserPassword(p.domain, p.password),
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/ddns-updater/internal/models"
|
||||
"github.com/qdm12/ddns-updater/internal/regex"
|
||||
"github.com/qdm12/ddns-updater/internal/settings/common"
|
||||
"github.com/qdm12/ddns-updater/internal/settings/constants"
|
||||
"github.com/qdm12/ddns-updater/internal/settings/errors"
|
||||
"github.com/qdm12/ddns-updater/internal/settings/headers"
|
||||
@@ -19,7 +19,7 @@ import (
|
||||
"github.com/qdm12/ddns-updater/pkg/publicip/ipversion"
|
||||
)
|
||||
|
||||
type provider struct {
|
||||
type Provider struct {
|
||||
domain string
|
||||
host string
|
||||
ipVersion ipversion.IPVersion
|
||||
@@ -29,7 +29,7 @@ type provider struct {
|
||||
}
|
||||
|
||||
func New(data json.RawMessage, domain, host string, ipVersion ipversion.IPVersion,
|
||||
matcher regex.Matcher) (p *provider, err error) {
|
||||
matcher common.Matcher) (p *Provider, err error) {
|
||||
extraSettings := struct {
|
||||
Email string `json:"email"`
|
||||
Password string `json:"password"`
|
||||
@@ -38,7 +38,7 @@ func New(data json.RawMessage, domain, host string, ipVersion ipversion.IPVersio
|
||||
if err := json.Unmarshal(data, &extraSettings); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p = &provider{
|
||||
p = &Provider{
|
||||
domain: domain,
|
||||
host: host,
|
||||
ipVersion: ipVersion,
|
||||
@@ -52,7 +52,7 @@ func New(data json.RawMessage, domain, host string, ipVersion ipversion.IPVersio
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (p *provider) isValid() error {
|
||||
func (p *Provider) isValid() error {
|
||||
switch {
|
||||
case len(p.email) == 0:
|
||||
return errors.ErrEmptyEmail
|
||||
@@ -64,31 +64,31 @@ func (p *provider) isValid() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *provider) String() string {
|
||||
func (p *Provider) String() string {
|
||||
return fmt.Sprintf("[domain: %s | host: %s | provider: Variomedia]", p.domain, p.host)
|
||||
}
|
||||
|
||||
func (p *provider) Domain() string {
|
||||
func (p *Provider) Domain() string {
|
||||
return p.domain
|
||||
}
|
||||
|
||||
func (p *provider) Host() string {
|
||||
func (p *Provider) Host() string {
|
||||
return p.host
|
||||
}
|
||||
|
||||
func (p *provider) IPVersion() ipversion.IPVersion {
|
||||
func (p *Provider) IPVersion() ipversion.IPVersion {
|
||||
return p.ipVersion
|
||||
}
|
||||
|
||||
func (p *provider) Proxied() bool {
|
||||
func (p *Provider) Proxied() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *provider) BuildDomainName() string {
|
||||
func (p *Provider) BuildDomainName() string {
|
||||
return utils.BuildDomainName(p.host, p.domain)
|
||||
}
|
||||
|
||||
func (p *provider) HTML() models.HTMLRow {
|
||||
func (p *Provider) HTML() models.HTMLRow {
|
||||
return models.HTMLRow{
|
||||
Domain: models.HTML(fmt.Sprintf("<a href=\"http://%s\">%s</a>", p.BuildDomainName(), p.BuildDomainName())),
|
||||
Host: models.HTML(p.Host()),
|
||||
@@ -97,7 +97,7 @@ func (p *provider) HTML() models.HTMLRow {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
func (p *Provider) Update(ctx context.Context, client *http.Client, ip net.IP) (newIP net.IP, err error) {
|
||||
host := "dyndns.variomedia.de"
|
||||
if p.useProviderIP {
|
||||
if ip.To4() == nil {
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/qdm12/ddns-updater/internal/models"
|
||||
"github.com/qdm12/ddns-updater/internal/regex"
|
||||
"github.com/qdm12/ddns-updater/internal/settings/common"
|
||||
"github.com/qdm12/ddns-updater/internal/settings/constants"
|
||||
"github.com/qdm12/ddns-updater/internal/settings/providers/aliyun"
|
||||
"github.com/qdm12/ddns-updater/internal/settings/providers/allinkl"
|
||||
@@ -62,7 +62,7 @@ var ErrProviderUnknown = errors.New("unknown provider")
|
||||
|
||||
//nolint:gocyclo
|
||||
func New(provider models.Provider, data json.RawMessage, domain, host string, //nolint:ireturn
|
||||
ipVersion ipversion.IPVersion, matcher regex.Matcher) (
|
||||
ipVersion ipversion.IPVersion, matcher common.Matcher) (
|
||||
settings Settings, err error) {
|
||||
switch provider {
|
||||
case constants.Aliyun:
|
||||
@@ -77,7 +77,7 @@ func New(provider models.Provider, data json.RawMessage, domain, host string, //
|
||||
return ddnss.New(data, domain, host, ipVersion)
|
||||
case constants.DigitalOcean:
|
||||
return digitalocean.New(data, domain, host, ipVersion)
|
||||
case constants.DnsOMatic:
|
||||
case constants.DNSOMatic:
|
||||
return dnsomatic.New(data, domain, host, ipVersion, matcher)
|
||||
case constants.DNSPod:
|
||||
return dnspod.New(data, domain, host, ipVersion)
|
||||
|
||||
@@ -14,7 +14,7 @@ type PublicIPFetcher interface {
|
||||
IP6(ctx context.Context) (net.IP, error)
|
||||
}
|
||||
|
||||
type Updater interface {
|
||||
type UpdaterInterface interface {
|
||||
Update(ctx context.Context, recordID int, ip net.IP, now time.Time) (err error)
|
||||
}
|
||||
|
||||
|
||||
@@ -13,10 +13,10 @@ import (
|
||||
"github.com/qdm12/golibs/logging"
|
||||
)
|
||||
|
||||
type runner struct {
|
||||
type Runner struct {
|
||||
period time.Duration
|
||||
db Database
|
||||
updater Updater
|
||||
updater UpdaterInterface
|
||||
force chan struct{}
|
||||
forceResult chan []error
|
||||
ipv6Mask net.IPMask
|
||||
@@ -27,10 +27,10 @@ type runner struct {
|
||||
timeNow func() time.Time
|
||||
}
|
||||
|
||||
func NewRunner(db Database, updater Updater, ipGetter PublicIPFetcher,
|
||||
func NewRunner(db Database, updater UpdaterInterface, ipGetter PublicIPFetcher,
|
||||
period time.Duration, ipv6Mask net.IPMask, cooldown time.Duration,
|
||||
logger logging.Logger, timeNow func() time.Time) *runner {
|
||||
return &runner{
|
||||
logger logging.Logger, timeNow func() time.Time) *Runner {
|
||||
return &Runner{
|
||||
period: period,
|
||||
db: db,
|
||||
updater: updater,
|
||||
@@ -45,7 +45,7 @@ func NewRunner(db Database, updater Updater, ipGetter PublicIPFetcher,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *runner) lookupIPsResilient(ctx context.Context, hostname string, tries int) (
|
||||
func (r *Runner) lookupIPsResilient(ctx context.Context, hostname string, tries int) (
|
||||
ipv4 net.IP, ipv6 net.IP, err error) {
|
||||
for i := 0; i < tries; i++ {
|
||||
ipv4, ipv6, err = r.lookupIPs(ctx, hostname)
|
||||
@@ -56,7 +56,7 @@ func (r *runner) lookupIPsResilient(ctx context.Context, hostname string, tries
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
func (r *runner) lookupIPs(ctx context.Context, hostname string) (ipv4 net.IP, ipv6 net.IP, err error) {
|
||||
func (r *Runner) lookupIPs(ctx context.Context, hostname string) (ipv4 net.IP, ipv6 net.IP, err error) {
|
||||
ips, err := r.resolver.LookupIP(ctx, "ip", hostname)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@@ -88,7 +88,7 @@ func doIPVersion(records []librecords.Record) (doIP, doIPv4, doIPv6 bool) {
|
||||
return doIP, doIPv4, doIPv6
|
||||
}
|
||||
|
||||
func (r *runner) getNewIPs(ctx context.Context, doIP, doIPv4, doIPv6 bool, ipv6Mask net.IPMask) (
|
||||
func (r *Runner) getNewIPs(ctx context.Context, doIP, doIPv4, doIPv6 bool, ipv6Mask net.IPMask) (
|
||||
ip, ipv4, ipv6 net.IP, errors []error) {
|
||||
var err error
|
||||
if doIP {
|
||||
@@ -116,7 +116,7 @@ func (r *runner) getNewIPs(ctx context.Context, doIP, doIPv4, doIPv6 bool, ipv6M
|
||||
return ip, ipv4, ipv6, errors
|
||||
}
|
||||
|
||||
func (r *runner) getRecordIDsToUpdate(ctx context.Context, records []librecords.Record,
|
||||
func (r *Runner) getRecordIDsToUpdate(ctx context.Context, records []librecords.Record,
|
||||
ip, ipv4, ipv6 net.IP, now time.Time, ipv6Mask net.IPMask) (recordIDs map[int]struct{}) {
|
||||
recordIDs = make(map[int]struct{})
|
||||
for id, record := range records {
|
||||
@@ -127,7 +127,7 @@ func (r *runner) getRecordIDsToUpdate(ctx context.Context, records []librecords.
|
||||
return recordIDs
|
||||
}
|
||||
|
||||
func (r *runner) shouldUpdateRecord(ctx context.Context, record librecords.Record,
|
||||
func (r *Runner) shouldUpdateRecord(ctx context.Context, record librecords.Record,
|
||||
ip, ipv4, ipv6 net.IP, now time.Time, ipv6Mask net.IPMask) (update bool) {
|
||||
isWithinBanPeriod := record.LastBan != nil && now.Sub(*record.LastBan) < time.Hour
|
||||
isWithinCooldown := now.Sub(record.History.GetSuccessTime()) < r.cooldown
|
||||
@@ -146,7 +146,7 @@ func (r *runner) shouldUpdateRecord(ctx context.Context, record librecords.Recor
|
||||
return r.shouldUpdateRecordWithLookup(ctx, hostname, ipVersion, ip, ipv4, ipv6, ipv6Mask)
|
||||
}
|
||||
|
||||
func (r *runner) shouldUpdateRecordNoLookup(hostname string, ipVersion ipversion.IPVersion,
|
||||
func (r *Runner) shouldUpdateRecordNoLookup(hostname string, ipVersion ipversion.IPVersion,
|
||||
lastIP, ip, ipv4, ipv6 net.IP) (update bool) {
|
||||
switch ipVersion {
|
||||
case ipversion.IP4or6:
|
||||
@@ -177,7 +177,7 @@ func (r *runner) shouldUpdateRecordNoLookup(hostname string, ipVersion ipversion
|
||||
return false
|
||||
}
|
||||
|
||||
func (r *runner) shouldUpdateRecordWithLookup(ctx context.Context, hostname string, ipVersion ipversion.IPVersion,
|
||||
func (r *Runner) shouldUpdateRecordWithLookup(ctx context.Context, hostname string, ipVersion ipversion.IPVersion,
|
||||
ip, ipv4, ipv6 net.IP, ipv6Mask net.IPMask) (update bool) {
|
||||
const tries = 5
|
||||
recordIPv4, recordIPv6, err := r.lookupIPsResilient(ctx, hostname, tries)
|
||||
@@ -255,7 +255,7 @@ func setInitialUpToDateStatus(db Database, id int, updateIP net.IP, now time.Tim
|
||||
return db.Update(id, record)
|
||||
}
|
||||
|
||||
func (r *runner) updateNecessary(ctx context.Context, ipv6Mask net.IPMask) (errors []error) {
|
||||
func (r *Runner) updateNecessary(ctx context.Context, ipv6Mask net.IPMask) (errors []error) {
|
||||
records := r.db.SelectAll()
|
||||
doIP, doIPv4, doIPv6 := doIPVersion(records)
|
||||
r.logger.Debug(fmt.Sprintf("configured to fetch IP: v4 or v6: %t, v4: %t, v6: %t", doIP, doIPv4, doIPv6))
|
||||
@@ -292,7 +292,7 @@ func (r *runner) updateNecessary(ctx context.Context, ipv6Mask net.IPMask) (erro
|
||||
return errors
|
||||
}
|
||||
|
||||
func (r *runner) Run(ctx context.Context, done chan<- struct{}) {
|
||||
func (r *Runner) Run(ctx context.Context, done chan<- struct{}) {
|
||||
defer close(done)
|
||||
ticker := time.NewTicker(r.period)
|
||||
for {
|
||||
@@ -308,7 +308,7 @@ func (r *runner) Run(ctx context.Context, done chan<- struct{}) {
|
||||
}
|
||||
}
|
||||
|
||||
func (r *runner) ForceUpdate(ctx context.Context) (errs []error) {
|
||||
func (r *Runner) ForceUpdate(ctx context.Context) (errs []error) {
|
||||
r.force <- struct{}{}
|
||||
|
||||
select {
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
"github.com/qdm12/golibs/logging"
|
||||
)
|
||||
|
||||
type updater struct {
|
||||
type Updater struct {
|
||||
db Database
|
||||
client *http.Client
|
||||
notify notifyFunc
|
||||
@@ -23,9 +23,9 @@ type updater struct {
|
||||
|
||||
type notifyFunc func(message string)
|
||||
|
||||
func NewUpdater(db Database, client *http.Client, notify notifyFunc, logger logging.Logger) *updater {
|
||||
func NewUpdater(db Database, client *http.Client, notify notifyFunc, logger logging.Logger) *Updater {
|
||||
client = makeLogClient(client, logger)
|
||||
return &updater{
|
||||
return &Updater{
|
||||
db: db,
|
||||
client: client,
|
||||
notify: notify,
|
||||
@@ -33,7 +33,7 @@ func NewUpdater(db Database, client *http.Client, notify notifyFunc, logger logg
|
||||
}
|
||||
}
|
||||
|
||||
func (u *updater) Update(ctx context.Context, id int, ip net.IP, now time.Time) (err error) {
|
||||
func (u *Updater) Update(ctx context.Context, id int, ip net.IP, now time.Time) (err error) {
|
||||
record, err := u.db.Select(id)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
type fetcher struct {
|
||||
type Fetcher struct {
|
||||
ring ring
|
||||
client Client
|
||||
client4 Client
|
||||
@@ -19,7 +19,7 @@ type ring struct {
|
||||
providers []Provider
|
||||
}
|
||||
|
||||
func New(options ...Option) (f *fetcher, err error) {
|
||||
func New(options ...Option) (f *Fetcher, err error) {
|
||||
settings := newDefaultSettings()
|
||||
for _, option := range options {
|
||||
if err := option(&settings); err != nil {
|
||||
@@ -31,7 +31,7 @@ func New(options ...Option) (f *fetcher, err error) {
|
||||
Timeout: settings.timeout,
|
||||
}
|
||||
|
||||
return &fetcher{
|
||||
return &Fetcher{
|
||||
ring: ring{
|
||||
counter: new(uint32),
|
||||
providers: settings.providers,
|
||||
|
||||
@@ -6,19 +6,19 @@ import (
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
func (f *fetcher) IP(ctx context.Context) (publicIP net.IP, err error) {
|
||||
func (f *Fetcher) IP(ctx context.Context) (publicIP net.IP, err error) {
|
||||
return f.ip(ctx, f.client)
|
||||
}
|
||||
|
||||
func (f *fetcher) IP4(ctx context.Context) (publicIP net.IP, err error) {
|
||||
func (f *Fetcher) IP4(ctx context.Context) (publicIP net.IP, err error) {
|
||||
return f.ip(ctx, f.client4)
|
||||
}
|
||||
|
||||
func (f *fetcher) IP6(ctx context.Context) (publicIP net.IP, err error) {
|
||||
func (f *Fetcher) IP6(ctx context.Context) (publicIP net.IP, err error) {
|
||||
return f.ip(ctx, f.client6)
|
||||
}
|
||||
|
||||
func (f *fetcher) ip(ctx context.Context, client Client) (
|
||||
func (f *Fetcher) ip(ctx context.Context, client Client) (
|
||||
publicIP net.IP, err error) {
|
||||
index := int(atomic.AddUint32(f.ring.counter, 1)) % len(f.ring.providers)
|
||||
provider := f.ring.providers[index]
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"github.com/qdm12/ddns-updater/pkg/publicip/ipversion"
|
||||
)
|
||||
|
||||
type fetcher struct {
|
||||
type Fetcher struct {
|
||||
client *http.Client
|
||||
timeout time.Duration
|
||||
ip4or6 urlsRing // URLs to get ipv4 or ipv6
|
||||
@@ -20,7 +20,7 @@ type urlsRing struct {
|
||||
urls []string
|
||||
}
|
||||
|
||||
func New(client *http.Client, options ...Option) (f *fetcher, err error) {
|
||||
func New(client *http.Client, options ...Option) (f *Fetcher, err error) {
|
||||
settings := newDefaultSettings()
|
||||
for _, option := range options {
|
||||
if err := option(&settings); err != nil {
|
||||
@@ -28,7 +28,7 @@ func New(client *http.Client, options ...Option) (f *fetcher, err error) {
|
||||
}
|
||||
}
|
||||
|
||||
fetcher := &fetcher{
|
||||
fetcher := &Fetcher{
|
||||
client: client,
|
||||
timeout: settings.timeout,
|
||||
}
|
||||
|
||||
@@ -17,11 +17,11 @@ func Test_New(t *testing.T) {
|
||||
|
||||
testCases := map[string]struct {
|
||||
options []Option
|
||||
fetcher *fetcher
|
||||
fetcher *Fetcher
|
||||
err error
|
||||
}{
|
||||
"no options": {
|
||||
fetcher: &fetcher{
|
||||
fetcher: &Fetcher{
|
||||
client: client,
|
||||
timeout: 5 * time.Second,
|
||||
ip4or6: urlsRing{
|
||||
@@ -45,7 +45,7 @@ func Test_New(t *testing.T) {
|
||||
SetProvidersIP6(Ipify),
|
||||
SetTimeout(time.Second),
|
||||
},
|
||||
fetcher: &fetcher{
|
||||
fetcher: &Fetcher{
|
||||
client: client,
|
||||
timeout: time.Second,
|
||||
ip4or6: urlsRing{
|
||||
|
||||
@@ -8,19 +8,19 @@ import (
|
||||
"github.com/qdm12/ddns-updater/pkg/publicip/ipversion"
|
||||
)
|
||||
|
||||
func (f *fetcher) IP(ctx context.Context) (publicIP net.IP, err error) {
|
||||
func (f *Fetcher) IP(ctx context.Context) (publicIP net.IP, err error) {
|
||||
return f.ip(ctx, f.ip4or6, ipversion.IP4or6)
|
||||
}
|
||||
|
||||
func (f *fetcher) IP4(ctx context.Context) (publicIP net.IP, err error) {
|
||||
func (f *Fetcher) IP4(ctx context.Context) (publicIP net.IP, err error) {
|
||||
return f.ip(ctx, f.ip4, ipversion.IP4)
|
||||
}
|
||||
|
||||
func (f *fetcher) IP6(ctx context.Context) (publicIP net.IP, err error) {
|
||||
func (f *Fetcher) IP6(ctx context.Context) (publicIP net.IP, err error) {
|
||||
return f.ip(ctx, f.ip6, ipversion.IP6)
|
||||
}
|
||||
|
||||
func (f *fetcher) ip(ctx context.Context, ring urlsRing, version ipversion.IPVersion) (
|
||||
func (f *Fetcher) ip(ctx context.Context, ring urlsRing, version ipversion.IPVersion) (
|
||||
publicIP net.IP, err error) {
|
||||
index := int(atomic.AddUint32(ring.counter, 1)) % len(ring.urls)
|
||||
url := ring.urls[index]
|
||||
|
||||
@@ -35,7 +35,7 @@ func Test_fetcher_IP(t *testing.T) {
|
||||
}),
|
||||
}
|
||||
|
||||
initialFetcher := &fetcher{
|
||||
initialFetcher := &Fetcher{
|
||||
client: client,
|
||||
timeout: time.Hour,
|
||||
ip4or6: urlsRing{
|
||||
@@ -43,7 +43,7 @@ func Test_fetcher_IP(t *testing.T) {
|
||||
urls: []string{"a", "b", "c"},
|
||||
},
|
||||
}
|
||||
expectedFetcher := &fetcher{
|
||||
expectedFetcher := &Fetcher{
|
||||
client: client,
|
||||
timeout: time.Hour,
|
||||
ip4or6: urlsRing{
|
||||
@@ -79,7 +79,7 @@ func Test_fetcher_IP4(t *testing.T) {
|
||||
}),
|
||||
}
|
||||
|
||||
initialFetcher := &fetcher{
|
||||
initialFetcher := &Fetcher{
|
||||
client: client,
|
||||
timeout: time.Hour,
|
||||
ip4: urlsRing{
|
||||
@@ -87,7 +87,7 @@ func Test_fetcher_IP4(t *testing.T) {
|
||||
urls: []string{"a", "b", "c"},
|
||||
},
|
||||
}
|
||||
expectedFetcher := &fetcher{
|
||||
expectedFetcher := &Fetcher{
|
||||
client: client,
|
||||
timeout: time.Hour,
|
||||
ip4: urlsRing{
|
||||
@@ -126,7 +126,7 @@ func Test_fetcher_IP6(t *testing.T) {
|
||||
}),
|
||||
}
|
||||
|
||||
initialFetcher := &fetcher{
|
||||
initialFetcher := &Fetcher{
|
||||
client: client,
|
||||
timeout: time.Hour,
|
||||
ip6: urlsRing{
|
||||
@@ -134,7 +134,7 @@ func Test_fetcher_IP6(t *testing.T) {
|
||||
urls: []string{"a", "b", "c"},
|
||||
},
|
||||
}
|
||||
expectedFetcher := &fetcher{
|
||||
expectedFetcher := &Fetcher{
|
||||
client: client,
|
||||
timeout: time.Hour,
|
||||
ip6: urlsRing{
|
||||
@@ -177,15 +177,15 @@ func Test_fetcher_ip(t *testing.T) {
|
||||
}
|
||||
|
||||
testCases := map[string]struct {
|
||||
initialFetcher *fetcher
|
||||
initialFetcher *Fetcher
|
||||
ctx context.Context
|
||||
publicIP net.IP
|
||||
err error
|
||||
finalFetcher *fetcher // client is ignored when comparing the two
|
||||
finalFetcher *Fetcher // client is ignored when comparing the two
|
||||
}{
|
||||
"first run": {
|
||||
ctx: context.Background(),
|
||||
initialFetcher: &fetcher{
|
||||
initialFetcher: &Fetcher{
|
||||
timeout: time.Hour,
|
||||
client: newTestClient("b", []byte(`55.55.55.55`), nil),
|
||||
ip4or6: urlsRing{
|
||||
@@ -194,7 +194,7 @@ func Test_fetcher_ip(t *testing.T) {
|
||||
},
|
||||
},
|
||||
publicIP: net.IP{55, 55, 55, 55},
|
||||
finalFetcher: &fetcher{
|
||||
finalFetcher: &Fetcher{
|
||||
timeout: time.Hour,
|
||||
ip4or6: urlsRing{
|
||||
counter: uint32Ptr(1),
|
||||
@@ -204,7 +204,7 @@ func Test_fetcher_ip(t *testing.T) {
|
||||
},
|
||||
"second run": {
|
||||
ctx: context.Background(),
|
||||
initialFetcher: &fetcher{
|
||||
initialFetcher: &Fetcher{
|
||||
timeout: time.Hour,
|
||||
client: newTestClient("a", []byte(`55.55.55.55`), nil),
|
||||
ip4or6: urlsRing{
|
||||
@@ -213,7 +213,7 @@ func Test_fetcher_ip(t *testing.T) {
|
||||
},
|
||||
},
|
||||
publicIP: net.IP{55, 55, 55, 55},
|
||||
finalFetcher: &fetcher{
|
||||
finalFetcher: &Fetcher{
|
||||
timeout: time.Hour,
|
||||
ip4or6: urlsRing{
|
||||
counter: uint32Ptr(2),
|
||||
@@ -223,7 +223,7 @@ func Test_fetcher_ip(t *testing.T) {
|
||||
},
|
||||
"max uint32": {
|
||||
ctx: context.Background(),
|
||||
initialFetcher: &fetcher{
|
||||
initialFetcher: &Fetcher{
|
||||
timeout: time.Hour,
|
||||
client: newTestClient("a", []byte(`55.55.55.55`), nil),
|
||||
ip4or6: urlsRing{
|
||||
@@ -232,7 +232,7 @@ func Test_fetcher_ip(t *testing.T) {
|
||||
},
|
||||
},
|
||||
publicIP: net.IP{55, 55, 55, 55},
|
||||
finalFetcher: &fetcher{
|
||||
finalFetcher: &Fetcher{
|
||||
timeout: time.Hour,
|
||||
ip4or6: urlsRing{
|
||||
counter: uint32Ptr(0),
|
||||
@@ -242,14 +242,14 @@ func Test_fetcher_ip(t *testing.T) {
|
||||
},
|
||||
"zero timeout": {
|
||||
ctx: context.Background(),
|
||||
initialFetcher: &fetcher{
|
||||
initialFetcher: &Fetcher{
|
||||
client: newTestClient("a", nil, nil),
|
||||
ip4or6: urlsRing{
|
||||
counter: uint32Ptr(1),
|
||||
urls: []string{"a", "b"},
|
||||
},
|
||||
},
|
||||
finalFetcher: &fetcher{
|
||||
finalFetcher: &Fetcher{
|
||||
ip4or6: urlsRing{
|
||||
counter: uint32Ptr(2),
|
||||
urls: []string{"a", "b"},
|
||||
@@ -259,7 +259,7 @@ func Test_fetcher_ip(t *testing.T) {
|
||||
},
|
||||
"canceled context": {
|
||||
ctx: canceledCtx,
|
||||
initialFetcher: &fetcher{
|
||||
initialFetcher: &Fetcher{
|
||||
timeout: time.Hour,
|
||||
client: newTestClient("a", nil, nil),
|
||||
ip4or6: urlsRing{
|
||||
@@ -267,7 +267,7 @@ func Test_fetcher_ip(t *testing.T) {
|
||||
urls: []string{"a", "b"},
|
||||
},
|
||||
},
|
||||
finalFetcher: &fetcher{
|
||||
finalFetcher: &Fetcher{
|
||||
timeout: time.Hour,
|
||||
ip4or6: urlsRing{
|
||||
counter: uint32Ptr(2),
|
||||
|
||||
@@ -15,7 +15,7 @@ type ipFetcher interface {
|
||||
IP6(ctx context.Context) (ipv6 net.IP, err error)
|
||||
}
|
||||
|
||||
type fetcher struct {
|
||||
type Fetcher struct {
|
||||
settings settings
|
||||
fetchers []ipFetcher
|
||||
// Cycling effect if both are enabled
|
||||
@@ -24,13 +24,13 @@ type fetcher struct {
|
||||
|
||||
var ErrNoFetchTypeSpecified = errors.New("at least one fetcher type must be specified")
|
||||
|
||||
func NewFetcher(dnsSettings DNSSettings, httpSettings HTTPSettings) (f *fetcher, err error) {
|
||||
func NewFetcher(dnsSettings DNSSettings, httpSettings HTTPSettings) (f *Fetcher, err error) {
|
||||
settings := settings{
|
||||
dns: dnsSettings,
|
||||
http: httpSettings,
|
||||
}
|
||||
|
||||
fetcher := &fetcher{
|
||||
fetcher := &Fetcher{
|
||||
settings: settings,
|
||||
counter: new(uint32),
|
||||
}
|
||||
@@ -58,14 +58,14 @@ func NewFetcher(dnsSettings DNSSettings, httpSettings HTTPSettings) (f *fetcher,
|
||||
return fetcher, nil
|
||||
}
|
||||
|
||||
func (f *fetcher) IP(ctx context.Context) (ip net.IP, err error) {
|
||||
func (f *Fetcher) IP(ctx context.Context) (ip net.IP, err error) {
|
||||
return f.getSubFetcher().IP(ctx)
|
||||
}
|
||||
|
||||
func (f *fetcher) IP4(ctx context.Context) (ipv4 net.IP, err error) {
|
||||
func (f *Fetcher) IP4(ctx context.Context) (ipv4 net.IP, err error) {
|
||||
return f.getSubFetcher().IP4(ctx)
|
||||
}
|
||||
|
||||
func (f *fetcher) IP6(ctx context.Context) (ipv6 net.IP, err error) {
|
||||
func (f *Fetcher) IP6(ctx context.Context) (ipv6 net.IP, err error) {
|
||||
return f.getSubFetcher().IP6(ctx)
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
func (f *fetcher) getSubFetcher() ipFetcher { //nolint:ireturn
|
||||
func (f *Fetcher) getSubFetcher() ipFetcher { //nolint:ireturn
|
||||
fetcher := f.fetchers[0]
|
||||
if len(f.fetchers) > 1 { // cycling effect
|
||||
index := int(atomic.AddUint32(f.counter, 1)) % len(f.fetchers)
|
||||
|
||||
Reference in New Issue
Block a user