Hotspot Users

Shared Users Limit Check - Per-User Data Limit — 6

Reads each user’s own limit-bytes-total and logs out all of that user’s active sessions once the user’s total traffic reaches it. Nothing to edit - limits come from the users themselves.

MikroTik Version

RouterOS 6

/system script add name=CheckSharedUsersUserLimit source={
    # EN: Only users that have a data limit set | AR: فقط المستخدمون الذين لديهم حد بيانات
    :foreach u in=[/ip hotspot user find where limit-bytes-total>0] do={
        :local name [/ip hotspot user get $u name];
        :local limit [/ip hotspot user get $u limit-bytes-total];
        # EN: Total traffic of the user (all sessions) | AR: إجمالي استهلاك المستخدم (كل الجلسات)
        :local used ([/ip hotspot user get $u bytes-in] + [/ip hotspot user get $u bytes-out]);

        :if ($used >= $limit) do={
            :local sessions [/ip hotspot active find where user=$name];
            # EN: Log out every active session of this user | AR: فصل كل الجلسات النشطة لهذا المستخدم
            :if ([:len $sessions] > 0) do={
                /ip hotspot active remove $sessions;
                :log info ("User $name reached the data limit and was logged out");
            }
        }
    }
}