Page 1 of 1
redirect if external login page not avaiable to internal
Posted: Tue Oct 26, 2010 8:02 pm
by gszpiniak
Hi,
I have a RB433AH with hotspot settings.
When users connect to the hotspot they are automatically redirected to our external login page and authenticate successfully.
My problem is that I want an alternative login page (internal) in case my external server is down.
Is there any solution to detect the external server is down? and if it is down, redirect to the internal login page?
Thank you!
I appreciate your help very much.
Re: redirect if external login page not avaiable to internal
Posted: Wed Oct 27, 2010 3:39 pm
by fewi
Have a second directory with the alternative, internal pages. On the external server keep a small file to download as a test. Write a script that uses the fetch tool to download that file from the external server, then see if it exists in the file system. If it does, just delete it and set the html-directory property of the Hotspot profile to the directory that contains the redirect to external. If it does not, set the same property to the directory for internal fallback. Schedules the script to run every five minutes.
Re: redirect if external login page not avaiable to internal
Posted: Wed Oct 27, 2010 4:45 pm
by gszpiniak
Thanks for your response.
I was trying with some javascript code with timeout but have not managed to make it work
Sounds like a good idea this way to check the status of the server, but I'm not familiar with mikrotik scripts. Can you give me some tips or examples?
Thank you for your help.
Re: redirect if external login page not avaiable to internal
Posted: Wed Oct 27, 2010 4:55 pm
by fewi
I'll try and lab it out today or tomorrow if I have enough time at work, and will post the result.
Re: redirect if external login page not avaiable to internal
Posted: Fri Oct 29, 2010 5:10 pm
by gszpiniak
would be great if you could do it!!
Thank you very much.
Re: redirect if external login page not avaiable to internal
Posted: Fri Oct 29, 2010 5:20 pm
by fewi
# change these five variables as necessary
:local testURL "http://example.com/test.txt";
:local localFile "connectivity-test";
:local HTMLdirForExternal "HotspotExternal";
:local HTMLdirForInternal "HotspotInternal";
:local HotspotProfileName "Hotspot";
# remove local file just in case something broke before
/file remove [/file find name=$localFile];
# try to fetch the tester URL
tool fetch url=$testURL dst-path=$localFile;
# check if it downloaded
:if ([:len [/file find name=$localFile]] > 0) do={
/ip hotspot profile set [/ip hotspot profile find name=$HotspotProfileName] html-directory=$HTMLdirForExternal;
} else={
/ip hotspot profile set [/ip hotspot profile find name=$HotspotProfileName] html-directory=$HTMLdirForInternal;
}
That's as far as I got (though that isn't much, it's fairly obvious up to that point). What that needs is the equivalent of a try/catch block around the "tool fetch" command - when confronted with a failure the script just bombs out. I remember dssmiktik posting something to that regard but I was unable to find it when I tried searching for it.
I'm posting that as incomplete because I'm going on vacation tomorrow and hopefully someone else can help you deal with the error condition and finish it. I won't have time until the second or third week of November. Sorry.
Re: redirect if external login page not avaiable to internal
Posted: Tue Jul 24, 2012 3:07 pm
by gszpiniak
I found a good solution to solve this issue. I leave it here if someone need it:
1.- First of all I create a folder named 'local' with the login file 'login.html'
login.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<body>
<center>Main Internet Feed is Down</center>
</body>
</html>
2.- Create a new Hotspot Server Profile copying the hotspot profile I use and change the html directory:
[root@DEMO] > /ip hotspot profile pr
Flags: * - default
0 * name="hsprof1" hotspot-address=1.1.1.1 dns-name="" html-directory=hotspot rate-limit="" http-proxy=0.0.0.0:0
smtp-server=0.0.0.0 login-by=cookie,http-pap,trial http-cookie-lifetime=3d split-user-domain=no trial-uptime=10m/4w2d
trial-user-profile=default use-radius=yes radius-accounting=yes radius-interim-update=received nas-port-type=ethernet
radius-default-domain="" radius-location-id="" radius-location-name="" radius-mac-format=XX:XX:XX:XX:XX:XX
1 name="hsprof_local" hotspot-address=1.1.1.1 dns-name="" html-directory=local rate-limit="" http-proxy=0.0.0.0:0
smtp-server=0.0.0.0 login-by=cookie,http-pap,trial http-cookie-lifetime=3d split-user-domain=no trial-uptime=10m/4w2d
trial-user-profile=default use-radius=yes radius-accounting=yes radius-interim-update=received nas-port-type=ethernet
radius-default-domain="" radius-location-id="" radius-location-name="" radius-mac-format=XX:XX:XX:XX:XX:XX
3.- Create a netwatch to some server [I use google dns 8.8.8.8 ] If is down I change the hotspot profile to the local one and remove all active users. If is up I turn it back the the normal hotspot profile:
/tool netwatch
add comment="DNS Google - Comprobacion conectividad" disabled=no down-script="\
:local dumplist [/ip hotspot active find]\r\
\n:foreach i in=\$dumplist do={\r\
\n\t/ip hotspot active remove \$i\r\
\n}\r\
\n/ip hotspot set hotspot1 profile=hsprof_local\r\
\n" host=8.8.8.8 interval=1m timeout=1s up-script=\
"/ip hotspot set hotspot1 profile=hsprof1\r\
\n"
That's it!!
It works grate