mirror of
https://git.eworm.de/cgit/routeros-scripts
synced 2025-07-25 21:34:30 +02:00
global-functions: generate user agent string in function...
... and add the caller and my shortened url.
This commit is contained in:
parent
576a2c97cf
commit
eb7919c1d8
3 changed files with 19 additions and 14 deletions
|
@ -48,7 +48,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 }) \
|
/tool/fetch check-certificate=yes-without-crl http-header-field=({ [ $FetchUserAgent $0 ] }) \
|
||||||
($CertRenewUrl . $CertFileName) dst-path=$CertFileName as-value;
|
($CertRenewUrl . $CertFileName) dst-path=$CertFileName as-value;
|
||||||
$WaitForFile $CertFileName;
|
$WaitForFile $CertFileName;
|
||||||
|
|
||||||
|
|
|
@ -14,12 +14,12 @@
|
||||||
:do {
|
:do {
|
||||||
:local ScriptName [ :jobname ];
|
:local ScriptName [ :jobname ];
|
||||||
|
|
||||||
:global FetchUserAgent;
|
|
||||||
:global FwAddrLists;
|
:global FwAddrLists;
|
||||||
:global FwAddrListTimeOut;
|
:global FwAddrListTimeOut;
|
||||||
|
|
||||||
:global CertificateAvailable;
|
:global CertificateAvailable;
|
||||||
:global EitherOr;
|
:global EitherOr;
|
||||||
|
:global FetchUserAgent;
|
||||||
:global LogPrint;
|
:global LogPrint;
|
||||||
:global LogPrintOnce;
|
:global LogPrintOnce;
|
||||||
:global ScriptLock;
|
:global ScriptLock;
|
||||||
|
@ -65,7 +65,7 @@
|
||||||
:if ($Data = false) do={
|
:if ($Data = false) do={
|
||||||
:do {
|
:do {
|
||||||
:set Data ([ /tool/fetch check-certificate=$CheckCertificate output=user \
|
: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={
|
} on-error={
|
||||||
:if ($I < 4) do={
|
:if ($I < 4) do={
|
||||||
$LogPrint debug $ScriptName ("Failed downloading, " . $I . ". try: " . $List->"url");
|
$LogPrint debug $ScriptName ("Failed downloading, " . $I . ". try: " . $List->"url");
|
||||||
|
|
|
@ -16,12 +16,6 @@
|
||||||
|
|
||||||
# global variables not to be changed by user
|
# global variables not to be changed by user
|
||||||
:global GlobalFunctionsReady false;
|
: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 Identity [ /system/identity/get name ];
|
||||||
|
|
||||||
# global functions
|
# global functions
|
||||||
|
@ -38,6 +32,7 @@
|
||||||
:global DownloadPackage;
|
:global DownloadPackage;
|
||||||
:global EitherOr;
|
:global EitherOr;
|
||||||
:global EscapeForRegEx;
|
:global EscapeForRegEx;
|
||||||
|
:global FetchUserAgent;
|
||||||
:global FormatLine;
|
:global FormatLine;
|
||||||
:global FormatMultiLines;
|
:global FormatMultiLines;
|
||||||
:global GetMacVendor;
|
:global GetMacVendor;
|
||||||
|
@ -137,11 +132,11 @@
|
||||||
:set CertificateDownload do={
|
:set CertificateDownload do={
|
||||||
:local CommonName [ :tostr $1 ];
|
:local CommonName [ :tostr $1 ];
|
||||||
|
|
||||||
:global FetchUserAgent;
|
|
||||||
:global ScriptUpdatesBaseUrl;
|
:global ScriptUpdatesBaseUrl;
|
||||||
:global ScriptUpdatesUrlSuffix;
|
:global ScriptUpdatesUrlSuffix;
|
||||||
|
|
||||||
:global CertificateNameByCN;
|
:global CertificateNameByCN;
|
||||||
|
:global FetchUserAgent;
|
||||||
:global LogPrint;
|
:global LogPrint;
|
||||||
:global UrlEncode;
|
:global UrlEncode;
|
||||||
:global WaitForFile;
|
:global WaitForFile;
|
||||||
|
@ -151,7 +146,7 @@
|
||||||
: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=({ $FetchUserAgent }) \
|
/tool/fetch check-certificate=yes-without-crl http-header-field=({ [ $FetchUserAgent $0 ] }) \
|
||||||
($ScriptUpdatesBaseUrl . "certs/" . $UrlFileName . $ScriptUpdatesUrlSuffix) \
|
($ScriptUpdatesBaseUrl . "certs/" . $UrlFileName . $ScriptUpdatesUrlSuffix) \
|
||||||
dst-path=$LocalFileName as-value;
|
dst-path=$LocalFileName as-value;
|
||||||
$WaitForFile $LocalFileName;
|
$WaitForFile $LocalFileName;
|
||||||
|
@ -396,6 +391,16 @@
|
||||||
:return $Return;
|
: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
|
# format a line for output
|
||||||
:set FormatLine do={
|
:set FormatLine do={
|
||||||
:local Key [ :tostr $1 ];
|
:local Key [ :tostr $1 ];
|
||||||
|
@ -975,7 +980,6 @@
|
||||||
: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;
|
||||||
|
@ -984,6 +988,7 @@
|
||||||
|
|
||||||
:global CertificateAvailable;
|
:global CertificateAvailable;
|
||||||
:global EitherOr;
|
:global EitherOr;
|
||||||
|
:global FetchUserAgent;
|
||||||
:global Grep;
|
:global Grep;
|
||||||
:global IfThenElse;
|
:global IfThenElse;
|
||||||
:global LogPrint;
|
:global LogPrint;
|
||||||
|
@ -1029,7 +1034,7 @@
|
||||||
:local Url ($BaseUrl . $ScriptVal->"name" . ".rsc" . $UrlSuffix);
|
:local Url ($BaseUrl . $ScriptVal->"name" . ".rsc" . $UrlSuffix);
|
||||||
$LogPrint debug $0 ("Fetching script '" . $ScriptVal->"name" . "' from url: " . $Url);
|
$LogPrint debug $0 ("Fetching script '" . $ScriptVal->"name" . "' from url: " . $Url);
|
||||||
:local Result [ /tool/fetch check-certificate=yes-without-crl \
|
: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={
|
:if ($Result->"status" = "finished") do={
|
||||||
:set SourceNew ($Result->"data");
|
:set SourceNew ($Result->"data");
|
||||||
}
|
}
|
||||||
|
@ -1112,7 +1117,7 @@
|
||||||
:local Url ($ScriptUpdatesBaseUrl . "news-and-changes.rsc" . $ScriptUpdatesUrlSuffix);
|
:local Url ($ScriptUpdatesBaseUrl . "news-and-changes.rsc" . $ScriptUpdatesUrlSuffix);
|
||||||
$LogPrint debug $0 ("Fetching news, changes and migration: " . $Url);
|
$LogPrint debug $0 ("Fetching news, changes and migration: " . $Url);
|
||||||
:local Result [ /tool/fetch check-certificate=yes-without-crl \
|
: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={
|
:if ($Result->"status" = "finished") do={
|
||||||
:set ChangeLogCode ($Result->"data");
|
:set ChangeLogCode ($Result->"data");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue