Skip to content

Commit

Permalink
Added Strato as Provider (#193)
Browse files Browse the repository at this point in the history
* 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: = <uogxs@student.kit.edu>
Co-authored-by: Philipp Wasser <mail@philippwasser.de>
  • Loading branch information
3 people authored Jan 17, 2023
1 parent b03832c commit 41d18ef
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 3 deletions.
34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -552,6 +555,35 @@ The GoDNS Linode handler currently uses a fixed TTL of 30 seconds for Linode DNS
```
</details>
#### 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/)
<details>
<summary>Example</summary>
```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": ""
}
```
</details>
### Notifications
GoDNS can send a notification each time the IP changes.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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

3 changes: 3 additions & 0 deletions internal/provider/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 2 additions & 0 deletions internal/provider/google/google_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
76 changes: 76 additions & 0 deletions internal/provider/strato/strato_handler.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 2 additions & 0 deletions internal/utils/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion internal/utils/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 41d18ef

Please sign in to comment.