I don't have a way to test "hotspot active user" values, hence why
the script I wrote uses the "hotspot user" values.
From what I can see "hotspot active user" has a "user" value with the username of the user. So making the script check that user and/or log out that user shouldn't be that hard.
Things I don't know is rather the "hotspot active user" byte values are for that one session or a total for that user.
For example if a user login, download 5 bytes, then logout and login again and then download another 7 bytes. what will each counter say?
My guess is that the "hotspot user" user will say 5 bytes and the "hotspot active user" will say 7 bytes. But I would like for you to possibly test this out for me.
Let me try to update this a little bit at least.
# Checks if limited users has reached the limit, if they have then set them to be limited slow state.
# Run this script every few minutes.
/ip hotspot user {
# Variables:
:local limitedProfile "Limited"
:local limitedSlowProfile "LimitedSlow"
:local trafLimit 10000
# Code:
:local userList [find profile=$limitedProfile]
:foreach user in=$userList do={
:local traf ([get $user bytes-in] + [get $user bytes-out])
:local activeUser [/ip hotspot active find user=[/ip hotspot user get $user name]]
:if ([:len $activeUser] != 0) do={
:set traf ($traf + [/ip hotspot active get $activeUser bytes-in] + [/ip hotspot active get $activeUser bytes-out])
}
:put ("User (" . [get $user name] . ") traf: " . $traf)
:if ($traf > $trafLimit) do={
set $user profile=$limitedSlowProfile
:put ("User (" . [get $user name] . ") reached the traf limit")
:if ([:len $activeUser] != 0) do={
/ip hotspot active remove $activeUser
:put ("User (" . [get $user name] . ") has been forcefully logged out")
}
:log warning ("User (" . [get $user name] . ") reached the traf limit")
}
}
}
# Reset counts are the limited users.
# Run this script once every day.
/ip hotspot user {
# Variables:
:local limitedProfile "Limited"
:local limitedSlowProfile "LimitedSlow"
# Code:
:foreach user in=[find (profile=$limitedProfile || profile=$limitedSlowProfile)] do={
/ip hotspot active remove [/ip hotspot active find user=[/ip hotspot user get $user name]]
}
reset-counters [find (profile=$limitedProfile || profile=$limitedSlowProfile)]
set [find profile=$limitedSlowProfile] profile=$limitedProfile
:log warning "All user limits has been reset"
}
This may work better, it is untested on a live system though.