Hotspot Users
Shared Users Limit Check - Active Sessions — 7
When one account is logged in on several devices, each session is counted separately. This script adds up all active sessions per user and logs them out when the combined traffic passes your limit. Run it from the Scheduler.
RouterOS 7
/system script add name=CheckSharedUsersActive source={
# EN: Combined limit per user in BYTES, as a number (example: 2500000000 = about 2.5GB)
# AR: الحد الإجمالي لكل مستخدم بالبايت كرقم (مثال: 2500000000 = حوالي 2.5 جيجا)
:local totalLimit "change here";
:if ([:typeof $totalLimit] != "num") do={ :error "Set totalLimit first" }
# EN: Array of total bytes per user name | AR: مصفوفة مجموع البايتات لكل اسم مستخدم
:local totals [:toarray ""];
# EN: Add up bytes of every active session per user | AR: جمع بايتات كل جلسة نشطة لكل مستخدم
:foreach s in=[/ip hotspot active find] do={
:local name [/ip hotspot active get $s user];
:local used ([/ip hotspot active get $s bytes-in] + [/ip hotspot active get $s bytes-out]);
:if ([:typeof ($totals->$name)] = "nil") do={ :set ($totals->$name) 0 };
:set ($totals->$name) (($totals->$name) + $used);
}
# EN: Log out all sessions of users over the limit | AR: فصل كل جلسات المستخدمين الذين تجاوزوا الحد
:foreach name,total in=$totals do={
:if ($total > $totalLimit) do={
/ip hotspot active remove [/ip hotspot active find where user=$name];
:log info ("User $name exceeded the limit and was logged out");
}
}
}