mirror of
https://github.com/eworm-de/routeros-scripts
synced 2024-05-14 08:04:19 +00:00
global-functions: define first, set later
This commit is contained in:
parent
64341690bf
commit
d064bd349e
1 changed files with 34 additions and 16 deletions
|
@ -14,8 +14,26 @@
|
||||||
:global SentLteFirmwareUpgradeNotification "-";
|
:global SentLteFirmwareUpgradeNotification "-";
|
||||||
:global Identity [ / system identity get name ];
|
:global Identity [ / system identity get name ];
|
||||||
|
|
||||||
|
# global functions
|
||||||
|
:global UrlEncode;
|
||||||
|
:global CharacterReplace;
|
||||||
|
:global CertificateAvailable;
|
||||||
|
:global SendEMail;
|
||||||
|
:global SendTelegram;
|
||||||
|
:global SendNotification;
|
||||||
|
:global GetMacVendor;
|
||||||
|
:global CleanFilePath;
|
||||||
|
:global DownloadPackage;
|
||||||
|
:global ScriptLock;
|
||||||
|
:global ScriptFromTerminal;
|
||||||
|
:global WaitForFile;
|
||||||
|
:global ParseKeyValueStore;
|
||||||
|
:global GetRandom;
|
||||||
|
:global RandomDelay;
|
||||||
|
:global DeviceInfo;
|
||||||
|
|
||||||
# url encoding
|
# url encoding
|
||||||
:global UrlEncode do={
|
:set UrlEncode do={
|
||||||
:local Input [ :tostr $1 ];
|
:local Input [ :tostr $1 ];
|
||||||
:local Return "";
|
:local Return "";
|
||||||
|
|
||||||
|
@ -41,7 +59,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
# character replace
|
# character replace
|
||||||
:global CharacterReplace do={
|
:set CharacterReplace do={
|
||||||
:local String [ :tostr $1 ];
|
:local String [ :tostr $1 ];
|
||||||
:local ReplaceFrom [ :tostr $2 ];
|
:local ReplaceFrom [ :tostr $2 ];
|
||||||
:local ReplaceWith [ :tostr $3 ];
|
:local ReplaceWith [ :tostr $3 ];
|
||||||
|
@ -62,7 +80,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
# check and import required certificates
|
# check and import required certificates
|
||||||
:global CertificateAvailable do={
|
:set CertificateAvailable do={
|
||||||
:local CommonName [ :tostr $1 ];
|
:local CommonName [ :tostr $1 ];
|
||||||
|
|
||||||
:global ScriptUpdatesBaseUrl;
|
:global ScriptUpdatesBaseUrl;
|
||||||
|
@ -91,7 +109,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
# send notification via e-mail
|
# send notification via e-mail
|
||||||
:global SendEMail do={
|
:set SendEMail do={
|
||||||
:local Subject [ :tostr $1 ];
|
:local Subject [ :tostr $1 ];
|
||||||
:local Message [ :tostr $2 ];
|
:local Message [ :tostr $2 ];
|
||||||
:local Attach [ :tostr $3 ];
|
:local Attach [ :tostr $3 ];
|
||||||
|
@ -116,7 +134,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
# send notification via telegram
|
# send notification via telegram
|
||||||
:global SendTelegram do={
|
:set SendTelegram do={
|
||||||
:local Subject [ :tostr $1 ];
|
:local Subject [ :tostr $1 ];
|
||||||
:local Message [ :tostr $2 ];
|
:local Message [ :tostr $2 ];
|
||||||
:local Silent [ :tostr $3 ];
|
:local Silent [ :tostr $3 ];
|
||||||
|
@ -143,7 +161,7 @@
|
||||||
|
|
||||||
# send notification via e-mail and telegram
|
# send notification via e-mail and telegram
|
||||||
# Note that attachment is ignored for telegram, silent is ignored for e-mail!
|
# Note that attachment is ignored for telegram, silent is ignored for e-mail!
|
||||||
:global SendNotification do={
|
:set SendNotification do={
|
||||||
:local Subject [ :tostr $1 ];
|
:local Subject [ :tostr $1 ];
|
||||||
:local Message [ :tostr $2 ];
|
:local Message [ :tostr $2 ];
|
||||||
:local Attach [ :tostr $3 ];
|
:local Attach [ :tostr $3 ];
|
||||||
|
@ -158,7 +176,7 @@
|
||||||
|
|
||||||
|
|
||||||
# get MAC vendor
|
# get MAC vendor
|
||||||
:global GetMacVendor do={
|
:set GetMacVendor do={
|
||||||
:local Mac [ :tostr $1 ];
|
:local Mac [ :tostr $1 ];
|
||||||
|
|
||||||
:global CertificateAvailable;
|
:global CertificateAvailable;
|
||||||
|
@ -175,7 +193,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
# clean file path
|
# clean file path
|
||||||
:global CleanFilePath do={
|
:set CleanFilePath do={
|
||||||
:local Path [ :tostr $1 ];
|
:local Path [ :tostr $1 ];
|
||||||
|
|
||||||
:global CharacterReplace;
|
:global CharacterReplace;
|
||||||
|
@ -194,7 +212,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
# download package from upgrade server
|
# download package from upgrade server
|
||||||
:global DownloadPackage do={
|
:set DownloadPackage do={
|
||||||
:local PkgName [ :tostr $1 ];
|
:local PkgName [ :tostr $1 ];
|
||||||
:local PkgVer [ :tostr $2 ];
|
:local PkgVer [ :tostr $2 ];
|
||||||
:local PkgArch [ :tostr $3 ];
|
:local PkgArch [ :tostr $3 ];
|
||||||
|
@ -239,7 +257,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
# lock script against multiple invocation
|
# lock script against multiple invocation
|
||||||
:global ScriptLock do={
|
:set ScriptLock do={
|
||||||
:local Script [ :tostr $1 ];
|
:local Script [ :tostr $1 ];
|
||||||
|
|
||||||
:if ([ / system script job print count-only where script=$Script ] > 1) do={
|
:if ([ / system script job print count-only where script=$Script ] > 1) do={
|
||||||
|
@ -249,7 +267,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
# check if script is run from terminal
|
# check if script is run from terminal
|
||||||
:global ScriptFromTerminal do={
|
:set ScriptFromTerminal do={
|
||||||
:local Script [ :tostr $1 ];
|
:local Script [ :tostr $1 ];
|
||||||
|
|
||||||
:foreach Job in=[ / system script job find where script=$Script ] do={
|
:foreach Job in=[ / system script job find where script=$Script ] do={
|
||||||
|
@ -267,7 +285,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
# wait for file to be available
|
# wait for file to be available
|
||||||
:global WaitForFile do={
|
:set WaitForFile do={
|
||||||
:global CleanFilePath;
|
:global CleanFilePath;
|
||||||
|
|
||||||
:local FileName [ $CleanFilePath [ :tostr $1 ] ];
|
:local FileName [ $CleanFilePath [ :tostr $1 ] ];
|
||||||
|
@ -284,7 +302,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
# parse key value store
|
# parse key value store
|
||||||
:global ParseKeyValueStore do={
|
:set ParseKeyValueStore do={
|
||||||
:global CharacterReplace;
|
:global CharacterReplace;
|
||||||
|
|
||||||
:local Source $1;
|
:local Source $1;
|
||||||
|
@ -302,7 +320,7 @@
|
||||||
# generate random number
|
# generate random number
|
||||||
# Warning: This is a *very* weak algorithm and in *no way*
|
# Warning: This is a *very* weak algorithm and in *no way*
|
||||||
# useful for cryptography or similar!
|
# useful for cryptography or similar!
|
||||||
:global GetRandom do={
|
:set GetRandom do={
|
||||||
:local Max ([ :tonum $1 ] + 1);
|
:local Max ([ :tonum $1 ] + 1);
|
||||||
:local Sum 0;
|
:local Sum 0;
|
||||||
|
|
||||||
|
@ -313,14 +331,14 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
# delay a random amount of seconds
|
# delay a random amount of seconds
|
||||||
:global RandomDelay do={
|
:set RandomDelay do={
|
||||||
:global GetRandom;
|
:global GetRandom;
|
||||||
|
|
||||||
:delay ([ $GetRandom $1 ] . "s");
|
:delay ([ $GetRandom $1 ] . "s");
|
||||||
}
|
}
|
||||||
|
|
||||||
# get readable device info
|
# get readable device info
|
||||||
:global DeviceInfo do={
|
:set DeviceInfo do={
|
||||||
:global ExpectedConfigVersion;
|
:global ExpectedConfigVersion;
|
||||||
:global GlobalConfigVersion;
|
:global GlobalConfigVersion;
|
||||||
:global Identity;
|
:global Identity;
|
||||||
|
|
Loading…
Reference in a new issue