Page 1 of 1

disable users by scripting

Posted: Wed Jan 29, 2014 10:35 pm
by obadaabdullah
how can i disable some of my hotspot users from 06:00 till 23:00 and enable them from 23:00 till 06:00???

Re: disable users by scripting

Posted: Thu Jan 30, 2014 7:01 am
by aacable
how can i disable some of my hotspot users from 06:00 till 23:00 and enable them from 23:00 till 06:00???
You have to create two scripts , one for disabling users at 06:00, and second for enabling them at 23:00 hrs, and schedule them as per required timings.

DISABLE Script name: disable-users
# Setting Clock Time
:local CurrentTime [/system clock get time];
:log warning "Disabling Users at  Current Time = $CurrentTime. . ."

# Setting Global Variables, You can duplicate your users entries here, simply copy paste line per user
:local user1 "test1";
:local user2 "test2";

# Disabling Users ...
/ip hotspot user disable $user1
/ip hotspot user disable $user2
# Removing active users 
#/ip hotspot active remove $user1
#/ip hotspot active remove $user2
:log warning "Disabling Users Completed . . ." 
ENABLE Script name: enable-users
# Setting Clock Time
:local CurrentTime [/system clock get time];
:log warning "Enabling Users at Current Time = $CurrentTime. . ."

# Setting Global Variables, You can duplicate your users entries here, simply copy paste line per user
:local user1 "test1";
:local user2 "test2";

# ENABLING Users ...
/ip hotspot user enable $user1
/ip hotspot user enable $user2
:log warning "ENABLING Users Completed . . ." 
& Following is Scheduler Entry to run both scripts at given timings.
/system scheduler
add interval=1d name=disable-user-at-0600-hours on-event=disable-users \
    policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api \
    start-date=jan/30/2014 start-time=06:00:00

add interval=1d name=enable-users-at-2300-hours on-event=enable-users policy=\
    ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api \
    start-date=jan/30/2014 start-time=23:00:00
This is very basic level, you can modify it as you like. For example You can shorten it by creating a text file and upload to your mikrotik, and then script take values from this file, and act accordingly :)

Hope it will help.
8)

Re: disable users by scripting

Posted: Thu Jan 30, 2014 9:02 am
by aacable
OR you can use this too if you want to read user names via text file and act accordingly.
:global content [/file get [/file find name=data.txt] contents] ;
:global contentLen [ :len $content ] ;
:global lineEnd 0;
:global line "";
:global lastEnd 0;
:do {
       :set lineEnd [:find $content "\r\n" $lastEnd ] ;
       :set line [:pick $content $lastEnd $lineEnd] ;
       :set lastEnd ( $lineEnd + 2 ) ;
       :local entry [:toarray $line] ;
   :if ( [:pick $entry] != "" ) do={
   :put $entry;
#:log warning "$entry"
/ip hotspot user disable $entry;
}
} while ($lineEnd < $contentLen)
Sample of data.txt which contains user names
test1
test2

Re: disable users by scripting

Posted: Thu Jul 21, 2016 1:06 pm
by adieyz
OR you can use this too if you want to read user names via text file and act accordingly.
:global content [/file get [/file find name=data.txt] contents] ;
:global contentLen [ :len $content ] ;
:global lineEnd 0;
:global line "";
:global lastEnd 0;
:do {
       :set lineEnd [:find $content "\r\n" $lastEnd ] ;
       :set line [:pick $content $lastEnd $lineEnd] ;
       :set lastEnd ( $lineEnd + 2 ) ;
       :local entry [:toarray $line] ;
   :if ( [:pick $entry] != "" ) do={
   :put $entry;
#:log warning "$entry"
/ip hotspot user disable $entry;
}
} while ($lineEnd < $contentLen)
Sample of data.txt which contains user names
test1
test2
data.txt whare can i put it?

Re: disable users by scripting

Posted: Fri Jul 22, 2016 5:28 pm
by loveman
how can i disable some of my hotspot users from 06:00 till 23:00 and enable them from 23:00 till 06:00???
You have to create two scripts , one for disabling users at 06:00, and second for enabling them at 23:00 hrs, and schedule them as per required timings.

DISABLE Script name: disable-users
# Setting Clock Time
:local CurrentTime [/system clock get time];
:log warning "Disabling Users at  Current Time = $CurrentTime. . ."

# Setting Global Variables, You can duplicate your users entries here, simply copy paste line per user
:local user1 "test1";
:local user2 "test2";

# Disabling Users ...
/ip hotspot user disable $user1
/ip hotspot user disable $user2
# Removing active users 
#/ip hotspot active remove $user1
#/ip hotspot active remove $user2
:log warning "Disabling Users Completed . . ." 
ENABLE Script name: enable-users
# Setting Clock Time
:local CurrentTime [/system clock get time];
:log warning "Enabling Users at Current Time = $CurrentTime. . ."

# Setting Global Variables, You can duplicate your users entries here, simply copy paste line per user
:local user1 "test1";
:local user2 "test2";

# ENABLING Users ...
/ip hotspot user enable $user1
/ip hotspot user enable $user2
:log warning "ENABLING Users Completed . . ." 
& Following is Scheduler Entry to run both scripts at given timings.
/system scheduler
add interval=1d name=disable-user-at-0600-hours on-event=disable-users \
    policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api \
    start-date=jan/30/2014 start-time=06:00:00

add interval=1d name=enable-users-at-2300-hours on-event=enable-users policy=\
    ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api \
    start-date=jan/30/2014 start-time=23:00:00
This is very basic level, you can modify it as you like. For example You can shorten it by creating a text file and upload to your mikrotik, and then script take values from this file, and act accordingly :)

Hope it will help.
8)
Your method is creating with winbox or user Manger?

Re: disable users by scripting

Posted: Thu Dec 29, 2016 5:27 pm
by Matellito
help please
I have a public hotspot with 20 users, with a single user and password the Limit Uptime I have 01:00:00 (1 hour).
While the Limit Uptime is valid you can connect any user at the same time, the problem is when Limit Uptime expires and no users can be logged in, so the user has not made use of the Hotspot and no longer logs in, the message " User XXX has reached uptime limit ",
I require a script that only removes the ip or mac of the User who is Terminated the Uptime,

Thank you

Thank you!

Re: disable users by scripting

Posted: Tue Oct 31, 2017 7:58 am
by tiks
OR you can use this too if you want to read user names via text file and act accordingly.
:global content [/file get [/file find name=data.txt] contents] ;
:global contentLen [ :len $content ] ;
:global lineEnd 0;
:global line "";
:global lastEnd 0;
:do {
       :set lineEnd [:find $content "\r\n" $lastEnd ] ;
       :set line [:pick $content $lastEnd $lineEnd] ;
       :set lastEnd ( $lineEnd + 2 ) ;
       :local entry [:toarray $line] ;
   :if ( [:pick $entry] != "" ) do={
   :put $entry;
#:log warning "$entry"
/ip hotspot user disable $entry;
}
} while ($lineEnd < $contentLen)
Sample of data.txt which contains user names
test1
test2
Tell me how to do if there is no user in the secret produces an error "no such item" how to work around? /ppp secret disable $entry;