npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

synology-srm-nodejs-api

v1.2.0

Published

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

Downloads

14

Readme

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