Community discussions

 
obadaabdullah
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 71
Joined: Wed Jan 08, 2014 7:41 pm

disable users by scripting

Wed Jan 29, 2014 10:35 pm

how can i disable some of my hotspot users from 06:00 till 23:00 and enable them from 23:00 till 06:00???
 
User avatar
aacable
Member
Member
Posts: 422
Joined: Wed Sep 17, 2008 11:58 am
Location: ISLAMIC Republic of PAKISTAN
Contact:

Re: disable users by scripting

Thu Jan 30, 2014 7:01 am

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)
_____________
Regard's

Syed Jahanzaib
Web: http://aacable.wordpress.com
Email: aacable [at] hotmail.com
 
User avatar
aacable
Member
Member
Posts: 422
Joined: Wed Sep 17, 2008 11:58 am
Location: ISLAMIC Republic of PAKISTAN
Contact:

Re: disable users by scripting

Thu Jan 30, 2014 9:02 am

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
_____________
Regard's

Syed Jahanzaib
Web: http://aacable.wordpress.com
Email: aacable [at] hotmail.com
 
adieyz
just joined
Posts: 1
Joined: Sun Jul 17, 2016 11:29 am

Re: disable users by scripting

Thu Jul 21, 2016 1:06 pm

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?
 
loveman
Member
Member
Posts: 303
Joined: Tue Mar 10, 2015 9:32 pm

Re: disable users by scripting

Fri Jul 22, 2016 5:28 pm

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?
 
Matellito
just joined
Posts: 4
Joined: Fri Sep 14, 2012 5:02 am

Re: disable users by scripting

Thu Dec 29, 2016 5:27 pm

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!
 
tiks
just joined
Posts: 2
Joined: Tue Oct 31, 2017 7:55 am

Re: disable users by scripting

Tue Oct 31, 2017 7:58 am

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;

Who is online

Users browsing this forum: No registered users and 35 guests