pritunl

0.0.4 • Public • Published

pritunl

NPM

Node.js Pritunl API

Install

$ npm install --save pritunl

Usage

To start a new Pritunl instance:

var Pritunl = require('pritunl');
 
var pritunl = new Pritunl({
  baseurl: <PRITUNL_SERVER_BASE_URL>,
  api_token: <API_TOKEN>,
  api_secret: <API_SECRET>
});

API

Method request()

In Pritunl, all API requests must be signed with the API token and secret. The API token and secret can be found in the Settings dialog, Pritunl admin page.

Read more: Pritunl API - Authentication

Helper object Global

pritunl.global.log

Returns a list of server log entries sorted by time.

pritunl.global.log().then(function(entries) {
  console.log('Log entries: %s', JSON.stringify(entries, null, 2));  
});

Read more: Pritunl API - GET /log

pritunl.global.ping

Server healthcheck.

pritunl.global.ping().then(function(result) {
  console.log('Ping status code: %s', JSON.stringify(result, null, 2));  
});

Read more: Pritunl API - GET /ping

pritunl.global.status

Returns general information about the pritunl server.

pritunl.global.status().then(function(status) {
  console.log('Server status: %s', JSON.stringify(status, null, 2));  
});

Read more: Pritunl API - GET /status

Helper object Organization

pritunl.organization.list

Returns a list of organizations on the server sorted by name.

pritunl.organization.list().then(function(result) {
  console.log('Organization list: %s', JSON.stringify(result, null, 2));
});

Read more: Pritunl API - GET /organization

pritunl.organization.get

Returns an organization.

var org_id = '<change_your_organization_id>';
pritunl.organization.get(org_id).then(function(item) {
  console.log('Organization item:%s: %s', org_id, JSON.stringify(item, null, 2));  
});

Read more: Pritunl API - GET /organization/:org_id

pritunl.organization.create

Create a new organization.

Promise.resolve().then(function() {
  return pritunl.organization.create({name: 'org_no_1'});
}).then(function() {
  return pritunl.organization.create({name: 'org_no_2'});
}).then(function() {
  return pritunl.organization.list();
}).then(function(organizations) {
  console.log('Organizations: %s', JSON.stringify(organizations, null, 2));
});

Read more: Pritunl API - POST /organization

pritunl.organization.update

Rename an existing organization.

 

Read more: Pritunl API - PUT /organization

pritunl.organization.delete

Delete an existing organization.

Promise.resolve().then(function() {
  return pritunl.organization.create({name: 'org_no_1'});
}).then(function() {
  return pritunl.organization.create({name: 'org_no_2'});
}).then(function() {
  return pritunl.organization.list();
}).then(function(organizations) {
  console.log('Organizations: %s', JSON.stringify(organizations, null, 2));
  return organizations;
}).then(function(organizations) {
  return pritunl.organization.delete(organizations[0].id);
}).then(function() {
  return pritunl.organization.list();
}).then(function(organizations) {
  console.log('Organizations: %s', JSON.stringify(organizations, null, 2));
  return organizations;
}).then(function(organizations) {
  return pritunl.organization.delete(organizations[0].id);
});

Read more: Pritunl API - DELETE /organization/:organization_id

Helper object User

pritunl.user.list

Returns a list of users in an organization sorted by name.

var org_id = '<your_organization_id>';
pritunl.user.list(org_id).then(function(result) {
  console.log('Organization list: %s', JSON.stringify(result, null, 2));
}); 

Read more: Pritunl API - GET /user/:organization_id

pritunl.user.get

Returns a user from an organization.

var org_id = '<your_organization_id>';
var user_id = '<your_user_id>';
pritunl.user.get(org_id, user_id).then(function(user) {
  console.log('User: %s', JSON.stringify(user, null, 2));
}); 

Read more: Pritunl API - GET /user/:organization_id

pritunl.user.create

Create a new user in an organization. An array of users can be sent for bulk adding users.

Promise.resolve().then(function() {
  return pritunl.organization.create({name: 'org_example'});
}).then(function() {
  return pritunl.organization.list();
}).then(function(organizations) {
  console.log('Organizations: %s', JSON.stringify(organizations, null, 2));
});

Read more: Pritunl API - POST /user/:organization_id

pritunl.user.update

Rename or disabled an existing user in an organization. Disabling will also disconnect the user.

 

Read more: Pritunl API - PUT /user/:organization_id/:user_id

pritunl.user.delete

Delete an existing user in an organization, this will disconnect the user.

pritunl.user.delete('<organization_id>', '<user_id>').then(function() {
  console.log('User has been successfully deleted');
}, function(statusCode) {
  console.log('Failed to delete user: %s', statusCode);
});

Read more: Pritunl API - DELETE /user/:organization_id/:user_id

Readme

Keywords

Package Sidebar

Install

npm i pritunl

Weekly Downloads

0

Version

0.0.4

License

ISC

Last publish

Collaborators

  • acegik