Skip to content

Commit 41d18ef

Browse files
Phiwatec=Philipp Wasser
authored
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: = <[email protected]> Co-authored-by: Philipp Wasser <[email protected]>
1 parent b03832c commit 41d18ef

File tree

7 files changed

+121
-3
lines changed

7 files changed

+121
-3
lines changed

README.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Currently supports updating A records for subdomains. Doesn't support updating o
4747
- [HE.net](#henet)
4848
- [Scaleway](#scaleway)
4949
- [Linode](#linode)
50+
- [Strato](#strato)
5051
- [Notifications](#notifications)
5152
- [Email](#email)
5253
- [Telegram](#telegram)
@@ -87,6 +88,8 @@ Currently supports updating A records for subdomains. Doesn't support updating o
8788
| [No-IP][no-ip] | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: |
8889
| [Scaleway][Scaleway] | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
8990
| [Linode][linode] | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
91+
| [Strato][strato] | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: |
92+
9093

9194
[cloudflare]: https://cloudflare.com
9295
[google.domains]: https://domains.google
@@ -99,7 +102,7 @@ Currently supports updating A records for subdomains. Doesn't support updating o
99102
[no-ip]: https://www.noip.com
100103
[Scaleway]: https://www.scaleway.com/
101104
[Linode]: https://www.linode.com
102-
105+
[Strato]: https://strato.de
103106
Tip: You can follow this [issue](https://github.com/TimothyYe/godns/issues/76) to view the current status of DDNS for root domains.
104107

105108
## Supported Platforms
@@ -552,6 +555,35 @@ The GoDNS Linode handler currently uses a fixed TTL of 30 seconds for Linode DNS
552555
```
553556
</details>
554557

558+
#### Strato
559+
560+
For Strato, you need to provide email & password, and config all the domains & subdomains.
561+
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/)
562+
563+
<details>
564+
<summary>Example</summary>
565+
566+
```json
567+
{
568+
"provider": "strato",
569+
"password": "Your_Password",
570+
"domains": [{
571+
"domain_name": "example.com",
572+
"sub_domains": ["www","test"]
573+
},{
574+
"domain_name": "example2.com",
575+
"sub_domains": ["www","test"]
576+
}
577+
],
578+
"resolver": "8.8.8.8",
579+
"ip_urls": ["https://api.ip.sb/ip"],
580+
"ip_type": "IPv4",
581+
"interval": 300,
582+
"socks5_proxy": ""
583+
}
584+
```
585+
</details>
586+
555587
### Notifications
556588

557589
GoDNS can send a notification each time the IP changes.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@ require (
3636
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
3737
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
3838
)
39-
4039
go 1.17
40+

internal/provider/factory.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/TimothyYe/godns/internal/provider/linode"
1515
"github.com/TimothyYe/godns/internal/provider/noip"
1616
"github.com/TimothyYe/godns/internal/provider/scaleway"
17+
"github.com/TimothyYe/godns/internal/provider/strato"
1718
"github.com/TimothyYe/godns/internal/settings"
1819
"github.com/TimothyYe/godns/internal/utils"
1920
)
@@ -44,6 +45,8 @@ func GetProvider(conf *settings.Settings) (IDNSProvider, error) {
4445
provider = &dynv6.DNSProvider{}
4546
case utils.LINODE:
4647
provider = &linode.DNSProvider{}
48+
case utils.STRATO:
49+
provider = &strato.DNSProvider{}
4750
default:
4851
return nil, fmt.Errorf("Unknown provider '%s'", conf.Provider)
4952
}

internal/provider/google/google_handler.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ func (provider *DNSProvider) updateIP(domain, subDomain, currentIP string) error
6868
log.Infof("Update IP success: %s", string(body))
6969
} else if strings.Contains(string(body), "nochg") {
7070
log.Infof("IP not changed: %s", string(body))
71+
} else {
72+
return fmt.Errorf("update IP failed: %s", string(body))
7173
}
7274

7375
return nil
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package strato
2+
3+
import (
4+
"fmt"
5+
"io"
6+
"net/http"
7+
"strings"
8+
9+
"github.com/TimothyYe/godns/internal/settings"
10+
"github.com/TimothyYe/godns/internal/utils"
11+
log "github.com/sirupsen/logrus"
12+
)
13+
14+
const (
15+
// URL the API address for Strato.
16+
URL = "https://%s:%[email protected]/nic/update?hostname=%s.%s&myip=%s"
17+
)
18+
19+
// DNSProvider struct.
20+
type DNSProvider struct {
21+
configuration *settings.Settings
22+
}
23+
24+
// Init passes DNS settings and store it to the provider instance.
25+
func (provider *DNSProvider) Init(conf *settings.Settings) {
26+
provider.configuration = conf
27+
}
28+
29+
func (provider *DNSProvider) UpdateIP(domainName, subdomainName, ip string) error {
30+
return provider.updateIP(domainName, subdomainName, ip)
31+
}
32+
33+
// updateIP update subdomain with current IP.
34+
func (provider *DNSProvider) updateIP(domain, subDomain, currentIP string) error {
35+
client := utils.GetHTTPClient(provider.configuration)
36+
resp, err := client.Get(fmt.Sprintf(URL,
37+
domain,
38+
provider.configuration.Password,
39+
subDomain,
40+
domain,
41+
currentIP))
42+
43+
if err != nil {
44+
// handle error
45+
log.Error("Failed to update sub domain:", subDomain)
46+
return err
47+
}
48+
49+
defer func(Body io.ReadCloser) {
50+
err := Body.Close()
51+
if err != nil {
52+
log.Error(err)
53+
}
54+
}(resp.Body)
55+
56+
if err != nil {
57+
log.Error("Err:", err.Error())
58+
return err
59+
}
60+
61+
body, _ := io.ReadAll(resp.Body)
62+
if resp.StatusCode != http.StatusOK {
63+
log.Errorf("Update IP failed: %s", string(body))
64+
return fmt.Errorf("update IP failed: %s", string(body))
65+
}
66+
67+
if strings.Contains(string(body), "good") {
68+
log.Infof("Update IP success: %s", string(body))
69+
} else if strings.Contains(string(body), "nochg") {
70+
log.Infof("IP not changed: %s", string(body))
71+
} else {
72+
return fmt.Errorf("update IP failed: %s", string(body))
73+
}
74+
75+
return nil
76+
}

internal/utils/constants.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ const (
2525
SCALEWAY = "Scaleway"
2626
// LINODE for Linode.
2727
LINODE = "Linode"
28+
// STRATO for Strato.
29+
STRATO = "Strato"
2830
// IPV4 for IPV4 mode.
2931
IPV4 = "IPV4"
3032
// IPV6 for IPV6 mode.

internal/utils/settings.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ func CheckSettings(config *settings.Settings) error {
6363
if config.LoginToken == "" {
6464
return errors.New("login token cannot be empty")
6565
}
66-
66+
case STRATO:
67+
if config.Password == "" {
68+
return errors.New("password cannot be empty")
69+
}
6770
default:
6871
message := fmt.Sprintf("'%s' is not a supported DNS provider", config.Provider)
6972
return errors.New(message)

0 commit comments

Comments
 (0)