Community discussions

MikroTik App
 
sammond
just joined
Topic Author
Posts: 8
Joined: Mon Mar 16, 2015 4:56 am

Custom hotspot scripting, assistance resolving a bug in the system

Thu Mar 10, 2016 2:59 am

We have a customised hotspot system running on a Mikrotik RB433AH with latest routerOS version.

Reaching out to anyone who has experience in customised hotspot scripting. Free advice is always welcome, however we are willing to book some paid time with any consultants who specialise in this area if they know how to resolve our issues.

The story so far:

We are finding that devices are being marked as overquota when in fact they are not overquota or they haven't been used at all. Additionally, I believe the script that is supposed to clear all user sessions daily is not removing the overquota users and therefore the following day they are still being reported as overquota.

The first script hotspot-user-clear is scheduled for 5am daily and is intended to clear all user sessions so the same devices can log in with a new data allowance every 24 hours:
:foreach counter in=[/ip hotspot user find ] do={/ip hotspot user remove $counter}
The second script hotspot-user-check is scheduled to run every 5 minutes and is intended to check each user's quota and mark them as overquota if they have used over 1GB:
#Download limit in MB
:local downquotamb 1000
 
### Do not modify anything below this line ###
:local downquota ($downquotamb * 1000 * 1000)
:local counter
:local datadown
:local username
:local macaddress
:foreach counter in=[/ip hotspot active find ] do={
:set datadown [/ip hotspot active get $counter bytes-out]
:if ($datadown>$downquota) do={
:set username [/ip hotspot active get $counter user]
:set macaddress [/ip hotspot active get $counter mac-address]
/ip hotspot user remove [/ip hotspot user find where name=$username]
 
:if ( $username="T-$macaddress") do={
/ip hotspot user add name=$username limit-bytes-out=$downquota mac-address=$macaddress
/ip hotspot active remove $counter
}
 
:log info "Logged out $username - Reached download quota"
}}
According to daily usage reports, it appears that users who have used less than 1GB are still being marked as overquota. This is an example of one such report, you can see at the bottom some users have 0/0 usage and others have smaller data amounts than 1GB:
Usage report start 
===== 
Live users: 
 User: T-4C:B1:99:2C:70:FB - 14/43 (MB UP/DOWN) / (Limit MB UP/Down) 
User: T-64:BC:0C:9D:FC:C6 - 10/146 (MB UP/DOWN) / (Limit MB UP/Down) 
User: T-5C:F5:DA:E2:DD:3F - 7/170 (MB UP/DOWN) / (Limit MB UP/Down) 
User: T-80:E6:50:4B:49:2C - 84/9 (MB UP/DOWN) / (Limit MB UP/Down) 
User: T-04:46:65:5A:D0:10 - 1/8 (MB UP/DOWN) / (Limit MB UP/Down) 
User: T-90:B9:31:84:FE:4C - 148/929 (MB UP/DOWN) / (Limit MB UP/Down) 
===== 
Overquota Users:  User: default-trial - 13545/57333 (MB UP/DOWN) / (Limit MB UP/Down) 
User: T-AC:29:3A:26:A6:C7 - 137/956 (MB UP/DOWN) /953 (Limit MB UP/Down) 
User: T-64:76:BA:A6:FE:64 - 34/989 (MB UP/DOWN) /953 (Limit MB UP/Down) 
User: T-80:EA:96:B7:FB:8B - 65/968 (MB UP/DOWN) /953 (Limit MB UP/Down) 
User: T-04:0C:CE:E3:35:4C - 13/954 (MB UP/DOWN) /953 (Limit MB UP/Down) 
User: T-6C:40:08:B8:35:6E - 41/1018 (MB UP/DOWN) /953 (Limit MB UP/Down) 
User: T-04:15:52:92:2F:13 - 32/1034 (MB UP/DOWN) /953 (Limit MB UP/Down) 
User: T-68:9C:70:20:1F:CC - 30/1011 (MB UP/DOWN) /953 (Limit MB UP/Down) 
User: T-A4:C3:61:26:33:AF - 33/987 (MB UP/DOWN) /953 (Limit MB UP/Down) 
User: T-70:3E:AC:2B:E2:B2 - 13/215 (MB UP/DOWN) / (Limit MB UP/Down) 
User: T-90:B9:31:D2:6E:19 - 1/12 (MB UP/DOWN) / (Limit MB UP/Down) 
User: T-04:46:65:5A:D0:10 - 0/0 (MB UP/DOWN) / (Limit MB UP/Down) 
User: T-90:B9:31:84:FE:4C - 0/0 (MB UP/DOWN) / (Limit MB UP/Down) 
User: T-80:E6:50:4B:49:2C - 0/0 (MB UP/DOWN) / (Limit MB UP/Down) 
User: T-5C:F5:DA:E2:DD:3F - 0/0 (MB UP/DOWN) / (Limit MB UP/Down) 
User: T-4C:B1:99:2C:70:FB - 0/0 (MB UP/DOWN) / (Limit MB UP/Down) 
User: T-64:BC:0C:9D:FC:C6 - 0/0 (MB UP/DOWN) / (Limit MB UP/Down) 
===== 
End of message
It is my understanding, that when the hotspot-user-clear script runs, it should remove all user entries from this list, ready for a new day. However, I ran the script manually this morning and the users remained in this list:

Image
 
User avatar
Sinan
Trainer
Trainer
Posts: 129
Joined: Tue Sep 01, 2015 7:00 am

Re: Custom hotspot scripting, assistance resolving a bug in the system

Fri Mar 11, 2016 6:18 am

The first problem is because there is a "default-trial" user which can't be removed or changed , so when you are trying to remove all users , an error will happen , to solve that use this to remove all the users:
/ip hotspot user remove [find name!=default-trial]
 
User avatar
Sinan
Trainer
Trainer
Posts: 129
Joined: Tue Sep 01, 2015 7:00 am

Re: Custom hotspot scripting, assistance resolving a bug in the system

Fri Mar 11, 2016 6:30 am

For the 2nd problem i think just limiting the bytes-out in the default-trial user and choosing a suitable profile will solve the problem ....

Who is online

Users browsing this forum: No registered users and 29 guests