This is a revised page on the JSON interface of CoovaChilli.
It is not intended to replace the original which I've created, but should be seen as a natural progression as things got more clear to me over time.
We start off with some background on JSONP. With an understanding of this background, the JSON interface of Coova Chilli should be a snap to understand.
This section tries to explain JSONP in as simple as possible terms.
It assumes that the reader has at least limited HTML, Java Script and PHP knowlege.
It will also be of advantage if the reader has access to a web server where they can try the sample code out.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>YFi Hotspot Manager</title> <script type="text/javascript"> function clicked(){ alert("Button Clicked"); var node = document.createElement("script"); node.type = "text/javascript"; node.src = "json_service.php?callback=completed"; document.getElementsByTagName("head")[0].appendChild(node); } function completed(arg){ alert("The argument is: "+arg.one); } </script> </head> <body> <button type="button" onclick="clicked();">Click Me!</button> </body> </html>
The HTML page does the following:
When you click the button, the following happens:
JSONP service
The page which gets sourced by the sample HTML page's script element looks as follows:
<? header('Content-type: application/javascript'); //Output as JavaScript $callback = $_GET["callback"]; //What should we wrap the JSON with $arr = array ('one'=>"One Attribute"); //PHP Object $json_obj = json_encode($arr); //JSON encode the PHP object print $callback."(".$json_obj.");"; //Wrap the JSON with the callback ?>
It gets called as follows:
"json_service.php?callback=completed"
This is a very simple JSONP service.
The P stands for padded. Pages like these are usually passed a query string. (callback in our example)
They will then wrap the JSON - which is an anonymous Java Script object inside the value of one of the query string's elements. (completed in our example)
It will then look something like the following:
callback_name;
EG completed({"one":"One Attribute"});
This will then effectively cause the Java Script engine of the browser to call the function which the JSONP service was instructed to wrap the JSON in as soon as the script element finished loading itself.
That is the reason 'completed' was called.
Coova Chilli offers its own JSONP service much like the above explanation.
Please refer to the following page to read more on Coova Chilli's JSONP Service (which they refer to as an interface)
One bit which is not documented though, is when you log in using pap passwords.
A pap password request will look as follows:
http://192.168.182.1:3990/json/logon?username=XXXX&password=0123456789abcdef
The value of password should be obtained from a UAM JSONP service.
The UAM JSONP service takes a challenge, the cleartext password supplied by the user, and a shared secret between chilli and the UAM JSONP service and do some special encryption on it in order to get in into a format that the Chilli program can understand.
Having an understanding how this fits together will help us to create our own login page which utilise the Coova Chilli's JSONP service.
This section will help you to install and configure the YFi Hotspot Manager's login page.
The login facilities provided by YFi Hotspot Manager provides two pages.
Download and install the login page bundle on a web server which will be used to define. You need to fetch it using SVN. Instructions on how to obtain it: SVN Download HOWTO
It is assumed that you are familiar with Coova Chilli's configuration setup - Where the main.conf file's values is determined by the values of variables defined in /etc/chilli.config.
In this sample, we have a server with an IP of 196.1.2.3 and the coova_json directory is in the root of the web server. We need to ensure that the following values are configured.
Location
File
Comment
Example
Coova Chilli (Server or Access Point)
/etc/chilli/main.conf
Created from the value of HS_UAMHOMEPAGE in /etc/chilli/config
uamhomepage http://196.1.2.3/coova_json/splash.php
Coova Chilli (Server or Access Point)
/etc/chilli/main.conf
Created from the value of HS_UAMFORMAT in /etc/chilli/config
uamserver http:/196.1.2.3/coova_json/hs_land.php
Coova Chilli (Server or Access Point)
/etc/chilli/main.conf
Created from the value of HS_UAMSECRET in /etc/chilli/config
uamsecret greatsecret
Coova Chilli (Server or Access Point)
/etc/chiili/config
Specify HS_UAMSERVER - Used by setup scripts like the firewall script
HS_UAMSERVER=196.1.2.3
Ubuntu Server with Apache
/var/www/coova_json/login.php
Ensure $uamsecret is same as Chilli's
$uamsecret = 'greatsecret';
Ubuntu Server with Apache
/var/www/coova_json/uam.php
Ensure $uamsecret is same as Chilli's
$uamsecret = 'greatsecret';
Ubuntu Server with Apache
/var/www/c2/yfi_cake/setup/coova_json/js/dojo/chilli/Json.js
You may want to use https for extra security
var uam_jsonp = 'http://196.1.2.3/coova_json/uam.php';
Make sure everything work as intended.
Hope you find this login-page suite useful.
Wiki: YfiTechCoovaLogin
Wiki: yfi_setup_nas_coova
Wiki: yfi_setup_svn