Skip to content
This repository has been archived by the owner on Jul 2, 2022. It is now read-only.

Node.js library to communicate with the shadowsocks-restful-api

License

Notifications You must be signed in to change notification settings

izzqz/shadowsocks-server-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

shadowsocks-server-api

Node.js library to communicate with the shadowsocks-restful-api

Installation

npm i shadowsocks-server-api

Usage

To start a new instance:

const SsApi = require('shadowsocks-server-api')

const ssApi = new SsApi()

let server = {
  host: 'Your server host',
  port: 4001, //Port of shadowsocks-restful-api
  token: '',
  password: 'pleaseChangeThisPassword'
}

Login

ssApi.login()
ssApi.login(server, (error, response, token) => {
    // Returns response Object and an error if it contains one
    console.log(token) //eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1NzE0NzIx...
  }
})

Ping

ssApi.getPing()
ssApi.getPing(server, (error, response, body) => {
    // Returns response Object and an error if it contains one
    console.log(body) // {"pong":"pong"}
  }
})

Add port

ssApi.addPort()
let portConfig = { // Config for shadowsocks port
  port: 'port_number',
  password: 'port_password',
  method: 'encryption_method'
}

ssApi.addPort(server, portConfig, (error, response, body) => {
    // Returns response Object and an error if it contains one
    console.log(response.statusCode) // 201 Created
  }
})

Get all ports

ssApi.getPorts()
ssApi.getPorts(server, (error, response, body) => {
    // Returns response Object and an error if it contains one
    console.log(body) // [{"port":port_number, "password":"port_password","method":"encryption_method"}, ... ]
  }
})

Delete a port

ssApi.deletePort()
let port_to_delete = 4242

ssApi.deletePort(server, port_to_delete, (error, response, body) => {
    // Returns response Object and an error if it contains one
    console.log(response.statusCode) // 204 No Content
  }
})

Get traffic for all ports

ssApi.getTrafic()
ssApi.getTrafic(server, (error, response, body) => {
    // Returns response Object and an error if it contains one
    console.log(body) // [{"port":port_number, "traffic": traffic_usage}, ... ]
  }
})

About

Node.js library to communicate with the shadowsocks-restful-api

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published