Mikrotik Active User Hotspot In A Day

แก้ไขค่า Comment ให้ตรงค่าของเรา นะครับ

Please edit comment mikrotik user match you comment.

{
# Calculates day of the week for a givien date
# Month: jan,feb … nov,dec (must be lower-case)
# Day: 1 – 31
# Year: 1900 – 2999
# mmm/dd/yyyy same format as [/system clock get date]
# (ex. jul/22/2009)

:local date [/system clock get date]

# Math Calculation here
:local result “”
:local months [:toarray “jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec”]
:local monthtbl [:toarray “0,3,3,6,1,4,6,2,5,0,3,5”]
:local daytbl [:toarray “sun,mon,tue,wed,thu,fri,sat”]

:local month [:pick $date 0 3]
:local day [:pick $date 4 6]
:local dayc [:pick $date 5 6]
:local century [:pick $date 7 9]
:local year [:pick $date 9 11]
:local yearc [:pick $date 10 11]

# if the first char is a 0 (zero) only read last char, else script fails
:if ([:pick $date 4 5] = 0) do={ :set day ($dayc)}
:if ([:pick $date 9 10] = 0) do=[:set year ($yearc)]

:local sum 0
:set sum ($sum + (2 * (3 – ($century – (($century / 4) * 4)))))
:set sum ($sum + ($year / 4))
:set sum ($sum + $year + $day)
:for mindex from=0 to=[:len $months] do={
:if ([:pick $months $mindex] = $month) do={:set sum ($sum + [:pick $monthtbl $mindex]) }
}
:set sum ($sum – (($sum / 7) * 7))
:set result [:pick $daytbl $sum]

# END Math Calculation

:put ([:pick $date 0 3] . “/” . [:pick $date 4 6] . “/” . [:pick $date 7 9] . [:pick $date 9 11] . ” is on a ” . $result)
#:log info ([:pick $date 0 3] . “/” . [:pick $date 4 6] . “/” . [:pick $date 7 9] . [:pick $date 9 11] . ” is on a ” . $result)

:if ($result = “mon”) do={/ip hotspot user set disable=no [find comment=Monday]} else= {/ip hotspot user set disable=yes [find comment=Monday]}
:if ($result = “tue”) do={/ip hotspot user set disable=no [find comment=Tuesday]} else= {/ip hotspot user set disable=yes [find comment=Tuesday]}
:if ($result = “wed”) do={/ip hotspot user set disable=no [find comment=Wednesday]} else= {/ip hotspot user set disable=yes [find comment=Wednesday]}
:if ($result = “thu”) do={/ip hotspot user set disable=no [find comment=Thursday]} else= {/ip hotspot user set disable=yes [find comment=Thursday]}
:if ($result = “fri”) do={/ip hotspot user set disable=no [find comment=Friday]} else= {/ip hotspot user set disable=yes [find comment=Friday]}
:if ($result = “sat”) do={/ip hotspot user set disable=no [find comment=Saturday]} else= {/ip hotspot user set disable=yes [find comment=Saturday]}
:if ($result = “sun”) do={/ip hotspot user set disable=no [find comment=Sunday]} else= {/ip hotspot user set disable=yes [find comment=Sunday]}
}

Leave a comment