global-functions: prepare user-agent for fetch in global variable

This commit is contained in:
Christian Hesse 2023-08-18 09:29:22 +02:00
parent 53a80c81b1
commit 047c74a4b3

View file

@ -16,6 +16,7 @@
# global variables not to be changed by user # global variables not to be changed by user
:global GlobalFunctionsReady false; :global GlobalFunctionsReady false;
:global FetchUserAgent ("User-Agent: Mikrotik/" . [ /system/resource/get version ] . " Fetch");
:global Identity [ /system/identity/get name ]; :global Identity [ /system/identity/get name ];
# global functions # global functions
@ -108,6 +109,7 @@
:set CertificateDownload do={ :set CertificateDownload do={
:local CommonName [ :tostr $1 ]; :local CommonName [ :tostr $1 ];
:global FetchUserAgent;
:global ScriptUpdatesBaseUrl; :global ScriptUpdatesBaseUrl;
:global ScriptUpdatesUrlSuffix; :global ScriptUpdatesUrlSuffix;
@ -116,14 +118,12 @@
:global UrlEncode; :global UrlEncode;
:global WaitForFile; :global WaitForFile;
:local UserAgent ("User-Agent: Mikrotik/" . [ /system/resource/get version ] . " Fetch");
$LogPrintExit2 info $0 ("Downloading and importing certificate with " . \ $LogPrintExit2 info $0 ("Downloading and importing certificate with " . \
"CommonName \"" . $CommonName . "\".") false; "CommonName \"" . $CommonName . "\".") false;
:do { :do {
:local LocalFileName ($CommonName . ".pem"); :local LocalFileName ($CommonName . ".pem");
:local UrlFileName ([ $UrlEncode $CommonName ] . ".pem"); :local UrlFileName ([ $UrlEncode $CommonName ] . ".pem");
/tool/fetch check-certificate=yes-without-crl http-header-field=$UserAgent \ /tool/fetch check-certificate=yes-without-crl http-header-field=$FetchUserAgent \
($ScriptUpdatesBaseUrl . "certs/" . $UrlFileName . $ScriptUpdatesUrlSuffix) \ ($ScriptUpdatesBaseUrl . "certs/" . $UrlFileName . $ScriptUpdatesUrlSuffix) \
dst-path=$LocalFileName as-value; dst-path=$LocalFileName as-value;
$WaitForFile $LocalFileName; $WaitForFile $LocalFileName;
@ -769,6 +769,7 @@
:local NewComment [ :tostr $2 ]; :local NewComment [ :tostr $2 ];
:global ExpectedConfigVersion; :global ExpectedConfigVersion;
:global FetchUserAgent;
:global Identity; :global Identity;
:global IDonate; :global IDonate;
:global NoNewsAndChangesNotification; :global NoNewsAndChangesNotification;
@ -806,7 +807,6 @@
:local ExpectedConfigVersionBefore $ExpectedConfigVersion; :local ExpectedConfigVersionBefore $ExpectedConfigVersion;
:local ReloadGlobalFunctions false; :local ReloadGlobalFunctions false;
:local ReloadGlobalConfig false; :local ReloadGlobalConfig false;
:local UserAgent ("User-Agent: Mikrotik/" . [ /system/resource/get version ] . " Fetch");
:foreach Script in=[ /system/script/find where source~"^#!rsc by RouterOS\r?\n" ] do={ :foreach Script in=[ /system/script/find where source~"^#!rsc by RouterOS\r?\n" ] do={
:local ScriptVal [ /system/script/get $Script ]; :local ScriptVal [ /system/script/get $Script ];
@ -836,7 +836,7 @@
:local Url ($BaseUrl . $ScriptVal->"name" . ".rsc" . $UrlSuffix); :local Url ($BaseUrl . $ScriptVal->"name" . ".rsc" . $UrlSuffix);
$LogPrintExit2 debug $0 ("Fetching script '" . $ScriptVal->"name" . "' from url: " . $Url) false; $LogPrintExit2 debug $0 ("Fetching script '" . $ScriptVal->"name" . "' from url: " . $Url) false;
:local Result [ /tool/fetch check-certificate=yes-without-crl http-header-field=$UserAgent \ :local Result [ /tool/fetch check-certificate=yes-without-crl http-header-field=$FetchUserAgent \
$Url output=user as-value ]; $Url output=user as-value ];
:if ($Result->"status" = "finished") do={ :if ($Result->"status" = "finished") do={
:set SourceNew ($Result->"data"); :set SourceNew ($Result->"data");
@ -920,7 +920,7 @@
:do { :do {
:local Url ($ScriptUpdatesBaseUrl . "news-and-changes.rsc" . $ScriptUpdatesUrlSuffix); :local Url ($ScriptUpdatesBaseUrl . "news-and-changes.rsc" . $ScriptUpdatesUrlSuffix);
$LogPrintExit2 debug $0 ("Fetching news, changes and migration: " . $Url) false; $LogPrintExit2 debug $0 ("Fetching news, changes and migration: " . $Url) false;
:local Result [ /tool/fetch check-certificate=yes-without-crl http-header-field=$UserAgent \ :local Result [ /tool/fetch check-certificate=yes-without-crl http-header-field=$FetchUserAgent \
$Url output=user as-value ]; $Url output=user as-value ];
:if ($Result->"status" = "finished") do={ :if ($Result->"status" = "finished") do={
:set ChangeLogCode ($Result->"data"); :set ChangeLogCode ($Result->"data");