aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2024-03-16 23:10:47 +0100
committerGravatar Christian Hesse <mail@eworm.de>2024-03-16 23:10:47 +0100
commiteb7919c1d8b4ad5c77e0d120136c4f54e1e157e6 (patch)
tree074d9babad2d09ad05399b2a3a2d1d9b84f6b0f7
parent576a2c97cf88b7d1b36907469fb6fd34618523b3 (diff)
global-functions: generate user agent string in function...
... and add the caller and my shortened url.
-rw-r--r--check-certificates.rsc2
-rw-r--r--fw-addr-lists.rsc4
-rw-r--r--global-functions.rsc27
3 files changed, 19 insertions, 14 deletions
diff --git a/check-certificates.rsc b/check-certificates.rsc
index 7504955..9aa24fd 100644
--- a/check-certificates.rsc
+++ b/check-certificates.rsc
@@ -48,7 +48,7 @@
:foreach Type in={ ".pem"; ".p12" } do={
:local CertFileName ([ $UrlEncode $Name ] . $Type);
:do {
- /tool/fetch check-certificate=yes-without-crl http-header-field=({ $FetchUserAgent }) \
+ /tool/fetch check-certificate=yes-without-crl http-header-field=({ [ $FetchUserAgent $0 ] }) \
($CertRenewUrl . $CertFileName) dst-path=$CertFileName as-value;
$WaitForFile $CertFileName;
diff --git a/fw-addr-lists.rsc b/fw-addr-lists.rsc
index 64233ac..3a422e8 100644
--- a/fw-addr-lists.rsc
+++ b/fw-addr-lists.rsc
@@ -14,12 +14,12 @@
:do {
:local ScriptName [ :jobname ];
- :global FetchUserAgent;
:global FwAddrLists;
:global FwAddrListTimeOut;
:global CertificateAvailable;
:global EitherOr;
+ :global FetchUserAgent;
:global LogPrint;
:global LogPrintOnce;
:global ScriptLock;
@@ -65,7 +65,7 @@
:if ($Data = false) do={
:do {
:set Data ([ /tool/fetch check-certificate=$CheckCertificate output=user \
- http-header-field=({ $FetchUserAgent }) ($List->"url") as-value ]->"data");
+ http-header-field=({ [ $FetchUserAgent $ScriptName ] }) ($List->"url") as-value ]->"data");
} on-error={
:if ($I < 4) do={
$LogPrint debug $ScriptName ("Failed downloading, " . $I . ". try: " . $List->"url");
diff --git a/global-functions.rsc b/global-functions.rsc
index c616724..8df70f1 100644
--- a/global-functions.rsc
+++ b/global-functions.rsc
@@ -16,12 +16,6 @@
# global variables not to be changed by user
:global GlobalFunctionsReady false;
-:global FetchUserAgent;
-{
- :local Resource [ /system/resource/get ];
- :set FetchUserAgent ("User-Agent: Mikrotik/" . $Resource->"version" . \
- " " . $Resource->"architecture-name" . " Fetch");
-}
:global Identity [ /system/identity/get name ];
# global functions
@@ -38,6 +32,7 @@
:global DownloadPackage;
:global EitherOr;
:global EscapeForRegEx;
+:global FetchUserAgent;
:global FormatLine;
:global FormatMultiLines;
:global GetMacVendor;
@@ -137,11 +132,11 @@
:set CertificateDownload do={
:local CommonName [ :tostr $1 ];
- :global FetchUserAgent;
:global ScriptUpdatesBaseUrl;
:global ScriptUpdatesUrlSuffix;
:global CertificateNameByCN;
+ :global FetchUserAgent;
:global LogPrint;
:global UrlEncode;
:global WaitForFile;
@@ -151,7 +146,7 @@
:do {
:local LocalFileName ($CommonName . ".pem");
:local UrlFileName ([ $UrlEncode $CommonName ] . ".pem");
- /tool/fetch check-certificate=yes-without-crl http-header-field=({ $FetchUserAgent }) \
+ /tool/fetch check-certificate=yes-without-crl http-header-field=({ [ $FetchUserAgent $0 ] }) \
($ScriptUpdatesBaseUrl . "certs/" . $UrlFileName . $ScriptUpdatesUrlSuffix) \
dst-path=$LocalFileName as-value;
$WaitForFile $LocalFileName;
@@ -396,6 +391,16 @@
:return $Return;
}
+# generate user agent string for fetch
+:global FetchUserAgent do={
+ :local Caller [ :tostr $1 ];
+
+ :local Resource [ /system/resource/get ];
+
+ :return ("User-Agent: Mikrotik/" . $Resource->"version" . " " . \
+ $Resource->"architecture-name" . " " . $Caller . "/Fetch (https://rsc.eworm.de/)");
+}
+
# format a line for output
:set FormatLine do={
:local Key [ :tostr $1 ];
@@ -975,7 +980,6 @@
:local NewComment [ :tostr $2 ];
:global ExpectedConfigVersion;
- :global FetchUserAgent;
:global Identity;
:global IDonate;
:global NoNewsAndChangesNotification;
@@ -984,6 +988,7 @@
:global CertificateAvailable;
:global EitherOr;
+ :global FetchUserAgent;
:global Grep;
:global IfThenElse;
:global LogPrint;
@@ -1029,7 +1034,7 @@
:local Url ($BaseUrl . $ScriptVal->"name" . ".rsc" . $UrlSuffix);
$LogPrint debug $0 ("Fetching script '" . $ScriptVal->"name" . "' from url: " . $Url);
:local Result [ /tool/fetch check-certificate=yes-without-crl \
- http-header-field=({ $FetchUserAgent }) $Url output=user as-value ];
+ http-header-field=({ [ $FetchUserAgent $0 ] }) $Url output=user as-value ];
:if ($Result->"status" = "finished") do={
:set SourceNew ($Result->"data");
}
@@ -1112,7 +1117,7 @@
:local Url ($ScriptUpdatesBaseUrl . "news-and-changes.rsc" . $ScriptUpdatesUrlSuffix);
$LogPrint debug $0 ("Fetching news, changes and migration: " . $Url);
:local Result [ /tool/fetch check-certificate=yes-without-crl \
- http-header-field=({ $FetchUserAgent }) $Url output=user as-value ];
+ http-header-field=({ [ $FetchUserAgent $0 ] }) $Url output=user as-value ];
:if ($Result->"status" = "finished") do={
:set ChangeLogCode ($Result->"data");
}