aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2020-03-20 08:44:24 +0100
committerGravatar Christian Hesse <mail@eworm.de>2020-03-20 09:26:12 +0100
commitf50e416e49a9f390408268a5c173b4e99ec81c0f (patch)
tree1babd1056fe61f3f658d15ed234939005a2fcad3
parent98585afe1cc068203e5d713eb9965c930ac762de (diff)
global-functions: introduce $MkDir
This is a dirty hack... RouterOS does not support creating directories, so we mis-use http server and fetch tool.
-rw-r--r--global-functions18
1 files changed, 18 insertions, 0 deletions
diff --git a/global-functions b/global-functions
index eda9ab6..3187036 100644
--- a/global-functions
+++ b/global-functions
@@ -27,6 +27,7 @@
:global GetRandom;
:global LogPrintExit;
:global MailServerIsUp;
+:global MkDir;
:global ParseKeyValueStore;
:global RandomDelay;
:global ScriptFromTerminal;
@@ -315,6 +316,23 @@
:return false;
}
+# create directory
+:set MkDir do={
+ :local Dir [ :tostr $1 ];
+
+ :global WaitForFile;
+
+ :if ([ / file print count-only where name=$Dir type="directory" ] = 0) do={
+ :local WwwVal [ / ip service get www ];
+ / ip service set www address=127.0.0.1/32 disabled=no port=80;
+ / tool fetch http://127.0.0.1/ dst-path=($Dir . "/tmp");
+ $WaitForFile ($Dir . "/tmp");
+ / file remove ($Dir . "/tmp");
+ / ip service set www address=($WwwVal->"address") \
+ disabled=($WwwVal->"disabled") port=($WwwVal->"port");
+ }
+}
+
# parse key value store
:set ParseKeyValueStore do={
:global CharacterReplace;