diff options
-rw-r--r-- | global-functions | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/global-functions b/global-functions index 8396f60..aba1cff 100644 --- a/global-functions +++ b/global-functions @@ -47,6 +47,7 @@ :global SymbolForNotification; :global TimeIsSync; :global UrlEncode; +:global ValidateSyntax; :global VersionToNum; :global WaitDefaultRouteReachable; :global WaitDNSResolving; @@ -615,6 +616,7 @@ :global ScriptInstallUpdate; :global SendNotification; :global SymbolForNotification; + :global ValidateSyntax; :if ([ $CertificateAvailable "R3" ] = false) do={ $LogPrintExit2 warning $0 ("Downloading certificate failed, trying without.") false; @@ -670,13 +672,7 @@ :if ([ :len $SourceNew ] > 0) do={ :if ($SourceNew != $ScriptVal->"source") do={ :if ([ :pick $SourceNew 0 18 ] = "#!rsc by RouterOS\n") do={ - :local SyntaxOK true; - :do { - [ :parse (":local ValidateFunction do={ " . $SourceNew . " }") ] - } on-error={ - :set SyntaxOK false; - } - :if ($SyntaxOK = true) do={ + :if ([ $ValidateSyntax $SourceNew ] = true) do={ :local DontRequirePermissions \ ($SourceNew~"\n# requires: dont-require-permissions=yes\n"); $LogPrintExit2 info $0 ("Updating script: " . $ScriptVal->"name") false; @@ -1030,6 +1026,18 @@ :return $Return; } +# basic syntax validation +:set ValidateSyntax do={ + :local Code [ :tostr $1 ]; + + :do { + [ :parse (":local Validate do={ " . $Code . " }") ]; + } on-error={ + :return false; + } + :return true; +} + # convert version string to numeric value :set VersionToNum do={ :local Input [ :tostr $1 ]; |