Loading plugins/letsencrypt/letsencrypt.cpp +14 −6 Original line number Diff line number Diff line Loading @@ -44,6 +44,7 @@ #include <htmlpp/html.h> #include <netplus/exception.h> #include <netplus/crypto/x509.h> #include "plugin.h" #include "conf.h" Loading Loading @@ -216,12 +217,19 @@ namespace blogi { if (!std::filesystem::exists(certPath)) return true; // Check if cert expires within 30 days auto ftime = std::filesystem::last_write_time(certPath); auto sctp = std::chrono::clock_cast<std::chrono::system_clock>(ftime); auto age = std::chrono::system_clock::now() - sctp; // Let's Encrypt certs valid for 90 days, renew at 60 days return age > std::chrono::hours(60 * 24); // Parse the certificate and check notAfter netplus::x509cert cert; if (!cert.loadFromFile(certPath)) return true; time_t notAfter = cert.getNotAfter(); if (notAfter == 0) return true; // Renew if cert expires within 30 days time_t now = time(nullptr); time_t thirtyDays = 30 * 24 * 3600; return (notAfter - now) < thirtyDays; } void requestCertificate(const std::string &domain) { Loading Loading
plugins/letsencrypt/letsencrypt.cpp +14 −6 Original line number Diff line number Diff line Loading @@ -44,6 +44,7 @@ #include <htmlpp/html.h> #include <netplus/exception.h> #include <netplus/crypto/x509.h> #include "plugin.h" #include "conf.h" Loading Loading @@ -216,12 +217,19 @@ namespace blogi { if (!std::filesystem::exists(certPath)) return true; // Check if cert expires within 30 days auto ftime = std::filesystem::last_write_time(certPath); auto sctp = std::chrono::clock_cast<std::chrono::system_clock>(ftime); auto age = std::chrono::system_clock::now() - sctp; // Let's Encrypt certs valid for 90 days, renew at 60 days return age > std::chrono::hours(60 * 24); // Parse the certificate and check notAfter netplus::x509cert cert; if (!cert.loadFromFile(certPath)) return true; time_t notAfter = cert.getNotAfter(); if (notAfter == 0) return true; // Renew if cert expires within 30 days time_t now = time(nullptr); time_t thirtyDays = 30 * 24 * 3600; return (notAfter - now) < thirtyDays; } void requestCertificate(const std::string &domain) { Loading