Fix status for certificates not updating.

This commit is contained in:
Eugene Bujak 2019-02-12 19:53:53 +03:00 committed by Eugene Bujak
parent c061bec6d8
commit 4b4faad9e8
1 changed files with 19 additions and 21 deletions

View File

@ -1057,8 +1057,6 @@ func handleTLSConfigure(w http.ResponseWriter, r *http.Request) {
return return
} }
var mainCert *x509.Certificate
if data.CertificateChain != "" { if data.CertificateChain != "" {
certPEM, err := base64.StdEncoding.DecodeString(data.CertificateChain) certPEM, err := base64.StdEncoding.DecodeString(data.CertificateChain)
if err != nil { if err != nil {
@ -1145,17 +1143,14 @@ func handleTLSConfigure(w http.ResponseWriter, r *http.Request) {
return return
} }
// spew.Dump(chains) // spew.Dump(chains)
}
config.TLS = data
// update status // update status
if mainCert != nil { if mainCert != nil {
config.TLS.StatusCertificate = fmt.Sprintf("Certificate expires on %s", mainCert.NotAfter) //, valid for hostname %s", mainCert.NotAfter, mainCert.Subject.CommonName) data.StatusCertificate = fmt.Sprintf("Certificate expires on %s", mainCert.NotAfter) //, valid for hostname %s", mainCert.NotAfter, mainCert.Subject.CommonName)
if len(mainCert.DNSNames) == 1 { if len(mainCert.DNSNames) == 1 {
config.TLS.StatusCertificate += fmt.Sprintf(", valid for hostname %s", mainCert.DNSNames[0]) data.StatusCertificate += fmt.Sprintf(", valid for hostname %s", mainCert.DNSNames[0])
} else if len(mainCert.DNSNames) > 1 { } else if len(mainCert.DNSNames) > 1 {
config.TLS.StatusCertificate += ", valid for hostnames " + strings.Join(mainCert.DNSNames, ", ") data.StatusCertificate += ", valid for hostnames " + strings.Join(mainCert.DNSNames, ", ")
} }
// issue a warning if certificate is about to expire // issue a warning if certificate is about to expire
@ -1163,12 +1158,15 @@ func handleTLSConfigure(w http.ResponseWriter, r *http.Request) {
if mainCert.NotAfter.AddDate(0, 0, -30).After(now) { if mainCert.NotAfter.AddDate(0, 0, -30).After(now) {
timeLeft := time.Until(mainCert.NotAfter) timeLeft := time.Until(mainCert.NotAfter)
if timeLeft > 0 { if timeLeft > 0 {
config.TLS.Warning = fmt.Sprintf("Your certificate expires in %.0f days, we recommend you update it soon", timeLeft.Hours()/24) data.Warning = fmt.Sprintf("Your certificate expires in %.0f days, we recommend you update it soon", timeLeft.Hours()/24)
} else { } else {
config.TLS.Warning = fmt.Sprintf("Your certificate has expired on %s, we recommend you update it immediatedly", mainCert.NotAfter) data.Warning = fmt.Sprintf("Your certificate has expired on %s, we recommend you update it immediatedly", mainCert.NotAfter)
} }
} }
} }
}
config.TLS = data
httpUpdateConfigReloadDNSReturnOK(w, r) httpUpdateConfigReloadDNSReturnOK(w, r)
} }