check-certificates: use $IfThenElse

This commit is contained in:
Christian Hesse 2020-07-16 21:18:12 +02:00
parent 4c61cd0b65
commit 6dfd8ed41a

View file

@ -12,6 +12,7 @@
:global CertificateAvailable :global CertificateAvailable
:global CertificateNameByCN; :global CertificateNameByCN;
:global IfThenElse;
:global LogPrintExit; :global LogPrintExit;
:global ParseKeyValueStore; :global ParseKeyValueStore;
:global SendNotification; :global SendNotification;
@ -104,12 +105,7 @@
:if ([ / certificate scep-server print count-only where ca-cert=($CertVal->"ca") ] > 0) do={ :if ([ / certificate scep-server print count-only where ca-cert=($CertVal->"ca") ] > 0) do={
$LogPrintExit debug ("Certificate \"" . ($CertVal->"name") . "\" is handled by SCEP, skipping.") false; $LogPrintExit debug ("Certificate \"" . ($CertVal->"name") . "\" is handled by SCEP, skipping.") false;
} else={ } else={
:local ExpiresAfter [ $FormatExpire ($CertVal->"expires-after") ]; :local State [ $IfThenElse (($CertVal->"expired") = true) "expired" "is about to expire" ];
:local State "is about to expire";
:if (($CertVal->"expired") = true) do={
:set ExpiresAfter "expired";
:set State "expired";
}
$SendNotification ("Certificate warning!") \ $SendNotification ("Certificate warning!") \
("A certificate on " . $Identity . " " . $State . ".\n\n" . \ ("A certificate on " . $Identity . " " . $State . ".\n\n" . \
@ -118,7 +114,7 @@
"Fingerprint: " . ($CertVal->"fingerprint") . "\n" . \ "Fingerprint: " . ($CertVal->"fingerprint") . "\n" . \
"Issuer: " . ($CertVal->"ca") . ([ $ParseKeyValueStore ($CertVal->"issuer") ]->"CN") . "\n" . \ "Issuer: " . ($CertVal->"ca") . ([ $ParseKeyValueStore ($CertVal->"issuer") ]->"CN") . "\n" . \
"Validity: " . ($CertVal->"invalid-before") . " to " . ($CertVal->"invalid-after") . "\n" . \ "Validity: " . ($CertVal->"invalid-before") . " to " . ($CertVal->"invalid-after") . "\n" . \
"Expires in: " . $ExpiresAfter); "Expires in: " . [ $IfThenElse (($CertVal->"expired") = true) "expired" [ $FormatExpire ($CertVal->"expires-after") ] ]);
$LogPrintExit warning ("The certificate " . ($CertVal->"name") . " " . $State . \ $LogPrintExit warning ("The certificate " . ($CertVal->"name") . " " . $State . \
", it is invalid after " . ($CertVal->"invalid-after") . ".") false; ", it is invalid after " . ($CertVal->"invalid-after") . ".") false;
} }