Skip to content

nioc/synology-srm-nodejs-api

Repository files navigation

synology-srm-nodejs-api

license: AGPLv3 Build Status Coverage Status GitHub release npms.io (final) npm

Unofficial dependency-free Node.js wrapper for Synology SRM API.

Key features

  • authentication,
  • get WAN status,
  • get WAN connection (ip, status, interface name),
  • get network utilization,
  • get devices with status, IP, etc... ,
  • get wifi devices with link quality, signal strength, max rate, band used, etc... ,
  • get devices traffic usage (live, day, week, month),
  • get mesh nodes with status, connected devices, etc... ,
  • get and update policy rules,
  • get access control groups with devices, online status, etc... ,
  • get Quality Of Service rules by devices,
  • get Smart WAN configuration (gateways list with status, load balancing / failover),
  • set Smart WAN configuration and switch WAN gateway,
  • get and set Wi-Fi configuration,
  • enable or disable a Wi-Fi radio by its SSID,
  • get wake-on-lan devices,
  • add wake-on-lan on a device,
  • wake-on-lan a device.

Installation

npm install synology-srm-nodejs-api

Usage

Disclaimer

This library lets you modify SRM's configuration. Its use is entirely at your own risk. We cannot be held responsible for any damage resulting from misuse or bugs.

SRM version

This library has been checked with SRM version 1.3.1-9346 Update 8.

Please note that future SRM updates may break its functionality, in which case please create a bug report.

Basic example

const { SrmClient } = require('synology-srm-nodejs-api')

// you need to set your own information
const baseUrl = 'https://10.0.0.1:8001'
const login = 'admin-user'
const password = 'admin-password'
let sid = null
const outputInline = false

function output (label, data) {
  if (outputInline) {
    console.log(`${label}: ${JSON.stringify(data)}`)
    return
  }
  console.log(label + ':')
  console.dir(data, { depth: null, colors: true })
}

async function main () {
  try {
    // create client
    const client = new SrmClient(baseUrl, sid, { timeout: 5000 })

    // authenticate
    if (sid === null) {
      sid = await client.authenticate(login, password)
      output('Session Id for further usage', sid)
    }

    // get WAN status
    const wanStatus = await client.getWanStatus()
    output('WAN is connected', wanStatus)

    // get WAN connection
    const wanConnection = await client.getWanConnectionStatus()
    output('WAN connection', wanConnection)

    // get devices traffic
    const traffic = await client.getTraffic('live')
    // [optionnal] add protocol label on each device/recording
    traffic
      .forEach(device => device.recs
        .forEach(record => record.protocollist
          .forEach(proto => {
            proto.label = client.getProtocolLabel(proto.protocol)
          })))
    output('Devices traffic', traffic)

    // get utilization by network
    const networkUtilization = await client.getNetworkUtilization()
    output('Utilization by network', networkUtilization)

    // get known devices
    const devices = await client.getDevices()
    output('Devices', devices)

    // get control groups
    const groups = await client.getAccessControlGroups(false)
    output('Control groups', groups)

    client.computeAccessControlGroupStatus(groups, devices)
    output('Control groups with online status and onlines devices count', groups)

    // get policy rules
    const rules = await client.getPolicyRoutes()
    output('Policy rules', rules)

    // update policy rules
    /* Commented in this sample code because it updates the configuration
    // change something in `rules` before request
    await client.setPolicyRoutes(rules)
    */

    // get Wi-Fi devices
    const wifiDevices = await client.getWifiDevices()
    output('Wi-Fi devices', wifiDevices)

    // get mesh nodes
    const meshNodes = await client.getMeshNodes()
    output('Mesh nodes', meshNodes)

    // get smart WAN gateways
    const smartWanGateways = await client.getSmartWanGateway()
    output('Smart WAN gateways', smartWanGateways)

    // get smart WAN configuration
    const smartWanConfiguration = await client.getSmartWan()
    output('Smart WAN configuration', smartWanConfiguration)

    // update smart WAN configuration
    /* Commented in this sample code because it updates the configuration
    // change something in `smartWanConfiguration` before request
    const updatedSmartWanConfiguration = await client.setSmartWan(smartWanConfiguration)
    output('Updated smart WAN gateways', updatedSmartWanConfiguration)
    */

    // switch smart WAN interfaces
    /* Commented in this sample code because it updates the configuration
    const switchedSmartWanConfiguration = await client.switchSmartWan()
    output('Updated smart WAN gateways (switch interfaces)', switchedSmartWanConfiguration)
    */

    // get wake on lan devices
    const wolDevices = await client.getWakeOnLanDevices()
    output('Wake on lan devices', wolDevices)

    // add a wake on lan device
    /* Commented in this sample code because it updates the configuration
    const mac = '00:00:00:00:00:00'
    const host = 'my-device'
    const wolDevice = await client.addWakeOnLan(mac, host)
    output('Added wake on lan device', wolDevice)
    */

    // wake on lan a device
    /* Commented in this sample code because it updates the configuration
    const mac = '00:00:00:00:00:00'
    await client.wakeOnLan(mac)
    */

    // get Quality Of Service rules by devices
    const qosRules = await client.getQos()
    output('Quality Of Service rules by devices', qosRules)

    // get Wi-Fi settings
    const wifiSettings = await client.getWifiSettings()
    output('Wi-Fi settings', wifiSettings)

    // switch Wi-Fi radio for SSID `Guests-Network`
    /* Commented in this sample code because it updates the configuration
    await client.switchWifiRadio('Guests-Network')
    */
  } catch (error) {
    output('Error during main process', error)
  }
}

main()

Versioning

synology-srm-nodejs-api is maintained under the semantic versioning guidelines.

See the releases on this repository for changelog.

License

This project is licensed under the GNU Affero General Public License v3.0 - see the LICENSE file for details