Desconectar usuarios por días en hotspot

Desconecta usuarios por días

{

:local date [ /system clock get date ]

:local time [ /system clock get time ]

:if ( [ /ip hotspot user get $user comment ] = "" ) do={

[ /ip hotspot user set $user comment="$date $time" ]

}

}

 

{

:local offset 1

:global today

:global hours

 

 

:global minutes

:global expired false

 

 

:global profile [/ip hotspot user get $user profile]

{

:local date [ /system clock get date ]

:local time [ /system clock get time ]

: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

:set hours [ :pick $time 0 1 ]

:if ( $hours = 0 ) do={

:set hours [ :pick $time 1 2 ]

} else {

:set hours [ :pick $time 0 2 ]

}

 

 

:set minutes [ :pick $time 3 4 ]

:if ( $minutes = 0 ) do={

:set minutes [ :pick $time 4 5 ]

} else {

:set minutes [ :pick $time 3 5 ]

}

 

 

}

 

:foreach i in [ /ip hotspot user find where disabled=no ] do={

:if ([ /ip hotspot user get $i comment ] != "counters and limits for trial users") do={

:if ([ /ip hotspot user get $i comment ] != "" ) do={

:local prof ([ /ip hotspot user get $i profile])

if ($profile = $prof) 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 ] )

:local hourc [ :pick $date 12 13 ]

:if ( $hourc = 0) do={

:set hourc [ :pick $date 13 14 ]

} else {

:set hourc [ :pick $date 12 14 ]

}

 

 

:local minutec [ :pick $date 15 16 ]

:if ( $minutec = 0 ) do={

:set minutec [ :pick $date 16 17 ]

} else {

:set minutec [ :pick $date 15 17 ]

}

 

 

:for nodays from=0 to=$months do={

:set days ( $days + [ :pick $monthdays $nodays ] )

}

:set days ($days + $year * 365)

:local difference ($today - $days)

:if ( $difference > $offset ) do={

:set $expired (true)

} else {

:if ( $difference = $offset ) do={

:if ( $hours > $hourc ) do={

:set $expired (true)

} else {

:if ( $hours = $hourc && $minutes >= $minutec) do={

:set $expired (true)

}

}

}

}

 

 

:if ( $expired = true ) 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=$name] ]

[ /ip hotspot cookie remove [find where user=$name] ]

}

 

 

}

}

}

}

}

}