-
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
b03832c
commit 41d18ef
Showing
7 changed files
with
121 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters