Community discussions

MikroTik App
 
satish
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 97
Joined: Sun Apr 03, 2011 10:52 am

How to enable user using script when it is disabled

Sat Jul 23, 2022 1:16 pm

Hi friends,

I have one CCR 1009 device. In that i have a user 1 & user 2 with full access.

User2 is disabling user1. But i need a script which will check in a particular time interval for disable. if that(user1) is disable need to re-enable using that script.

Kindly help. Thanks in advance.
 
BrookXVll
just joined
Posts: 7
Joined: Sat Jul 23, 2022 1:13 pm

Re: How to enable user using script when it is disabled

Sat Jul 23, 2022 1:46 pm


:local userName "userName"
:local disabledStatus []

:set disabledStatus [user get [find name=$userName] disabled]

:if ($disabledStatus) do={ 
    /user set $userName disabled=no
    :log info "User $userName is enabled"
}
Last edited by BrookXVll on Sat Jul 23, 2022 1:53 pm, edited 1 time in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: How to enable user using script when it is disabled

Sat Jul 23, 2022 3:15 pm

for time interval, simply use the scheduler to launch the control at a given time
/user enable [find where name="user1" and disabled=yes]

if you want log also when the user is enabled (and not everytime if is enabled or not)
:local user "user1"
/user
:if ([:len [find where name=$user and disabled=yes]] > 0) do={
    enable [find where name=$user]
    :log info "User $user enabled again"
}

if you want continuosly check, but activate on given time interval (do not overlap with midnight!!!)
without logging
:local user     "user1"
:local timefrom "14:00:00"
:local timeto   "18:00:00"

:local now [/sys clock get time]
:if ( ([:totime $timefrom] < $now) and ($now < [:totime $timeto]) ) do={
    /user enable [find where name=$user and disabled=yes]
}

with logging
:local user     "user1"
:local timefrom "14:00:00"
:local timeto   "18:00:00"

:local now [/sys clock get time]
:if ( ([:totime $timefrom] < $now) and ($now < [:totime $timeto]) ) do={
    /user
    :if ([:len [find where name=$user and disabled=yes]] > 0) do={
        enable [find where name=$user]
        :log info "User $user enabled again"
    }
}

Who is online

Users browsing this forum: Kanzler, ko00000000001, nichky and 16 guests