Hotspot on-login script to add static routes

Hi,
We are looking at a way to add static routes for each hotspot user that logs in to the system.
Teting on MT Ver. 5.25+ / 6.4

By default the user gets a private ip address assigned by the DHCP (running on MT).
Once the user authenticates a new static route is added from the public ip pool as defined in the
hotspot user profile.

The current script which works about 90% of the time is as follows:

hotspot on-login script


[/ip hotspot host remove [find DHCP=yes]]

:local who $user;
:local macaddr [/ip hotspot active get [find user=$who] mac-address];
:local fromaddr [/ip hotspot host get [find mac-address=$macaddr] address];
:local toaddr [/ip hotspot host get [find mac-address=$macaddr] to-address];

:log info (“IP :”.$fromaddr." - TO-IP “.$macaddr.” To Addr ".$toaddr);
[/ip route add distance=2 dst-address=$address gateway=$fromaddr comment=$who]


hotspot on-logout script


:local who $user;
[/ip route remove [find comment=$who] ]


The problem that we face is if we need to give some users “Shared User” / “Simultaneous use” access,
multiple logins from the same userid.
First login of the userid works but the second login, logs - in to the system but wont get the route installed or
will just not work.

Any help would be appreciated.

regards
RB

I don’t know if this will solve the problem, but it should take care of the “shared user” route problem. Instead of using only the username as the comment, use something like the combination of the username+MAC. That way, when one of the “shared users” logs out, they are only removing the route that is specific to them.