Skip to content

Commit

Permalink
feat: online docsis viewer (#13)
Browse files Browse the repository at this point in the history
* feat: compress docsis values for url transmition

* chore: updated readme with experimental features

* feat: add web diagnosing url to the diagnose module

* chore: rename smmwio to web-diagnose

* chore: prepare for release
  • Loading branch information
totev authored Feb 28, 2022
1 parent 5f90c1e commit 199181c
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 14 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
v1.2.3
---
- Add docsis values sharing via https://docsis-diagnose.totev.dev

**Full Changelog**: https://github.com/totev/vodafone-station-cli/compare/v1.2.2...v1.2.3

v1.2.2
---
- Respect log level
Expand Down
30 changes: 21 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Access your Arris TG3442DE or Technicolor CGA4322DE, CGA6444VF (aka Vodafone Sta
[![npm](https://img.shields.io/npm/v/vodafone-station-cli)](https://www.npmjs.com/package/vodafone-station-cli)

<!-- toc -->
* [Features](#features)
* [Demo](#demo)
* [Supported hardware](#supported-hardware)
* [Notes](#notes)
Expand All @@ -18,6 +19,15 @@ Access your Arris TG3442DE or Technicolor CGA4322DE, CGA6444VF (aka Vodafone Sta
* [Commands](#commands)
<!-- tocstop -->

# Features

* discover your vodafone station's IP in your local network
* Retrieve the current docsis connection state and transform it into JSON
* diagnose your docsis connection state to quickly detect abnormalities
* restart your vodafone station
* see your docsis connection information plotted in a web browser
* share your docsis connection information with others via URL

# Demo
<p align="center">

Expand Down Expand Up @@ -424,7 +434,7 @@ $ npm install -g vodafone-station-cli
$ vodafone-station-cli COMMAND
running command...
$ vodafone-station-cli (--version)
vodafone-station-cli/1.2.2 darwin-arm64 node-v17.5.0
vodafone-station-cli/1.2.3 darwin-arm64 node-v17.6.0
$ vodafone-station-cli --help [COMMAND]
USAGE
$ vodafone-station-cli COMMAND
Expand All @@ -445,10 +455,11 @@ Diagnose the quality of the docsis connection.

```
USAGE
$ vodafone-station-cli diagnose [-p <value>]
$ vodafone-station-cli diagnose [-p <value>] [-w]
FLAGS
-p, --password=<value> router/modem password
-w, --web review the docsis values in a webapp
DESCRIPTION
Diagnose the quality of the docsis connection.
Expand All @@ -457,7 +468,7 @@ EXAMPLES
$ vodafone-station-cli diagnose
```

_See code: [dist/commands/diagnose.ts](https://github.com/totev/vodafone-station-cli/blob/v1.2.2/dist/commands/diagnose.ts)_
_See code: [dist/commands/diagnose.ts](https://github.com/totev/vodafone-station-cli/blob/v1.2.3/dist/commands/diagnose.ts)_

## `vodafone-station-cli discover`

Expand All @@ -474,29 +485,30 @@ EXAMPLES
$ vodafone-station-cli discover
```

_See code: [dist/commands/discover.ts](https://github.com/totev/vodafone-station-cli/blob/v1.2.2/dist/commands/discover.ts)_
_See code: [dist/commands/discover.ts](https://github.com/totev/vodafone-station-cli/blob/v1.2.3/dist/commands/discover.ts)_

## `vodafone-station-cli docsis`

Get the current docsis status as reported by the modem in a JSON format.

```
USAGE
$ vodafone-station-cli docsis [-p <value>] [-f]
$ vodafone-station-cli docsis [-p <value>] [-f] [-w]
FLAGS
-f, --file write out a report file
-f, --file write out a report file under ./reports/${CURRENT_UNIX_TIMESTAMP}_docsisStatus.json
-p, --password=<value> router/modem password
-w, --web review the docsis values in a webapp
DESCRIPTION
Get the current docsis status as reported by the modem in a JSON format.
EXAMPLES
$ vodafone-station-cli docsis -p PASSWORD
JSON data
{JSON data}
```

_See code: [dist/commands/docsis.ts](https://github.com/totev/vodafone-station-cli/blob/v1.2.2/dist/commands/docsis.ts)_
_See code: [dist/commands/docsis.ts](https://github.com/totev/vodafone-station-cli/blob/v1.2.3/dist/commands/docsis.ts)_

## `vodafone-station-cli help [COMMAND]`

Expand Down Expand Up @@ -536,5 +548,5 @@ EXAMPLES
$ vodafone-station-cli restart -p PASSWORD
```

_See code: [dist/commands/restart.ts](https://github.com/totev/vodafone-station-cli/blob/v1.2.2/dist/commands/restart.ts)_
_See code: [dist/commands/restart.ts](https://github.com/totev/vodafone-station-cli/blob/v1.2.3/dist/commands/restart.ts)_
<!-- commandsstop -->
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vodafone-station-cli",
"description": "Access your Vodafone Station from the comfort of the command line.",
"version": "1.2.2",
"version": "1.2.3",
"author": "Dobroslav Totev",
"bin": {
"vodafone-station-cli": "./bin/run"
Expand Down Expand Up @@ -33,6 +33,7 @@
"@oclif/plugin-plugins": "^2.0.1",
"axios": "^0.26.0",
"axios-cookiejar-support": "^2.0.3",
"brotli": "^1.3.2",
"dotenv": "^10.0.0",
"sjcl": "^1.0.8",
"tough-cookie": "^4.0.0"
Expand Down
9 changes: 9 additions & 0 deletions src/commands/diagnose.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Flags } from '@oclif/core';
import Command from '../base-command';
import DocsisDiagnose from "../modem/docsis-diagnose";
import { webDiagnoseLink } from "../modem/web-diagnose";
import { getDocsisStatus } from "./docsis";

export default class Diagnose extends Command {
Expand All @@ -16,6 +17,10 @@ export default class Diagnose extends Command {
char: 'p',
description: 'router/modem password',
}),
web: Flags.boolean({
char: 'w',
description: 'review the docsis values in a webapp',
}),
};

async run(): Promise<void> {
Expand All @@ -39,6 +44,10 @@ export default class Diagnose extends Command {
this.log(diagnosedDocsisStatusJSON)
}

if (flags.web) {
this.log(`Review your docsis state online -> ${webDiagnoseLink(docsisStatus)}`)
}

this.log(diagnoser.printDeviationsConsole())
} catch (error) {
this.error(error as Error,{message:"Something went wrong"})
Expand Down
12 changes: 11 additions & 1 deletion src/commands/docsis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { Flags} from '@oclif/core'
import {promises as fsp} from 'fs'
import Command from '../base-command'
import {discoverModemIp, ModemDiscovery} from '../modem/discovery'
import type {DocsisStatus} from '../modem/modem'
import { DocsisStatus} from '../modem/modem'
import {modemFactory} from '../modem/factory'
import {Log } from '../logger'
import { webDiagnoseLink } from "../modem/web-diagnose"

export async function getDocsisStatus(password: string, logger:Log): Promise<DocsisStatus> {
const modemIp = await discoverModemIp()
Expand Down Expand Up @@ -41,6 +42,10 @@ export default class Docsis extends Command {
char: 'f',
description: 'write out a report file under ./reports/${CURRENT_UNIX_TIMESTAMP}_docsisStatus.json',
}),
web: Flags.boolean({
char: 'w',
description: 'review the docsis values in a webapp',
}),
};

async writeDocsisStatus(docsisStatusJson: string): Promise<void> {
Expand Down Expand Up @@ -69,6 +74,11 @@ export default class Docsis extends Command {
} else {
this.log(docsisStatusJSON)
}

if (flags.web) {
this.log(`Review your docsis state online -> ${webDiagnoseLink(docsisStatus)}`)
}

this.exit()
} catch (error) {
this.error(error as Error,{message:"Something went wrong"})
Expand Down
3 changes: 1 addition & 2 deletions src/modem/modem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,4 @@ export abstract class Modem implements GenericModem {
timeout: 30000
}))
}
}

}
13 changes: 13 additions & 0 deletions src/modem/web-diagnose.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { brotliDecompressSync } from "zlib"
import { DocsisStatus } from "./modem"
import { compressDocsisStatus } from "./web-diagnose"
import fixtureDocsisStatus from './__fixtures__/docsisStatus_normalized.json'

test('should compress json status with brotli', () => {
const status = compressDocsisStatus(fixtureDocsisStatus as DocsisStatus)
console.log(status)
const decompressed = brotliDecompressSync((Buffer.from(status, "base64url")))
const decompressedStatus = JSON.parse(decompressed.toString("utf-8"))

expect(decompressedStatus).toStrictEqual(fixtureDocsisStatus)
})
12 changes: 12 additions & 0 deletions src/modem/web-diagnose.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { DocsisStatus } from "./modem";
import { brotliCompressSync } from "zlib";

export function compressDocsisStatus(docsisStatus: DocsisStatus): string{
const json = JSON.stringify(docsisStatus)
const compressed = brotliCompressSync(Buffer.from(json, 'utf-8'))
return compressed.toString('base64url')
}

export function webDiagnoseLink(docsisStatus: DocsisStatus): string{
return `https://docsis-diagnose.totev.dev/#docsis=${compressDocsisStatus(docsisStatus)}`
}
9 changes: 8 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1518,7 +1518,7 @@ balanced-match@^1.0.0:
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee"
integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==

base64-js@^1.0.2, base64-js@^1.3.1:
base64-js@^1.0.2, base64-js@^1.1.2, base64-js@^1.3.1:
version "1.5.1"
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a"
integrity sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==
Expand Down Expand Up @@ -1576,6 +1576,13 @@ braces@^3.0.1:
dependencies:
fill-range "^7.0.1"

brotli@^1.3.2:
version "1.3.2"
resolved "https://registry.yarnpkg.com/brotli/-/brotli-1.3.2.tgz#525a9cad4fcba96475d7d388f6aecb13eed52f46"
integrity sha1-UlqcrU/LqWR119OI9q7LE+7VL0Y=
dependencies:
base64-js "^1.1.2"

browser-process-hrtime@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/browser-process-hrtime/-/browser-process-hrtime-1.0.0.tgz#3c9b4b7d782c8121e56f10106d84c0d0ffc94626"
Expand Down

0 comments on commit 199181c

Please sign in to comment.