you should look better in my resources....
viewtopic.php?t=177551#p977175
Just some hint:
:foreach i in=[ip hotspot user find where name!="admin" and name!="default-trial" and disabled=no] do={
:global datetime2epoch do={
[…]
}
[…]
}
do not define everytime for each cycle the function....
the corect way is this:
:global datetime2epoch do={
[…]
}
:foreach i in=[ip hotspot user find where name!="admin" and name!="default-trial" and disabled=no] do={
[…]
}
"EXPIRED user: $user" is wrong, must be $User with uppercase.
"Checked user: $User, Expires: $ts1, Epoch: $epoch" on the
else $ts1 do not exist....
"limit-uptime" is time format like 7d, 1d etc and can't be used as number.... (for example from 1w00:00:00 is 604800 seconds)
revised for v6 and v7 but untested code
:global datetime2epoch do={
:local dtime [:tostr $1]
/system clock
:local cyear [get date] ; :if ($cyear ~ "....-..-..") do={:set cyear [:pick $cyear 0 4]} else={:set cyear [:pick $cyear 7 11]}
:if (([:len $dtime] = 10) or ([:len $dtime] = 11)) do={:set dtime "$dtime 00:00:00"}
:if ([:len $dtime] = 15) do={:set dtime "$[:pick $dtime 0 6]/$cyear $[:pick $dtime 7 15]"}
:if ([:len $dtime] = 14) do={:set dtime "$cyear-$[:pick $dtime 0 5] $[:pick $dtime 6 14]"}
:if ([:len $dtime] = 8) do={:set dtime "$[get date] $dtime"}
:if ([:tostr $1] = "") do={:set dtime ("$[get date] $[get time]")}
:local vdate [:pick $dtime 0 [:find $dtime " " -1]]
:local vtime [:pick $dtime ([:find $dtime " " -1] + 1) [:len $dtime]]
:local vgmt [get gmt-offset]; :if ($vgmt > 0x7FFFFFFF) do={:set vgmt ($vgmt - 0x100000000)}
:if ($vgmt < 0) do={:set vgmt ($vgmt * -1)}
:local arrm [:toarray "0,0,31,59,90,120,151,181,212,243,273,304,334"]
:local vdoff [:toarray "0,4,5,7,8,10"]
:local MM [:pick $vdate ($vdoff->2) ($vdoff->3)]
:local M [:tonum $MM]
:if ($vdate ~ ".../../....") do={
:set vdoff [:toarray "7,11,1,3,4,6"]
:set M ([:find "xxanebarprayunulugepctovecANEBARPRAYUNULUGEPCTOVEC" [:pick $vdate ($vdoff->2) ($vdoff->3)] -1] / 2)
:if ($M>12) do={:set M ($M - 12)}
}
:local yyyy [:pick $vdate ($vdoff->0) ($vdoff->1)] ; :if ((($yyyy - 1968) % 4) = 0) do={:set ($arrm->1) -1; :set ($arrm->2) 30}
:local totd ((($yyyy - 1970) * 365) + (($yyyy - 1968) / 4) + ($arrm->$M) + ([:pick $vdate ($vdoff->4) ($vdoff->5)] - 1))
:return (((((($totd * 24) + [:pick $vtime 0 2]) * 60) + [:pick $vtime 3 5]) * 60) + [:pick $vtime 6 8] - $vgmt)
}
:global timetoseconds do={
:local inTime $1
:local wPos [:find $inTime "w" -1]
:local dPos [:find $inTime "d" -1]
:local itLen [:find $inTime "." -1] ; :if ([:typeof $itLen] = "nil") do={:set itLen [:len $inTime]}
:local itSec [:pick $inTime ($itLen - 2) $itLen]
:local itMin [:pick $inTime ($itLen - 5) ($itLen - 3)]
:local itHou [:pick $inTime ($itLen - 8) ($itLen - 6)]
:local itDay 0
:local itWee 0
:if (([:typeof $wPos] = "nil") and ([:typeof $dPos] = "num")) do={:set itDay [:pick $inTime 0 $dPos] }
:if (([:typeof $wPos] = "num") and ([:typeof $dPos] = "num")) do={:set itDay [:pick $inTime ($wPos + 1) $dPos] }
:if ([:typeof $wPos] = "num") do={:set itWee [:pick $inTime 0 $wPos] }
:local totitSec ($itSec + (60 * $itMin) + (3600 * $itHou) + (86400 * $itDay) + (604800 * $itWee))
:return $totitSec
}
/ip hotspot user
{
:local epoch [$datetime2epoch]
:local User "" ; :local Limit 0 ; :local Comment ; :local ts1 0
:foreach i in=[find where name!="admin" and name!="default-trial" and disabled=no] do={
:set User [get $i name]
:set Limit [$timetoseconds [get $i limit-uptime]]
:set Comment [:tonum [get $i comment]]
:if ([:typeof $Comment] = "num") do={
:set ts1 ($Comment + $Limit)
:log info "DEBUG User: $User, Expires: $ts1, Epoch: $epoch"
:if ($epoch >= $ts1) do={
:log info "EXPIRED User: $User, Expires: $ts1, Epoch: $epoch"
remove $i
.. cookie remove [find where user=$User]
.. active remove [find where user=$User]
}
} else={
:log info "Checked user: $User, Expires: $ts1, Epoch: $epoch"
}
}
}