]> Git [git.vados.ru] :: Repos - Mikrotiks/ros.vados.ru.git/commitdiff
Autocommit in repo: ros.vados.ru, generated by owner: root, in 09:35:02 01.05.2026.
authorvados-dev <192440777+vados-dev@users.noreply.github.com>
Fri, 1 May 2026 06:35:03 +0000 (09:35 +0300)
committervados-dev <192440777+vados-dev@users.noreply.github.com>
Fri, 1 May 2026 06:35:03 +0000 (09:35 +0300)
html/AM-GlobalFunc.rsc

index f6a51582854a307c2e410e8246572b55c4cd7d83..c3e96225b61b875c2ceeebae7da9b77974c3bf85 100644 (file)
@@ -17,9 +17,9 @@
 :global GlobalFuncReady false;
 
 # Git commit id & info, expected configuration version
-:global CommitId "main/367/2a8f526e";
+:global CommitId "main/368/b69ddb1c";
 :global CommitTAG "unknown";
-:global CommitInfo "Autocommit in repo: ros.vados.ru, generated by owner: root, in 09:10:02 01.05.2026.";
+:global CommitInfo "Autocommit in repo: ros.vados.ru, generated by owner: root, in 09:35:02 01.05.2026.";
 
 # The variables are received right here.
 :global GlobalConfVersion 138;
 }
 
 # check and download required certificate
+# Usage: $CertificateAvailable "Common Name" "intended use for certificate (e.g. "fetch", "tls", "all", "undefined")"
 :set CertificateAvailable do={
   :local CommonName [ :tostr $1 ];
   :local UseFor     [ :tostr $2 ];
 
   :global CertificateDownload;
-  :global LogPrint;
   :global ParseKeyValueStore;
 
   :if ([ :len $UseFor ] = 0) do={
-    $LogPrint warning $0 ("The intended use is undefined!");
+    :log warning ($0 . "The intended use is undefined!");
     :set UseFor "undefined";
   }
-
   :if ([ /system/resource/get free-hdd-space ] < 8388608 && \
        [ /certificate/settings/get crl-download ] = true && \
        [ /certificate/settings/get crl-store ] = "system") do={
-    $LogPrint warning $0 ("This system has low free flash space but " . \
+    :log warning ($0 . "This system has low free flash space but " . \
       "is configured to download certificate CRLs to system!");
   }
-
   :if ([ :len $CommonName ] = 0) do={
-    $LogPrint warning $0 ("No CommonName given!");
+    :log warning ($0 . "No CommonName given!");
     :return false;
   }
-
   :local CertSettings [ /certificate/settings/get ];
   :if ((($CertSettings->"builtin-trust-anchors") = "trusted" || \
         ($CertSettings->"builtin-trust-store") ~ $UseFor || \
        [ :len [ /certificate/builtin/find where common-name=$CommonName ] ] > 0) do={
     :return true;
   }
-
   :if ([ :len [ /certificate/find where common-name=$CommonName ] ] = 0) do={
-    $LogPrint info $0 ("Certificate with CommonName '" . $CommonName . "' not available.");
+    :log info ($0 . "Certificate with CommonName '" . $CommonName . "' not available.");
     :if ([ $CertificateDownload $CommonName ] = false) do={
       :return false;
     }
   }
-
   :if ([ :len [ /certificate/find where common-name=$CommonName ] ] > 1) do={
-    $LogPrint info $0 ("There are " . $CertCount . " Certificates with CommonName '" . $CommonName . "'. Should be ok.");
+    :log info ($0 . "There are " . $CertCount . " Certificates with CommonName '" . $CommonName . "'. Should be ok.");
     :return true;
   }
-
   :local CertVal [ /certificate/get [ find where common-name=$CommonName ] ];
   :while (($CertVal->"akid") != "" && ($CertVal->"akid") != ($CertVal->"skid")) do={
     :if ([ :len [ /certificate/find where skid=($CertVal->"akid") ] ] = 0) do={
       :local IssuerCN ([ $ParseKeyValueStore ($CertVal->"issuer") ]->"CN");
-      $LogPrint info $0 ("Certificate chain for '" . $CommonName . "' is incomplete, missing '" . $IssuerCN . "'.");
+      :log info ($0 . "Certificate chain for '" . $CommonName . "' is incomplete, missing '" . $IssuerCN . "'.");
       :if ([ $CertificateDownload $IssuerCN ] = false) do={
         :return false;
       }
 }
 
 # download and import certificate
+# Usage: $CertificateDownload "Common Name"
 :set CertificateDownload do={
   :local CommonName [ :tostr $1 ];
-
   :global ScriptUpdatesBaseUrl;
   :global ScriptUpdatesUrlSuffix;
-
   :global CertificateNameByCN;
   :global CleanName;
   :global FetchUserAgentStr;
-  :global LogPrint;
   :global RmFile;
   :global WaitForFile;
 
-  $LogPrint info $0 ("Downloading and importing certificate with " . \
+  :log info ($0 . "Downloading and importing certificate with " . \
       "CommonName '" . $CommonName . "'.");
   :local FileName ([ $CleanName $CommonName ] . ".pem");
   :do {
       dst-path=$FileName as-value;
     $WaitForFile $FileName;
   } on-error={
-    $LogPrint warning $0 ("Failed downloading certificate with CommonName '" . $CommonName . \
+    :log warning ($0 . " Failed downloading certificate with CommonName '" . $CommonName . \
       "' from repository! Trying fallback to mkcert.org...");
     :do {
       :local CertSettings [ /certificate/settings/get ];
               ($CertSettings->"builtin-trust-store") ~ "fetch" || \
               ($CertSettings->"builtin-trust-store") = "all") && \
              [ :len [ /certificate/builtin/find where common-name="ISRG Root X1" ] ] > 0)) do={
-        $LogPrint error $0 ("Required certificate is not available.");
+        :log error ($0 . " Required certificate is not available.");
         :return false;
       }
       /tool/fetch check-certificate=yes-without-crl http-header-field=({ [ $FetchUserAgentStr $0 ] }) \
         :error false;
       }
     } on-error={
-      $LogPrint warning $0 ("Failed downloading certificate with CommonName '" . $CommonName . "'!");
+      :log warning ($0 . " Failed downloading certificate with CommonName '" . $CommonName . "'!");
       :return false;
     }
   }
-
   /certificate/import file-name=$FileName passphrase="" as-value;
   :delay 1s;
   $RmFile $FileName;
-
   :if ([ :len [ /certificate/find where common-name=$CommonName ] ] = 0) do={
     /certificate/remove [ find where name~("^" . $FileName . "_[0-9]+\$") ];
-    $LogPrint warning $0 ("Certificate with CommonName '" . $CommonName . "' still unavailable!");
+    :log warning ($0 . " Certificate with CommonName '" . $CommonName . "' still unavailable!");
     :return false;
   }
-
   :foreach Cert in=[ /certificate/find where name~("^" . $FileName . "_[0-9]+\$") ] do={
     $CertificateNameByCN [ /certificate/get $Cert common-name ];
   }
 }
 
 # name a certificate by its common-name
+# Usage: $CertificateNameByCN "Common Name"
 :set CertificateNameByCN do={
   :local Match [ :tostr $1 ];
-
   :global CleanName;
-  :global LogPrint;
-
   :local Cert ([ /certificate/find where (common-name=$Match or fingerprint=$Match or name=$Match) ]->0);
   :if ([ :len $Cert ] = 0) do={
-    $LogPrint warning $0 ("No matching certificate found.");
+    :log warning ($0 ." No matching certificate found.");
     :return false;
   }
   :local CommonName [ /certificate/get $Cert common-name ];