Skip to content

Commit

Permalink
Clean ssl fix
Browse files Browse the repository at this point in the history
  • Loading branch information
willnode committed Oct 19, 2024
1 parent ec75780 commit 7c4c870
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/domcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ jobs:
webhook_auth: ${{ secrets.WEBHOOK_AUTH_SGP }}
data: >-
{"commands":["git pull","npm i","npm test","sudo systemctl restart bridge"]}
- name: Invoke MNZ deployment hook
uses: distributhor/workflow-webhook@v3
env:
webhook_url: https://my.domcloud.co/api/githubdeploy
webhook_secret: ${{ secrets.WEBHOOK_SECRET_MNZ }}
webhook_auth: ${{ secrets.WEBHOOK_AUTH_MNZ }}
data: >-
{"commands":["git pull","npm i","npm test","sudo systemctl restart bridge"]}
# - name: Invoke MNZ deployment hook
# uses: distributhor/workflow-webhook@v3
# env:
# webhook_url: https://my.domcloud.co/api/githubdeploy
# webhook_secret: ${{ secrets.WEBHOOK_SECRET_MNZ }}
# webhook_auth: ${{ secrets.WEBHOOK_AUTH_MNZ }}
# data: >-
# {"commands":["git pull","npm i","npm test","sudo systemctl restart bridge"]}
31 changes: 24 additions & 7 deletions sudocleanssl.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ function cmd(str) {
}).stdout.trim();
}

/**
*
* @param {string} domain
* @param {string} domainFile
*/
function disableRenewal(domain, domainFile) {
var c = cat(domainFile).replace(/\nletsencrypt_renew=1/, '');
new ShellString(c).to(domainFile);
count++;
}

const listCertsRenewals = cmd(cmdListCertsRenewals).trim().split('\n');

let count = 0;
Expand All @@ -32,15 +43,23 @@ for (const domain of listCertsRenewals) {
const lastIssuedDateStr = domainDetail.match(/Lets Encrypt cert issued: (.+)/);
const expiryDateStr = domainDetail.match(/SSL cert expiry: (.+)/);
const domainFileStr = domainDetail.match(/File: (.+)/);
const sharedWithStr = domainDetail.match(/SSL shared with: (.+)/);
if (lastIssuedDateStr && expiryDateStr && domainFileStr) {
const lastIssuedDate = Date.parse(lastIssuedDateStr[1]);
const expiryDate = Date.parse(expiryDateStr[1]);
const domainFile = domainFileStr[1];
const deltaExp = Math.trunc((expiryDate - Date.now()) / (3600000 * 24));
const deltaHour = Math.trunc((Date.now() - lastIssuedDate) / (3600000));
if (deltaExp > 30) {
if (sharedWithStr) {
if (test) {
console.log(`TEST: Skipping ${domain} due to expiry ${deltaHour} days`);
console.log(`TEST: Will disable renewal for ${domain} due to sharing`);
continue;
}
console.log(`Disabling renewal for ${domain} due to sharing`);
disableRenewal(domain, domainFile);
} else if (deltaExp > 30) {
if (test) {
console.log(`TEST: Skipping ${domain} due to expiry ${deltaExp} days`);
}
} else if (deltaHour < 24) {
if (test) {
Expand All @@ -51,10 +70,8 @@ for (const domain of listCertsRenewals) {
console.log(`TEST: Will check ${domain} due to last issue ${deltaHour} hours`);
continue;
}
console.log(`Disabling renewal for ${domain}`);
var c = cat(domainFile).replace(/\nletsencrypt_renew=1/, '');
new ShellString(c).to(domainFile);
count++;
console.log(`Disabling renewal for ${domain} due to unable renew`);
disableRenewal(domain, domainFile);
}
}
}
Expand All @@ -64,4 +81,4 @@ if (count == 0) {
} else {
console.log(`Change applied for ${count} domains`);
console.log(`Total domains in active renewal: ${cmd(cmdListCertsRenewals).split('\n').length}`)
}
}

0 comments on commit 7c4c870

Please sign in to comment.