mirror of
https://github.com/eworm-de/routeros-scripts.git
synced 2024-05-11 05:55:19 +00:00
check-certificates: move conditions to loop
This commit is contained in:
@@ -18,12 +18,8 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
:foreach Cert in=[ / certificate find where !revoked ] do={
|
:foreach Cert in=[ / certificate find where !revoked expires-after<2w expires-after>0 ] do={
|
||||||
:local CertName [ / certificate get $Cert name ];
|
:local CertName [ / certificate get $Cert name ];
|
||||||
:local ExpiresAfter [ / certificate get $Cert expires-after ];
|
|
||||||
|
|
||||||
:if ([ :typeof $ExpiresAfter ] = "time") do={
|
|
||||||
:if ($ExpiresAfter < 2w) do={
|
|
||||||
:local CommonName [ / certificate get $Cert common-name ];
|
:local CommonName [ / certificate get $Cert common-name ];
|
||||||
:local FingerPrint [ / certificate get $Cert fingerprint ];
|
:local FingerPrint [ / certificate get $Cert fingerprint ];
|
||||||
|
|
||||||
@@ -36,7 +32,7 @@
|
|||||||
/ certificate import file-name=($CommonName . ".pem") passphrase=$CertRenewPass;
|
/ certificate import file-name=($CommonName . ".pem") passphrase=$CertRenewPass;
|
||||||
/ file remove [ find where name=($CommonName . ".pem") ];
|
/ file remove [ find where name=($CommonName . ".pem") ];
|
||||||
|
|
||||||
:local CertNew [ / certificate find where common-name=$CommonName fingerprint!=$FingerPrint ];
|
:local CertNew [ / certificate find where common-name=$CommonName fingerprint!=$FingerPrint expires-after>2w ];
|
||||||
:local CertNameNew [ / certificate get $CertNew name ];
|
:local CertNameNew [ / certificate get $CertNew name ];
|
||||||
|
|
||||||
:foreach IpService in=[ / ip service find where certificate=$CertName ] do={
|
:foreach IpService in=[ / ip service find where certificate=$CertName ] do={
|
||||||
@@ -60,7 +56,6 @@
|
|||||||
:set CommonName [ / certificate get $CertNew common-name ];
|
:set CommonName [ / certificate get $CertNew common-name ];
|
||||||
:set FingerPrint [ / certificate get $CertNew fingerprint ];
|
:set FingerPrint [ / certificate get $CertNew fingerprint ];
|
||||||
|
|
||||||
|
|
||||||
$SendNotification ("Certificate renewed") \
|
$SendNotification ("Certificate renewed") \
|
||||||
("A certificate on " . $Identity . " has been renewed.\n\n" . \
|
("A certificate on " . $Identity . " has been renewed.\n\n" . \
|
||||||
"Name: " . $CertName . "\n" . \
|
"Name: " . $CertName . "\n" . \
|
||||||
@@ -70,6 +65,7 @@
|
|||||||
"Validity: " . $InvalidBefore . " to " . $InvalidAfter);
|
"Validity: " . $InvalidBefore . " to " . $InvalidAfter);
|
||||||
:log info ("The certificate " . $CertName . " has been renewed.");
|
:log info ("The certificate " . $CertName . " has been renewed.");
|
||||||
} on-error={
|
} on-error={
|
||||||
|
:local ExpiresAfter [ / certificate get $Cert expires-after ];
|
||||||
:local InvalidBefore [ / certificate get $Cert invalid-before ];
|
:local InvalidBefore [ / certificate get $Cert invalid-before ];
|
||||||
:local InvalidAfter [ / certificate get $Cert invalid-after ];
|
:local InvalidAfter [ / certificate get $Cert invalid-after ];
|
||||||
:local Issuer [ $GetIssuerCN [ / certificate get $Cert issuer ] ];
|
:local Issuer [ $GetIssuerCN [ / certificate get $Cert issuer ] ];
|
||||||
@@ -83,10 +79,4 @@
|
|||||||
"Validity: " . $InvalidBefore . " to " . $InvalidAfter);
|
"Validity: " . $InvalidBefore . " to " . $InvalidAfter);
|
||||||
:log warning ("The certificate " . $CertName . " is about to expire in " . $ExpiresAfter . ".");
|
:log warning ("The certificate " . $CertName . " is about to expire in " . $ExpiresAfter . ".");
|
||||||
}
|
}
|
||||||
} else={
|
|
||||||
:log debug ("The certificate " . $CertName . " expires in " . $ExpiresAfter . ".");
|
|
||||||
}
|
|
||||||
} else={
|
|
||||||
:log debug ("The certificate " . $CertName . " is just a template.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user