UNPKG

vodafone-station-cli

Version:

Access your Vodafone Station from the comfort of the command line.

50 lines (49 loc) 2.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.extractCryptoVars = extractCryptoVars; exports.extractFirmwareVersion = extractFirmwareVersion; exports.extractDocsisStatus = extractDocsisStatus; exports.extractCredentialString = extractCredentialString; const nonceMatcher = /var csp_nonce = "(?<nonce>.*?)";/gm; const ivMatcher = /var myIv = ["|'](?<iv>.*?)["|'];/gm; const saltMatcher = /var mySalt = ["|'](?<salt>.*?)["|'];/gm; const sessionIdMatcher = /var currentSessionId = ["|'](?<sessionId>.*?)["|'];/gm; const swVersionMatcher = /_ga.swVersion = ["|'](?<swVersion>.*?)["|'];/gm; function extractCryptoVars(html) { const nonce = nonceMatcher.exec(html)?.groups?.nonce; const iv = ivMatcher.exec(html)?.groups?.iv; const salt = saltMatcher.exec(html)?.groups?.salt; const sessionId = sessionIdMatcher.exec(html)?.groups?.sessionId; return { iv, nonce, salt, sessionId, }; } function extractFirmwareVersion(html) { return swVersionMatcher.exec(html)?.groups?.swVersion; } function extractDocsisStatus(html, date = new Date()) { const docsisMatcher = { dsChannels: /js_dsNums = ["|'](?<dsChannels>.*?)["|'];/gm, dsData: /json_dsData = (?<dsData>.*?);/gm, ofdmChannels: /js_ofdmNums = ["|'](?<ofdmChannels>.*?)["|'];/gm, usChannels: /js_usNums = ["|'](?<usChannels>.*?)["|'];/gm, usData: /json_usData = (?<usData>.*?);/gm, }; const downstream = docsisMatcher.dsData.exec(html)?.groups?.dsData ?? '[]'; const upstream = docsisMatcher.usData.exec(html)?.groups?.usData ?? '[]'; const downstreamChannels = docsisMatcher.dsChannels.exec(html)?.groups?.dsChannels ?? '0'; const upstreamChannels = docsisMatcher.usChannels.exec(html)?.groups?.usChannels ?? '0'; const ofdmChannels = docsisMatcher.ofdmChannels.exec(html)?.groups?.ofdmChannels ?? '0'; return { downstream: JSON.parse(downstream), downstreamChannels: Number.parseInt(downstreamChannels, 10), ofdmChannels: Number.parseInt(ofdmChannels, 10), time: date.toISOString(), upstream: JSON.parse(upstream), upstreamChannels: Number.parseInt(upstreamChannels, 10), }; } function extractCredentialString(html) { const matcher = /createCookie\([\n]*\s*"credential"\s*,[\n]*\s*["|'](?<credential>.*?)["|']\s*/gims; return matcher.exec(html)?.groups?.credential ?? ''; }