Bom dia pessoal,
Quem usa o userman como servidor Radius já deve ter se deparado com usuários que após alguma falha ficam conectados no userman quando na verdade já não estão mais, então quando eles tentam reconectar eles não conseguem, então nos tecnicos temos que remover a sessão dos mesmos para eles reconectar.
Após uma incansavel busca na internet achei cerca de 10 scripts, mas nenhum deles funcionou.
Mikrotik 5.24
Vou deixar abaixo alguns dos que eu achei. Se alguem tem um que funcione e quer compartilhar fico grato.
Att leandro
------------------------------------------------------------------------------------------------------
# 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] - [ick $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]);
}
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
#This script remove false active sessions in User Manager v5
#when the last update of the session (till-time) is to long ago then the session will be closed
#Setting Timeout in Seconds (my UserManager update session every minute),
#Timeout in Seconds, when session update is older -> session clossed
: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] - [ick $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 close-session numbers=$i
:log info (" removed false active session" . [/tool user-manager session get $i user]);
}
}
---------------------------------------------------------------------------------------------------
# ver. 1.0 2013-09-06
# ver. 1.1 2013-11-01 - end of the month all sessions get killed problem solved
# - logging killed sessions in log as warning
# ver. 1.2 2014-03-09 - GMToffset not needed in 6.10 and higher (possibly 6.x)
#
# SCRIPT: radius-close-inactive-sessions
# PURPOSE: close sessions which are active in radius, but last-seen is older than $actTimeout
# this typically happens when client site loses connection to radius and user leaves hotspot
#------------------------------------------------------------------------------
# settings
# --------
# enable debugging { false | true }
local debug true
# after how many seconds of inactivity kill the session
local actTimeout (10*60)
# offset from GMT - this is not needed in User Manager 6.10 and higher - should be 0
local GMToffset [/system clock get gmt-offset]
if ( [/system clock get dst-active] != yes ) do={ :set GMToffset ( $GMToffset - 3600 ) }
local GMToffset 0
# variables
# ---------
local sessions
local testD [/system clock get date]
local testDayOfMonth [ick $testD 4 6]
local testT [/system clock get time]
local testTsec ( ($testDayOfMonth*24*3600) + [ick $testT 0 2]*3600 + [ick $testT 3 5]*60 + [ick $testT 6 8] )
:set sessions [/tool user-manager session find where active=yes]
if ($debug = true) do={
ut ("testD: " . $testD)
ut ("testDayOfMonth: " . $testDayOfMonth )
ut ("testT: " . $testT)
ut ("testTsec: " . $testTsec)
ut ("Sessions: " . [:len $sessions])
}
foreach session in $sessions do={
:local userName [/tool user-manager session get $session user ]
:local uptime [/tool user-manager session get $session uptime ]
:local hostIP [/tool user-manager session get $session "host-ip" ]
:local lastSeen [/tool user-manager user get $userName last-seen ]
local lastActD [ick $lastSeen 0 11]
local lastActDayOfMonth [ick $lastSeen 4 6]
local lastActT [:totime [ick $lastSeen 12 20]]
local lastActTsec ( ($lastActDayOfMonth*24*3600) + [ick $lastActT 0 2]*3600 + [ick $lastActT 3 5]*60 + [ick $lastActT 6 8] )
if ($debug = true) do={
ut ("id=".$session . " " . " user " . $userName . " uptime " . $uptime . " lastSeen " . $lastSeen . " hostIP ". $hostIP)
ut ("lastActD: " . $lastActD)
ut ("lastActDayOfMonth: " . $lastActDayOfMonth)
ut ("lastActT: " . $lastActT)
ut ("lastActTsec: " . $lastActTsec)
}
:set lastActTsec ($lastActTsec + $GMToffset)
if ($debug = true) do={
ut ("lastActTsec after GMT correction: " . $lastActTsec)
}
#make sure we are at least end of month + $actTimeout
if ( $testTsec > $actTimeout) do={
#difference is bigger than $actTimeout, but not bigger than 27 days (new month)
#for period localtime-GMT script will be ineffective once a month
if ( (($testTsec - $lastActTsec) > $actTimeout) and (($testTsec - $lastActTsec) < 27*3600*24) ) do={
if ($debug = true) do={
ut ("radius inactive session killed, difference " . ($testTsec - $lastActTsec) . "s actTimeout=" . $actTimeout . "s")
}
/tool user-manager session close-session $session
:log warning ("radius inactive session killed, difference " . ($testTsec - $lastActTsec) . " user " . $userName . " uptime " . $uptime . " lastSeen " . $lastSeen . " hostIP ". $hostIP)
} else={
if ($debug = true) do={
ut ("No need kill session, difference " . ($testTsec - $lastActTsec) . "s actTimeout=" . $actTimeout . "s")
}
}
}
}
---------------------------------------------------------------------------------------------------
# remove-false-active-sessions script
# by Vichaya Sirisanthana
# Policy
#
# ftp reboot
# x read x write
# policy x test
# password sniff
# sensitive
# :log info "Running script remove-false-active-sessions"
# Change path to userman session
/tool user-manager session
# Loop thru each active session
:foreach session in=[find where active=yes] do={
:local sessionTillTime [get $session till-time]
# :local sessionTimeout ([/system clock get time] - [ick $sessionTillTime ([:find $sessionTillTime " "]+1) [:len $sessionTillTime]] - [/system clock get gmt-offset])
# :local sessionTimeout ([/system clock get time] - [ick $sessionTillTime ([:find $sessionTillTime " "]+1) [:len $sessionTillTime]])
:local sessionTimeout (([/system clock get time] - [/system clock get gmt-offset]) - ([ick $sessionTillTime ([:find $sessionTillTime " "]+1) [:len $sessionTillTime]] - [/tool user-manager customer get [find login=punspace] time-zone]))
# If sessionTimeout is negative, it may be a new day so add 24 hours.
:if ($sessionTimeout < 0) do={
# :log info "sessionTimeout is negative: $sessionTimeout"
:set sessionTimeout ($sessionTimeout + [:totime 86400])
# :log info "sessionTimeout is: $sessionTimeout"
}
# Remove session if last session update (session till time) is more than 2 minutes ago
:if ($sessionTimeout > 120) do={
:local sessionUser [get $session user]
:local sessionUserIp [get $session user-ip]
:local sessionFromTime [get $session from-time]
:local sessionUptime [get $session uptime]
# :log info "Removing session $session $sessionUser $sessionUserIp $sessionFromTime $sessionTillTime $sessionUptime $sessionTimeout"
:do {
remove numbers=$session
:log info "Successfully removed session $session $sessionUser $sessionUserIp $sessionFromTime $sessionTillTime $sessionUptime $sessionTimeout"
} on-error={
:log error "Failed to remove session $session $sessionUser $sessionUserIp $sessionFromTime $sessionTillTime $sessionUptime $sessionTimeout"
}
}
}
# Reset path to root
/
# :log info "Finished running script remove-false-active-sessions"
------------------------------------------------------------------------------------------