This commit is contained in:
Quentin McGaw
2019-05-23 17:14:29 +02:00
parent 86cf72fec8
commit 206e9a50ba
3 changed files with 10 additions and 11 deletions

View File

@@ -16,7 +16,7 @@ type SettingsType struct {
Delay time.Duration
NoDNSLookup bool
// Provider dependent fields
Password string // Namecheap only
Password string // Namecheap and NoIP only
Key string // GoDaddy, Dreamhost and Cloudflare only
Secret string // GoDaddy only
Token string // DuckDNS only
@@ -25,6 +25,7 @@ type SettingsType struct {
ZoneIdentifier string // Cloudflare only
Identifier string // Cloudflare only
Proxied bool // Cloudflare only
Username string // NoIP only
}
func (settings *SettingsType) String() string {
@@ -140,10 +141,10 @@ func (settings *SettingsType) Verify() error {
return fmt.Errorf("unsupported IP update method for settings %s", settings)
}
case PROVIDERNOIP:
if !regex.MatchEmail(settings.Email) {
return fmt.Errorf("invalid email format for settings %s", settings)
} else if len(settings.Email) > 50 {
return fmt.Errorf("email cannot be longer than 50 characters for settings %s", settings)
if len(settings.Username) == 0 {
return fmt.Errorf("username cannot be empty for settings %s", settings)
} else if len(settings.Username) > 50 {
return fmt.Errorf("username cannot be longer than 50 characters for settings %s", settings)
} else if len(settings.Password) == 0 {
return fmt.Errorf("password cannot be empty for settings %s", settings)
} else if settings.Host == "*" {

View File

@@ -1,7 +1,6 @@
package update
import (
"encoding/base64"
"encoding/json"
"encoding/xml"
"fmt"
@@ -103,7 +102,7 @@ func update(
ip, err = updateNoIP(
httpClient,
recordConfig.Settings.BuildDomainName(),
recordConfig.Settings.Email,
recordConfig.Settings.Username,
recordConfig.Settings.Password,
ip,
)
@@ -415,7 +414,7 @@ func updateDreamhost(httpClient *http.Client, domain, key, ip, domainName string
return nil
}
func updateNoIP(httpClient *http.Client, hostname, email, password, ip string) (newIP string, err error) {
func updateNoIP(httpClient *http.Client, hostname, username, password, ip string) (newIP string, err error) {
url := strings.ToLower(noIPURL + "?hostname=" + hostname)
if len(ip) > 0 {
url += "&myip=" + ip
@@ -424,8 +423,7 @@ func updateNoIP(httpClient *http.Client, hostname, email, password, ip string) (
if err != nil {
return "", err
}
credsEncoded := base64.StdEncoding.EncodeToString([]byte(email + ":" + password))
r.Header.Set("Authorization", "Basic "+credsEncoded)
r.Header.Set("Authorization", "Basic "+username+":"+password)
r.Header.Set("User-Agent", "DDNS-Updater quentin.mcgaw@gmail.com")
status, content, err := network.DoHTTPRequest(httpClient, r)
if err != nil {