From 41d18ef016469d9d285642961645ae5bdade1d7b Mon Sep 17 00:00:00 2001 From: Philipp Wasser <52720981+Phiwatec@users.noreply.github.com> Date: Tue, 17 Jan 2023 02:43:13 +0100 Subject: [PATCH] Added Strato as Provider (#193) * Created Strato provider file * Added Strato to provider config list * Update README.md * Update README.md * Fixed link * Username is domain not email * Username is not configured as the username is the domain * Added folder and file * Delete internal/provider/hetzner directory Fixed empty File. Pushed to wrong branch * Working * Added error handling for wrong password * Moved strato_provider to strato_handler * Removed debugging prints * Update README.md * Describtion added Strato * Fixed typos * Fixed go mod to point to repo * Better error message * lower case Error * Changed to lowercase #2 Co-authored-by: = Co-authored-by: Philipp Wasser --- README.md | 34 +++++++++- go.mod | 2 +- internal/provider/factory.go | 3 + internal/provider/google/google_handler.go | 2 + internal/provider/strato/strato_handler.go | 76 ++++++++++++++++++++++ internal/utils/constants.go | 2 + internal/utils/settings.go | 5 +- 7 files changed, 121 insertions(+), 3 deletions(-) create mode 100644 internal/provider/strato/strato_handler.go diff --git a/README.md b/README.md index 21d33983..b3c4f0de 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ Currently supports updating A records for subdomains. Doesn't support updating o - [HE.net](#henet) - [Scaleway](#scaleway) - [Linode](#linode) + - [Strato](#strato) - [Notifications](#notifications) - [Email](#email) - [Telegram](#telegram) @@ -87,6 +88,8 @@ Currently supports updating A records for subdomains. Doesn't support updating o | [No-IP][no-ip] | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: | | [Scaleway][Scaleway] | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | | [Linode][linode] | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| [Strato][strato] | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: | + [cloudflare]: https://cloudflare.com [google.domains]: https://domains.google @@ -99,7 +102,7 @@ Currently supports updating A records for subdomains. Doesn't support updating o [no-ip]: https://www.noip.com [Scaleway]: https://www.scaleway.com/ [Linode]: https://www.linode.com - +[Strato]: https://strato.de Tip: You can follow this [issue](https://github.com/TimothyYe/godns/issues/76) to view the current status of DDNS for root domains. ## Supported Platforms @@ -552,6 +555,35 @@ The GoDNS Linode handler currently uses a fixed TTL of 30 seconds for Linode DNS ``` +#### Strato + +For Strato, you need to provide email & password, and config all the domains & subdomains. +More Info: [German](https://www.strato.de/faq/hosting/so-einfach-richten-sie-dyndns-fuer-ihre-domains-ein/) [English](https://www.strato-hosting.co.uk/faq/hosting/this-is-how-easy-it-is-to-set-up-dyndns-for-your-domains/) + +
+Example + +```json +{ + "provider": "strato", + "password": "Your_Password", + "domains": [{ + "domain_name": "example.com", + "sub_domains": ["www","test"] + },{ + "domain_name": "example2.com", + "sub_domains": ["www","test"] + } + ], + "resolver": "8.8.8.8", + "ip_urls": ["https://api.ip.sb/ip"], + "ip_type": "IPv4", + "interval": 300, + "socks5_proxy": "" +} +``` +
+ ### Notifications GoDNS can send a notification each time the IP changes. diff --git a/go.mod b/go.mod index 69cce919..172b38c5 100644 --- a/go.mod +++ b/go.mod @@ -36,5 +36,5 @@ require ( gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect ) - go 1.17 + diff --git a/internal/provider/factory.go b/internal/provider/factory.go index 7dc6c4e6..30d5e786 100644 --- a/internal/provider/factory.go +++ b/internal/provider/factory.go @@ -14,6 +14,7 @@ import ( "github.com/TimothyYe/godns/internal/provider/linode" "github.com/TimothyYe/godns/internal/provider/noip" "github.com/TimothyYe/godns/internal/provider/scaleway" + "github.com/TimothyYe/godns/internal/provider/strato" "github.com/TimothyYe/godns/internal/settings" "github.com/TimothyYe/godns/internal/utils" ) @@ -44,6 +45,8 @@ func GetProvider(conf *settings.Settings) (IDNSProvider, error) { provider = &dynv6.DNSProvider{} case utils.LINODE: provider = &linode.DNSProvider{} + case utils.STRATO: + provider = &strato.DNSProvider{} default: return nil, fmt.Errorf("Unknown provider '%s'", conf.Provider) } diff --git a/internal/provider/google/google_handler.go b/internal/provider/google/google_handler.go index 91aa6d04..c7df462b 100644 --- a/internal/provider/google/google_handler.go +++ b/internal/provider/google/google_handler.go @@ -68,6 +68,8 @@ func (provider *DNSProvider) updateIP(domain, subDomain, currentIP string) error log.Infof("Update IP success: %s", string(body)) } else if strings.Contains(string(body), "nochg") { log.Infof("IP not changed: %s", string(body)) + } else { + return fmt.Errorf("update IP failed: %s", string(body)) } return nil diff --git a/internal/provider/strato/strato_handler.go b/internal/provider/strato/strato_handler.go new file mode 100644 index 00000000..7df5d90e --- /dev/null +++ b/internal/provider/strato/strato_handler.go @@ -0,0 +1,76 @@ +package strato + +import ( + "fmt" + "io" + "net/http" + "strings" + + "github.com/TimothyYe/godns/internal/settings" + "github.com/TimothyYe/godns/internal/utils" + log "github.com/sirupsen/logrus" +) + +const ( + // URL the API address for Strato. + URL = "https://%s:%s@dyndns.strato.com/nic/update?hostname=%s.%s&myip=%s" +) + +// DNSProvider struct. +type DNSProvider struct { + configuration *settings.Settings +} + +// Init passes DNS settings and store it to the provider instance. +func (provider *DNSProvider) Init(conf *settings.Settings) { + provider.configuration = conf +} + +func (provider *DNSProvider) UpdateIP(domainName, subdomainName, ip string) error { + return provider.updateIP(domainName, subdomainName, ip) +} + +// updateIP update subdomain with current IP. +func (provider *DNSProvider) updateIP(domain, subDomain, currentIP string) error { + client := utils.GetHTTPClient(provider.configuration) + resp, err := client.Get(fmt.Sprintf(URL, + domain, + provider.configuration.Password, + subDomain, + domain, + currentIP)) + + if err != nil { + // handle error + log.Error("Failed to update sub domain:", subDomain) + return err + } + + defer func(Body io.ReadCloser) { + err := Body.Close() + if err != nil { + log.Error(err) + } + }(resp.Body) + + if err != nil { + log.Error("Err:", err.Error()) + return err + } + + body, _ := io.ReadAll(resp.Body) + if resp.StatusCode != http.StatusOK { + log.Errorf("Update IP failed: %s", string(body)) + return fmt.Errorf("update IP failed: %s", string(body)) + } + + if strings.Contains(string(body), "good") { + log.Infof("Update IP success: %s", string(body)) + } else if strings.Contains(string(body), "nochg") { + log.Infof("IP not changed: %s", string(body)) + } else { + return fmt.Errorf("update IP failed: %s", string(body)) + } + + return nil +} diff --git a/internal/utils/constants.go b/internal/utils/constants.go index e344091e..b2e93c45 100644 --- a/internal/utils/constants.go +++ b/internal/utils/constants.go @@ -25,6 +25,8 @@ const ( SCALEWAY = "Scaleway" // LINODE for Linode. LINODE = "Linode" + // STRATO for Strato. + STRATO = "Strato" // IPV4 for IPV4 mode. IPV4 = "IPV4" // IPV6 for IPV6 mode. diff --git a/internal/utils/settings.go b/internal/utils/settings.go index 643d7995..cf3ab58e 100644 --- a/internal/utils/settings.go +++ b/internal/utils/settings.go @@ -63,7 +63,10 @@ func CheckSettings(config *settings.Settings) error { if config.LoginToken == "" { return errors.New("login token cannot be empty") } - + case STRATO: + if config.Password == "" { + return errors.New("password cannot be empty") + } default: message := fmt.Sprintf("'%s' is not a supported DNS provider", config.Provider) return errors.New(message)