mirror of
https://git.eworm.de/cgit/routeros-scripts
synced 2025-06-22 09:43:30 +02:00
check-certificates: format information in a local function
This commit is contained in:
parent
f585b6ee32
commit
a263fcdec2
1 changed files with 24 additions and 20 deletions
|
@ -27,9 +27,25 @@
|
||||||
:global WaitForFile;
|
:global WaitForFile;
|
||||||
:global WaitFullyConnected;
|
:global WaitFullyConnected;
|
||||||
|
|
||||||
:local FormatExpire do={
|
:local FormatInfo do={
|
||||||
:global CharacterReplace;
|
:local CertVal $1;
|
||||||
:return [ $CharacterReplace [ $CharacterReplace [ :tostr $1 ] "w" "w " ] "d" "d " ];
|
|
||||||
|
:global IfThenElse;
|
||||||
|
:global ParseKeyValueStore;
|
||||||
|
|
||||||
|
:local FormatExpire do={
|
||||||
|
:global CharacterReplace;
|
||||||
|
:return [ $CharacterReplace [ $CharacterReplace [ :tostr $1 ] "w" "w " ] "d" "d " ];
|
||||||
|
}
|
||||||
|
|
||||||
|
:return ( \
|
||||||
|
"Name: " . ($CertVal->"name") . "\n" . \
|
||||||
|
"CommonName: " . ($CertVal->"common-name") . "\n" . \
|
||||||
|
"Private key: " . [ $IfThenElse (($CertVal->"private-key") = true) "available" "missing" ] . "\n" . \
|
||||||
|
"Fingerprint: " . ($CertVal->"fingerprint") . "\n" . \
|
||||||
|
"Issuer: " . ($CertVal->"ca") . ([ $ParseKeyValueStore ($CertVal->"issuer") ]->"CN") . "\n" . \
|
||||||
|
"Validity: " . ($CertVal->"invalid-before") . " to " . ($CertVal->"invalid-after") . "\n" . \
|
||||||
|
"Expires in: " . [ $IfThenElse (($CertVal->"expired") = true) "expired" [ $FormatExpire ($CertVal->"expires-after") ] ]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$WaitFullyConnected;
|
$WaitFullyConnected;
|
||||||
|
@ -95,18 +111,13 @@ $WaitFullyConnected;
|
||||||
|
|
||||||
/certificate/remove $Cert;
|
/certificate/remove $Cert;
|
||||||
/certificate/set $CertNew name=($CertVal->"name");
|
/certificate/set $CertNew name=($CertVal->"name");
|
||||||
|
:set CertNewVal;
|
||||||
|
:set CertVal [ /certificate/get $CertNew ];;
|
||||||
}
|
}
|
||||||
|
|
||||||
$SendNotification2 ({ origin=$0; \
|
$SendNotification2 ({ origin=$0; silent=true; \
|
||||||
subject=([ $SymbolForNotification "lock-with-ink-pen" ] . "Certificate renewed"); \
|
subject=([ $SymbolForNotification "lock-with-ink-pen" ] . "Certificate renewed"); \
|
||||||
message=("A certificate on " . $Identity . " has been renewed.\n\n" . \
|
message=("A certificate on " . $Identity . " has been renewed.\n\n" . [ $FormatInfo $CertVal ]) });
|
||||||
"Name: " . ($CertVal->"name") . "\n" . \
|
|
||||||
"CommonName: " . ($CertNewVal->"common-name") . "\n" . \
|
|
||||||
"Private key: " . [ $IfThenElse (($CertNewVal->"private-key") = true) "available" "missing" ] . "\n" . \
|
|
||||||
"Fingerprint: " . ($CertNewVal->"fingerprint") . "\n" . \
|
|
||||||
"Issuer: " . ([ $ParseKeyValueStore ($CertNewVal->"issuer") ]->"CN") . "\n" . \
|
|
||||||
"Validity: " . ($CertNewVal->"invalid-before") . " to " . ($CertNewVal->"invalid-after") . "\n" . \
|
|
||||||
"Expires in: " . [ $FormatExpire ($CertNewVal->"expires-after") ]); silent=true });
|
|
||||||
$LogPrintExit2 info $0 ("The certificate " . ($CertVal->"name") . " has been renewed.") false;
|
$LogPrintExit2 info $0 ("The certificate " . ($CertVal->"name") . " has been renewed.") false;
|
||||||
} on-error={
|
} on-error={
|
||||||
$LogPrintExit2 debug $0 ("Could not renew certificate " . ($CertVal->"name") . ".") false;
|
$LogPrintExit2 debug $0 ("Could not renew certificate " . ($CertVal->"name") . ".") false;
|
||||||
|
@ -124,14 +135,7 @@ $WaitFullyConnected;
|
||||||
|
|
||||||
$SendNotification2 ({ origin=$0; \
|
$SendNotification2 ({ origin=$0; \
|
||||||
subject=([ $SymbolForNotification "warning-sign" ] . "Certificate warning!"); \
|
subject=([ $SymbolForNotification "warning-sign" ] . "Certificate warning!"); \
|
||||||
message=("A certificate on " . $Identity . " " . $State . ".\n\n" . \
|
message=("A certificate on " . $Identity . " " . $State . ".\n\n" . [ $FormatInfo $CertVal ]) });
|
||||||
"Name: " . ($CertVal->"name") . "\n" . \
|
|
||||||
"CommonName: " . ($CertVal->"common-name") . "\n" . \
|
|
||||||
"Private key: " . [ $IfThenElse (($CertVal->"private-key") = true) "available" "missing" ] . "\n" . \
|
|
||||||
"Fingerprint: " . ($CertVal->"fingerprint") . "\n" . \
|
|
||||||
"Issuer: " . ($CertVal->"ca") . ([ $ParseKeyValueStore ($CertVal->"issuer") ]->"CN") . "\n" . \
|
|
||||||
"Validity: " . ($CertVal->"invalid-before") . " to " . ($CertVal->"invalid-after") . "\n" . \
|
|
||||||
"Expires in: " . [ $IfThenElse (($CertVal->"expired") = true) "expired" [ $FormatExpire ($CertVal->"expires-after") ] ]) });
|
|
||||||
$LogPrintExit2 info $0 ("The certificate " . ($CertVal->"name") . " " . $State . \
|
$LogPrintExit2 info $0 ("The certificate " . ($CertVal->"name") . " " . $State . \
|
||||||
", it is invalid after " . ($CertVal->"invalid-after") . ".") false;
|
", it is invalid after " . ($CertVal->"invalid-after") . ".") false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue