Hotspot - Data Limit for Trial Users

ScreenHunter_06 Oct. 16 13.37.jpg
ScreenHunter_07 Oct. 16 13.40.jpg
ScreenHunter_08 Oct. 16 14.25.jpg

copy and paste to New Terminal

first you can change to your own rate-limit

/ip hotspot user profile
add address-list=TRIAL incoming-packet-mark=no-mark insert-queue-before=first
mac-cookie-timeout=10m name=TRIAL on-login="/system script run [ find name
="# Turn Trial in Test User #" ]\r
\n\r
\n\r
\n\r
\n" outgoing-packet-mark=no-mark queue-type=hotspot-default rate-limit=
128k/256k session-timeout=15s
add incoming-packet-mark=no-mark insert-queue-before=
first mac-cookie-timeout=1d name=TEST outgoing-packet-mark=no-mark
queue-type=hotspot-default rate-limit=40k/80k session-timeout=1d

\

copy and paste to New Terminal

/system script
add comment="# Turn Trial in Test User #" name="# Turn Trial in Test User #"
policy=
ftp,reboot,read,write,policy,test,password,sniff,sensitive source=" # Tur
n Trial in Test User with Data Limit #\r
\n# set your up and download Limit in Mib here #\r
\n:local in "25"\r
\n:local out "50"\r
\n# set max uptime days here #\r
\n:local days "1"\r
\n# set the user Password here # \r
\n:local password "12345678"\r
\n# do not edit the following #\r
\n:foreach user in=[ /ip hotspot active find ] do={\r
\n:local upload [($in10241024)];\r
\n:local download [($out10241024)];\r
\n:local up [($days*86400)];\r
\n:local pw [$password];\r
\n:local mac [ /ip hotspot active get $user mac-address ];\r
\n:local address [ /ip hotspot active get $user address ];\r
\n:local date [ /system clock get date ];\r
\n:local name [ /ip hotspot active get $user user ];\r
\n/ip dhcp-server lease make-static [ find dynamic=yes active-mac-address=
$mac ];\r
\n/ip dhcp-server lease set [ find dynamic=no mac-address=$mac ] use-src-
mac=yes client-id="1:$mac"\ \r
\nserver=dhcp1 always-broadcast=yes comment="$mac" ;\r
\n:if ( [ /ip hotspot user find name="$mac" ] = "" ) do={\r
\n/ip hotspot user add server=hotspot profile=TEST name="$mac" address=
$address mac-address=$mac\\r
\npassword=$pw limit-bytes-in=$upload limit-bytes-out=$download limit-u
ptime=$up comment="$date"\r
\n }\r
\n}"

\

copy and paste to New Terminal

/system scheduler
add comment="# Expire TEST #" interval=2h14s name="# Expire TEST #" on-event="
\r
\n{\r
\n:local offset 1\r
\n:global today\r
\n\r
\n{\r
\n:local date [ /system clock get date ]\r
\n:local montharray ( "jan","feb","mar","apr","may","jun","ju
l","aug","sep","oct","nov","dec" )\r
\n:local monthdays ( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 )\r
\n:local days [ :pick $date 4 6 ]\r
\n:local monthtxt [ :pick $date 0 3 ]\r
\n:local year [ :pick $date 7 11 ]\r
\n:local months ([ :find $montharray $monthtxt] )\r
\n:for nodays from=0 to=[:tonum $months] do={\r
\n:set days ( $days + [ :pick $monthdays $nodays ] )\r
\n}\r
\n:set days ($days + $year * 365) \r
\n:set today $days\r
\n}\r
\n\r
\n:foreach i in [ /ip hotspot user find where profile=TEST ] do={\r
\n:if ([ :find [ /ip hotspot user get $i comment ] ] = 0 ) do={\r
\n:local date [ /ip hotspot user get $i comment ]\r
\n:local montharray ( "jan","feb","mar","apr","may","jun","ju
l","aug","sep","oct","nov","dec" )\r
\n:local monthdays ( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 )\r
\n:local days [ :pick $date 4 6 ]\r
\n:local monthtxt [ :pick $date 0 3 ]\r
\n:local year [ :pick $date 7 11 ]\r
\n:local months ( [ :find $montharray $monthtxt ] )\r
\n:for nodays from=0 to=[:tonum $months] do={\r
\n:set days ( $days + [ :pick $monthdays $nodays ] )\r
\n}\r
\n:set days ($days + $year * 365)\r
\n:if ( ($days + $offset) < $today ) do={ \r
\n:local name [/ip hotspot user get $i name]\r
\n:log info "HOTSPOT EXPIRE SCRIPT: Removing Hotspot user $name first lo
gged in $date"\r
\n[ /ip hotspot user remove $i ]\r
\n[ /ip hotspot active remove [ find where user=$user ] ]\r
\n[ /ip dhcp-server lease remove [ find where comment=$name ] ]\r
\n}\r
\n}\r
\n}\r
\n}\r
\n" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive
start-time=startup

copy and paste to New Terminal

/system scheduler
add comment="Disable Hotspot User with reached Data Limit" interval=10m name=
"Disable Hotspot User with reached Data Limit" on-event="# Bytes in Limit
#\r
\n:foreach i in=[/ip hotspot user find profile=TEST] do={\r
\n:if ([/ip hotspot user get $i limit-bytes-in]<=[/ip hotspot user get $
i bytes-in]) do={\r
\n/ip hotspot user disable $i\r
\n }\r
\n}\r
\n# Bytes out Limit\r
\n:foreach i in=[/ip hotspot user find profile=TEST] do={\r
\n:if ([/ip hotspot user get $i limit-bytes-out]<=[/ip hotspot user get
$i bytes-out]) do={\r
\n/ip hotspot user disable $i\r
\n }\r
\n}" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive
start-time=startup

:sunglasses:

To inform your users what is their user name you must edit the html Login Page, after the reached trial-uptime-limit ( in my case is it 15 seconds)

the hotspot servlet goes back to the Login Page and Users can see their Mac inside the User Field, next is your Users must remove the T- in front of their mac-address and then adding the password which you must advertising on your html Login Page, my Trial Uptime Reset is setted to 10 min #

\

my editet html

Senha Padrão=12345678
Clique em PLANOS é ler
o MANUAL DO USOÁRIO como
ganhar 50 Megas de graça!