Community discussions

MikroTik App
 
onowojemma
Member Candidate
Member Candidate
Topic Author
Posts: 129
Joined: Sun Sep 11, 2005 5:27 pm
Location: Nigeria

Periodic username on hotspot

Sun Aug 23, 2009 8:14 am

Hi please i have been trying to configure my hotspot such that some user name could only be use at night time and be disable during the day say from 8am till 6pm and will be active from 6pm through the night till 7am in the morning
Thanks in advances for all your contribution and help.
 
eneimi
Member
Member
Posts: 387
Joined: Sun Sep 09, 2007 12:55 pm

Re: Periodic username on hotspot

Sun Aug 23, 2009 8:20 pm

You can use simple queue with time interval setting.
One rule with the 8am - 6pm restriction (1k/1k) and a second rule permitting normal browsing between 6pm and 7am.

However you can only apply the queue to a specific ip or subnet and not to a user; so if you use static IPs it's straightforward but if you use dhcp, then you will need to do ip binding in hotspot.

OR

Here's a wiki alternative based on scripting and scheduling.
http://wiki.mikrotik.com/wiki/Limit_Dif ... _and_Night
For 8am - 6pm you can limit-at 1k/1k.

Again, you can only apply it to ip addresses.
 
fewi
Forum Guru
Forum Guru
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Re: Periodic username on hotspot

Sun Aug 23, 2009 8:49 pm

Write a script that goes through the existing users and disables those that match a certain condition (for example, configure all users to be disabled on a schedule to have a certain string in their comment field). Have that script also remove the active sessions for those users. Write a second script that enables those accounts. Use the system scheduler to fire the scripts at the times you want them wih a 24 hour delay between runs.

HTH,
Felix
 
onowojemma
Member Candidate
Member Candidate
Topic Author
Posts: 129
Joined: Sun Sep 11, 2005 5:27 pm
Location: Nigeria

Re: Periodic username on hotspot

Mon Aug 24, 2009 10:20 am

All right now please can u help me with one because am not good in writing script. our if there is a material that explain that very well i will appreciate.
Thanks
 
fewi
Forum Guru
Forum Guru
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Re: Periodic username on hotspot

Mon Aug 24, 2009 5:52 pm

The below scripts assume that all users to be on a limited schedule to have a comment field exactly equal to "Schedule limited user":
/ip hotspot user set [/ip hotspot user find name=test] comment="Schedule limited user"
Script #1 disables all users that have such a comment, name it disableScheduleLimitedUsers:
# find all users that need to be disabled
:foreach user in=[/ip hotspot user find comment="Schedule limited user"] do={
# remove all active user sessions for that name
	:local name [/ip hotspot user get $user name];
	:foreach activeuser in=[/ip hotspot active find name=$name] do={
		/ip hotspot active remove $activeuser
	}
# set the user to disabled
	/ip hotspot user disable $user
}
Script #2 re-enables them, name it enableScheduleLimitedUsers:
# find all users that need to be enabled
:foreach user in=[/ip hotspot user find comment="Schedule limited user"] do={
# enable the user
	/ip hotspot user enable $user
}
Add two scheduled jobs, one running at 7am every day disabling all the users, another one running at 8pm every day enabling all the users:

/system scheduler add name=disableScheduleLimitedUsers on-event=disableScheduleLimitedUsers start-date=jan/01/2009 start-time=07:00:00 interval=24h
/system scheduler add name=enableScheduleLimitedUsers on-event=enableScheduleLimitedUsers start-date=jan/01/2009 start-time=20:00:00 interval=24h
That code compiles though I haven't had a chance to properly test it yet. Should get you going, though.

HTH,
Felix

Edit: Tested and works on 3.28
 
onowojemma
Member Candidate
Member Candidate
Topic Author
Posts: 129
Joined: Sun Sep 11, 2005 5:27 pm
Location: Nigeria

Re: Periodic username on hotspot

Mon Aug 24, 2009 9:54 pm

Thanks a lot am almost getting there, please i may still have to border you the names i want to disable were created with userman.
 
fewi
Forum Guru
Forum Guru
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Re: Periodic username on hotspot

Mon Aug 24, 2009 10:00 pm

If the Usermanager instance and the hotspot itself run on the same machine, adjusting the scripts like so:
# find all users that need to be disabled
:foreach user in=[/tool user-manager user find comment="Schedule limited user"] do={
# remove all active user sessions for that name
   :local name [/tool user-manager user get $user name];
   :foreach activeuser in=[/ip hotspot active find name=$name] do={
      /ip hotspot active remove $activeuser
   }
# set the user to disabled
   /tool user-manager user disable $user
}
# find all users that need to be enabled
:foreach user in=[/tool user-manager user find comment="Schedule limited user"] do={
# enable the user
   /tool user-manager user enable $user
}
might work. It will of course not work if the hotspot is on a different machine than the Usermanager. I can't test this scenario as I don't use Usermanager.

Hope it works,
Felix
 
onowojemma
Member Candidate
Member Candidate
Topic Author
Posts: 129
Joined: Sun Sep 11, 2005 5:27 pm
Location: Nigeria

Re: Periodic username on hotspot

Tue Aug 25, 2009 3:08 am

All work great thanks a million i use it with some other variable
code 1
# find all users that need to be disabled
:foreach user in=[/tool user-manager user find comment="night"] do={
# remove all active user sessions for that name
:local name [/tool user-manager user get $user name];
:foreach activeuser in=[/ip hotspot active find name=$name] do={
/ip hotspot active remove $activeuser
}
# set the user to disabled
/tool user-manager user disable $user
}

code 2

# find all users that need to be enabled
:foreach user in=[/tool user-manager user find group-name=night] do={
# enable the user
/tool user-manager user enable $user
}

i then create a profile for night users call night on /ip hotspot user profile add name=night
and from userman when createing the user on the group field i enter night
and every thing work well,i also see one could use some other variables that are there too.
once more thanks
 
fewi
Forum Guru
Forum Guru
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Re: Periodic username on hotspot

Tue Aug 25, 2009 3:11 am

Just to make sure:

You'll want to change
:foreach user in=[/tool user-manager user find comment="night"] do={
in the first script to
:foreach user in=[/tool user-manager user find group-name="night"] do={
like you did in the second script.

I'm glad it's working.

Felix
 
onowojemma
Member Candidate
Member Candidate
Topic Author
Posts: 129
Joined: Sun Sep 11, 2005 5:27 pm
Location: Nigeria

Re: Periodic username on hotspot

Tue Aug 25, 2009 4:07 am

Yea i did the second one but i also try with the first they bolt work fine and some other variable but i prefer group-name
were can i learn more about the user of those command like
code
:foreach user ,do={:local name,$user name, ;" what they mean and how to use them "
do={,

I hope am not asking too many questions
Regards Onowojemma.
 
fewi
Forum Guru
Forum Guru
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Re: Periodic username on hotspot

Tue Aug 25, 2009 5:44 am

The wiki has a section on scripting.
 
E51
just joined
Posts: 4
Joined: Sun Jul 01, 2007 12:42 am

Re: Periodic username on hotspot

Fri Jan 22, 2010 12:52 pm

Hello Fewi,

I just upgraded from v 2.9.27 to 4.5 and tried to use the script. They worked fine. Great Job.

Cheers!
 
User avatar
dunga
Member Candidate
Member Candidate
Posts: 254
Joined: Fri Jan 23, 2009 9:51 am
Location: Nigeria

Re: Periodic username on hotspot

Thu Feb 04, 2010 9:28 pm

Fewi,
You are extremely powerful as far as Miktotik is concerned. Will it be possible to have ur private mail add so dat i can PM you incase i run into some configurations issues.

How can i assign a server/mirotik that hass about 3 cafes, using about 10pcs each to share this bandwidth 98kbps/196kbps (Upload/Downlaod) so that all of my lan/hotspot users will share that bandwidth alone.

My plan is to make sure that other bandwidth from my ISP is shared where, tha above will be for those on the hotspot alone whilke others will be for other servers housing my office.
 
User avatar
JP_Wireless
Member Candidate
Member Candidate
Posts: 276
Joined: Thu Dec 13, 2007 4:31 pm
Location: Lagos Nigeria
Contact:

Re: Periodic username on hotspot

Sat Mar 06, 2010 8:12 pm

This script is great!

But can UM developer help us make it available in GUI form? for more flexibility like configuring some user to browse for a maximum of 2hours in a day and so on.

I need this but going by script is cumbersome as I have plenty script running already and very soon everything will be confusing and difficult to trouble shoot.

Thanks for your effort and time.
 
JJX
Frequent Visitor
Frequent Visitor
Posts: 84
Joined: Fri Nov 11, 2005 2:36 pm

Re: Periodic username on hotspot

Fri Apr 30, 2010 4:22 pm

This script is nice, but has a minor problem:
when it runs it will disconnect ALL users that are currently connected to hotspot and all users have to relogin.
Is possible to find a way that will remove only the matched users from the active list?!

Thank you
 
JJX
Frequent Visitor
Frequent Visitor
Posts: 84
Joined: Fri Nov 11, 2005 2:36 pm

Re: Periodic username on hotspot

Fri Apr 30, 2010 4:40 pm

# find all users that need to be disabled
:foreach user in=[/tool user-manager user find comment="Schedule limited user"] do={
# remove all active user sessions for that name
Re
   :foreach activeuser in=[/ip hotspot active find name=$name] do={
      /ip hotspot active remove $activeuser
   }
# set the user to disabled
   /tool user-manager user disable $user
}

replace the 5th line:
:foreach activeuser in=[/ip hotspot active find name=$user] do={

This will not disconnect all connected users , will disconnect only the users matched!
 
fewi
Forum Guru
Forum Guru
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Re: Periodic username on hotspot

Fri Apr 30, 2010 5:27 pm

I don't think that would work. $user is a reference to the actual user object and basically equals an id, not a name (a string).

I don't see how the original code logs out all connected users. It first finds all user objects that have a specific comment set, then gets the name of that user object, and then logs off all active sessions logged in under that name.
 
JJX
Frequent Visitor
Frequent Visitor
Posts: 84
Joined: Fri Nov 11, 2005 2:36 pm

Re: Periodic username on hotspot

Fri Apr 30, 2010 10:07 pm

2nd line: :foreach user : $user list include all users id with the specific comment,isnt it?
5th line , name=$name : this actually match all users, correct?

I have checked my script three times, and always worked disconnecting only the correct client and disabling the correct usernames! :/

Is there a way to match users according to their name, and based on a pattern or regular expression?
Mikrotik has released a manual explaining all this macros?
 
dssmiktik
Forum Veteran
Forum Veteran
Posts: 732
Joined: Fri Aug 17, 2007 8:42 am

Re: Periodic username on hotspot

Sat May 01, 2010 1:16 am

Is there a way to match users according to their name, and based on a pattern or regular expression?
You could do this a couple ways.

1 - You could include the names in the script itself:
:local users "user1,user2,user3"

/ip hotspot active {
   :foreach item in=[find] do={
      :foreach u in=[:toarray $users] do={
         :if ([get $item user] = [:tostr $u]) do={
#         user name found, perform action here
            :put ("Found active user: " . [get $item user])
         }
      }
   }
# /ip hotspot active
}
2 - Search for name using regular expression (version >= 3.23):
:local userregex "<user regex string>"

/ip hotspot active {
   :foreach item in=[find] do={
      :if ([get $item user] ~ [:tostr $userregex]) do={
#      user name found, perform action here
         :put ("Found active user: " . [get $item user])
      }
   }
# /ip hotspot active
}
A great article about regular expression syntax can be found here: http://en.wikipedia.org/wiki/Regular_ex ... Unix.5D.29
 
JJX
Frequent Visitor
Frequent Visitor
Posts: 84
Joined: Fri Nov 11, 2005 2:36 pm

Re: Periodic username on hotspot

Sat May 01, 2010 4:16 pm

I am not searching a tutorial for regex but for mikrotik scripting language! (I dont know how they named it)

thx
 
dssmiktik
Forum Veteran
Forum Veteran
Posts: 732
Joined: Fri Aug 17, 2007 8:42 am

Re: Periodic username on hotspot

Sun May 02, 2010 12:30 am

I am not searching a tutorial for regex but for mikrotik scripting language! (I dont know how they named it)

thx
A simple google search for Mikrotik scripting revealed this site: http://wiki.mikrotik.com/wiki/Manual:Scripting
You can easily find things by searching for them.
 
trevorlc1234
just joined
Posts: 19
Joined: Tue May 25, 2010 8:46 am

Re: Periodic username on hotspot

Tue May 25, 2010 9:09 am

I've stumbled upon this script as I am looking for a way to remove all active users currently on the hotspot, if a certain condition occurs.
What I have setup is a custom login.html for my hotspot login page, inside the html is:

<center><img src='http://www.website.com/images/cleardot.gif' onerror="this.src='/images/systemdown.jpg'" / align="middle"></center>

What this does, is when a user logs into the hotspot, if the internet is up, it will be able to load a 1x1 pixal gif of nothingness on the login.html hotspot login page. This nothingness gif is located on a reliable webserver and is always available. So the user will see nothing,

However if the internet is down, it will load a systemdown.jpg, that is stored locally on the router. This systemdown.jpg, just states on it that if you see this message the internet is down and we are currently working on the problem to resolve it.

Now this works great except that currently logged in users, or users with cookies that are active will not ever see the login page again when the internet goes down.

What I wanted to do was use the Netwatch feature, to monitor say http://www.google.ca and ping it, if it fails at pinging google more then 5 times, it will then execute a command to remove all active users and cookies on the router, thus forcing the users back to the main login page, in which they will see the network outtage notice.

I'm not the best at writing scripts, I was wondering if anyone had any ideas how this could be implemented
Basically it would be as such
-----------------------------
1.Every 5 seconds ping http://www.google.com, if it is respond do nothing
2. If ping fails 5 times,
3. remove all active users and their cookies on the router forcing them to have to log in again and thus see the network outage page.

I know with my current knowledge it would take me forever to try and write something like this, but from what I've seem in this thread it seems possible. Any help would be awesome.

EDIT: NVM I've figured it out. http://forum.mikrotik.com/viewtopic.php ... 80#p210880
for anyone else that is interested.

Who is online

Users browsing this forum: almdandi, gianricci, NetworqAndy, patrikg, sinaaram and 78 guests