Skip to content

mpangrazzi/pepper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

(chilli) Pepper

Build Status

Tiny JS client library for CoovaChilli JSON Interface.

Basically it's a rewrite of ChilliLibrary.js with some improvements:

  • code is more modular
  • works with Browserify, AMD or simply including the minified script and use it globally.
  • can be used both in browser or in Node.js
  • functional tests
  • examples

Examples

Browserify / Node.js / io.js

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
  }

  // ...

});

Global

For globally use Pepper you must build it first. It's very easy:

  1. git clone this repo
  2. Run npm install
  3. Build Pepper running npm run build or npm run build-min (if you want a minified version). You'll find builded version in ./dist folder
  4. Include the builded script in your webapp

Then 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
  }

  // ...

});

var pepper = Pepper(options)

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:

  • You don't specify host/port
  • Pepper can't extract required data from CoovaChilli redirect querystring

Public methods

.refresh(callback)

Update internal status calling CoovaChilli status API. Callback is optional.

Callback arguments are:

  • err: Any error encountered during procedure
  • data: CoovaChilli status response.

.logon(username, password[, options], callback)

  • username: String user's username
  • password: String user's password
  • options: 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 procedure
  • data: CoovaChilli logon response. If user is correctly authenticated, clientState property will be 1 (see examples above).

.logoff(callback)

Performs a logoff. Callback is optional.

Callback arguments are:

  • err: Any error encountered during procedure
  • data: CoovaChilli logoff response.

.startAutoRefresh(interval)

  • 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.

.stopAutoRefresh()

Stops automatic status refresh.

Public properties

.status

User's status object. This will be updated:

  • Everytime you call logon, logoff, or refresh methods
  • Every interval ms (if specified)

Debug

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

Test

Run tests in Node.js (using jsdom):

npm test

Run tests in browser:

npm run test-server

Then go to http://localhost:4000

TODO

  • write more tests
  • add test coverage info

License

The MIT License (MIT)

Copyright (c) 2015 Michele Pangrazzi <[email protected]>

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.

About

Tiny JS client library for CoovaChilli JSON Interface

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published