@@ 22,10 22,11 @@ type DomainOwner struct {
// Domain contains a domains information.
type Domain struct {
- ID string
- APIKey string
- Domain string
- A string
+ ID string
+ APIKey string
+ Domain string
+ A string
+ AcmeChallenge string
Owner DomainOwner
}
@@ 173,3 174,36 @@ func RefreshDomainAPIKey(id string, userID string) error {
}
return nil
}
+
+// FetchDomainAcmeChallenge fetches the ACME challenge string of a domain.
+func FetchDomainAcmeChallenge(ddnsDomain string) (string, error) {
+ var acmeChallengeString string
+ err := DBConn.QueryRow(`SELECT acme_challenge FROM domains WHERE ddns_domain = $1`,
+ ddnsDomain).Scan(&acmeChallengeString)
+ if err != nil {
+ return "", err
+ }
+ return acmeChallengeString, nil
+}
+
+// UpdateDomainAcmeChallenge updates the ACME challenge string of a domain.
+func UpdateDomainAcmeChallenge(ddnsDomain string, acmeChallengeString string) error {
+ _, err := DBConn.Exec(`UPDATE domains SET acme_challenge = $1 WHERE ddns_domain = $2`,
+ acmeChallengeString, ddnsDomain)
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
+
+// DeleteDomainAcmeChallenge deletes the ACME challenge string of a domain.
+func DeleteDomainAcmeChallenge(ddnsDomain string) error {
+ _, err := DBConn.Exec(`UPDATE domains SET acme_challenge = NULL WHERE ddns_domain = $1`,
+ ddnsDomain)
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
@@ 82,5 82,7 @@ func migrations() []string {
a_record TEXT,
FOREIGN KEY(owner) REFERENCES users(id)
)`),
+ fmt.Sprintf(`ALTER TABLE domains
+ ADD acme_challenge TEXT`),
}
}