73 lines
2.5 KiB
Plaintext
73 lines
2.5 KiB
Plaintext
# Monitor hotspot user expiry — unified
|
|
# Monitors: Bulanan2, Bulanan4, Family, home
|
|
# Voucher (vc-2K3J, vc-5K10J): removed when expired
|
|
# Bulanan/Family/home: limit-uptime=1s when expired
|
|
|
|
:local montharray { "jan"; "feb"; "mar"; "apr"; "may"; "jun"; "jul"; "aug"; "sep"; "oct"; "nov"; "dec" }
|
|
|
|
:local dateint do={
|
|
:local days [:pick $d 4 6]
|
|
:local monthstr [:pick $d 0 3]
|
|
:local year [:pick $d 7 11]
|
|
:local monthint ([ :find $montharray $monthstr ] + 1)
|
|
:local month "$monthint"
|
|
:if ([len $month] = 1) do={ :set month "0$month" }
|
|
:return [:tonum "$year$month$days"]
|
|
}
|
|
|
|
:local timeint do={
|
|
:local hours [:pick $t 0 2]
|
|
:local minutes [:pick $t 3 5]
|
|
:return ($hours * 60 + $minutes)
|
|
}
|
|
|
|
:local now [/system clock get date]
|
|
:local nowtime [/system clock get time]
|
|
:local today [$dateint d=$now]
|
|
:local curtime [$timeint t=$nowtime]
|
|
|
|
:local profiles { "Bulanan2"; "Bulanan4"; "Family"; "home" }
|
|
:local vouchProfiles { "vc-2K3J"; "vc-5K10J" }
|
|
|
|
:local expiredCount 0
|
|
|
|
:foreach profile in=$profiles do={
|
|
:foreach i in=[/ip hotspot user find where profile=$profile] do={
|
|
:local comment [/ip hotspot user get $i comment]
|
|
:local name [/ip hotspot user get $i name]
|
|
:if (([:pick $comment 3] = "/") and ([:pick $comment 6] = "/")) do={
|
|
:local expd [$dateint d=$comment]
|
|
:local exptStart [:pick $comment 12 20]
|
|
:local exptMin [$timeint t=$exptStart]
|
|
:if (($expd < $today) or (($expd = $today) and ($exptMin < $curtime))) do={
|
|
/ip hotspot user set limit-uptime=1s $i
|
|
/ip hotspot active remove [find where user=$name]
|
|
:set expiredCount ($expiredCount + 1)
|
|
:log info ("Expired: " . $name . " (" . $profile . ")")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
:foreach profile in=$vouchProfiles do={
|
|
:foreach i in=[/ip hotspot user find where profile=$profile] do={
|
|
:local comment [/ip hotspot user get $i comment]
|
|
:local name [/ip hotspot user get $i name]
|
|
:if (([:pick $comment 3] = "/") and ([:pick $comment 6] = "/")) do={
|
|
:local expd [$dateint d=$comment]
|
|
:local exptStart [:pick $comment 12 20]
|
|
:local exptMin [$timeint t=$exptStart]
|
|
:if (($expd < $today) or (($expd = $today) and ($exptMin < $curtime))) do={
|
|
/ip hotspot user remove $i
|
|
/ip hotspot active remove [find where user=$name]
|
|
:set expiredCount ($expiredCount + 1)
|
|
:log info ("Voucher expired & removed: " . $name)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
:if ($expiredCount > 0) do={
|
|
:log info ("Monitor-expiry: " . $expiredCount . " user(s) expired")
|
|
}
|