mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2026-11-10 12:28:28 +00:00
Merge pull request #6005 from mikeyhenein/certificate-delete-files
Remove a certificate's certbot files on delete even when revoking fails
This commit is contained in:
1 file changed
+30
@@ -418,10 +418,40 @@ const internalCertificate = {
|
||||
if (row.provider === "letsencrypt") {
|
||||
// Revoke the cert
|
||||
await internalCertificate.revokeLetsEncryptSsl(row);
|
||||
// Certbot leaves the files behind when it can't revoke (e.g. a broken renewal config); remove them anyway
|
||||
internalCertificate.removeLetsEncryptFiles(row.id);
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Removes a certificate's certbot files, as `certbot delete` would.
|
||||
*
|
||||
* @param {Number} certificateId
|
||||
*/
|
||||
removeLetsEncryptFiles: (certificateId) => {
|
||||
const paths = [
|
||||
internalCertificate.getLiveCertPath(certificateId),
|
||||
`/etc/letsencrypt/archive/npm-${certificateId}`,
|
||||
`/etc/letsencrypt/renewal/npm-${certificateId}.conf`,
|
||||
`/etc/letsencrypt/credentials/credentials-${certificateId}`,
|
||||
];
|
||||
const failed = [];
|
||||
for (const p of paths) {
|
||||
try {
|
||||
fs.rmSync(p, { recursive: true, force: true });
|
||||
} catch (err) {
|
||||
logger.error(`Could not remove ${p}: ${err.message}`);
|
||||
failed.push(p);
|
||||
}
|
||||
}
|
||||
if (failed.length) {
|
||||
throw new error.ValidationError(
|
||||
`The certificate was removed from NPM, but these files could not be deleted: ${failed.join(", ")}. Delete them by hand.`,
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* All Certs
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user