Page 1 of 1

Automatic Hotspot Binding

Posted: Mon Feb 24, 2014 6:44 pm
by ericmule
The login script below works like a champ. However, it creates a binding for every "active" user instead of the single user logging in.
:foreach users in=[/ip hotspot active find] do={
:local date [ /system clock get date ];
:local ip [/ip hotspot active get $users address];
:local mac [/ip hotspot active get $users mac-address];
:local username [/ip hotspot active get $users user];
/ip hotspot ip-binding add type=bypassed mac-address=$mac address=0.0.0.0 comment=$date;
}
I simply want a user to login with a special login/password that will automatically get a binding. The script above creates a binding for everyone who is active, not just the single user.

Any ideas?

Re: Automatic Hotspot Binding

Posted: Mon Feb 24, 2014 7:00 pm
by boen_robot
Redefine the script as an "on-login" script for the user's profile (if it's not already one), and use the $user variable within that script to get the username that logged on.

i.e.

ros code

:local date [ /system clock get date ];
:local ip [/ip hotspot active get $user address];
:local mac [/ip hotspot active get $user mac-address];
/ip hotspot ip-binding add type=bypassed mac-address=$mac address=0.0.0.0 comment=$date;

Re: Automatic Hotspot Binding

Posted: Mon Feb 24, 2014 9:07 pm
by ericmule
Excuse my ignorance. I'm not a programmer. The code I listed above is part of the "on-login script". I tried the code you provided and it failed to create a binding. Can you provide the entire script needed for this?

FYI, I currently have only two users configured for hotspot. One user is "hotspot" with default profile. The other user is "hotspot" with a separate profile which included the log-in script.

Thank you for your help.

Re: Automatic Hotspot Binding

Posted: Tue Feb 25, 2014 1:32 pm
by boen_robot
That should be all of it.

Assuming your extra user profile is called "profile1", all you need to do to set this script should be to execute the following one time from terminal:

ros code

/ip hotspot user profile set "profile1" on-login=":local date [ /system clock get date ];\n:local ip [/ip hotspot active get \$user address];\n:local mac [/ip hotspot active get \$user mac-address];\n/ip hotspot ip-binding add type=bypassed mac-address=\$mac address=0.0.0.0 comment=\$date;\n"
See this page from the manual. BTW, what RouterOS version are you using?

Re: Automatic Hotspot Binding

Posted: Tue Feb 25, 2014 4:32 pm
by ericmule
Cannot get the script to work. It does authenticate the user, however the binding doesn't get created. Log shows "bypass (10.5.50.145): logged out: host removed: administrator request"

RB750 SW 6.5

Re: Automatic Hotspot Binding

Posted: Sat May 09, 2015 3:19 pm
by KennyPowers
Hi,

How do I run these scripts I've been trying all morning with no joy running v6.15

Re: Automatic Hotspot Binding

Posted: Mon May 11, 2015 2:06 am
by KennyPowers
Here is what worked for me, just copy and past into user profile, script - on login
 :local date [ /system clock get date ];
 if ($user = "vip" ) do={ :local mac [/ip hotspot active get [find where user=$user] mac-address]
 :local host [/ip dhcp-server lease get [find where mac-address=$mac] host-name]
/ip hotspot ip-binding add type=bypassed mac-address=$mac address=0.0.0.0 comment="$host - $date";
 }

Re: Automatic Hotspot Binding

Posted: Wed May 13, 2015 1:35 am
by KennyPowers
Here is what worked for me, just copy and past into user profile, script - on login
 :local date [ /system clock get date ];
 if ($user = "vip" ) do={ :local mac [/ip hotspot active get [find where user=$user] mac-address]
 :local host [/ip dhcp-server lease get [find where mac-address=$mac] host-name]
/ip hotspot ip-binding add type=bypassed mac-address=$mac address=0.0.0.0 comment="$host - $date";
 }

OK so it turns out this doesn't work if there is more than 1 user logged in, anyone know what I need to add to make it go through all users and only add usernames with vip?