Do not use ch.DNSName

This commit is contained in:
斟酌 鵬兄 2022-03-14 07:05:38 +09:00
parent 9a7e0ef027
commit fb99ace026
2 changed files with 17 additions and 13 deletions

View File

@ -34,6 +34,12 @@ const URI_DELETE_RECORD = "https://freedns.afraid.org/subdomain/delete2.php?data
// const URI_LOGIN string = "http://127.0.0.1:1234/" // const URI_LOGIN string = "http://127.0.0.1:1234/"
func GetDomainFromZone(Zone string) string {
_segs := strings.Split(Zone, ".")
_segs = _segs[len(_segs)-2:]
return strings.Join(_segs, ".")
}
func _HttpRequest(method string, url string, PostData url.Values, ExCookie *http.Cookie) (*http.Response, string, error) { func _HttpRequest(method string, url string, PostData url.Values, ExCookie *http.Cookie) (*http.Response, string, error) {
client := http.Client{ client := http.Client{
CheckRedirect: func(req *http.Request, via []*http.Request) error { CheckRedirect: func(req *http.Request, via []*http.Request) error {

24
main.go
View File

@ -104,22 +104,23 @@ func (c *customDNSProviderSolver) Present(ch *v1alpha1.ChallengeRequest) error {
username := string(secretObj.Data["username"]) username := string(secretObj.Data["username"])
password := string(secretObj.Data["password"]) password := string(secretObj.Data["password"])
freedns := freedns.FreeDNS{} dnsObj := freedns.FreeDNS{}
err = freedns.Login(username, password) err = dnsObj.Login(username, password)
if err != nil { if err != nil {
return err return err
} }
err = freedns.SelectDomain(ch.DNSName) domainName := freedns.GetDomainFromZone(ch.ResolvedZone)
err = dnsObj.SelectDomain(domainName)
if err != nil { if err != nil {
return err return err
} }
_zone := strings.TrimRight(ch.ResolvedZone, ch.DNSName) _zone := strings.TrimRight(ch.ResolvedZone, domainName)
_key := "\"" + ch.Key + "\"" _key := "\"" + ch.Key + "\""
freedns.AddRecord("TXT", _zone, _key, true, "") dnsObj.AddRecord("TXT", _zone, _key, true, "")
c.freedns = &freedns c.freedns = &dnsObj
return nil return nil
} }
@ -130,13 +131,9 @@ func (c *customDNSProviderSolver) Present(ch *v1alpha1.ChallengeRequest) error {
// This is in order to facilitate multiple DNS validations for the same domain // This is in order to facilitate multiple DNS validations for the same domain
// concurrently. // concurrently.
func (c *customDNSProviderSolver) CleanUp(ch *v1alpha1.ChallengeRequest) error { func (c *customDNSProviderSolver) CleanUp(ch *v1alpha1.ChallengeRequest) error {
_zone := strings.TrimRight(ch.ResolvedZone, ch.DNSName)
_key := "\"" + ch.Key + "\""
_id, err := c.freedns.FindRecord(_zone, "TXT", _key)
if err != nil { _key := "\"" + ch.Key + "\""
return err _id, err := c.freedns.FindRecord(ch.ResolvedZone, "TXT", _key)
}
if _id != "" { if _id != "" {
err = c.freedns.DeleteRecord(_id) err = c.freedns.DeleteRecord(_id)
@ -144,7 +141,8 @@ func (c *customDNSProviderSolver) CleanUp(ch *v1alpha1.ChallengeRequest) error {
return err return err
} }
} }
return nil
return c.freedns.Logout()
} }
// Initialize will be called when the webhook first starts. // Initialize will be called when the webhook first starts.