Some error messages
This commit is contained in:
parent
929e92e187
commit
778852b76a
@ -1,4 +1,4 @@
|
|||||||
FROM golang:1.16-alpine AS build_deps
|
FROM golang:1.17-alpine AS build_deps
|
||||||
|
|
||||||
RUN apk add --no-cache git
|
RUN apk add --no-cache git
|
||||||
|
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
# The GroupName here is used to identify your company or business unit that
|
# The GroupName here is used to identify your company or business unit that
|
||||||
# created this webhook.
|
# created this webhook.
|
||||||
# For freedns, this may be "acme.mycompany.com".
|
# For freedns, this may be "acme.freedns.afraid.org".
|
||||||
# This name will need to be referenced in each Issuer's `webhook` stanza to
|
# This name will need to be referenced in each Issuer's `webhook` stanza to
|
||||||
# inform cert-manager of where to send ChallengePayload resources in order to
|
# inform cert-manager of where to send ChallengePayload resources in order to
|
||||||
# solve the DNS01 challenge.
|
# solve the DNS01 challenge.
|
||||||
# This group name should be **unique**, hence using your own company's domain
|
# This group name should be **unique**, hence using your own company's domain
|
||||||
# here is recommended.
|
# here is recommended.
|
||||||
groupName: acme.mycompany.com
|
groupName: acme.freedns.afraid.org
|
||||||
|
|
||||||
certManager:
|
certManager:
|
||||||
namespace: cert-manager
|
namespace: cert-manager
|
||||||
serviceAccountName: cert-manager
|
serviceAccountName: cert-manager
|
||||||
|
|
||||||
image:
|
image:
|
||||||
repository: mycompany/webhook-image
|
repository: penguinade/cert-manager-webhook-freedns
|
||||||
tag: latest
|
tag: latest
|
||||||
pullPolicy: IfNotPresent
|
pullPolicy: IfNotPresent
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
logf "github.com/jetstack/cert-manager/pkg/logs"
|
logf "github.com/jetstack/cert-manager/pkg/logs"
|
||||||
@ -33,8 +34,6 @@ const URI_SUBDOMAIN_EDIT = "https://freedns.afraid.org/subdomain/edit.php?data_i
|
|||||||
const URI_LOGOUT = "https://freedns.afraid.org/logout/"
|
const URI_LOGOUT = "https://freedns.afraid.org/logout/"
|
||||||
const URI_DELETE_RECORD = "https://freedns.afraid.org/subdomain/delete2.php?data_id[]=%s&submit=delete%%20selected"
|
const URI_DELETE_RECORD = "https://freedns.afraid.org/subdomain/delete2.php?data_id[]=%s&submit=delete%%20selected"
|
||||||
|
|
||||||
// const URI_LOGIN string = "http://127.0.0.1:1234/"
|
|
||||||
|
|
||||||
func LogInfo(Mesg string) {
|
func LogInfo(Mesg string) {
|
||||||
// fmt.Println(Mesg)
|
// fmt.Println(Mesg)
|
||||||
logf.V(logf.InfoLevel).Info(Mesg)
|
logf.V(logf.InfoLevel).Info(Mesg)
|
||||||
@ -175,7 +174,7 @@ loop:
|
|||||||
for {
|
for {
|
||||||
attrKey, attrValue, moreAttr := htmlTokens.TagAttr()
|
attrKey, attrValue, moreAttr := htmlTokens.TagAttr()
|
||||||
_href := string(attrValue)
|
_href := string(attrValue)
|
||||||
if string(attrKey) == "href" && strings.Contains(_href, "/subdomain/?limit=") {
|
if string(attrKey) == "href" && strings.HasPrefix(_href, "/subdomain/?limit=") {
|
||||||
dnsObj.DomainId = strings.TrimPrefix(_href, "/subdomain/?limit=")
|
dnsObj.DomainId = strings.TrimPrefix(_href, "/subdomain/?limit=")
|
||||||
LogDebug(fmt.Sprintf("Domain id for \"%s\" is %s\n", DomainName, dnsObj.DomainId))
|
LogDebug(fmt.Sprintf("Domain id for \"%s\" is %s\n", DomainName, dnsObj.DomainId))
|
||||||
break loop
|
break loop
|
||||||
@ -222,6 +221,11 @@ func (dnsObj *FreeDNS) AddRecord(RecordType string, Subdomain string, Address st
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Try get a sense of the problem
|
||||||
|
var errorMesgs []string
|
||||||
|
lookForNextEl := 0
|
||||||
|
lookForText := false
|
||||||
|
_strBuffer := ""
|
||||||
htmlTokens := html.NewTokenizer(strings.NewReader(respStr))
|
htmlTokens := html.NewTokenizer(strings.NewReader(respStr))
|
||||||
loop:
|
loop:
|
||||||
for {
|
for {
|
||||||
@ -230,8 +234,38 @@ func (dnsObj *FreeDNS) AddRecord(RecordType string, Subdomain string, Address st
|
|||||||
case html.ErrorToken:
|
case html.ErrorToken:
|
||||||
break loop
|
break loop
|
||||||
case html.TextToken:
|
case html.TextToken:
|
||||||
case html.StartTagToken:
|
_text := strings.TrimSpace(string(htmlTokens.Text()))
|
||||||
|
// Search for the "1 error" / "N errors" message
|
||||||
|
if strings.HasSuffix(_text, "error") || strings.HasSuffix(_text, "errors") {
|
||||||
|
_text = strings.TrimSpace(strings.TrimSuffix(strings.TrimSuffix(_text, "s"), "error"))
|
||||||
|
_n, _ := strconv.ParseInt(_text, 10, 8)
|
||||||
|
// + 1 because we are already inside a font tag
|
||||||
|
// The next closing </font> is ourself
|
||||||
|
lookForNextEl = int(_n) + 1
|
||||||
|
} else if lookForText {
|
||||||
|
_strBuffer = _strBuffer + _text
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case html.StartTagToken:
|
||||||
|
_t, _ := htmlTokens.TagName()
|
||||||
|
tagName := string(_t)
|
||||||
|
if tagName == "font" && 0 < lookForNextEl {
|
||||||
|
lookForText = true
|
||||||
|
_strBuffer = ""
|
||||||
|
}
|
||||||
|
case html.EndTagToken:
|
||||||
|
_t, _ := htmlTokens.TagName()
|
||||||
|
tagName := string(_t)
|
||||||
|
if tagName == "font" && 0 < lookForNextEl {
|
||||||
|
lookForText = false
|
||||||
|
errorMesgs = append(errorMesgs, strings.TrimSpace(_strBuffer))
|
||||||
|
lookForNextEl--
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if 0 < len(errorMesgs) {
|
||||||
|
return errors.New(strings.Join(errorMesgs, ", "))
|
||||||
}
|
}
|
||||||
|
|
||||||
return errors.New("Unknown error while submitting record")
|
return errors.New("Unknown error while submitting record")
|
||||||
@ -242,7 +276,7 @@ func (dnsObj *FreeDNS) AddRecord(RecordType string, Subdomain string, Address st
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.Contains(_Location.Path, "/zc.php") {
|
if strings.HasPrefix(_Location.Path, "/zc.php") {
|
||||||
LogDebug("Error on AddRecord: Cookie expired")
|
LogDebug("Error on AddRecord: Cookie expired")
|
||||||
return errors.New("dns_cookie maybe expired")
|
return errors.New("dns_cookie maybe expired")
|
||||||
}
|
}
|
||||||
@ -291,7 +325,7 @@ func (dnsObj *FreeDNS) FindRecord(Subdomain string, RecordType string, Address s
|
|||||||
CurrRecordType := ""
|
CurrRecordType := ""
|
||||||
CurrRecordAddr := ""
|
CurrRecordAddr := ""
|
||||||
CurrTagName := ""
|
CurrTagName := ""
|
||||||
lookForNextTD := 0
|
lookForNextEl := 0
|
||||||
|
|
||||||
htmlTokens := html.NewTokenizer(strings.NewReader(respStr))
|
htmlTokens := html.NewTokenizer(strings.NewReader(respStr))
|
||||||
loop:
|
loop:
|
||||||
@ -301,13 +335,13 @@ loop:
|
|||||||
case html.ErrorToken:
|
case html.ErrorToken:
|
||||||
break loop
|
break loop
|
||||||
case html.TextToken:
|
case html.TextToken:
|
||||||
if CurrTagName == "a" && lookForNextTD == 1 && CurrRecordAddr == "" {
|
if CurrTagName == "a" && lookForNextEl == 1 && CurrRecordAddr == "" {
|
||||||
CurrRecordAddr = strings.TrimSpace(string(htmlTokens.Text()))
|
CurrRecordAddr = strings.TrimSpace(string(htmlTokens.Text()))
|
||||||
} else if CurrTagName == "td" {
|
} else if CurrTagName == "td" {
|
||||||
if lookForNextTD == 1 {
|
if lookForNextEl == 1 {
|
||||||
CurrRecordType = string(htmlTokens.Text())
|
CurrRecordType = string(htmlTokens.Text())
|
||||||
lookForNextTD = 2
|
lookForNextEl = 2
|
||||||
} else if lookForNextTD == 2 {
|
} else if lookForNextEl == 2 {
|
||||||
_Addr := string(htmlTokens.Text())
|
_Addr := string(htmlTokens.Text())
|
||||||
if CurrRecordType == RecordType && CurrRecordAddr == Subdomain {
|
if CurrRecordType == RecordType && CurrRecordAddr == Subdomain {
|
||||||
if _Addr == Address {
|
if _Addr == Address {
|
||||||
@ -316,7 +350,7 @@ loop:
|
|||||||
DeepSearchCandidates = append(DeepSearchCandidates, CurrRecordId)
|
DeepSearchCandidates = append(DeepSearchCandidates, CurrRecordId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lookForNextTD = 0
|
lookForNextEl = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/** Each record is displayed with the following structure
|
/** Each record is displayed with the following structure
|
||||||
@ -336,7 +370,7 @@ loop:
|
|||||||
attrKey, attrValue, moreAttr := htmlTokens.TagAttr()
|
attrKey, attrValue, moreAttr := htmlTokens.TagAttr()
|
||||||
_href := string(attrValue)
|
_href := string(attrValue)
|
||||||
if string(attrKey) == "href" && strings.Contains(_href, "edit.php?data_id=") {
|
if string(attrKey) == "href" && strings.Contains(_href, "edit.php?data_id=") {
|
||||||
lookForNextTD = 1
|
lookForNextEl = 1
|
||||||
CurrRecordAddr = ""
|
CurrRecordAddr = ""
|
||||||
CurrRecordId = strings.TrimPrefix(_href, "edit.php?data_id=")
|
CurrRecordId = strings.TrimPrefix(_href, "edit.php?data_id=")
|
||||||
break
|
break
|
||||||
|
Loading…
Reference in New Issue
Block a user