mirror of
https://github.com/eworm-de/routeros-scripts.git
synced 2026-01-12 20:19:32 +00:00
Warn if scripts lacks required policies
I noticed that unless the script has the `read,write,policy,test` permissions set, it won't be able to read global variables from the environment.
This commit is contained in:
parent
b78df91b23
commit
a8b8e3fe99
1 changed files with 13 additions and 0 deletions
|
|
@ -1169,11 +1169,24 @@
|
|||
http-header-field=({ [ $FetchUserAgentStr $0 ] }) $Url output=user as-value ]->"data") ];
|
||||
} on-error={ }
|
||||
|
||||
:local RequiredPolicies {"read";"write";"policy";"test"};
|
||||
|
||||
:foreach Script in=[ /system/script/find where source~"^#!rsc by RouterOS\r?\n" ] do={
|
||||
:local ScriptVal [ /system/script/get $Script ];
|
||||
:local ScriptInfo [ $ParseKeyValueStore ($ScriptVal->"comment") ];
|
||||
:local SourceNew;
|
||||
|
||||
:local MissingPolicies "";
|
||||
:foreach Policy in=$RequiredPolicies do={
|
||||
:if ([:find ($ScriptVal->"policy") $Policy -1] < 0) do={
|
||||
:set MissingPolicies ($MissingPolicies . $Policy . ", ")
|
||||
}
|
||||
}
|
||||
:if ([:len $MissingPolicies]) do={
|
||||
:set MissingPolicies [:pick $MissingPolicies 0 ([:len $MissingPolicies] - 2)]
|
||||
$LogPrint warning $0 ("Script '" . $ScriptVal->"name" . "' is missing policies ". $MissingPolicies "!")
|
||||
}
|
||||
|
||||
:foreach Scheduler in=[ /system/scheduler/find where on-event~("\\b" . $ScriptVal->"name" . "\\b") ] do={
|
||||
:local SchedulerVal [ /system/scheduler/get $Scheduler ];
|
||||
:if ($ScriptVal->"policy" != $SchedulerVal->"policy") do={
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue