mirror of
https://git.eworm.de/cgit/routeros-scripts
synced 2025-07-16 13:04:30 +02:00
global-functions: split $CertificateAvailable to $CertificateDownload
This allows to force download even if certificate is available. We need this for a clean update path with Let's Encrypt.
This commit is contained in:
parent
afb9839073
commit
cb1e520965
1 changed files with 28 additions and 17 deletions
|
@ -17,6 +17,7 @@
|
||||||
# global functions
|
# global functions
|
||||||
:global UrlEncode;
|
:global UrlEncode;
|
||||||
:global CharacterReplace;
|
:global CharacterReplace;
|
||||||
|
:global CertificateDownload;
|
||||||
:global CertificateAvailable;
|
:global CertificateAvailable;
|
||||||
:global SendEMail;
|
:global SendEMail;
|
||||||
:global SendTelegram;
|
:global SendTelegram;
|
||||||
|
@ -79,8 +80,8 @@
|
||||||
:return ($Return . $String);
|
:return ($Return . $String);
|
||||||
}
|
}
|
||||||
|
|
||||||
# check and import required certificates
|
# download and import certificate
|
||||||
:set CertificateAvailable do={
|
:set CertificateDownload do={
|
||||||
:local CommonName [ :tostr $1 ];
|
:local CommonName [ :tostr $1 ];
|
||||||
|
|
||||||
:global ScriptUpdatesBaseUrl;
|
:global ScriptUpdatesBaseUrl;
|
||||||
|
@ -89,22 +90,32 @@
|
||||||
:global UrlEncode;
|
:global UrlEncode;
|
||||||
:global WaitForFile;
|
:global WaitForFile;
|
||||||
|
|
||||||
|
:log info ("Downloading and importing certificate with " . \
|
||||||
|
"CommonName " . $CommonName . ".");
|
||||||
|
:do {
|
||||||
|
:local LocalFileName ($CommonName . ".pem");
|
||||||
|
:local UrlFileName ([ $UrlEncode $CommonName ] . ".pem");
|
||||||
|
/ tool fetch check-certificate=yes-without-crl \
|
||||||
|
($ScriptUpdatesBaseUrl . "certs/" . \
|
||||||
|
$UrlFileName . $ScriptUpdatesUrlSuffix) \
|
||||||
|
dst-path=$LocalFileName;
|
||||||
|
$WaitForFile $LocalFileName;
|
||||||
|
/ certificate import file-name=$LocalFileName passphrase="";
|
||||||
|
/ file remove $LocalFileName;
|
||||||
|
} on-error={
|
||||||
|
:log warning "Failed imprting certificate!";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# check and download required certificate
|
||||||
|
:set CertificateAvailable do={
|
||||||
|
:local CommonName [ :tostr $1 ];
|
||||||
|
|
||||||
|
:global CertificateDownload;
|
||||||
|
|
||||||
:if ([ / certificate print count-only where common-name=$CommonName ] = 0) do={
|
:if ([ / certificate print count-only where common-name=$CommonName ] = 0) do={
|
||||||
:log info ("Certificate with CommonName " . $CommonName . \
|
:log info ("Certificate with CommonName " . $CommonName . " not available.");
|
||||||
" not available, downloading and importing.");
|
$CertificateDownload $CommonName;
|
||||||
:do {
|
|
||||||
:local LocalFileName ($CommonName . ".pem");
|
|
||||||
:local UrlFileName ([ $UrlEncode $CommonName ] . ".pem");
|
|
||||||
/ tool fetch check-certificate=yes-without-crl \
|
|
||||||
($ScriptUpdatesBaseUrl . "certs/" . \
|
|
||||||
$UrlFileName . $ScriptUpdatesUrlSuffix) \
|
|
||||||
dst-path=$LocalFileName;
|
|
||||||
$WaitForFile $LocalFileName;
|
|
||||||
/ certificate import file-name=$LocalFileName passphrase="";
|
|
||||||
/ file remove $LocalFileName;
|
|
||||||
} on-error={
|
|
||||||
:log warning "Failed imprting certificate!";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue