Skip to content

Commit 62b8ee9

Browse files
authored
Merge pull request #1190 from itflow-org/cron-certificate-notifs
Cron certificate notifs
2 parents eedd92c + e69d697 commit 62b8ee9

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

scripts/cron.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,30 @@
226226
$certificate_name = sanitizeInput($row['certificate_name']);
227227
$certificate_domain = sanitizeInput($row['certificate_domain']);
228228
$certificate_expire = sanitizeInput($row['certificate_expire']);
229+
$certificate_public_key = $row['certificate_public_key']; // Sanitize input breaks parsing
229230
$client_id = intval($row['client_id']);
230231
$client_name = sanitizeInput($row['client_name']);
231232

232-
appNotify("Certificate Expiring", "Certificate $certificate_name for $client_name will expire in $day Days on $certificate_expire", "certificates.php?client_id=$client_id", $client_id);
233+
// Calculate the validity period
234+
if (!empty($certificate_public_key)) {
235+
$cert_public_key_obj = openssl_x509_parse($certificate_public_key);
236+
$validity_days = intval(round(($cert_public_key_obj['validTo_time_t'] - $cert_public_key_obj['validFrom_time_t']) / (60 * 60 * 24)));
237+
238+
// Only raise a notification at 45 days if the certificate is valid for more than 90 days (i.e. not a LE)
239+
240+
if ($day == 45 && $validity_days < 91) {
241+
// LE certificate - Do nothing here
242+
echo "Not raising notification for LE certificate $certificate_name expiring in 45 days";
243+
244+
} else {
245+
// This certificate is either expiring in 1 or 7 days or is a non-LE certificate expiring in 45 days
246+
appNotify("Certificate Expiring", "Certificate $certificate_name for $client_name will expire in $day day(s) on $certificate_expire", "certificates.php?client_id=$client_id", $client_id);
247+
}
248+
249+
} else {
250+
// No public key - notify anyway as we can't check the validity period
251+
appNotify("Certificate Expiring", "Certificate $certificate_name for $client_name will expire in $day day(s) on $certificate_expire", "certificates.php?client_id=$client_id", $client_id);
252+
}
233253

234254
}
235255

0 commit comments

Comments
 (0)