Mikrotik ‘User Manager‘ is a free and builtin package of mikrotik which provides basic level of radius / billing capabilities. Its good for smaller networks but form its introduction till the latest version, it always contains few bugs that can be sometimes annoying for the admin and surely not suitable for large production environment like ISP’s. One little example is FALSE active sessions in userman where user actually not active any more in the Mikrotik connected session but the userman shows it active thus preventing user from re-connecting.
This usually happens when users lost connectivity [specially wifi users] or disconnected from the mikrotik but userman still keep it in its active session therefore the user gets denied when he try to re-connect. so when the admin manually remove its Active session from the userman web interface, user then able to connect.
This is no mean a solution, but you can say as a workaround only a script was posted in mikrotik forums, therefore re-posting with some mods it so that it may help others as well. Just for reference purposes.
Schedule it to run according to your router load. on the load of around 150+ users with low end router, I schedule it to run after every 5 minutes as this script does take some times to calculate each user so take a note of it. adjust value accordingly.
# Script Source : Mikrotik Forums # This script remove false active sessions in User Manager v5 or above # I only tested it with ver 6.32.1 and it worked very well in a active network. [Jahanzaib] # Script Starts Here. # Setting Timeout in Seconds # Timeout in Seconds, when session update is older -> session closed :local Timeout 60 #------------------------------------------ :local LastSessionUpdate; :local SessionTimeout; :foreach i in=[/tool user-manager session find where active=yes] do={ # When was the last Update of the session-informations :set LastSessionUpdate [/tool user-manager session get $i till-time] # SessionTimeout is a value that tells me how many seconds ago the last update of this session was :set SessionTimeout ([system clock get time] - [:pick $LastSessionUpdate ([:find $LastSessionUpdate " "]+1) [:len $LastSessionUpdate]]-[/system clock get gmt-offset]) # if last update is more then Timeout seconds ago then close session and log it :if ($SessionTimeout > $Timeout) do={ /tool user-manager session remove numbers=$i :log warning (" Removed false active session by Zaib - Username is " . [/tool user-manager session get $i user]); } }
So, where to load the script ?
LikeLike
Comment by Soam — September 23, 2015 @ 11:26 AM
home
Mikrotik User Manager False Active Session Removal Scripts | Syed Jahanzaib Personal Blog to Share Knowledge !
LikeLike
Trackback by home — October 16, 2015 @ 4:26 PM
I Run the given script but still the issue remains same.
LikeLike
Comment by Ravindra — June 14, 2016 @ 9:05 PM
You really need to modify it, and before modifying, make sure radclient is able to disconnect users on mikrotik by terminal command. test first.
LikeLike
Comment by Syed Jahanzaib / Pinochio~:) — June 15, 2016 @ 10:19 AM
dear sir
problem ye hay k users disconect hojaty hain or log may check karta hun to log may ye show hota hay
xyz logged out
terminating… peer is not responding
disconnected
phir 2 se 3 mint baad users khud hi connect ho jaty phir kisi bhi waqt phir yehi problem hota hay
mujhy samajh nai a rahi k is tarha kyun horaha hay
is ka kya solution hay sir plz help????
LikeLike
Comment by afnan — June 17, 2017 @ 4:15 AM
I tried it but still the same issue
LikeLike
Comment by salim — June 30, 2017 @ 2:51 AM
User Manager is not much reliable. try external billing system like either cloud base or freeradiu base, example radius manager
LikeLike
Comment by Syed Jahanzaib / Pinochio~:) — June 30, 2017 @ 4:29 PM
how can I apply this script I do not use usermanager, only hotspot
Thank you
LikeLike
Comment by matellito — December 30, 2017 @ 2:16 AM
modify : # Script Source : Mikrotik Forums
# This script remove false active sessions in User Manager v5 or above
# I only tested it with ver 6.32.1 and it worked very well in a active network. [Ganif]
:log warning (“This script remove false active sessions in User Manager”)
# Script Starts Here.
# Setting Timeout in Seconds
# Timeout in Seconds, when session update is older -> session closed
:local Timeout -120
#——————————————
:local LastSessionUpdate;
:local SessionTimeout;
:foreach i in=[/tool user-manager session find where active=yes] do={
# When was the last Update of the session-informations
:set $LastSessionUpdate [/tool user-manager session get $i till-time]
# SessionTimeout is a value that tells me how many seconds ago the last update of this session was
:set $SessionTimeout ([system clock get time] – [:pick $LastSessionUpdate ([:find $LastSessionUpdate ” “]+1) [:len $LastSessionUpdate]]);
:log warning ( “$Timeout”);
:log warning ( “$SessionTimeout”);
# if last update is more then Timeout seconds ago then close session and log it
:if ($SessionTimeout < $Timeout) do={
:log warning (" Removed false active session by Ganif – Username is " . [/tool user-manager session get $i user])
/tool user-manager session remove numbers=$i
}
}
:log warning ("users aktif oke")
LikeLike
Comment by Hendri Ganif Cahyono — February 21, 2018 @ 2:41 AM
when i run this script, there is no log message. i dont know if its working.
LikeLike
Comment by Nen — March 7, 2019 @ 7:05 AM