modified on 8 June 2010 at 04:33 ••• 14,946 views

Notify your customers internet is down, monitor connectivity

From MikroTik Wiki

Jump to: navigation, search

When the internet is up, your users will see the Systemup.gif on your login page telling them all systems are normal. When the internet is down, they will see the Systemdown.gif page telling them internet is down and all active sessions and cookies will get removed from the router, forcing active users when they try to load a webpage, back to the login page so they can see the Systemdown notice.

A requirement is that you must have the hotspot package installed and operational first.

Then

Add the following code to your login.html hotspot page as such

<center><img src='http://www.SOME-EXTERNAL-WEBSITE.com/images/Systemup.gif' 
onerror="this.src='/images/Systemdown.gif'" / align="middle"></center>

Save and upload the below image to some external website, and adjust the link in the code above for the first img src link to point to this Systemup.gif image. Obviously edit the link in the above to the path where you put this gif file. Something like a imagehost service would work well


Systemup.gif Systemup.gif

Then take this image gif below and place it in the /hotspot/images on your mikrotik router.


Systemdown.gif Systemdown.gif

Now you need to add a allow dst-host entry in your walled-garden for the http://www.SOME-EXTERNAL-WEBSITE.com that you used in the above code for your login.html, so that when your login page gets loaded when your users first login, the login.html page will attempt to load the enternal website with that Systemup.gif, successfully loading up the http://www.SOME-EXTERNAL-WEBSITE.com/images/Systemup.gif proving that the internet is UP... If it fails to load that image, the internet must be down, so it then loads just the local image Systemdown.gif stored in /hotspot/images of your mikrotik router.

Now alot of us use cookies to keep our users logged in for 24hour or however long. So if the internet goes down, our currently active users would never see the login page because their sessions stay active until their cookies expire and they are not requested to login.

So to solve this problem. We need to use the Netwatch feature to ping a known up ip address, like google.com and if it fails to ping the IP, then our internet must be down, so we run a script to remove all active sessions and cookies from the mikrotik router, causing the users to be directed back to the login page, thus seeing the Systemdown.gif message. The code for the netwatch is as follows.

:local dumplist [/ip hotspot active find]
:foreach i in=$dumplist do={
    /ip hotspot active remove $i
}
:local dumplist [/ip hotspot cookie find]
:foreach i in=$dumplist do={
    /ip hotspot cookie remove $i
}

Your netwatch should look sometihng like this

Netwatch.jpg

Thats all there is too it. I know its a lot, but if you follow the instructions and try it out, it will work perfectly. When the internet is up, they will see the Systemup.gif on your login page, When the internet is down, they will see the Systemdown.gif page and all active sessions and cookies will get removed, forcing active users when they try to load a webpage, back to the login page to see the Systemdown notice.

Once this is setup, the only requirement is that 1. that Systemup.gif is accessable on the external website, you can use something like imagehost to host the Systemup.gif 2. that google can be pinged.

The only fault is if google.com is not pingable, because a route to the host is not up, but the rest of the internet is, then you may cause your active users to be booted back to the login page. But there are other script out there if you look that you can use, that will test a couple of IP addresses and say if all 3 or however many you specify fail at pinging, then run the script code to remove active users and sessions. The other thing is that, if after the internet goes down, the sessions and cookies are removed, the active users ge booted back to the login page and sees the main login page with the notice. If the try to login again, then they there cookie will get re-established, and they will be logged in again for the cookie liketime. They will no longer see the hotspot login page with the notice again. Maybe again with a better script written, like I mentioned above to ping 3 locations, you could schedule it to run every 10 seconds or whatever, meaning, that if it continued to fail eachtime the schedule ran, it would remove active cookies again. Thus booting those active users out again that tried to login after they were booted the first time. So it will continually clean the active sessions and cookies, as long as the 3 pings test fail.