pivpn-js

0.0.9 • Public • Published

pivpn-js

Overview

This is a library, which wraps pivpn with JavaScript and makes it possible to interact with the cli-commands much faster and more efficient.

Prerequisites

  • pivpn
  • qrencode
  • node.js >= 12.19.0

Install

NPM

npm install pivpn-js

From source

git clone https://github.com/caio-silva/pivpn-js.git
cd pivpn-js
npm install

Getting started

const PiVPNJs = require("pivpn-js")
const confPath = "/path/to/dir/containing/conf/files"

const pivpnJs = new PiVPNJs(confPath)
// or 
// const pivpnJs = new PiVPNJs()
// pivpnJs.setConfPath(confPath)

(async function(){

  console.log(pivpnJs.getConfPath())

  const userName = "john-do-phone"
  wasUserAdded = await pivpnJs.addUser(userName)
  console.log(`Was user added: ${wasUserAdded}`)

  const userFileLocation = await pivpnJs.getUserFileLocation(userName)
  console.log(`Path to conf file: ${userFileLocation}`)

  const userQrCodePath = await pivpnJs.generateUserQrCode(userName)
  console.log(`Path to qr code: ${userQrCodePath}`)
  // or (this method first checks if qr exists if not it creates it)
  // const userQrCodePath = await pivpnJs.getUserQrCodePath(userName)
  // console.log(`Path to qr code: ${userQrCodePath}`)

  const connectionDetailsForUser = await pivpnJs.getConnectionDetailsForUser(userName)
  console.table(connectionDetailsForUser)

  const connectionDetailsForAllUsers = await pivpnJs.getConnectionDetailsForAllUsers()
  console.table(connectionDetailsForAllUsers)

  const userInfo = await pivpnJs.getUserInfo(userName)
  console.table(userInfo)

  const allUsersInfo = await pivpnJs.getAllUsersInfo()
  console.table(allUsersInfo)

  const userQrCodeStream = await getUserQrCodeStream(userName)

  const wasUserRemoved = await pivpnJs.removeUser(userName)
  console.log(`Was user removed: ${wasUserRemoved}`)

  const wasPiVPNUpdated = await pivpnJs.updatePiVPN()
  console.log(`Was pivpn updated: ${wasPiVPNUpdated}`)

  const backupInfo = await pivpnJs.backup()
  console.log(backupInfo)

})()

Package Sidebar

Install

npm i pivpn-js

Weekly Downloads

0

Version

0.0.9

License

ISC

Unpacked Size

9.9 kB

Total Files

3

Last publish

Collaborators

  • caio-gsilva