{
# author : niammuddin
# company : PT. Subnet data nusantara
# description : otomatis hapus session yang till-time 5 menit yang lalu / expired
# date : 23-07-2022
:local sdate
:local tillTime
:local convertTillTime
:local datenow [/system clock get date]
:local timenow ([/system clock get time] - [/system clock get gmt-offset ])
:local monthsDict {"jan"="01";"feb"="02";"mar"="03";"apr"="04";"may"="05";"jun"="06";"jul"="07";"aug"="08";"sep"="09";"oct"="10";"nov"="11";"dec"="12"};
:local dateTime ([:pick $datenow 7 11].($monthsDict->([:pick $datenow 0 3])).[:pick $datenow 4 6].[:pick $timenow 0 2].[:pick $timenow 3 5].[:pick $timenow 6 8])
# set dateTime (tanggal & jam saat ini) dikurangi (300 = 5 menit)
:set dateTime ($dateTime-300)
# cari session yang aktif
:foreach i in=[/tool user-manager session find where active=yes] do={
:set tillTime [/tool user-manager session get $i till-time]
# set session dateTime dari tillTime
:set sdate [:pick $tillTime 0 11]
# convert tillTime ke angka saja (untuk perbandingan waktu) tipe data boolean
:set convertTillTime ([:pick $sdate 7 11].($monthsDict->([:pick $sdate 0 3])).[:pick $sdate 4 6].[:pick $tillTime 12 14].[:pick $tillTime 15 17].[:pick $tillTime 18 20])
# jika dateTime-UTC saat ini yang sudah (dikurangi 5 menit) lebih besar dari Session till-time maka akan dihapus
:if ($dateTime > $convertTillTime) do={
/tool user-manager session remove numbers=$i;
:log error ("deleted ".[/tool user-manager session get $i user]);
}
}
}
By Niammuddin Mz
July 23, 2022
Userman Mikrotik: otomatis hapus session till-time 5 menit yang lalu / expired
Script otomatis hapus session till-time 5 menit yang lalu / expired