check-certificates: pass script name into local function

This commit is contained in:
Christian Hesse 2024-03-20 13:55:55 +01:00
parent 6845eb69b3
commit 81f1d9aa99

View file

@ -31,7 +31,8 @@
:global WaitFullyConnected; :global WaitFullyConnected;
:local CheckCertificatesDownloadImport do={ :local CheckCertificatesDownloadImport do={
:local Name [ :tostr $1 ]; :local ScriptName [ :tostr $1 ];
:local Name [ :tostr $2 ];
:global CertRenewUrl; :global CertRenewUrl;
:global CertRenewPass; :global CertRenewPass;
@ -48,7 +49,7 @@
:foreach Type in={ ".pem"; ".p12" } do={ :foreach Type in={ ".pem"; ".p12" } do={
:local CertFileName ([ $UrlEncode $Name ] . $Type); :local CertFileName ([ $UrlEncode $Name ] . $Type);
:do { :do {
/tool/fetch check-certificate=yes-without-crl http-header-field=({ [ $FetchUserAgent $0 ] }) \ /tool/fetch check-certificate=yes-without-crl http-header-field=({ [ $FetchUserAgent $ScriptName ] }) \
($CertRenewUrl . $CertFileName) dst-path=$CertFileName as-value; ($CertRenewUrl . $CertFileName) dst-path=$CertFileName as-value;
$WaitForFile $CertFileName; $WaitForFile $CertFileName;
@ -62,7 +63,7 @@
/file/remove [ find where name=$CertFileName ]; /file/remove [ find where name=$CertFileName ];
:if ($DecryptionFailed = true) do={ :if ($DecryptionFailed = true) do={
$LogPrint warning $0 ("Decryption failed for certificate file '" . $CertFileName . "'."); $LogPrint warning $ScriptName ("Decryption failed for certificate file '" . $CertFileName . "'.");
} }
:foreach CertInChain in=[ /certificate/find where name~("^" . [ $EscapeForRegEx $CertFileName ] . "_[0-9]+\$") \ :foreach CertInChain in=[ /certificate/find where name~("^" . [ $EscapeForRegEx $CertFileName ] . "_[0-9]+\$") \
@ -72,7 +73,7 @@
:set Return true; :set Return true;
} on-error={ } on-error={
$LogPrint debug $0 ("Could not download certificate file '" . $CertFileName . "'."); $LogPrint debug $ScriptName ("Could not download certificate file '" . $CertFileName . "'.");
} }
} }
@ -150,11 +151,11 @@
:local ImportSuccess false; :local ImportSuccess false;
:set LastName ($CertVal->"common-name"); :set LastName ($CertVal->"common-name");
:set ImportSuccess [ $CheckCertificatesDownloadImport $LastName ]; :set ImportSuccess [ $CheckCertificatesDownloadImport $ScriptName $LastName ];
:foreach SAN in=($CertVal->"subject-alt-name") do={ :foreach SAN in=($CertVal->"subject-alt-name") do={
:if ($ImportSuccess = false) do={ :if ($ImportSuccess = false) do={
:set LastName [ :pick $SAN ([ :find $SAN ":" ] + 1) [ :len $SAN ] ]; :set LastName [ :pick $SAN ([ :find $SAN ":" ] + 1) [ :len $SAN ] ];
:set ImportSuccess [ $CheckCertificatesDownloadImport $LastName ]; :set ImportSuccess [ $CheckCertificatesDownloadImport $ScriptName $LastName ];
} }
} }
:if ($ImportSuccess = false) do={ :error false; } :if ($ImportSuccess = false) do={ :error false; }