Thursday, March 27, 2014

Mikrotik Hotspot Information Restrict Trial

Mikrotik's hotspot service is quite amazing considering what it costs. It does convey to a greater extent than or less limitations though. One of these is the fact that yous cannot ready a information bound to the case account, entirely a fourth dimension limit.

Luckily in that place are a few workarounds for this, the master concept for this comes from www.mikrotik-routeros.com but I convey corrected a twosome of bugs together with added to a greater extent than or less functionality.


Start past times creating your FreeUser profile:
IP>HOTSPOT>USER PROFILES>ADD

Name: FreeUser

You tin customize this every bit yous like, my preference is to entirely allocate 512k of bandwidth to the complimentary users



Create the next 2 scripts on your routerboard past times going to SYSTEM>SCRIPTS>ADD

Script 1:
The kickoff script is the 1 that checks if a user has reached your specified limit, yous tin alter the bound inwards the mo business of the script.

Name: limitdata

#Set your dowload bound inwards MegaBYTES!
:local downloadlimitmb "50"

### You volition non demand to edit anything below this business ###
:local downloadlimit  [($downloadlimitmb  * 1048576)]
:local counter
:local datadown
:local username
:local macaddress
:foreach counter in=[/ip hotspot active abide by where user "^[T][-].{17}"] do={
:set datadown [/ip hotspot active larn $counter bytes-out]
:if ($datadown>$downloadlimit) do={
:set username [/ip hotspot active larn $counter user]
:set macaddress [/ip hotspot active larn $counter mac-address]
/ip hotspot user take away [/ip hotspot user abide by where name=$username profile=FreeUser]
/ip hotspot user add together name=$username limit-bytes-out=$downloadlimit mac-address=$macaddress profile=FreeUser
/ip hotspot active take away $counter
:log information "Force logout on user: $username - Reached download quota"
}}

Script 2:
The mo script resets the counters of all complimentary users thus that they tin have a novel allocation.

Name: clearusers
:log information "Checking Users"
:local counter

:foreach counter in=[/ip hotspot user abide by profile="FreeUser" ] do={
/ip hotspot user take away $counter
}

You thus demand to add together 2 scheduled tasks nether SYSTEM>SCHEDULER:

The kickoff chore volition decide how frequently a specific mac address' usage is reset. I run it at midnight every day, which agency that inwards my illustration people tin utilization 50MB per twenty-four hr catamenia for free.
add together disabled=no interval=1d name=ClearUsers on-event=clearusers policy=\
    ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api \
    start-date=jan/01/2002 start-time=00:00:01

The mo chore volition decide how frequently the arrangement volition banking concern gibe if a user has reached the quota. I run it every 10 seconds, only on a busy routerboard yous may convey to ready this to a higher value:
add together disabled=no interval=10s name=DataLimit on-event=limitdata policy=\
    ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api \
    start-date=oct/07/2013 start-time=00:00:00

You should right away locomote able to convey users utilization the predefined case without needing a login. Just remeber to enable to case selection for your hotspot.