aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2024-03-27 23:01:38 +0100
committerGravatar Christian Hesse <mail@eworm.de>2024-04-06 00:43:39 +0200
commit5323052290177ff3cfbae5f80a846f5657ae9afd (patch)
treeae52a4bcb527cf90ab1e7b80eda7d0dd6b7621d5
parent86d0f71acb760793c8ccd5320351320f684ce052 (diff)
global-functions: introduce $FetchHugerouteros-7.13-4
-rw-r--r--README.md2
-rw-r--r--global-functions.rsc39
2 files changed, 39 insertions, 2 deletions
diff --git a/README.md b/README.md
index 5109173..4516736 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@ RouterOS Scripts
[![GitHub stars](https://img.shields.io/github/stars/eworm-de/routeros-scripts?logo=GitHub&style=flat&color=red)](https://github.com/eworm-de/routeros-scripts/stargazers)
[![GitHub forks](https://img.shields.io/github/forks/eworm-de/routeros-scripts?logo=GitHub&style=flat&color=green)](https://github.com/eworm-de/routeros-scripts/network)
[![GitHub watchers](https://img.shields.io/github/watchers/eworm-de/routeros-scripts?logo=GitHub&style=flat&color=blue)](https://github.com/eworm-de/routeros-scripts/watchers)
-[![required RouterOS version](https://img.shields.io/badge/RouterOS-7.12-yellow?style=flat)](https://mikrotik.com/download/changelogs/)
+[![required RouterOS version](https://img.shields.io/badge/RouterOS-7.13-yellow?style=flat)](https://mikrotik.com/download/changelogs/)
[![Telegram group @routeros_scripts](https://img.shields.io/badge/Telegram-%40routeros__scripts-%2326A5E4?logo=telegram&style=flat)](https://t.me/routeros_scripts)
[![donate with PayPal](https://img.shields.io/badge/Like_it%3F-Donate!-orange?logo=githubsponsors&logoColor=orange&style=flat)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=A4ZXBD6YS2W8J)
diff --git a/global-functions.rsc b/global-functions.rsc
index e19ed65..bd35cdf 100644
--- a/global-functions.rsc
+++ b/global-functions.rsc
@@ -4,7 +4,7 @@
# Michael Gisbers <michael@gisbers.de>
# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
#
-# requires RouterOS, version=7.12
+# requires RouterOS, version=7.13
#
# global functions
# https://git.eworm.de/cgit/routeros-scripts/about/
@@ -32,6 +32,7 @@
:global DownloadPackage;
:global EitherOr;
:global EscapeForRegEx;
+:global FetchHuge;
:global FetchUserAgentStr;
:global FormatLine;
:global FormatMultiLines;
@@ -389,6 +390,42 @@
:return $Return;
}
+# fetch huge data to file, read in chunks
+:set FetchHuge do={
+ :local ScriptName [ :tostr $1 ];
+ :local Url [ :tostr $2 ];
+
+ :global GetRandom20CharAlNum;
+ :global LogPrint;
+ :global MkDir;
+ :global WaitForFile;
+
+ :if ([ $MkDir "tmpfs/" . $ScriptName ] = false) do={
+ $LogPrint error $0 ("Failed creating directory!");
+ :return false;
+ }
+
+ :local FileName ("tmpfs/" . $ScriptName . "/" . $0 . "-" . [ $GetRandom20CharAlNum ]);
+
+ :do {
+ /tool/fetch check-certificate=yes-without-crl $Url dst-path=$FileName as-value;
+ } on-error={
+ $LogPrint debug $0 ("Failed downloading from: " . $Url);
+ :return false;
+ }
+ $WaitForFile $FileName;
+
+ :local FileSize [ /file/get $FileName size ];
+ :local Return "";
+ :local VarSize 0;
+ :while ($VarSize < $FileSize) do={
+ :set Return ($Return . ([ /file/read offset=$VarSize chunk-size=32768 file=$FileName as-value ]->"data"));
+ :set VarSize [ :len $Return ];
+ }
+ /file/remove $FileName;
+ :return $Return;
+}
+
# generate user agent string for fetch
:set FetchUserAgentStr do={
:local Caller [ :tostr $1 ];