Tiny JS client library for CoovaChilli JSON Interface.
Basically it's a rewrite of ChilliLibrary.js with some improvements:
npm install chilli-pepper
, then:
var Pepper = require('chilli-pepper');
var pepper = Pepper({
host: '192.168.1.1',
port: 3990
});
pepper.logon('john', 'd0E', function(err, data) {
if (data.clientState === 1) {
// User is now logged in
}
// ...
});
For globally use Pepper you must build it first. It's very easy:
git clone
this reponpm install
npm run build
or npm run build-min
(if you want a minified version). You'll find builded version in ./dist
folderThen you'll have a global Pepper
object ready to use:
var pepper = Pepper({
host: '192.168.1.1',
port: 3990
});
pepper.logon('john', 'd0E', function(err, data) {
if (data.clientState === 1) {
// User is now logged in
}
// ...
});
Get a new Pepper instance. Available options are listed below.
Note that all options are optional: by default Pepper will try to extract required data from CoovaChilli redirect querystring.
host
: String. Host name (or IP address) of CoovaChilli. If not specified, Pepper will try to extract host from CoovaChilli redirect querystring.
port
: Number. Port of CoovaChilli. If not specified, Pepper will try to extract host from CoovaChilli redirect querystring.
ssl
: Boolean. If you're using SSL on CoovaChilli, turn this on. By default, Pepper will automatically set this according to window.location.protocol
.
ident
: String. Hex encoded string used for CHAP-Password calculation. Default is 00
.
interval
: Number. If specified, Pepper will update status informations (clientState, ...) every {interval} ms.
uamservice
: String. If specified, Pepper will do a JSONP call to this service in order to obtain a CHAP-Password (instead of calculating on the client side). See documentation below for more informations.
querystring
String: Optional parameter if you want to manually pass CoovaChilli redirect querystring.
Note that Pepper will throw an exception if fails to build base CoovaChilli API url. This usually happens if:
Update internal status calling CoovaChilli status
API. Callback is optional.
Callback arguments are:
err
: Any error encountered during proceduredata
: CoovaChilli status response.username
: String user's usernamepassword
: String user's passwordoptions
: Object optional logon options (see below)callback
: Function callback function.Performs a logon (checking current status first).
Available options
are:
protocol
: String authentication protocol. Currently, PAP
and CHAP
are supported, and the default is CHAP
.Callback arguments are:
err
: Any error encountered during proceduredata
: CoovaChilli logon response. If user is correctly authenticated, clientState
property will be 1
(see examples above).Performs a logoff. Callback is optional.
Callback arguments are:
err
: Any error encountered during proceduredata
: CoovaChilli logoff response.interval
: Number. Interval length in milliseconds.Starts automatic status refresh every interval
ms.
Note that this function is called automatically if you specify interval
option when creating Pepper instance, but you can also call it manually whenever you want.
Stops automatic status refresh.
User's status object. This will be updated:
logon
, logoff
, or refresh
methodsinterval
ms (if specified)This library is builded with debug module.
If you want to see debug messages in browser:
localStorage.debug = '*' // in a JS console
If you want to see debug messages in Node.js:
DEBUG=* {yourScript}.js
Run tests in Node.js (using jsdom):
npm test
Run tests in browser:
npm run test-server
Then go to http://localhost:4000
The MIT License (MIT)
Copyright (c) 2015 Michele Pangrazzi <xmikex83@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.