mirror of
https://github.com/fosrl/pangolin.git
synced 2025-12-15 20:46:27 +00:00
Try to fix the expires at problem
This commit is contained in:
@@ -142,8 +142,24 @@ export class TraefikConfigManager {
|
|||||||
const wildcardExists = await this.fileExists(wildcardPath);
|
const wildcardExists = await this.fileExists(wildcardPath);
|
||||||
|
|
||||||
let lastModified: Date | null = null;
|
let lastModified: Date | null = null;
|
||||||
const expiresAt: Date | null = null;
|
let expiresAt: number | null = null;
|
||||||
let wildcard = false;
|
let wildcard = false;
|
||||||
|
const expiresAtPath = path.join(domainDir, ".expires_at");
|
||||||
|
const expiresAtExists = await this.fileExists(expiresAtPath);
|
||||||
|
|
||||||
|
if (expiresAtExists) {
|
||||||
|
try {
|
||||||
|
const expiresAtStr = fs
|
||||||
|
.readFileSync(expiresAtPath, "utf8")
|
||||||
|
.trim();
|
||||||
|
expiresAt = parseInt(expiresAtStr, 10);
|
||||||
|
if (isNaN(expiresAt)) {
|
||||||
|
expiresAt = null;
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
expiresAt = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (lastUpdateExists) {
|
if (lastUpdateExists) {
|
||||||
try {
|
try {
|
||||||
@@ -179,7 +195,7 @@ export class TraefikConfigManager {
|
|||||||
|
|
||||||
state.set(domain, {
|
state.set(domain, {
|
||||||
exists: certExists && keyExists,
|
exists: certExists && keyExists,
|
||||||
lastModified,
|
lastModified: lastModified ? Math.floor(lastModified.getTime() / 1000) : null,
|
||||||
expiresAt,
|
expiresAt,
|
||||||
wildcard
|
wildcard
|
||||||
});
|
});
|
||||||
@@ -259,9 +275,9 @@ export class TraefikConfigManager {
|
|||||||
|
|
||||||
// Check if certificate is expiring soon (within 30 days)
|
// Check if certificate is expiring soon (within 30 days)
|
||||||
if (localState.expiresAt) {
|
if (localState.expiresAt) {
|
||||||
const daysUntilExpiry =
|
const nowInSeconds = Math.floor(Date.now() / 1000);
|
||||||
(localState.expiresAt - Math.floor(Date.now() / 1000)) /
|
const secondsUntilExpiry = localState.expiresAt - nowInSeconds;
|
||||||
(1000 * 60 * 60 * 24);
|
const daysUntilExpiry = secondsUntilExpiry / (60 * 60 * 24);
|
||||||
if (daysUntilExpiry < 30) {
|
if (daysUntilExpiry < 30) {
|
||||||
logger.info(
|
logger.info(
|
||||||
`Fetching certificates due to upcoming expiry for ${domain} (${Math.round(daysUntilExpiry)} days remaining)`
|
`Fetching certificates due to upcoming expiry for ${domain} (${Math.round(daysUntilExpiry)} days remaining)`
|
||||||
@@ -770,6 +786,16 @@ export class TraefikConfigManager {
|
|||||||
"utf8"
|
"utf8"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Store the certificate expiry time
|
||||||
|
if (cert.expiresAt) {
|
||||||
|
const expiresAtPath = path.join(domainDir, ".expires_at");
|
||||||
|
fs.writeFileSync(
|
||||||
|
expiresAtPath,
|
||||||
|
cert.expiresAt.toString(),
|
||||||
|
"utf8"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
`Certificate updated for domain: ${cert.domain}${cert.wildcard ? " (wildcard)" : ""}`
|
`Certificate updated for domain: ${cert.domain}${cert.wildcard ? " (wildcard)" : ""}`
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user