global-functions: RouterOS v7 path syntax

This commit is contained in:
Christian Hesse 2022-05-10 14:07:11 +02:00
parent b996f00dd5
commit 0ccebc39c7

View file

@ -14,7 +14,7 @@
# global variables not to be changed by user # global variables not to be changed by user
:global GlobalFunctionsReady false; :global GlobalFunctionsReady false;
:global Identity [ / system identity get name ]; :global Identity [ /system/identity/get name ];
# global functions # global functions
:global CertificateAvailable; :global CertificateAvailable;
@ -69,30 +69,30 @@
:global LogPrintExit2; :global LogPrintExit2;
:global ParseKeyValueStore; :global ParseKeyValueStore;
:if ([ / system resource get free-hdd-space ] < 8388608 && \ :if ([ /system/resource/get free-hdd-space ] < 8388608 && \
[ / certificate settings get crl-download ] = true && \ [ /certificate/settings/get crl-download ] = true && \
[ / certificate settings get crl-store ] = "system") do={ [ /certificate/settings/get crl-store ] = "system") do={
$LogPrintExit2 warning $0 ("This system has low free flash space but " . \ $LogPrintExit2 warning $0 ("This system has low free flash space but " . \
"is configured to download certificate CRLs to system!") false; "is configured to download certificate CRLs to system!") false;
} }
:if ([ :len [ / certificate find where common-name=$CommonName ] ] = 0) do={ :if ([ :len [ /certificate/find where common-name=$CommonName ] ] = 0) do={
$LogPrintExit2 info $0 ("Certificate with CommonName \"" . $CommonName . "\" not available.") false; $LogPrintExit2 info $0 ("Certificate with CommonName \"" . $CommonName . "\" not available.") false;
:if ([ $CertificateDownload $CommonName ] = false) do={ :if ([ $CertificateDownload $CommonName ] = false) do={
:return false; :return false;
} }
} }
:local CertVal [ / certificate get [ find where common-name=$CommonName ] ]; :local CertVal [ /certificate/get [ find where common-name=$CommonName ] ];
:while (($CertVal->"akid") != "" && ($CertVal->"akid") != ($CertVal->"skid")) do={ :while (($CertVal->"akid") != "" && ($CertVal->"akid") != ($CertVal->"skid")) do={
:if ([ :len [ / certificate find where skid=($CertVal->"akid") ] ] = 0) do={ :if ([ :len [ /certificate/find where skid=($CertVal->"akid") ] ] = 0) do={
$LogPrintExit2 info $0 ("Certificate chain for \"" . $CommonName . \ $LogPrintExit2 info $0 ("Certificate chain for \"" . $CommonName . \
"\" is incomplete, missing \"" . ([ $ParseKeyValueStore ($CertVal->"issuer") ]->"CN") . "\".") false; "\" is incomplete, missing \"" . ([ $ParseKeyValueStore ($CertVal->"issuer") ]->"CN") . "\".") false;
:if ([ $CertificateDownload $CommonName ] = false) do={ :if ([ $CertificateDownload $CommonName ] = false) do={
:return false; :return false;
} }
} }
:set CertVal [ / certificate get [ find where skid=($CertVal->"akid") ] ]; :set CertVal [ /certificate/get [ find where skid=($CertVal->"akid") ] ];
} }
:return true; :return true;
} }
@ -114,16 +114,16 @@
: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 \ /tool/fetch check-certificate=yes-without-crl \
($ScriptUpdatesBaseUrl . "certs/" . \ ($ScriptUpdatesBaseUrl . "certs/" . \
$UrlFileName . $ScriptUpdatesUrlSuffix) \ $UrlFileName . $ScriptUpdatesUrlSuffix) \
dst-path=$LocalFileName as-value; dst-path=$LocalFileName as-value;
$WaitForFile $LocalFileName; $WaitForFile $LocalFileName;
/ certificate import file-name=$LocalFileName passphrase="" as-value; /certificate/import file-name=$LocalFileName passphrase="" as-value;
/ file remove $LocalFileName; /file/remove $LocalFileName;
:foreach Cert in=[ / certificate find where name~("^" . $LocalFileName . "_[0-9]+\$") ] do={ :foreach Cert in=[ /certificate/find where name~("^" . $LocalFileName . "_[0-9]+\$") ] do={
$CertificateNameByCN [ / certificate get $Cert common-name ]; $CertificateNameByCN [ /certificate/get $Cert common-name ];
} }
} on-error={ } on-error={
$LogPrintExit2 warning $0 ("Failed importing certificate with " . \ $LogPrintExit2 warning $0 ("Failed importing certificate with " . \
@ -139,8 +139,8 @@
:global CharacterReplace; :global CharacterReplace;
:local Cert [ / certificate find where common-name=$CommonName ]; :local Cert [ /certificate/find where common-name=$CommonName ];
/ certificate set $Cert \ /certificate/set $Cert \
name=[ $CharacterReplace [ $CharacterReplace [ $CharacterReplace $CommonName "'" "-" ] " " "-" ] "---" "-" ]; name=[ $CharacterReplace [ $CharacterReplace [ $CharacterReplace $CommonName "'" "-" ] " " "-" ] "---" "-" ];
} }
@ -185,7 +185,7 @@
# default route is reachable # default route is reachable
:set DefaultRouteIsReachable do={ :set DefaultRouteIsReachable do={
:if ([ :len [ / ip route find where dst-address=0.0.0.0/0 active routing-table=main ] ] > 0) do={ :if ([ :len [ /ip/route/find where dst-address=0.0.0.0/0 active routing-table=main ] ] > 0) do={
:return true; :return true;
} }
:return false; :return false;
@ -199,13 +199,13 @@
:global IfThenElse; :global IfThenElse;
:local Resource [ / system resource get ]; :local Resource [ /system/resource/get ];
:local RouterBoard; :local RouterBoard;
:do { :do {
:set RouterBoard [ / system routerboard get ]; :set RouterBoard [[ :parse "/system/routerboard/get" ]];
} on-error={ } } on-error={ }
:local License [ / system license get ]; :local License [ /system/license/get ];
:local Update [ / system package update get ]; :local Update [ /system/package/update/get ];
:return ( \ :return ( \
"Hostname: " . $Identity . \ "Hostname: " . $Identity . \
@ -259,8 +259,8 @@
:global WaitForFile; :global WaitForFile;
:if ([ :len $PkgName ] = 0) do={ :return false; } :if ([ :len $PkgName ] = 0) do={ :return false; }
:if ([ :len $PkgVer ] = 0) do={ :set PkgVer [ / system package update get installed-version ]; } :if ([ :len $PkgVer ] = 0) do={ :set PkgVer [ /system/package/update/get installed-version ]; }
:if ([ :len $PkgArch ] = 0) do={ :set PkgArch [ / system resource get architecture-name ]; } :if ([ :len $PkgArch ] = 0) do={ :set PkgArch [ /system/resource/get architecture-name ]; }
:if ($PkgName = "system") do={ :set PkgName "routeros"; } :if ($PkgName = "system") do={ :set PkgName "routeros"; }
@ -273,7 +273,7 @@
:return false; :return false;
} }
:if ([ :len [ / file find where name=$PkgDest type="package" ] ] > 0) do={ :if ([ :len [ /file/find where name=$PkgDest type="package" ] ] > 0) do={
$LogPrintExit2 info $0 ("Package file " . $PkgName . " already exists.") false; $LogPrintExit2 info $0 ("Package file " . $PkgName . " already exists.") false;
:return true; :return true;
} }
@ -288,17 +288,17 @@
:local Retry 3; :local Retry 3;
:while ($Retry > 0) do={ :while ($Retry > 0) do={
:do { :do {
/ tool fetch check-certificate=yes-without-crl $Url dst-path=$PkgDest; /tool/fetch check-certificate=yes-without-crl $Url dst-path=$PkgDest;
$WaitForFile $PkgDest; $WaitForFile $PkgDest;
:if ([ / file get [ find where name=$PkgDest ] type ] = "package") do={ :if ([ /file/get [ find where name=$PkgDest ] type ] = "package") do={
:return true; :return true;
} }
} on-error={ } on-error={
$LogPrintExit2 debug $0 ("Downloading package file failed.") false; $LogPrintExit2 debug $0 ("Downloading package file failed.") false;
} }
/ file remove [ find where name=$PkgDest ]; /file/remove [ find where name=$PkgDest ];
:set Retry ($Retry - 1); :set Retry ($Retry - 1);
} }
@ -348,28 +348,28 @@
:local AllDone true; :local AllDone true;
:local QueueLen [ :len $EmailQueue ]; :local QueueLen [ :len $EmailQueue ];
:if ([ :len [ / system scheduler find where name="FlushEmailQueue" ] ] > 0 && $QueueLen = 0) do={ :if ([ :len [ /system/scheduler/find where name="FlushEmailQueue" ] ] > 0 && $QueueLen = 0) do={
$LogPrintExit2 warning $0 ("Flushing E-Mail messages from scheduler, but queue is empty.") false; $LogPrintExit2 warning $0 ("Flushing E-Mail messages from scheduler, but queue is empty.") false;
} }
/ system scheduler set interval=($QueueLen . "m") [ find where name="FlushEmailQueue" ]; /system/scheduler/set interval=($QueueLen . "m") [ find where name="FlushEmailQueue" ];
:foreach Id,Message in=$EmailQueue do={ :foreach Id,Message in=$EmailQueue do={
:if ([ :typeof $Message ] = "array" ) do={ :if ([ :typeof $Message ] = "array" ) do={
:local Attach [ $EitherOr ($Message->"attach") "" ]; :local Attach [ $EitherOr ($Message->"attach") "" ];
:while ([ / tool e-mail get last-status ] = "in-progress") do={ :delay 1s; } :while ([ /tool/e-mail/get last-status ] = "in-progress") do={ :delay 1s; }
/ tool e-mail send to=($Message->"to") cc=($Message->"cc") subject=($Message->"subject") \ /tool/e-mail/send to=($Message->"to") cc=($Message->"cc") subject=($Message->"subject") \
body=($Message->"body") file=$Attach; body=($Message->"body") file=$Attach;
:local Wait true; :local Wait true;
:do { :do {
:delay 1s; :delay 1s;
:local Status [ / tool e-mail get last-status ]; :local Status [ /tool/e-mail/get last-status ];
:if ($Status = "succeeded") do={ :if ($Status = "succeeded") do={
:set ($EmailQueue->$Id); :set ($EmailQueue->$Id);
:set Wait false; :set Wait false;
:if (($Message->"remove-attach") = true) do={ :if (($Message->"remove-attach") = true) do={
:foreach File in=[ :toarray $Attach ] do={ :foreach File in=[ :toarray $Attach ] do={
/ file remove $File; /file/remove $File;
} }
} }
} }
@ -382,10 +382,10 @@
} }
:if ($AllDone = true && $QueueLen = [ :len $EmailQueue ]) do={ :if ($AllDone = true && $QueueLen = [ :len $EmailQueue ]) do={
/ system scheduler remove [ find where name="FlushEmailQueue" ]; /system/scheduler/remove [ find where name="FlushEmailQueue" ];
:set EmailQueue; :set EmailQueue;
} else={ } else={
/ system scheduler set interval=1m [ find where name="FlushEmailQueue" ]; /system/scheduler/set interval=1m [ find where name="FlushEmailQueue" ];
} }
} }
@ -400,12 +400,12 @@
:if ([ $CertificateAvailable "Cloudflare Inc ECC CA-3" ] = false) do={ :if ([ $CertificateAvailable "Cloudflare Inc ECC CA-3" ] = false) do={
$LogPrintExit2 warning $0 ("Downloading required certificate failed.") true; $LogPrintExit2 warning $0 ("Downloading required certificate failed.") true;
} }
:local Vendor ([ / tool fetch check-certificate=yes-without-crl \ :local Vendor ([ /tool/fetch check-certificate=yes-without-crl \
("https://api.macvendors.com/" . [ :pick $Mac 0 8 ]) output=user as-value ]->"data"); ("https://api.macvendors.com/" . [ :pick $Mac 0 8 ]) output=user as-value ]->"data");
:return $Vendor; :return $Vendor;
} on-error={ } on-error={
:do { :do {
/ tool fetch check-certificate=yes-without-crl ("https://api.macvendors.com/") \ /tool/fetch check-certificate=yes-without-crl ("https://api.macvendors.com/") \
output=none as-value; output=none as-value;
$LogPrintExit2 debug $0 ("The mac vendor is not known in database.") false; $LogPrintExit2 debug $0 ("The mac vendor is not known in database.") false;
} on-error={ } on-error={
@ -417,7 +417,7 @@
# generate random 20 chars hex (0-9 and a-f) # generate random 20 chars hex (0-9 and a-f)
:set GetRandom20CharHex do={ :set GetRandom20CharHex do={
:return ([ / certificate scep-server otp generate minutes-valid=0 as-value ]->"password"); :return ([ /certificate/scep-server/otp/generate minutes-valid=0 as-value ]->"password");
} }
# generate random number # generate random number
@ -515,20 +515,20 @@
:return true; :return true;
} }
:if ([ :len [ / file find where name=$Dir type="directory" ] ] = 1) do={ :if ([ :len [ /file/find where name=$Dir type="directory" ] ] = 1) do={
:return true; :return true;
} }
:local Return true; :local Return true;
:local Name ($Dir . "-" . [ $GetRandom20CharHex ]); :local Name ($Dir . "-" . [ $GetRandom20CharHex ]);
:do { :do {
/ ip smb share add disabled=yes directory=$Dir name=$Name; /ip/smb/share/add disabled=yes directory=$Dir name=$Name;
$WaitForFile $Dir; $WaitForFile $Dir;
} on-error={ } on-error={
$LogPrintExit2 warning $0 ("Making directory '" . $Dir . "' failed!") false; $LogPrintExit2 warning $0 ("Making directory '" . $Dir . "' failed!") false;
:set Return false; :set Return false;
} }
/ ip smb share remove [ find where name=$Name ]; /ip/smb/share/remove [ find where name=$Name ];
:return $Return; :return $Return;
} }
@ -555,7 +555,7 @@
:local To [ $EitherOr ($EmailGeneralToOverride->($Notification->"origin")) $EmailGeneralTo ]; :local To [ $EitherOr ($EmailGeneralToOverride->($Notification->"origin")) $EmailGeneralTo ];
:local Cc [ $EitherOr ($EmailGeneralCcOverride->($Notification->"origin")) $EmailGeneralCc ]; :local Cc [ $EitherOr ($EmailGeneralCcOverride->($Notification->"origin")) $EmailGeneralCc ];
:local EMailSettings [ / tool e-mail get ]; :local EMailSettings [ /tool/e-mail/get ];
:if ([ :len $To ] = 0 || ($EMailSettings->"address") = "0.0.0.0" || ($EMailSettings->"from") = "<>") do={ :if ([ :len $To ] = 0 || ($EMailSettings->"address") = "0.0.0.0" || ($EMailSettings->"from") = "<>") do={
:return false; :return false;
} }
@ -563,7 +563,7 @@
:if ([ :typeof $EmailQueue ] = "nothing") do={ :if ([ :typeof $EmailQueue ] = "nothing") do={
:set EmailQueue [ :toarray "" ]; :set EmailQueue [ :toarray "" ];
} }
:local Signature [ / system note get note ]; :local Signature [ /system/note/get note ];
:set ($EmailQueue->[ :len $EmailQueue ]) { :set ($EmailQueue->[ :len $EmailQueue ]) {
to=$To; cc=$Cc; to=$To; cc=$Cc;
subject=[ $QuotedPrintable ("[" . $Identity . "] " . ($Notification->"subject")) ]; subject=[ $QuotedPrintable ("[" . $Identity . "] " . ($Notification->"subject")) ];
@ -571,8 +571,8 @@
[ $IfThenElse ([ :len ($Notification->"link") ] > 0) ("\n\n" . ($Notification->"link")) "" ] . \ [ $IfThenElse ([ :len ($Notification->"link") ] > 0) ("\n\n" . ($Notification->"link")) "" ] . \
[ $IfThenElse ([ :len $Signature ] > 0) ("\n-- \n" . $Signature) "" ]); \ [ $IfThenElse ([ :len $Signature ] > 0) ("\n-- \n" . $Signature) "" ]); \
attach=($Notification->"attach"); remove-attach=($Notification->"remove-attach") }; attach=($Notification->"attach"); remove-attach=($Notification->"remove-attach") };
:if ([ :len [ / system scheduler find where name="FlushEmailQueue" ] ] = 0) do={ :if ([ :len [ /system/scheduler/find where name="FlushEmailQueue" ] ] = 0) do={
/ system scheduler add name=FlushEmailQueue interval=1s start-time=startup \ /system/scheduler/add name=FlushEmailQueue interval=1s start-time=startup \
on-event=(":global FlushEmailQueue; \$FlushEmailQueue;"); on-event=(":global FlushEmailQueue; \$FlushEmailQueue;");
} }
} }
@ -653,7 +653,7 @@
:global IfThenElse; :global IfThenElse;
:global LogPrintExit2; :global LogPrintExit2;
:global VersionToNum; :global VersionToNum;
:if ([ $VersionToNum $Required ] > [ $VersionToNum [ / system package update get installed-version ] ]) do={ :if ([ $VersionToNum $Required ] > [ $VersionToNum [ /system/package/update/get installed-version ] ]) do={
:if ($Warn = "true") do={ :if ($Warn = "true") do={
$LogPrintExit2 warning $0 ("This " . [ $IfThenElse ([ :pick $Caller 0 ] = ("\$")) "function" "script" ] . \ $LogPrintExit2 warning $0 ("This " . [ $IfThenElse ([ :pick $Caller 0 ] = ("\$")) "function" "script" ] . \
" '" . $Caller . "' (at least specific functionality) requires RouterOS " . $Required . ". Please update!") false; " '" . $Caller . "' (at least specific functionality) requires RouterOS " . $Required . ". Please update!") false;
@ -669,10 +669,10 @@
:global LogPrintExit2; :global LogPrintExit2;
:foreach Job in=[ / system script job find where script=$Script ] do={ :foreach Job in=[ /system/script/job/find where script=$Script ] do={
:set Job [ / system script job get $Job ]; :set Job [ /system/script/job/get $Job ];
:while ([ :typeof ($Job->"parent") ] = "id") do={ :while ([ :typeof ($Job->"parent") ] = "id") do={
:set Job [ / system script job get [ find where .id=($Job->"parent") ] ]; :set Job [ /system/script/job/get [ find where .id=($Job->"parent") ] ];
} }
:if (($Job->"type") = "login") do={ :if (($Job->"type") = "login") do={
$LogPrintExit2 debug $0 ("Script " . $Script . " started from terminal.") false; $LogPrintExit2 debug $0 ("Script " . $Script . " started from terminal.") false;
@ -712,9 +712,9 @@
} }
:foreach Script in=$Scripts do={ :foreach Script in=$Scripts do={
:if ([ :len [ / system script find where name=$Script ] ] = 0) do={ :if ([ :len [ /system/script/find where name=$Script ] ] = 0) do={
$LogPrintExit2 info $0 ("Adding new script: " . $Script) false; $LogPrintExit2 info $0 ("Adding new script: " . $Script) false;
/ system script add name=$Script owner=$Script source="#!rsc by RouterOS\n" comment=$NewComment; /system/script/add name=$Script owner=$Script source="#!rsc by RouterOS\n" comment=$NewComment;
} }
} }
@ -722,17 +722,17 @@
:local ReloadGlobalFunctions false; :local ReloadGlobalFunctions false;
:local ReloadGlobalConfig false; :local ReloadGlobalConfig false;
:foreach Script in=[ / system script find where source~"^#!rsc by RouterOS\n" ] do={ :foreach Script in=[ /system/script/find where source~"^#!rsc by RouterOS\n" ] do={
:local ScriptVal [ / system script get $Script ]; :local ScriptVal [ /system/script/get $Script ];
:local ScriptFile [ / file find where name=("script-updates/" . $ScriptVal->"name") ]; :local ScriptFile [ /file/find where name=("script-updates/" . $ScriptVal->"name") ];
:local SourceNew; :local SourceNew;
:if ([ :len $ScriptFile ] > 0) do={ :if ([ :len $ScriptFile ] > 0) do={
:set SourceNew [ / file get $ScriptFile content ]; :set SourceNew [ /file/get $ScriptFile content ];
/ file remove $ScriptFile; /file/remove $ScriptFile;
} }
:foreach Scheduler in=[ / system scheduler find where on-event~("\\b" . $ScriptVal->"name" . "\\b") ] do={ :foreach Scheduler in=[ /system/scheduler/find where on-event~("\\b" . $ScriptVal->"name" . "\\b") ] do={
:local SchedulerVal [ / system scheduler get $Scheduler ]; :local SchedulerVal [ /system/scheduler/get $Scheduler ];
:if ($ScriptVal->"policy" != $SchedulerVal->"policy") do={ :if ($ScriptVal->"policy" != $SchedulerVal->"policy") do={
$LogPrintExit2 warning $0 ("Policies differ for script '" . $ScriptVal->"name" . \ $LogPrintExit2 warning $0 ("Policies differ for script '" . $ScriptVal->"name" . \
"' and its scheduler '" . $SchedulerVal->"name" . "'!") false; "' and its scheduler '" . $SchedulerVal->"name" . "'!") false;
@ -750,7 +750,7 @@
:local Url ($BaseUrl . $ScriptVal->"name" . $UrlSuffix); :local Url ($BaseUrl . $ScriptVal->"name" . $UrlSuffix);
$LogPrintExit2 debug $0 ("Fetching script '" . $ScriptVal->"name" . "' from url: " . $Url) false; $LogPrintExit2 debug $0 ("Fetching script '" . $ScriptVal->"name" . "' from url: " . $Url) false;
:local Result [ / tool fetch check-certificate=yes-without-crl $Url output=user as-value ]; :local Result [ /tool/fetch check-certificate=yes-without-crl $Url output=user as-value ];
:if ($Result->"status" = "finished") do={ :if ($Result->"status" = "finished") do={
:set SourceNew ($Result->"data"); :set SourceNew ($Result->"data");
} }
@ -767,7 +767,7 @@
:local DontRequirePermissions \ :local DontRequirePermissions \
($SourceNew~"\n# requires: dont-require-permissions=yes\n"); ($SourceNew~"\n# requires: dont-require-permissions=yes\n");
$LogPrintExit2 info $0 ("Updating script: " . $ScriptVal->"name") false; $LogPrintExit2 info $0 ("Updating script: " . $ScriptVal->"name") false;
/ system script set owner=($ScriptVal->"name") source=$SourceNew \ /system/script/set owner=($ScriptVal->"name") source=$SourceNew \
dont-require-permissions=$DontRequirePermissions $Script; dont-require-permissions=$DontRequirePermissions $Script;
:if ($ScriptVal->"name" = "global-config") do={ :if ($ScriptVal->"name" = "global-config") do={
:set ReloadGlobalConfig true; :set ReloadGlobalConfig true;
@ -794,7 +794,7 @@
:if ($ReloadGlobalFunctions = true) do={ :if ($ReloadGlobalFunctions = true) do={
$LogPrintExit2 info $0 ("Reloading global functions.") false; $LogPrintExit2 info $0 ("Reloading global functions.") false;
:do { :do {
/ system script run global-functions; /system/script/run global-functions;
} on-error={ } on-error={
$LogPrintExit2 error $0 ("Reloading global functions failed!") false; $LogPrintExit2 error $0 ("Reloading global functions failed!") false;
} }
@ -803,7 +803,7 @@
:if ($ReloadGlobalConfig = true) do={ :if ($ReloadGlobalConfig = true) do={
$LogPrintExit2 info $0 ("Reloading global configuration.") false; $LogPrintExit2 info $0 ("Reloading global configuration.") false;
:do { :do {
/ system script run global-config; /system/script/run global-config;
} on-error={ } on-error={
$LogPrintExit2 error $0 ("Reloading global configuration failed!" . \ $LogPrintExit2 error $0 ("Reloading global configuration failed!" . \
" Syntax error or missing overlay\?") false; " Syntax error or missing overlay\?") false;
@ -818,7 +818,7 @@
:do { :do {
:local Url ($ScriptUpdatesBaseUrl . "global-config.changes" . $ScriptUpdatesUrlSuffix); :local Url ($ScriptUpdatesBaseUrl . "global-config.changes" . $ScriptUpdatesUrlSuffix);
$LogPrintExit2 debug $0 ("Fetching news, changes and migration: " . $Url) false; $LogPrintExit2 debug $0 ("Fetching news, changes and migration: " . $Url) false;
:local Result [ / tool fetch check-certificate=yes-without-crl $Url output=user as-value ]; :local Result [ /tool/fetch check-certificate=yes-without-crl $Url output=user as-value ];
:if ($Result->"status" = "finished") do={ :if ($Result->"status" = "finished") do={
:set ChangeLogCode ($Result->"data"); :set ChangeLogCode ($Result->"data");
} }
@ -918,7 +918,7 @@
:local JobCount do={ :local JobCount do={
:local Script [ :tostr $1 ]; :local Script [ :tostr $1 ];
:return [ :len [ / system script job find where script=$Script ] ]; :return [ :len [ /system/script/job/find where script=$Script ] ];
} }
:local TicketCount do={ :local TicketCount do={
@ -990,7 +990,7 @@
:set ($ScriptLockOrder->$Script) [ :toarray "" ]; :set ($ScriptLockOrder->$Script) [ :toarray "" ];
} }
:if ([ :len [ / system script find where name=$Script ] ] = 0) do={ :if ([ :len [ /system/script/find where name=$Script ] ] = 0) do={
$LogPrintExit2 error $0 ("A script named '" . $Script . "' does not exist!") true; $LogPrintExit2 error $0 ("A script named '" . $Script . "' does not exist!") true;
} }
@ -1001,7 +1001,7 @@
:if ([ $TicketCount $Script ] >= [ $JobCount $Script ]) do={ :if ([ $TicketCount $Script ] >= [ $JobCount $Script ]) do={
$LogPrintExit2 error $0 ("More tickets than running scripts '" . $Script . "', resetting!") false; $LogPrintExit2 error $0 ("More tickets than running scripts '" . $Script . "', resetting!") false;
:set ($ScriptLockOrder->$Script) [ :toarray "" ]; :set ($ScriptLockOrder->$Script) [ :toarray "" ];
/ system script job remove [ find where script=$Script ]; /system/script/job/remove [ find where script=$Script ];
} }
:local MyTicket [ $GetRandom20CharHex ]; :local MyTicket [ $GetRandom20CharHex ];
@ -1107,21 +1107,21 @@
:set TimeIsSync do={ :set TimeIsSync do={
:global LogPrintExit2; :global LogPrintExit2;
:if ([ / system ntp client get enabled ] = true) do={ :if ([ /system/ntp/client/get enabled ] = true) do={
:do { :do {
:if ([ / system ntp client get status ] = "synchronized") do={ :if ([ /system/ntp/client/get status ] = "synchronized") do={
:return true; :return true;
} }
} on-error={ } on-error={
:if ([ :typeof [ / system ntp client get last-adjustment ] ] = "time") do={ :if ([ :typeof [ /system/ntp/client/get last-adjustment ] ] = "time") do={
:return true; :return true;
} }
} }
:return false; :return false;
} }
:if ([ / ip cloud get ddns-enabled ] = true && [ / ip cloud get update-time ] = true) do={ :if ([ /ip/cloud/get ddns-enabled ] = true && [ /ip/cloud/get update-time ] = true) do={
:if ([ :typeof [ / ip cloud get public-address ] ] = "ip") do={ :if ([ :typeof [ /ip/cloud/get public-address ] ] = "ip") do={
:return true; :return true;
} }
:return false; :return false;
@ -1226,7 +1226,7 @@
:set FileName [ $CleanFilePath $FileName ]; :set FileName [ $CleanFilePath $FileName ];
:local I 0; :local I 0;
:while ([ :len [ / file find where name=$FileName ] ] = 0) do={ :while ([ :len [ /file/find where name=$FileName ] ] = 0) do={
:if ($I > 20) do={ :if ($I > 20) do={
:return false; :return false;
} }
@ -1253,10 +1253,10 @@
:global TimeIsSync; :global TimeIsSync;
:while ([ $TimeIsSync ] = false) do={ :while ([ $TimeIsSync ] = false) do={
:if ([ :len [ / system script find where name="rotate-ntp" ] ] > 0 && \ :if ([ :len [ /system/script/find where name="rotate-ntp" ] ] > 0 && \
([ / system resource get uptime ] % (180 * 1000000000)) = 0s) do={ ([ /system/resource/get uptime ] % (180 * 1000000000)) = 0s) do={
:do { :do {
/ system script run rotate-ntp; /system/script/run rotate-ntp;
} on-error={ } on-error={
$LogPrintExit2 debug $0 ("Running rotate-ntp failed.") false; $LogPrintExit2 debug $0 ("Running rotate-ntp failed.") false;
} }
@ -1266,11 +1266,11 @@
} }
# load modules # load modules
:foreach Script in=[ / system script find where name ~ "^mod/." ] do={ :foreach Script in=[ /system/script/find where name ~ "^mod/." ] do={
:local ScriptVal [ / system script get $Script ]; :local ScriptVal [ /system/script/get $Script ];
:if ([ $ValidateSyntax ($ScriptVal->"source") ] = true) do={ :if ([ $ValidateSyntax ($ScriptVal->"source") ] = true) do={
:do { :do {
/ system script run $Script; /system/script/run $Script;
} on-error={ } on-error={
$LogPrintExit2 error $0 ("Module '" . $ScriptVal->"name" . "' failed to run.") false; $LogPrintExit2 error $0 ("Module '" . $ScriptVal->"name" . "' failed to run.") false;
} }
@ -1280,12 +1280,7 @@
} }
# check for required RouterOS version # check for required RouterOS version
:if ([ $RequiredRouterOS $0 "7.0" false ] = true) do={
$RequiredRouterOS $0 "7.1" true; $RequiredRouterOS $0 "7.1" true;
} else={
$LogPrintExit2 warning $0 ("Still running RouterOS v6, please switch to branch " . \
"'routeros-v6', see https://git.eworm.de/cgit/routeros-scripts/about/#changes-for-routeros-v6") false;
}
# signal we are ready # signal we are ready
:set GlobalFunctionsReady true; :set GlobalFunctionsReady true;