aboutsummaryrefslogtreecommitdiffstats
path: root/global-functions
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2021-02-25 16:36:44 +0100
committerGravatar Christian Hesse <mail@eworm.de>2021-02-25 16:50:10 +0100
commitbd6b67ad7a643eebdacb0b00e5b92da28c45cdd8 (patch)
treedf68764450401b713de27daea63fbd95084ccd0d /global-functions
parentd0cdad791c937c48fe3598338599f678f1cd1e0d (diff)
global-functions: $ScriptInstallUpdate: add syntax validation
Diffstat (limited to 'global-functions')
-rw-r--r--global-functions48
1 files changed, 30 insertions, 18 deletions
diff --git a/global-functions b/global-functions
index 7dddb50..8396f60 100644
--- a/global-functions
+++ b/global-functions
@@ -670,26 +670,38 @@
:if ([ :len $SourceNew ] > 0) do={
:if ($SourceNew != $ScriptVal->"source") do={
:if ([ :pick $SourceNew 0 18 ] = "#!rsc by RouterOS\n") do={
- :local DontRequirePermissions \
- ($SourceNew~"\n# requires: dont-require-permissions=yes\n");
- $LogPrintExit2 info $0 ("Updating script: " . $ScriptVal->"name") false;
- / system script set owner=($ScriptVal->"name") source=$SourceNew \
- dont-require-permissions=$DontRequirePermissions $Script;
- :if ($ScriptVal->"name" = "global-config") do={
- $LogPrintExit2 info $0 ("Reloading global configuration and overlay.") false;
- :do {
- / system script { run global-config; run global-config-overlay; }
- } on-error={
- $LogPrintExit2 error $0 ("Reloading global configuration and overlay failed! Syntax error\?") false;
- }
+ :local SyntaxOK true;
+ :do {
+ [ :parse (":local ValidateFunction do={ " . $SourceNew . " }") ]
+ } on-error={
+ :set SyntaxOK false;
}
- :if ($ScriptVal->"name" = "global-functions") do={
- $LogPrintExit2 info $0 ("Reloading global functions.") false;
- :do {
- / system script run global-functions;
- } on-error={
- $LogPrintExit2 error $0 ("Reloading global functions failed!") false;
+ :if ($SyntaxOK = true) do={
+ :local DontRequirePermissions \
+ ($SourceNew~"\n# requires: dont-require-permissions=yes\n");
+ $LogPrintExit2 info $0 ("Updating script: " . $ScriptVal->"name") false;
+ / system script set owner=($ScriptVal->"name") source=$SourceNew \
+ dont-require-permissions=$DontRequirePermissions $Script;
+ :if ($ScriptVal->"name" = "global-config") do={
+ $LogPrintExit2 info $0 ("Reloading global configuration and overlay.") false;
+ :do {
+ / system script { run global-config; run global-config-overlay; }
+ } on-error={
+ $LogPrintExit2 error $0 ("Reloading global configuration and overlay failed!" . \
+ " Syntax error or missing overlay\?") false;
+ }
+ }
+ :if ($ScriptVal->"name" = "global-functions") do={
+ $LogPrintExit2 info $0 ("Reloading global functions.") false;
+ :do {
+ / system script run global-functions;
+ } on-error={
+ $LogPrintExit2 error $0 ("Reloading global functions failed!") false;
+ }
}
+ } else={
+ $LogPrintExit2 warning $0 ("Syntax validation for script " . $ScriptVal->"name" . \
+ " failed! Ignoring!") false;
}
} else={
$LogPrintExit2 warning $0 ("Looks like new script " . $ScriptVal->"name" . \