Skip to content

Commit

Permalink
chore(dyn): change password -> client_key
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Dec 14, 2022
1 parent 2165b69 commit 3fd82ab
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
4 changes: 2 additions & 2 deletions docs/dyndns.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"domain": "domain.com",
"host": "@",
"username": "username",
"password": "password",
"client_key": "client_key",
"ip_version": "ipv4",
"provider_ip": true
}
Expand All @@ -25,7 +25,7 @@
- `"domain"`
- `"host"` is your host and can be a subdomain or `"@"`
- `"username"`
- `"password"`
- `"client_key"`

### Optional parameters

Expand Down
19 changes: 13 additions & 6 deletions internal/settings/providers/dyn/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,33 @@ type Provider struct {
host string
ipVersion ipversion.IPVersion
username string
password string
clientKey string
useProviderIP bool
}

func New(data json.RawMessage, domain, host string,
ipVersion ipversion.IPVersion) (p *Provider, err error) {
extraSettings := struct {
Username string `json:"username"`
Password string `json:"password"`
Password string `json:"password"` // Retro-compatibility
ClientKey string `json:"client_key"`
UseProviderIP bool `json:"provider_ip"`
}{}
if err := json.Unmarshal(data, &extraSettings); err != nil {
return nil, err
}

clientKey := extraSettings.ClientKey
if clientKey == "" { // Retro-compatibility try
clientKey = extraSettings.Password
}

p = &Provider{
domain: domain,
host: host,
ipVersion: ipVersion,
username: extraSettings.Username,
password: extraSettings.Password,
clientKey: clientKey,
useProviderIP: extraSettings.UseProviderIP,
}
if err := p.isValid(); err != nil {
Expand All @@ -55,7 +62,7 @@ func (p *Provider) isValid() error {
switch {
case len(p.username) == 0:
return errors.ErrEmptyUsername
case len(p.password) == 0:
case p.clientKey == "":
return errors.ErrEmptyPassword
case p.host == "*":
return errors.ErrHostWildcard
Expand Down Expand Up @@ -99,7 +106,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) {
u := url.URL{
Scheme: "https",
User: url.UserPassword(p.username, p.password),
User: url.UserPassword(p.username, p.clientKey),
Host: "members.dyndns.org",
Path: "/v3/update",
}
Expand Down Expand Up @@ -137,7 +144,7 @@ func (p *Provider) Update(ctx context.Context, client *http.Client, ip net.IP) (
case strings.HasPrefix(s, constants.Notfqdn):
return nil, errors.ErrHostnameNotExists
case strings.HasPrefix(s, "badrequest"):
return nil, fmt.Errorf("%w: %s", errors.ErrBadRequest, strings.TrimPrefix(s, "badrequest"))
return nil, fmt.Errorf("%w", errors.ErrBadRequest)
case strings.HasPrefix(s, "good"):
return ip, nil
default:
Expand Down

0 comments on commit 3fd82ab

Please sign in to comment.