Script Expire users a after number of days

Expire users a after number of days

Apply this to a hotspot user profile:
{
:local date [ /system clock get date ]
:if ( [ /ip hotspot user get $user comment ] = “” ) do={
[ /ip hotspot user set $user comment=$date ]
}
}


Run this once per day:
{
:local offset 7
:global today

{
: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=$months do={
:set days ( $days + [ :pick $monthdays $nodays ] )
}
:set days ($days + $year * 365)
:set today $days
}

:foreach i in [ /ip hotspot user find where disabled=no ] 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=$months do={
:set days ( $days + [ :pick $monthdays $nodays ] )
}
:set days ($days + $year * 365)
:if ( ($days + $offset) < $today ) do={
:local name [/ip hotspot user get $i name]
:log info “HOTSPOT EXPIRE SCRIPT: Disabling Hotspot user $name first logged in $date”
[ /ip hotspot user disable $i ]
[ /ip hotspot active remove [find where user=$user] ]
}
}
}
}

I have Problem to Calculate ???

  1. Add Day in Feburary(29day)
  2. Calculate Add Day in next year etc. 30/December/2016

Yes there are many drawbacks in this script
i already developed a script for that which will work perfectly
i ll try to publish it soon

Session_timeout

And idle_timeout

should both work

#comment format on hotspot user: 201710180000 yyyymmddhhmm
#run script with scheduler
#script
:local thisDate
:local thisYear
:local thisDay
:local thisMonth
:local thisTime
:local thisTime1
:local thisTime2
:set thisDate [/ system clock get date]
:set thisTime [/ system clock get time]
:set thisYear [:pick $thisDate 7 11]
:if ($thisYear > “2010”) do={
:set thisDay [:pick $thisDate 4 6]
:set thisMonth [:pick $thisDate 0 3]
:set thisTime1 [:pick $thisTime 0 2]
:set thisTime2 [:pick $thisTime 3 5]
:if ($thisMonth = “jan”) do={ :set thisMonth “01” }
:if ($thisMonth = “feb”) do={ :set thisMonth “02” }
:if ($thisMonth = “mar”) do={ :set thisMonth “03” }
:if ($thisMonth = “apr”) do={ :set thisMonth “04” }
:if ($thisMonth = “may”) do={ :set thisMonth “05” }
:if ($thisMonth = “jun”) do={ :set thisMonth “06” }
:if ($thisMonth = “jul”) do={ :set thisMonth “07” }
:if ($thisMonth = “aug”) do={ :set thisMonth “08” }
:if ($thisMonth = “sep”) do={ :set thisMonth “09” }
:if ($thisMonth = “oct”) do={ :set thisMonth “10” }
:if ($thisMonth = “nov”) do={ :set thisMonth “11” }
:if ($thisMonth = “dec”) do={ :set thisMonth “12” }
:set thisDate ($thisYear.$thisMonth.$thisDay.$thisTime1.$thisTime2)
:local users [/ip hotspot user find]
:local i
:local expirationDate
:foreach i in=$users do={
:set expirationDate [/ ip hotspot user get $i comment]
:if ([:len $expirationDate] = 12) do={
:local expNum [:tonum $expirationDate]
:local thisNum [:tonum $thisDate]
:if (([:typeof $expNum] = “num”) and($expNum < $thisNum)) do={
:local userName [/ip hotspot user get $i name]
:local activeUser [/ip hotspot active find where user=$userName]
/ip hotspot user remove $i
/ip hotspot active remove $activeUser
:log info “Detected hotspot expired user”
}
}
:delay 0.5s
}
}

To shorten you script look at this example

[admin@x86] >:global aaa {a=1;b=2}
[admin@x86] > :put ($aaa->"a")
1
[admin@x86] > :put ($aaa->"b")
2

Which script i have to apply on user profiles on login script. I want to disable users after 30d from 1st login.