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

edge-router-utils

v1.0.1

Published

Management of Ubiquity UniFy EdgeRouter

Downloads

3

Readme

edge-router-utils

Management of Ubiquity UniFy EdgeRouter. Module extends SSH2Promise class, and adds few methods specific for working with EdgeRouters.

Installation

npm install edge-router-utils

Configuring router

  1. Log into your EdgeRouter console:
  • either click CLI icon in topright of GUI window
  • or use your existing SSH/Telnet connection
  1. Generate authentication key pair for accessing router and add public key for authorisation:
cd /tmp
ssh-keygen -t rsa -b 4096 -C "edge-router-utils" -N "" -f auth.key
configure
set system login user edge-router-utils authentication plaintext-password `head -2 auth.key | tail -1`
set system login user edge-router-utils authentication public-keys edge-router-utils type ssh-rsa
set system login user edge-router-utils authentication public-keys edge-router-utils key `sed -E "s/ssh-rsa ([^[:space:]]+).*/\1/" auth.key.pub`
set system login user edge-router-utils level admin
commit
save
exit
  1. Copy content of your private key /tmp/auth.key and save it on your local computer in auth.key file somewhere on your system, usually close to your NodeJS script:
cat /tmp/auth.key
  1. Optionally copy also content of your public key /tmp/auth.key.pub and save it on your local computer in auth.key.pub file somewhere on your system, usually close to your NodeJS script:
/tmp/auth.key.pub
  1. Delete the key pair from router:
rm /tmp/auth.key*

Note: If you already have key pair, you could also use following command to copy private key for authorisation easily on Mac and Linux:

ssh-copy-id -i auth.key -o PreferredAuthentications=password -o PubkeyAuthentication=no edge_username@edge_ip_address

Usage

'use strict'
const EdgeRouter = require('edge-router-utils')
const CONNECTION = {
  host: '192.168.0.1',
  username: 'admin',
  identity: '/path/to/auth.key',
}
async function run(){
  const router = new EdgeRouter(CONNECTION)
  try{
    await router.connect()
    console.log('DHCP:', await router.dhcp())
    console.log('DNS:', await router.dns())
  }catch(e){
    console.error('Error:',e.message)
  }
  try{ await router.close() }catch(e){}
}
run()

API

require('edge-router-utils')

Key methods derived from SSH2Promise

Note: these are described for convenience only and the description is only partial. Consult SSH2Promise for all details and additional methods available.

constructor(< array >|< object >sshConfig, < (Promise) >disableCache)

Creates and returns a new SSH2Promise instance. Single or multiple sshconfigs can be passed. sshConfig passed to SSH2Promise is aligned to ssh2 library. It has few extra options other than ssh2 configuration.

  • host - string - Hostname or IP address of the server. Default: 'localhost'

  • port - integer - Port number of the server. Default: 22

  • username - string - Username for authentication. Default: (none)

  • password - string - Password for password-based user authentication. Default: (none)

  • privateKey - mixed - Buffer or string that contains a private key for either key-based or hostbased user authentication (OpenSSH format). Default: (none)

  • passphrase - string - For an encrypted private key, this is the passphrase used to decrypt it. Default: (none)

  • identity - to directly pass the path of private key file.

close() - (Promise)

Close the sshconnection and associated tunnels.

Added methods specific for edge-router-utils

loadConfig(< boolean >reload) - (Promise)

Loads EdgeRouter configuration to local cache for other methods. If already loaded, cached version will be returnned unless reload parameter is true. Usually not needed to be called, as other methods call it themselves automatically.

dhcp() - (Promise)

Returns EdgeRouter DHCP clients. It automatically calls this.loadConfig() if config has not been loaded. Returned resolved promise is a hash in a form below:

{
  '192.168.1.4': { mac: '12:34:56:78:9a:bc', host: 'my-laptop', static: 1 },
  '192.168.1.5': { mac: '34:56:78:9a:bc:12', host: 'my-desktop', static: 1 },
  '192.168.1.101': { mac: '56:78:9a:bc:12:34', host: '' }
}

Property static indicates this is a static assignment of IP address, otherwise it is dynamic lease.

dns() - (Promise)

Returns EdgeRouter static DNS records. It automatically calls this.loadConfig() if config has not been loaded. Returned resolved promise is a hash in a form below:

{
  '192.168.1.4': [ 'my-laptop', 'my-laptop-alias' },
  '192.168.1.5': { 'my-desktop' }
}

First item in array is configured hostname, all others are configured aliases for this hostname.