Skip to content

Commit

Permalink
Fixed or adjusted most comments. Ready for another review.
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberAustin committed Feb 2, 2024
1 parent 9ed3041 commit 431c31e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 31 deletions.
16 changes: 5 additions & 11 deletions docs/goip.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,21 @@
"settings": [
{
"provider": "goip.de",
"domain": "subdomain",
"subdomain": "subdomain",
"username": "username",
"password": "password",
"provider_ip": true,
"ip_version": "ipv4",
"ipv6_suffix": ""
}
]
}
```

### Compulsory parameters

- `"domain"`
- `"username"` is your goip.de username listed un "Routers"
- `"password"` is your router username password
- `"subdomain"`
- `"username"` is your goip.de username listed under "Routers"
- `"password"` is your router account password

### Optional parameters

- `"ip_version"` can be `ipv4` (A records), or `ipv6` (AAAA records) or `ipv4 or ipv6` (update one of the two, depending on the public ip found). It defaults to `ipv4 or ipv6`.
- `"ipv6_suffix"` is the IPv6 interface identifiersuffix to use. It can be for example `0:0:0:0:72ad:8fbb:a54e:bedd/64`. If left empty, it defaults to no suffix and the raw public IPv6 address obtained is used in the record updating.
- `"provider_ip"` can be set to `true` to let your DNS provider determine your IPv4 address (and/or IPv6 address) automatically when you send an update request, without sending the new IP address detected by the program in the request.

## Domain setup
- `"provider_ip"` can be set to `true` to let your DNS provider determine your IPv4 address (and/or IPv6 address) automatically when you send an update request, without sending the new IP address detected by the program in the request.

Check failure on line 29 in docs/goip.md

View workflow job for this annotation

GitHub Actions / markdown

Files should end with a single newline character

docs/goip.md:29:235 MD047/single-trailing-newline Files should end with a single newline character https://github.com/DavidAnson/markdownlint/blob/v0.32.1/doc/md047.md
4 changes: 2 additions & 2 deletions internal/provider/constants/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const (
Gandi models.Provider = "gandi"
GCP models.Provider = "gcp"
GoDaddy models.Provider = "godaddy"
GoIP models.Provider = "goip"
GoIP models.Provider = "goip"
HE models.Provider = "he"
Hetzner models.Provider = "hetzner"
Infomaniak models.Provider = "infomaniak"
Expand Down Expand Up @@ -72,7 +72,7 @@ func ProviderChoices() []models.Provider {
Gandi,
GCP,
GoDaddy,
GoIP,
GoIP,
HE,
Hetzner,
Infomaniak,
Expand Down
6 changes: 3 additions & 3 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"github.com/qdm12/ddns-updater/internal/provider/providers/gandi"
"github.com/qdm12/ddns-updater/internal/provider/providers/gcp"
"github.com/qdm12/ddns-updater/internal/provider/providers/godaddy"
"github.com/qdm12/ddns-updater/internal/provider/providers/goip"
"github.com/qdm12/ddns-updater/internal/provider/providers/goip"
"github.com/qdm12/ddns-updater/internal/provider/providers/he"
"github.com/qdm12/ddns-updater/internal/provider/providers/hetzner"
"github.com/qdm12/ddns-updater/internal/provider/providers/infomaniak"
Expand Down Expand Up @@ -117,8 +117,8 @@ func New(providerName models.Provider, data json.RawMessage, domain, host string
return gcp.New(data, domain, host, ipVersion, ipv6Suffix)
case constants.GoDaddy:
return godaddy.New(data, domain, host, ipVersion, ipv6Suffix)
case constants.GoIP:
return goip.New(data, domain, ipVersion, ipv6Suffix)
case constants.GoIP:
return goip.New(data, domain, ipVersion, ipv6Suffix)
case constants.HE:
return he.New(data, domain, host, ipVersion, ipv6Suffix)
case constants.Hetzner:
Expand Down
26 changes: 11 additions & 15 deletions internal/provider/providers/goip/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ import (
)

type Provider struct {
domain string
subdomain string
ipVersion ipversion.IPVersion
ipv6Suffix netip.Prefix
username string
password string
useProviderIP bool
}

func New(data json.RawMessage, domain string,
func New(data json.RawMessage, subdomain string,
ipVersion ipversion.IPVersion, ipv6Suffix netip.Prefix) (
p *Provider, err error) {
extraSettings := struct {
Expand All @@ -40,7 +40,7 @@ func New(data json.RawMessage, domain string,
return nil, err
}
p = &Provider{
domain: domain,
subdomain: subdomain,
ipVersion: ipVersion,
ipv6Suffix: ipv6Suffix,
username: extraSettings.Username,
Expand All @@ -64,14 +64,16 @@ func (p *Provider) isValid() error {
return nil
}

// "@" necessary to prevent ToString from appending a "." to the FQDN
func (p *Provider) String() string {
return utils.ToString(p.domain, "@", constants.GoIP, p.ipVersion)
return utils.ToString(p.subdomain, "@", constants.GoIP, p.ipVersion)
}

func (p *Provider) Domain() string {
return p.domain
return p.subdomain
}

// "@" hard coded for compatibility with other provider implementations
func (p *Provider) Host() string {
return "@"
}
Expand All @@ -89,7 +91,7 @@ func (p *Provider) Proxied() bool {
}

func (p *Provider) BuildDomainName() string {
return p.domain
return p.subdomain
}

func (p *Provider) HTML() models.HTMLRow {
Expand All @@ -109,7 +111,7 @@ func (p *Provider) Update(ctx context.Context, client *http.Client, ip netip.Add
Path: "/setip",
}
values := url.Values{}
values.Set("subdomain", p.domain)
values.Set("subdomain", p.subdomain)
values.Set("username", p.username)
values.Set("password", p.password)
values.Set("shortResponse", "true")
Expand All @@ -133,8 +135,6 @@ func (p *Provider) Update(ctx context.Context, client *http.Client, ip netip.Add

switch response.StatusCode {
case http.StatusOK:
case http.StatusNoContent:
return ip, nil
case http.StatusUnauthorized:
return netip.Addr{}, fmt.Errorf("%w", errors.ErrAuth)
case http.StatusConflict:
Expand All @@ -143,8 +143,6 @@ func (p *Provider) Update(ctx context.Context, client *http.Client, ip netip.Add
return netip.Addr{}, fmt.Errorf("%w", errors.ErrAccountInactive)
case http.StatusLengthRequired:
return netip.Addr{}, fmt.Errorf("%w: %s", errors.ErrIPSentMalformed, ip)
case http.StatusPreconditionFailed:
return netip.Addr{}, fmt.Errorf("%w: %s", errors.ErrPrivateIPSent, ip)
case http.StatusServiceUnavailable:
return netip.Addr{}, fmt.Errorf("%w", errors.ErrDNSServerSide)
default:
Expand All @@ -158,12 +156,10 @@ func (p *Provider) Update(ctx context.Context, client *http.Client, ip netip.Add
}
s := string(b)
switch {
case strings.HasPrefix(s, p.domain+" ("+ip.String()+")"):
case strings.HasPrefix(s, p.subdomain+" ("+ip.String()+")"):
return ip, nil
case strings.HasPrefix(s, "Zugriff verweigert"):
case strings.HasPrefix(strings.ToLower(s), "zugriff verweigert"):
return netip.Addr{}, fmt.Errorf("Username, Password or Subdomain incorrect")
case strings.HasPrefix(s, "Die Datenübertragung war fehlerhaft"):
return netip.Addr{}, fmt.Errorf(("IP address incorrectly formatted"))
default:
return netip.Addr{}, fmt.Errorf("%w: %s", errors.ErrUnknownResponse, s)
}
Expand Down

0 comments on commit 431c31e

Please sign in to comment.