Hotspot Variables - [SOLVED]

Hi i was trying to change a few thing on my Hospot page, but i can’t seem to find the codes i need.

I would like to know if there is any way to have the login form present and working in all of the hotspot’s pages (except the alogin.html of course) and allow the user to login from it, or if the users are only allowed to login from the login.html page?

Also if there is a way to login from any hospot page, i would like to know the variables that i can use to check the user status (Logged in or not) for the If-Then-Else variables that i want to use.

This is an example of the If-Then-Else that i want to use:

If “user logged in”:

Show user info like username, IP and MAC

If “user not logged in”:

Show the login Form and some info like IP and MAC

This is my current hotspot page:
hotspot1.JPG
hotspot2.JPG
Thank you for your attention, best regards,
Paulo Brinca.

It’s even simpler then that. Basically the hotspot will do the work for you. It will display login.html if the user is not logged in, and display rstatus.html (or status.html) if the user is logged in, automatically when requesting the router.

More info here: http://wiki.mikrotik.com/wiki/Manual:Customizing_Hotspot#Serving_Servlet_Pages

I have seen that link, but thanks anyway…

One of the questions is if the user has to login from the login.html or not.

My hotspot has standalone user registration, wich means that users create their accounts to use the internet (yes, it is a free hotspot, no charges). After that they will stay in the registration page with the login form, but that login is not working right now…

The other question is related to the detection of the user status.

Since this hotspot will have more contents i would like to allow users to browse the different hotspot pages and have their account info on the top if they are logged in, or the login form if they are not logged in.

I have tryed with the logged-in variable, but without sucess.

An example would help since i have been around this all day, and may be doing something wrong :smiley:

thank you for your time.

The user logs in by submitting - via POST or GET - the username and password variables to /login. It is irrelevant what the referrer is for that resource.

All variables are available on all pages served by the Hotspot servlet.

I am not going to question you, but could you please download my hotspot template and test it to check, i am not able to login from the User registration page (called “registar.html”).

Files removed…

I don’t have anything on this machine that can read RAR files. Please post the source code of the HTML page that is giving you trouble in line wrapped in

 tags.

Here you go:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pt" lang="pt">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="skin/normal/css/css.css" type="text/css" />
<title>Picom&aacute;tica Wireless - A sua liga&ccedil;&atilde;o ao mundo - Bem Vindo(a)</title>
<script type="text/javascript" src="javascript/publicidade.js"></script>
</head>

<body>
<!-- Inicio do Wrapper -->
<!-- Inicio do Script -->
<div id="script" style="display:none">
$(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 language="JavaScript" src="javascript/md5.js">
	</script>
	<script language="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)
</div>
<!-- Fim do Script -->
<!-- Inicio do Wrapper -->
<table id="wrapper" border="0" cellspacing="0" cellpadding="0">
	<tr>
		<td id="bordatopoleft" align="center" valign="top"></td>
		<!-- Inicio do Site -->
		<td id="site">
			<!-- Inicio do Header -->
			<table id="header" border="0" cellspacing="0" cellpadding="0">
				<tr>
					<td id="logo" valign="middle" class="semborda">
					<a href=""><img src="skin/normal/imagens/logo.png" title="Picomatica Wireless" alt="Picomatica Wireless" class="semborda" /></a>
			    	</td>
					<td id="utilizador">
						<div id="login">
							<form name="login" action="$(link-login-only)" method="post" $(if chap-id) onSubmit="return doLogin()" $(endif)>
								<table width="300" border="0">
									<tr>
										<td colspan="2"><label class="verde">Autentica&ccedil;&atilde;o:</label></td>
									</tr>
									<tr>
										<td width="150"><label>Nome de Utilizador:</label></td>
										<td><label>Senha:</label></td>
									</tr>
									<tr>
										<td width="150"><input name="username" value="$(username)" type="text" size="19" /></td>
										<td><input name="password" value="" type="password" size="19" /></td>
									</tr>
									<tr>
										<td width="150"><label>Endereço IP:</label></td>
										<td><label>Endereço MAC:</label></td>
									</tr>
									<tr>
										<td width="150">$(ip)</td>
										<td>$(mac)</td>
									</tr>
									<tr>
										<td colspan="2" class="direita">
											<input type="hidden" name="dst" value="$(link-orig)">
											<input type="hidden" name="popup" value="true">
											<input class="botao" type="submit" value="Entrar"/>
										</td>
									</tr>
								</table>
							</form>
						</div>	
                    </td>
				</tr>
				<tr>
                	<td id="idioma" valign="bottom">
							<table id="idiomadentro" border="0" cellspacing="0" cellpadding="0">
								<tr>
   								  <td><a href="login.html"><img src="imagens/flags/pt.jpg" class="semborda" width="20" height="12" alt="Portugês" longdesc="Altera o idioma para Português" /></a>&nbsp;<a href="en/login.html" style="display:none"><img src="imagens/flags/en.jpg" class="semborda" width="20" height="12" alt="Inglês" longdesc="Altera i idioma para Inglês" /></a></td>
  								</tr>
							</table>
					</td>
					<td id="navegacao" valign="bottom">
						<ul class="navegacao">
							<li><a href="registar.html" title="Registo de Utilizador" class="current">Registo de Utilizador</a></li>
							<li><a href="login.html" title="P&aacute;gina Inicial" class="other">Autentica&ccedil;&atilde;o</a></li>
						</ul>
					</td>
				</tr>
			</table>
			<!-- Fim do Header -->
    </td>
		<td id="bordatoporight" align="center" valign="top"></td>
	</tr>
	<tr>
		<td id="bordaleft" align="center" valign="top"></td>
		<td>

			<!-- Inicio do Corpo -->
			<table id="corpo" border="0" cellspacing="0" cellpadding="0">
				<tr>
					<td>
					<!-- Inicio da Esquerda -->
						<table id="esquerda" border="0" cellpadding="0" cellspacing="0">
							<tr>
								<td>
                                	<div class="justificadosite">
                                		<h1>Publicidade:</h1>
										<div align="center">
											<script type="text/javascript">
											show_banners('lateral');
                                        	</script><br />
											<script type="text/javascript">
											show_banners('lateral');
                                        	</script><br />
											<script type="text/javascript">
											show_banners('lateral');
                                        	</script><br />
											<script type="text/javascript">
											show_banners('lateral');
                                        	</script><br />
											<script type="text/javascript">
											show_banners('lateral');
                                        	</script><br />
											<script type="text/javascript">
											show_banners('lateral');
                                        	</script><br />
                                        </div>
									</div>
								</td>
							</tr>
						</table>
						<!-- Fim da Esquerda -->
						<!-- Inicio dos Conteúdos -->
						<table id="principal" border="0" cellpadding="0" cellspacing="0">
							<tr>
								<td>
                                	<div class="justificadosite">
										<br />
										<div align="center">
										<script type="text/javascript">
										show_banners('fundo');
										</script><br />
										</div>
										<div class="separador"></div>
                                        <p align="center">
											Página de registo desactivada por motivos de segurança
										</p>
										<div class="separador"></div>
                                        <br />
										<div align="center">
										<script type="text/javascript">
										show_banners('fundo');
										</script><br />
										</div>
									</div>
								</td>
							</tr>
						</table>
						<!-- Fim dos Conteúdos -->
                        <!-- Inicio da Direita -->
						<table id="direita" border="0" cellpadding="0" cellspacing="0">
							<tr>
								<td>
									<div class="justificadosite">
                    					<h1>Colaboradores:</h1>
										<div align="center">
                                    		<img src="imagens/logojunta.png" alt="Junta de Freguesia das Lajes do Pico" title="Junta de Freguesia das Lajes do Pico" width="150" height="157" border="0" class="semborda" /><br /><br />
											<a href="http://www.redespt.com/" target="_blank"><img src="imagens/logoofficelan.png" alt="Officelan,LDA" title="Officelan,LDA" width="150" height="61" border="0" /></a>
	  									</div>
                                    </div>
								</td>
							</tr>
						</table>
                        <!-- Fim da Direita -->
					</td>
				</tr>
                <!-- Fim do Corpo -->
                <!-- Inicio do Fundo -->
                <tr>
					<td>
						<table id="fundo" border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td id="fundodentro">
									<p><strong>Picom&aacute;tica Wireless - A sua liga&ccedil;&atilde;o ao mundo </strong>&copy; 2009 - Todos os direitos reservados.</p>
								</td>
							</tr>
						</table>
					</td>
				</tr>
			<!-- Fim do Fundo -->
            </table>
			<!-- Fim do Corpo -->
		</td>
		<td id="bordaright" align="center" valign="top"></td>
	</tr>
</table>
<!-- Fim do Site -->
</body>
</html>

That should work. Turn on Hotspot debugging and see if you can see the login attempts, and what errors are thrown.

I will do that tomorrow, since right now it is 23:43h here in the Azores.

Thank you for your time, i will post some news tomorrow.

I don’t have anything on this machine that can read RAR files.

I recommend 7zip. It reads all archive formats and it’s free and stable software with no ads. And RAR is a good format, better than ZIP. I think 7zip’s own format could be even better than RAR but not sure.

Just my advice, since I use login-by=http-chap and fewi uses login-by=http-pap, insure the md5.js file is in the correct directory. In your html code:

In this case, the md5.js file should be in the /hotspot/javascript/ directory. If it is in the same directory as the login.html doc (like on the router in the /hotspot directory), it should be
src=“/md5.js”

@normis: Thanks for the tip on 7zip!

Thanks SurferTim the md5.js is inside the javascript folder, and this code is the same as the login.html, the only thing that changes is the content of

Since the “login.html” is working, the “registar.html” should also be allowing the user to login from there…

I would like to know if i post the files can someone please take a look at the code and possibly test it in their hotspot…

@normis - Do you wan’t me to remove the code from above and place a .txt file with it?

Thank you.

Did you do what fewi suggested? Try the login from that page and check the log. I’m fairly certain fewi will ask if you tried that. You should be able to test it by calling it from a client machine.
http://192.168.0.1/registrar.html
Change the ip to your router’s hotspot address.

You are aware that the hotspot will call login.html when the requested page is redirected. You will either need to rename your doc login.html, or redirect the login.html page to your new page with Javascript.

ADD: I don’t know if the variables $(chap-id) and $(chap-challenge) will be correct on the registrar.html doc. You might want to “View Source” on that page when it loads to insure those are there.

What Tim said. Always check the logs when testing. Also, try it with PAP instead of CHAP and see if that works to determine if the md5 algorithm is the root of your issue.

That either is way over my head or i’m not getting the big picture here :smiley:

I will look for more information on that subject and then make some testing…

Right now i have a machine set up for testing, when i try to login from the “registar.html” on the browser i get the error:

web browser did not send challenge response (try again, enable JavaScript)

And on the Mikrotik Log i get the error:

begreat (192.168.12.136):login failed: no chap for http-chap login method

That means there’s either a problem how you’re integrating the md5.js, or the $(chap-id) variables aren’t getting populated as Tim hinted towards. Look at the page in source view on the test client and see if the variable is filled out - if it’s not, CHAP can’t work.

A simple “no worries” workaround would be if you had an SSL certificate you can use on the Hotspot. PAP is perfectly safe over SSL/TLS, and pages for PAP are much easier to write and debug than CHAP ones.

On the test pc i have, the code view of the login.html shows this:

<!-- Inicio do Script -->
<div id="script" style="display:none">
 
	<form name="sendin" action="http://hotspot.picomatica.dom/login" method="post">
		<input type="hidden" name="username">
		<input type="hidden" name="password">
		<input type="hidden" name="dst" value="">
 
		<input type="hidden" name="popup" value="true">
	</form>
	<script language="JavaScript" src="javascript/md5.js">
	</script>
	<script language="JavaScript">
	<!--
	    function doLogin() {
		document.sendin.username.value = document.login.username.value;
		document.sendin.password.value = hexMD5('\075' + document.login.password.value + '\143\273\017\226\171\317\337\325\301\362\230\110\174\130\360\321');
		document.sendin.submit();
		return false;
	    }
	//-->
	</script>
 
</div>
<!-- Fim do Script -->

and the code view of the registar.html shows this:

<!-- Inicio do Script -->
<div id="script" style="display:none">
 
</div>
<!-- Fim do Script -->

I don’t know if it makes a difference, but i have my own RadiusManager license from DMASoftLAB.

If there was no “function doLogin” script, then the $(chap-id) variable was blank. You will need to replace the login.html with your page. I would save the original login.html page in case you need a reference for your new page, and something to go back to if yours doesn’t work like you expected.

Then try again. Same thing. Check “View Source”, then try the login and check the log.

I enable the hotspot and radius logging when testing.

/system logging
add topics=hotspot action=memory
add topics=radius action=memory

There is a “function doLogin” script, the page’s HTML is a few posts above.

I have checked everything (according to my knowledge), and i can’t find the error, it should be working, but for some reason users can only login using the login.html file, no other file allows the users to login, imagine i would like the user to login from login2.html while login.html had some hotspot intro…