aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2021-02-26 14:44:54 +0100
committerGravatar Christian Hesse <mail@eworm.de>2021-02-26 14:49:10 +0100
commitc48ad50f24458b28f4fc2f7d2845c519b541673a (patch)
tree4f3ac1c1950d809dba80813c29b0e86aa31fe916
parent464dd55bbdc008f0e8c8ac1b8405e9dc880506c4 (diff)
global-functions: introduce and use $ValidateSyntax
-rw-r--r--global-functions22
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 ];