global-functions: introduce and use $CertificateNameByCN

This commit is contained in:
Christian Hesse 2020-02-06 18:09:52 +01:00
parent 38b23ddc10
commit e376845b12

View file

@ -17,6 +17,7 @@
# global functions # global functions
:global UrlEncode; :global UrlEncode;
:global CharacterReplace; :global CharacterReplace;
:global CertificateNameByCN;
:global CertificateDownload; :global CertificateDownload;
:global CertificateAvailable; :global CertificateAvailable;
:global SendEMail; :global SendEMail;
@ -79,6 +80,16 @@
:return ($Return . $String); :return ($Return . $String);
} }
# name a certificate by its common-name
:set CertificateNameByCN do={
:local CommonName [ :tostr $1 ];
:global CharacterReplace;
:local Cert [ / certificate find where common-name=$CommonName ];
/ certificate set $Cert name=[ $CharacterReplace [ $CharacterReplace $CommonName " " "-" ] "---" "-" ];
}
# download and import certificate # download and import certificate
:set CertificateDownload do={ :set CertificateDownload do={
:local CommonName [ :tostr $1 ]; :local CommonName [ :tostr $1 ];
@ -86,7 +97,7 @@
:global ScriptUpdatesBaseUrl; :global ScriptUpdatesBaseUrl;
:global ScriptUpdatesUrlSuffix; :global ScriptUpdatesUrlSuffix;
:global CharacterReplace; :global CertificateNameByCN;
:global UrlEncode; :global UrlEncode;
:global WaitForFile; :global WaitForFile;
@ -104,7 +115,7 @@
/ file remove $LocalFileName; / file remove $LocalFileName;
:foreach Cert in=[ / certificate find where name~("^" . $LocalFileName . "_[0-9]+\$") ] do={ :foreach Cert in=[ / certificate find where name~("^" . $LocalFileName . "_[0-9]+\$") ] do={
/ certificate set $Cert name=[ $CharacterReplace [ $CharacterReplace [ get $Cert common-name ] " " "-" ] "---" "-" ]; $CertificateNameByCN [ / certificate get $Cert common-name ];
} }
} on-error={ } on-error={
:log warning "Failed imprting certificate!"; :log warning "Failed imprting certificate!";