Community discussions

MikroTik App
 
User avatar
techguy79
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 66
Joined: Tue Mar 24, 2009 10:34 pm
Contact:

script to change hotspot user password fails to work

Wed Oct 21, 2009 8:59 pm

we have a few mikrotiks deployed at hotels with hotspot setup
on those units we have the following script.
this is copied from a mikrotik where the script is in fact working.


:set date [/system clock get date]
:set month [:pick $date 0 3]
:set day[:pick $date 4 6]
:set year[:pick $date 7 11]
:if ($month = jan) do={
/ip hotspot user set user1 password="CASS01";
/sy sche set HotspotCodeChange start-date=("feb/01/" . $year);}
:if ($month = feb) do={
/ip hotspot user set user1 password="CASS02";
/sy sche set HotspotCodeChange start-date=("mar/01/" . $year);}
:if ($month = mar) do={
/ip hotspot user set user1 password="CASS03";
/sy sche set HotspotCodeChange start-date=("apr/01/" . $year);}
:if ($month = apr) do={
/ip hotspot user set user1 password="CASS04";
/sy sche set HotspotCodeChange start-date=("may/01/" . $year);}
:if ($month = may) do={
/ip hotspot user set user1 password="CASS05";
/sy sche set HotspotCodeChange start-date=("jun/01/" . $year);}
:if ($month = jun) do={
/ip hotspot user set user1 password="CASS06";
/sy sche set HotspotCodeChange start-date=("jul/01/" . $year);}
:if ($month = jul) do={
/ip hotspot user set user1 password="CASS07";
/sy sche set HotspotCodeChange start-date=("aug/01/" . $year);}
:if ($month = aug) do={
/ip hotspot user set user1 password="CASS08";
/sy sche set HotspotCodeChange start-date=("sep/01/" . $year);}
:if ($month = sep) do={
/ip hotspot user set user1 password="CASS09";
/sy sche set HotspotCodeChange start-date=("oct/01/" . $year);}
:if ($month = oct) do={
/ip hotspot user set user1 password="CASS10";
/sy sche set HotspotCodeChange start-date=("nov/01/" . $year);}
:if ($month = nov) do={
/ip hotspot user set user1 password="CASS11";
/sy sche set HotspotCodeChange start-date=("dec/01/" . $year);}
:if ($month = dec) do={
/ip hotspot user set user1 password="CASS12";
:set year ($year + 1);
/sy sche set HotspotCodeChange start-date=("jan/01/" . $year);}

below is the scheduler script

/sy script run HotspotCodeChanger

this all works fine on currently deployed mikrotiks using ros versions pre v3
im trying to setup a new mikrotik for an existing hotel customer requesting this kind of functionality to eliminate people from leeching the bandwidth.

I have everything setup properly i copied the above scripts and only modified what the password should be changed to every month.

When i manually run the script then gointo ip>>hotspot>>user the password field remains empty
if i open new terminal and type /ip hotspot user set user1 password="CASS09"; then go back into ip>>hotspot>>user there is indeed a password now assigned to user1 this script works in pre v3 ros why isn't it changing the password in this newer mikrotik running ros 3.22 hardware on this newer router is rb433 not that it should matter.

My thinking is even if there were an issue with the scheduler component when i manually run the script it should create the password for user1 I know its not because when i run this script on the newer mikrotik then check ip>>hotspot>user then double click on user1 the password field remains blank, whereas on the working mikrotiks you can see the user1 password and know its working.

I ask the mikrotik community to please help me out.
In my mind this seems to be an issue with coding changes between the various ros versions.
since the same script works fine in mikrotiks running ros v2.9.46 and lower.
 
fewi
Forum Guru
Forum Guru
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Re: script to change hotspot user password fails to work

Wed Oct 21, 2009 10:21 pm

Without testing in detail, try this - at least the syntax is correct:
:local date [/system clock get date]
:local month [:pick $date 0 3]
:local day [:pick $date 4 6]
:local year [:pick $date 7 11]
:if ($month = "jan") do={
/ip hotspot user set user1 password="CASS01";
/sy sche set HotspotCodeChange start-date=("feb/01/" . $year);}
:if ($month = "feb") do={
/ip hotspot user set user1 password="CASS02";
/sy sche set HotspotCodeChange start-date=("mar/01/" . $year);}
:if ($month = "mar") do={
/ip hotspot user set user1 password="CASS03";
/sy sche set HotspotCodeChange start-date=("apr/01/" . $year);}
:if ($month = "apr") do={
/ip hotspot user set user1 password="CASS04";
/sy sche set HotspotCodeChange start-date=("may/01/" . $year);}
:if ($month = "may") do={
/ip hotspot user set user1 password="CASS05";
/sy sche set HotspotCodeChange start-date=("jun/01/" . $year);}
:if ($month = "jun") do={
/ip hotspot user set user1 password="CASS06";
/sy sche set HotspotCodeChange start-date=("jul/01/" . $year);}
:if ($month = "jul") do={
/ip hotspot user set user1 password="CASS07";
/sy sche set HotspotCodeChange start-date=("aug/01/" . $year);}
:if ($month = "aug") do={
/ip hotspot user set user1 password="CASS08";
/sy sche set HotspotCodeChange start-date=("sep/01/" . $year);}
:if ($month = "sep") do={
/ip hotspot user set user1 password="CASS09";
/sy sche set HotspotCodeChange start-date=("oct/01/" . $year);}
:if ($month = "oct") do={
/ip hotspot user set user1 password="CASS10";
/sy sche set HotspotCodeChange start-date=("nov/01/" . $year);}
:if ($month = "nov") do={
/ip hotspot user set user1 password="CASS11";
/sy sche set HotspotCodeChange start-date=("dec/01/" . $year);}
:if ($month = "dec") do={
/ip hotspot user set user1 password="CASS12";
:set year ($year + 1);
/sy sche set HotspotCodeChange start-date=("jan/01/" . $year);}
 
User avatar
techguy79
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 66
Joined: Tue Mar 24, 2009 10:34 pm
Contact:

Re: script to change hotspot user password fails to work

Thu Oct 22, 2009 4:09 pm

fewi thanks alot this seems to work for me other then syntax i noticed theres a local declaration which i didn't have initially.
My question to you is on the other deployed mikrotiks we are using the script the way it was and the script works w/o the
:local line of script I'm wondering why it worked at all before.

On a sidenote now that i have the user password change functioning I'm looking at editing the html login page.
Heres my question looking over the html it appears the value of the password text field is hardcoded to "password"
this is fine when you leave user1's password set to password but what about when using an password that changes monthly?
I know you guys (mikrotik community) feel you should understand html when editing html i agree and am quite good with html however javascript isn't my strong point and i'd love to understand how the forms work , where does the inputted data go ?
I'd love to build a nice looking login.html however im afraid to make changes to any of the forms as this could break functionality.

I DON'T want someone to do the work for me in fact I'm hoping someone can break down how the forms work , if i understand that i dont need to worry about breaking functionality.
 
fewi
Forum Guru
Forum Guru
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Re: script to change hotspot user password fails to work

Thu Oct 22, 2009 6:05 pm

I don't know when they introduced the ":local" and ":global" keywords, I'm afraid. I used inherited 2.x systems about 4 years ago until we replaced them all, but never did scripting on them. Your problem was essentially that you were trying to set undeclared variables. ":local" declares variables of local scope, ":global" declares variables of global scope.

The form variables used in login.html are outlined in the manual: http://www.mikrotik.com/testdocs/ros/2. ... hp#7.41.15. The Wiki unfortunately doesn't contain any HTTP customization information.

As you can see, login.html takes several parameters, one called 'username' and one called 'password'. You are free to hard code either one of them. If the password is hardcoded, your scheduled script of course will not work, much like you noted. If you're hardcoding the password, I'm assuming you want the user to only provide one credential, not two (username AND password). To make that happen simply hardcode the username as 'user1' and set the form input type for that parameter to 'hidden', and have the user provide the password only. Even a hidden form input type will be submitted to /login, 'user1' will always match and access will then be granted if the user provided the correct password for the month.

Hope that helps.
 
User avatar
techguy79
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 66
Joined: Tue Mar 24, 2009 10:34 pm
Contact:

Re: script to change hotspot user password fails to work

Thu Oct 22, 2009 6:43 pm

fewi
thanks again you've been most helpful. but I'm still left wondering where does the password go when they submit it?

How does typing the monthly password in the box then submitting using the button actually interface with the mikrotik and check to see if the password is right?

Is this the responsiblity of the chap challenge code or what?

I'm trying to wrap my head around how i would go about cleaning up the code and customizing my page without breaking the functionality.

i have a friend that is a web developer and he explained to me how it works when the username and password values are hardcoded and i get that.

However with the password changing and never being hardcoded in the html how does the form submit the user input (password) and match that value with the value of the password field in ip>>hotspot>>users password field?

I'm sorry if these questions have been asked before but I want to understand the whole thing so i can customize our hotspot pages from scratch if needed in the future.

I read over the link you provided and that does appear to be the most useful info i've found so far on the inner workings.
 
fewi
Forum Guru
Forum Guru
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Re: script to change hotspot user password fails to work

Thu Oct 22, 2009 7:25 pm

I'm not sure I fully understand the question - but when you fill out the form in login.html and hit the submit button, it submits to '/login', which is a "magic" URL in the RouterOS filesystem that interprets several parameters passed on to it, among them 'username' and 'password'. This can be a straight username and password (HTTP PAP), a scrambled username and password (HTTP CHAP), or other variants.

Upon submission it checks those credentials against local users, and then RADIUS users if configured to do so. If it finds matching credentials the user is authenticated. If it does not, it redirects the user back to the authentication screens along with an error message that the user credentials could not be found.
 
User avatar
techguy79
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 66
Joined: Tue Mar 24, 2009 10:34 pm
Contact:

Re: script to change hotspot user password fails to work

Thu Oct 22, 2009 7:36 pm

ok im copying my code below when i try testing the hotspot i am getting invalid username or password error.
I can't log in i think it has to do with the value for password being set to password, i could set it to the current password for user1 but that would mean every month i'd have to hardcode the password value to the current monthly password.
am i missing something here?


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>mikrotik hotspot > login</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="expires" content="-1" />
<style type="text/css">
body {color: #737373; font-size: 10px; font-family: verdana;}

textarea,input,select {
background-color: #FFFFFF;
border: 1px solid #BBBBBB;
padding: 2px;
margin: 1px;
font-size: 14px;
color: #808080;
}

a, a:link, a:visited, a:active { color: #AAAAAA; text-decoration: none; font-size: 10px; }
a:hover { border-bottom: 1px dotted #c1c1c1; color: #AAAAAA; }
img {border: none;}
td { font-size: 14px; color: #7A7A7A; }
</style>

</head>

<body background="img/background.gif">
$(if chap-id)
<form name="sendin" action="$(link-login-only)" method="post">
<input type="hidden" name="username" />
<input type="hidden" name="password" />
<input type="hidden" name="dst" value="$(link-orig)" />
<input type="hidden" name="popup" value="true" />
</form>

<script type="text/javascript" src="/md5.js"></script>
<script type="text/javascript">

function doLogin() {
document.sendin.username.value = document.login.username.value;
document.sendin.password.value = hexMD5('$(chap-id)' + document.login.password.value + '$(chap-challenge)');
document.sendin.submit();
return false;
}

</script>
$(endif)



<table width="100%" style="margin-top: 2%;">
<tr>
<td align=center>

<table width=75% style="border: 1px solid #cccccc; padding: 6px;" bgcolor=white cellpadding="0" cellspacing="0">
<tr>
<td align=left>

<center><IMG SRC="img/felix.gif"><P></center>
<!-- LEGAL COPY HERE -->


<div style="height:300px; overflow:scroll; text-align:center;">
<p><strong>By accessing the Internet using Hotel Felix's Complimentary Internet Access, you Agree to be bound by the terms and conditions listed herein. If you do not agree to be bound by these terms and conditions or are not a registered Guest of Hotel Felix, you are not entitled to use the complementary Internet Access at the Hotel Felix.</strong></p>


<p>Customer's Use of Service:<BR>
Customer represents that Customer is responsible for overseeing any individual accessing the Internet through Hotel Felix complimentary Internet service who is under 18 years of age. Customer understands that certain materials available online may not be suitable for individuals under the age of 18.</p>


<p>Offensive Materials. Customer understands that the Internet contains unedited materials some of which may be
offensive, including but not limited to sexually explicit materials. Customer accesses such materials at Customer's own
risk. Customer acknowledges that Hotel Felix has no control over and accepts no responsibility for such materials
or any other materials or information obtained from the Internet using Hotel Felix complimentary Internet service.</p>


<p>Distributing viruses to and from Hotel Felix's complimentary Internet systems. Installation of 'auto-responders', 'cancel-bots' or similar automated or manual routines which generate excessive amounts of net traffic, or disrupt net newsgroups or e-mail use by others. Engaging in any of the above activities using the service of another provider but channeling such activities through a Hotel Felix's complimentary Internet service or re-mailer, or using another account as a mail drop for responses. Customers are liable for having unsecured services, and would be held liable if unknown 3rd parties utilize these services at any time. It is the customer's responsibility to monitor these services. Examples of unsecured services would be use of SMTP relay, incorrect configuration of Proxy or SOCKS services or unsecured operating systems. Customers are responsible for configuring their services to prevent the disruption of service to other customers. (PC Anywhere, SNMP Broadcasters, etc).</p>


<p>HOTEL FELIX'S COMPLIMENTARY INTERNET SERVICE IS PROVIDED WITHOUT WARRANTIES. HOTEL FELIX'S COMPLIMENTARY INTERNET SERVICE IS PROVIDED ON AN "AS IS" AND "AS AVAILABLE" BASIS WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF TITLE, NONINFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE OR ANY WARRANTIES ARISING FROM COURSE OF DEALING OR USAGE OF TRADE. NO ADVICE OR INFORMATION GIVEN BY FORESITE, ITS AFFILIATES, LICENSER, CONTRACTORS OR THEIR RESPECTIVE EMPLOYEES SHALL CREATE A WARRANTY. NEITHER HOTEL FELIX NOR ITS AFFILIATES, LICENSERS, CONTRACTORS OR THEIR RESPECTIVE EMPLOYEES WARRANTS THAT THE SERVICE WILL BE UNINTERRUPTED OR ERROR FREE OR THAT ANY INFORMATION, SOFTWARE OR OTHER MATERIAL ACCESSIBLE VIA FORESITE'S WIRELESS SERVICE IS FREE OF VIRUSES, CANCEBOTS, WORMS, TROJAN HORSES OR OTHER HARMFUL COMPONENTS.</p>
</div>
<!-- END LEGAL COPY -->
&nbsp;<P>
<form name="login" action="$(link-login-only)" method="post"
$(if chap-id) onSubmit="return doLogin()" $(endif)>
<input type="hidden" name="dst" value="$(link-orig)" />
<input type="hidden" name="popup" value="true" />
<input type="hidden" name="username" value="user1" />
<input type="hidden" name="password" value="password" />
<CENTER>
$(if error)<FONT color="#FFFFFF" size=3><U>$(error)</U></FONT>$(endif)<P>
<P><B>Access Code Required:</B>
<input style="TEXT-TRANSFORM: uppercase; width: 80px" name="password" type="text" onkeyup="return cUpper(this);"/></P>
<BR>
<CENTER><input STYLE="font-style:strong; background:#000000; color:#FFFFFF" type="submit" value="I Accept These Terms And Conditions" /></A>

</form>
</td>
</tr>

</table>

</br><div style="color: #c1c1c1; font-size: 9px">For Technical Support call xxx-xxx-xxxx</div>
$(if error)<br /><div style="color: #000000; font-size: 9px">$(error)</div>$(endif)
</td>
</tr>
</table>

</body>
</html>



Like I said im sure the password input value could be hardcoded to the currently set password and this would probably work but then i'd have to do that every month when the password changes.
 
fewi
Forum Guru
Forum Guru
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Re: script to change hotspot user password fails to work

Thu Oct 22, 2009 8:02 pm

I'm not particularly skilled in Javascript, but when I change this:
<input style="TEXT-TRANSFORM: uppercase; width: 80px" name="password" type="text" onkeyup="return cUpper(this);"/></P>
to this:
<input style="TEXT-TRANSFORM: uppercase; width: 80px" name="password" type="text"/></P>
the page still convers every keystroke to uppercase and I can login fine in my lab via HTTP PAP.
 
User avatar
techguy79
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 66
Joined: Tue Mar 24, 2009 10:34 pm
Contact:

Re: script to change hotspot user password fails to work

Thu Oct 22, 2009 8:15 pm

I just discovered this..
if i comment out the following line:

<!----<input type="hidden" name="password" value="password" />

i can login to hotspot and it does appear to check user inputted password as i tried random passwords and received invalid user or password error but when i type the actual password for user1 I am able to successfully login.

Thanks for your help you are a very helpful person and i hope maybe this post will help others looking to do the same thing.

If anyone from the community has any questions i might be able to answer hit me up as I'd like to be able to be a contributing member of the community.

Network Admin
Foresite Wireless
Chicago based WISP

Who is online

Users browsing this forum: No registered users and 10 guests