Community discussions

 
ericmule
just joined
Topic Author
Posts: 10
Joined: Fri Mar 30, 2007 6:19 pm

Automatic Hotspot Binding

Mon Feb 24, 2014 6:44 pm

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?
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2411
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Automatic Hotspot Binding

Mon Feb 24, 2014 7:00 pm

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;
PEAR2_Net_RouterOS(1.0.0b6) - My API client in PHP
(Rate my posts? If you want... no pressure...)
 
ericmule
just joined
Topic Author
Posts: 10
Joined: Fri Mar 30, 2007 6:19 pm

Re: Automatic Hotspot Binding

Mon Feb 24, 2014 9:07 pm

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.
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2411
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Automatic Hotspot Binding

Tue Feb 25, 2014 1:32 pm

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?
PEAR2_Net_RouterOS(1.0.0b6) - My API client in PHP
(Rate my posts? If you want... no pressure...)
 
ericmule
just joined
Topic Author
Posts: 10
Joined: Fri Mar 30, 2007 6:19 pm

Re: Automatic Hotspot Binding

Tue Feb 25, 2014 4:32 pm

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
 
KennyPowers
Frequent Visitor
Frequent Visitor
Posts: 59
Joined: Tue May 05, 2015 6:18 pm

Re: Automatic Hotspot Binding

Sat May 09, 2015 3:19 pm

Hi,

How do I run these scripts I've been trying all morning with no joy running v6.15
 
KennyPowers
Frequent Visitor
Frequent Visitor
Posts: 59
Joined: Tue May 05, 2015 6:18 pm

Re: Automatic Hotspot Binding

Mon May 11, 2015 2:06 am

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";
 }
 
KennyPowers
Frequent Visitor
Frequent Visitor
Posts: 59
Joined: Tue May 05, 2015 6:18 pm

Re: Automatic Hotspot Binding

Wed May 13, 2015 1:35 am

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?

Who is online

Users browsing this forum: No registered users and 6 guests