Expire Hotspot Users RouterOS v6.37rc27

Expire Hotspot User

One Script for more Profiles

Testet on RouterOS v6.37rc27

{
:global today
:global prof
:global offset
{
:local date [/system clock get date ]
:local montharray ( "jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec" )
:local monthdays ( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 )
:local days [ :pick $date 4 6 ]
:local monthtxt [ :pick $date 0 3 ]
:local year [ :pick $date 7 11 ]
:local months ( [ :find $montharray $monthtxt] )
:for nodays from=0 to=[ :tonum $months] do={
:set days ( $days + [ :pick $monthdays $nodays ] )
}
:set days ( $days + $year * 365)
:set today $days
}

-- Below you can add more user-profiles --

:foreach i in=[/ip hotspot user find where disabled=no ( profile=1 || profile=2 ) ] do={
:if ([ :find [/ip hotspot user get $i comment ]] = 0 ) do={
:local Date [/ip hotspot user get $i comment ]
:local montharray ( "jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec" )
:local monthdays ( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 )
:local days [ :pick $Date 4 6 ]
:local monthtxt [:pick $Date 0 3 ]
:local year [ :pick $Date 7 11 ]
:local months ([:find $montharray $monthtxt ] )
:for nodays from=0 to=[ :tonum $months] do={
:set days ( $days + [ :pick $monthdays $nodays ] )
:set prof [/ip hotspot user get $i profile ]
:if ($prof = 1 ) do={

!!-- offset means the days to expire user --!!

:set offset 3
} else={
:if ($prof = 2 ) do={
:set offset 6
}}}
:set days ($days + $year * 365)
:if (($days + $offset) < $today ) do={
:local name [/ip hotspot user get $i name]
:local mac [/ip hotspot user get $i mac-address]
:log warning "EXPIRE PROFILE $prof : Offset:$offset : Hotspot user:$name Mac:$mac first logged in $Date"
[/ip hotspot user disable $i ]
[/ip hotspot active remove [ find where mac-address=$mac ]]
}}}}