Community discussions

MikroTik App
 
tvermoes
just joined
Topic Author
Posts: 10
Joined: Thu Mar 29, 2012 11:38 pm

Hotspot Send Email on Trial User login.

Thu Jul 04, 2013 9:23 pm

Wanted to get an Email when a new trial account logs in.
We only wanted Trial users to be able to login once (no reset).
Trial users is deleted when router reboots....WE DONT WANT THAT.

OBS : You need to get email sending working on your router before doing this.

Tested on ROS 6.1

Here is what i came up with :

1: Create a hotspot user profile for disabled trial users.
/ip hotspot user profile add add-mac-cookie=no idle-timeout=1s keepalive-timeout=1s name=getlost rate-limit=1k/1k session-timeout=1s status-autorefresh=60m transparent-proxy=yes
2: On Trilal user profile edit and add the following "On Login" script.
This will grab users ip and mac-address and send you an Email on login.
:local freeuser
:set freeuser "$user"
:local freeuserno [/ip hotspot active find where user=$freeuser];
:local freemac [/ip hotspot active get $freeuserno mac-address];
:local freeip [/ip hotspot active get $freeuserno address];
:local emailaddress "YOUREMAIL@YOURDOMAIN:COM"
:local date [/system clock get date]
:local time [/system clock get time]
:local emailsubject
:local emailbody
:set emailsubject "New Hotspot Login ($freeuser)"
:set emailbody "Trial: $freemac\r\n$time, $date\r\nIP: $freeip\r\n";
/tool e-mail send to="$emailaddress" subject="$emailsubject" body="$emailbody"
3: On Trilal user profile, add the following "On Logout" script.
This will delete the dynamic Trial user, and add a permanent user instead, to prevent more than 1 trial period.
And if somone manages to login anyway, they will get a very shitty connection :lol:
:local freeuser
:set freeuser "$user"
:local freeuserno [/ip hotspot user find where name=$freeuser];
:local freemac [/ip hotspot user get $freeuserno mac-address];
/ip hotspot user remove $freeuser
/ip hotspot user add name=$freeuser  password=disabled profile=getlost mac-address=$freemac
Just wanted to share :D
 
tvermoes
just joined
Topic Author
Posts: 10
Joined: Thu Mar 29, 2012 11:38 pm

Re: Hotspot Send Email on Trial User login.

Tue Jul 09, 2013 7:41 pm

Have made some changes :
1.Only Write to log when TrialUser First logon :
ON LOGON :
:local freeuser
:set freeuser "$user"
:local freeuserno [/ip hotspot active find where user=$freeuser];
:local freeip [/ip hotspot active get $freeuserno address];
:log info ($freeuser." TRIAL Login on IP :".$freeip)
2. On logout get stats, disable Trial account permanntly and send email
ON LOGOUT:
:local freeuser
:set freeuser "$user"
:local freeuserno [/ip hotspot user find where name=$freeuser];
:local freemac [/ip hotspot user get $freeuserno mac-address];
:local utime [/ip hotspot user get $freeuserno uptime];
:local byteup [/ip hotspot user get $freeuserno bytes-in];
:local bytedown [/ip hotspot user get $freeuserno bytes-out];
:local pckup [/ip hotspot user get $freeuserno packets-in];
:local pckdown [/ip hotspot user get $freeuserno packets-out];
:local dhleaseno [ip dhcp-server lease find where mac-address=$freemac]
:local freeip [ip dhcp-server lease get $dhleaseno active-address]
:local freehost [ip dhcp-server lease get $dhleaseno host-name]
:local emailaddress "YOUREMAIL@YOURDOMAIN.COM"
:local date [/system clock get date]
:local time [/system clock get time]
:local emailsubject
:local emailbody
:set emailsubject "New Hotspot Login ($freeuser)"
:set emailbody "Trial: $freemac\r\n$time, $date\r\nHostname : $freehost\r\nIP : $freeip\r\nUptime: $utime\r\nBytes Download : $bytedown\r\nBytes Upload : $byteup\r\nPackets Download : $pckdown\r\nPackets Upload : $pckup\r\n";
/tool e-mail send to="$emailaddress" subject="$emailsubject" body="$emailbody"
/ip hotspot user remove $freeuser
/ip hotspot user add name=$freeuser password=disabled profile=getlost server=server1 mac-address=$freemac limit-uptime=1s
 
User avatar
samir494
Member Candidate
Member Candidate
Posts: 236
Joined: Thu Aug 06, 2009 11:27 am
Location: India

Re: Hotspot Send Email on Trial User login.

Wed Jul 24, 2013 3:27 pm

hi,
thanks its very helpfull in my case

i need one more help from you,

i want to send mail to user only once when i create his userid in hotspot

like,

Dear <User_Name>
Your Account is created and Login Details are here as below

Your LogID= < Userid> and Paasword =<password>.



how can i do with script ?
 
tvermoes
just joined
Topic Author
Posts: 10
Joined: Thu Mar 29, 2012 11:38 pm

Re: Hotspot Send Email on Trial User login.

Thu Jul 25, 2013 7:36 pm

The easy way :-)

Allow signup in user-manager, and create new users via signup page :-)
 
User avatar
samir494
Member Candidate
Member Candidate
Posts: 236
Joined: Thu Aug 06, 2009 11:27 am
Location: India

Re: Hotspot Send Email on Trial User login.

Fri Jul 26, 2013 9:05 am

The easy way :-)

Allow signup in user-manager, and create new users via signup page :-)
i do it using script , not in userman
 
tvermoes
just joined
Topic Author
Posts: 10
Joined: Thu Mar 29, 2012 11:38 pm

Re: Hotspot Send Email on Trial User login.

Fri Jul 26, 2013 6:17 pm

If you create users by script running on the router, where do you get their email addresses from ?
I would use a php script for generating users, and sending them login/pass.
 
User avatar
samir494
Member Candidate
Member Candidate
Posts: 236
Joined: Thu Aug 06, 2009 11:27 am
Location: India

Re: Hotspot Send Email on Trial User login.

Mon Jul 29, 2013 7:32 am

If you create users by script running on the router, where do you get their email addresses from ?
I would use a php script for generating users, and sending them login/pass.
hi,
can you share your php let me check i think it useful to me
 
tvermoes
just joined
Topic Author
Posts: 10
Joined: Thu Mar 29, 2012 11:38 pm

Re: Hotspot Send Email on Trial User login.

Mon Jul 29, 2013 12:55 pm

Hi Samir
Sorry to say that i dont got a script for that, but it should be pretty easy to put together.

a function in php i use elsewhere for generating usernames and passwords :
function generate_random_string($name_length = 8) {
	$alpha_numeric = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
	return substr(str_shuffle($alpha_numeric), 0, $name_length);
}
and sending E-mail is allso pretty easy :
$to = "someone@example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse@example.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
And for communicating with ROS you can use :
http://wiki.mikrotik.com/wiki/API_PHP_class

I Hope this helps.
 
dolle
just joined
Posts: 1
Joined: Wed Feb 19, 2014 12:13 am

Re: Hotspot Send Email on Trial User login.

Wed Feb 19, 2014 12:23 am

Hello i dig this topic because I am interesting is it any of users has got this solution on his Mikrotik Hotspot. Actually i use only standard users login and passwords without limit.

When I was in city center I saw new wifi solution i you want to login for 15 minutes you just put on login space your email adress. Then you get access to network. If you want to use this wifi you need to have reply email and activate it then your username and password do not have time limit. I am thinking to myself is any mikrotik do that things?

Please answer for this question.

Good Night.

Who is online

Users browsing this forum: quanbau and 17 guests