mirror of
https://git.eworm.de/cgit/routeros-scripts
synced 2025-07-19 18:34:42 +02:00
global-functions: introduce and use $ValidateSyntax
This commit is contained in:
parent
464dd55bbd
commit
c48ad50f24
1 changed files with 15 additions and 7 deletions
|
@ -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 ];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue