Hi everyone
I have a senario as follows:
I have 3 router users for example userA, userB and userC.
and I have 3 scripts in system/scripts ... for example scriptA, scriptB and scriptC
now what I need is, when userA login to router via winbox, web or other ways only can execute scriptA, userB should execute only scriptB, and userC should can execute only scriptC
I try some solution but no successs:
1- via web skin design : it dosn't allow to restrict at specific script level, only can restrict Script section but not script inside it
2- in each script first of all check the logged in user and if for example loggedin user="userA" then scriptA will be execute but I couldn't get current logged in username, problem is $user dosn't return anything
what can i do to solve this senario?
thanks in advanced
Simply put:
RouterOS doesn't have a comprehensive rights management platform.
There's nothing else to add.
However, how to simulate this behavior using tricks remains to be found.
You can do it like that:
# ScriptA
# Allowed user name
:local allowedUser "userA"
# Get current script name
:local currentScript [:jobname]
# Read current user
:local jobData [/system/script/job/print as-value where script=$currentScript ]
:local currentUser ($jobData->0->"owner")
:if ($currentUser = $allowedUser) do={
:log info ("Script $currentScript was executed by $currentUser")
# Your code
} else={
:log warning "You are not allowed to execute this script!"
}
But it's important, what your script is doing. If it requires write access to do your task, there is no any sense, because the user will be able to just edit the script and overcome all restrictions.
And this won't work correctly, if your scripts are some long-running tasks and if the users can execute them simultaneously.