Skip to content

Commit

Permalink
Add support for Infomaniak as provider (#219)
Browse files Browse the repository at this point in the history
Add support for Infomaniak(.com), follows the same schema as Google Domains
  • Loading branch information
diizzyy authored Oct 22, 2023
1 parent 3302715 commit 6ddeca8
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 0 deletions.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
- [Linode](#linode)
- [Strato](#strato)
- [LoopiaSE](#loopiase)
- [Infomaniak](#infomaniak)
- [OVH](#ovh)
- [Dynu](#dynu)
- [Notifications](#notifications)
Expand Down Expand Up @@ -93,6 +94,7 @@
| [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: |
| [LoopiaSE][loopiase] | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: |
| [Infomaniak][infomaniak] | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: |
| [Hetzner][hetzner] | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| [OVH][ovh] | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: |
| [Dynu][dynu] | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: |
Expand All @@ -110,6 +112,7 @@
[linode]: https://www.linode.com
[strato]: https://strato.de
[loopiase]: https://www.loopia.se/
[infomaniak]: https://www.infomaniak.com/
[hetzner]: https://hetzner.com/
[ovh]: https://www.ovh.com
[dynu]: https://www.dynu.com/
Expand Down Expand Up @@ -654,6 +657,39 @@ More info: [Swedish](https://support.loopia.se/wiki/om-dyndns-stodet/)

</details>

#### Infomaniak

For Infomaniak, you need to provide username & password, and config all the domains & subdomains.
More info: [English](https://faq.infomaniak.com/2376)

<details>
<summary>Example</summary>

```json
{
"provider": "Infomaniak",
"email": "Your_Username",
"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>

#### Hetzner

For Hetzner, you have to create an access token. This can be done in the DNS-Console.
Expand Down
3 changes: 3 additions & 0 deletions internal/provider/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/TimothyYe/godns/internal/provider/hetzner"

Check failure on line 15 in internal/provider/factory.go

View workflow job for this annotation

GitHub Actions / Auto triggered CI job

File is not `goimports`-ed (goimports)
"github.com/TimothyYe/godns/internal/provider/linode"
"github.com/TimothyYe/godns/internal/provider/loopiase"
"github.com/TimothyYe/godns/internal/provider/infomaniak"
"github.com/TimothyYe/godns/internal/provider/noip"
"github.com/TimothyYe/godns/internal/provider/ovh"
"github.com/TimothyYe/godns/internal/provider/scaleway"
Expand Down Expand Up @@ -53,6 +54,8 @@ func GetProvider(conf *settings.Settings) (IDNSProvider, error) {
provider = &strato.DNSProvider{}
case utils.LOOPIASE:
provider = &loopiase.DNSProvider{}
case utils.INFOMANIAK:
provider = &infomaniak.DNSProvider{}
case utils.HETZNER:
provider = &hetzner.DNSProvider{}
case utils.OVH:
Expand Down
76 changes: 76 additions & 0 deletions internal/provider/infomaniak/infomaniak_handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package infomaniak

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 Infomaniak.
URL = "https://%s:%[email protected]/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,
provider.configuration.Email,
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 @@ -31,6 +31,8 @@ const (
STRATO = "Strato"
// LOOPIASE for LoopiaSE.
LOOPIASE = "LoopiaSE"
// INFOMANIAK for Infomaniak.
INFOMANIAK = "Infomaniak"
// HETZNER for Hetzner.
HETZNER = "Hetzner"
// OVH for OVH.
Expand Down
4 changes: 4 additions & 0 deletions internal/utils/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ func CheckSettings(config *settings.Settings) error {
if config.Password == "" {
return errors.New("password cannot be empty")
}
case INFOMANIAK:
if config.Password == "" {
return errors.New("password cannot be empty")
}
case HETZNER:
if config.LoginToken == "" {
return errors.New("login token cannot be empty")
Expand Down

0 comments on commit 6ddeca8

Please sign in to comment.