-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add commands for manipulating IPv6 host exposure settings on Arris mo…
…dems (#160) * Add host-exposure:get command for Arris modems * Add host-exposure:set command for Arris modems * Add host-exposure:(en|dis)able commands for Arris * Add topic description for `host-exposure` commands Without it, the help description just lists the description of the first subcommand in lexical order (`disable` in this case).
- Loading branch information
Showing
8 changed files
with
402 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import {Flags} from '@oclif/core' | ||
import Command from '../../base-command' | ||
import {toggleHostExposureEntries} from '../../modem/host-exposure'; | ||
|
||
export default class DisableHostExposureEntries extends Command { | ||
static description = | ||
'Disable a set of host exposure entries'; | ||
|
||
static examples = [ | ||
`$ vodafone-station-cli host-exposure:disable -p PASSWORD [ENTRY NAME | [ENTRY NAME...]]`, | ||
]; | ||
|
||
static args = [ | ||
{ | ||
name: "entries", | ||
description: 'Host exposure entries to disable. Pass no names to disable every existing entry.', | ||
required: false, | ||
} | ||
]; | ||
|
||
static flags = { | ||
password: Flags.string({ | ||
char: 'p', | ||
description: 'router/modem password', | ||
}), | ||
}; | ||
|
||
static strict = false | ||
|
||
async run(): Promise<void> { | ||
const {argv, flags} = await this.parse(DisableHostExposureEntries) | ||
|
||
const password = flags.password ?? process.env.VODAFONE_ROUTER_PASSWORD | ||
if (!password || password === '') { | ||
this.log( | ||
'You must provide a password either using -p or by setting the environment variable VODAFONE_ROUTER_PASSWORD' | ||
) | ||
this.exit() | ||
} | ||
|
||
try { | ||
await toggleHostExposureEntries(false, argv as string[], password!, this.logger) | ||
} | ||
catch (error) { | ||
this.error(error as Error, {message: 'Something went wrong.'}) | ||
} | ||
|
||
|
||
this.exit() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import {Flags} from '@oclif/core' | ||
import Command from '../../base-command' | ||
import {toggleHostExposureEntries} from '../../modem/host-exposure'; | ||
|
||
export default class EnableHostExposureEntries extends Command { | ||
static description = | ||
'Enable a set of host exposure entries'; | ||
|
||
static examples = [ | ||
`$ vodafone-station-cli host-exposure:enable -p PASSWORD [ENTRY NAME | [ENTRY NAME...]]`, | ||
]; | ||
|
||
static args = [ | ||
{ | ||
name: "entries", | ||
description: 'Host exposure entries to enable. Pass no names to enable every existing entry.', | ||
required: false, | ||
} | ||
]; | ||
|
||
static flags = { | ||
password: Flags.string({ | ||
char: 'p', | ||
description: 'router/modem password', | ||
}), | ||
}; | ||
|
||
static strict = false | ||
|
||
async run(): Promise<void> { | ||
const {argv, flags} = await this.parse(EnableHostExposureEntries) | ||
|
||
const password = flags.password ?? process.env.VODAFONE_ROUTER_PASSWORD | ||
if (!password || password === '') { | ||
this.log( | ||
'You must provide a password either using -p or by setting the environment variable VODAFONE_ROUTER_PASSWORD' | ||
) | ||
this.exit() | ||
} | ||
|
||
try { | ||
await toggleHostExposureEntries(true, argv as string[], password!, this.logger) | ||
} | ||
catch (error) { | ||
this.error(error as Error, {message: 'Something went wrong.'}) | ||
} | ||
|
||
|
||
this.exit() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import {Flags} from '@oclif/core' | ||
import Command from '../../base-command' | ||
import {discoverModemIp, ModemDiscovery} from '../../modem/discovery' | ||
import {modemFactory} from '../../modem/factory' | ||
import {Log} from '../../logger' | ||
import {HostExposureSettings} from '../../modem/modem'; | ||
|
||
|
||
export async function getHostExposureSettings(password: string, logger: Log): Promise<HostExposureSettings> { | ||
const modemIp = await discoverModemIp() | ||
const discoveredModem = await new ModemDiscovery(modemIp, logger).discover() | ||
const modem = modemFactory(discoveredModem, logger) | ||
try { | ||
await modem.login(password) | ||
const settings = await modem.getHostExposure() | ||
return settings | ||
} catch (error) { | ||
console.error('Could not get host exposure settings from modem.', error) | ||
throw error | ||
} finally { | ||
await modem.logout() | ||
} | ||
} | ||
|
||
export default class GetHostExposure extends Command { | ||
static description = | ||
'Get the current IPV6 host exposure settings'; | ||
|
||
static examples = [ | ||
`$ vodafone-station-cli host-exposure:get -p PASSWORD | ||
{JSON data} | ||
`, | ||
]; | ||
|
||
static flags = { | ||
password: Flags.string({ | ||
char: 'p', | ||
description: 'router/modem password', | ||
}), | ||
}; | ||
|
||
async run(): Promise<void> { | ||
const {flags} = await this.parse(GetHostExposure) | ||
|
||
const password = flags.password ?? process.env.VODAFONE_ROUTER_PASSWORD | ||
if (!password || password === '') { | ||
this.log( | ||
'You must provide a password either using -p or by setting the environment variable VODAFONE_ROUTER_PASSWORD' | ||
) | ||
this.exit() | ||
} | ||
try { | ||
const settings = await getHostExposureSettings(password!, this.logger) | ||
const settingsJSON = JSON.stringify(settings, undefined, 4) | ||
this.log(settingsJSON) | ||
} | ||
catch (error) { | ||
this.error(error as Error, {message: 'Something went wrong.'}) | ||
} | ||
|
||
|
||
this.exit() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import {readFile} from 'node:fs/promises' | ||
import {Flags} from '@oclif/core' | ||
import Command from '../../base-command' | ||
import {discoverModemIp, ModemDiscovery} from '../../modem/discovery' | ||
import {modemFactory} from '../../modem/factory' | ||
import {Log} from '../../logger' | ||
import {HostExposureSettings} from '../../modem/modem'; | ||
|
||
|
||
export async function setHostExposureSettings(settings: HostExposureSettings, password: string, logger: Log): Promise<HostExposureSettings> { | ||
const modemIp = await discoverModemIp() | ||
const discoveredModem = await new ModemDiscovery(modemIp, logger).discover() | ||
const modem = modemFactory(discoveredModem, logger) | ||
try { | ||
await modem.login(password) | ||
await modem.setHostExposure(settings) | ||
return settings | ||
} catch (error) { | ||
logger.error('Could not get host exposure settings from modem.', error) | ||
throw error | ||
} finally { | ||
await modem.logout() | ||
} | ||
} | ||
|
||
export default class SetHostExposure extends Command { | ||
static description = | ||
'Set the current IPV6 host exposure settings from a JSON file'; | ||
|
||
static examples = [ | ||
`$ vodafone-station-cli host-exposure:set -p PASSWORD <FILE>`, | ||
]; | ||
|
||
static args = [ | ||
{ | ||
name: "file", | ||
description: "input JSON file", | ||
required: true, | ||
} | ||
]; | ||
|
||
static flags = { | ||
password: Flags.string({ | ||
char: 'p', | ||
description: 'router/modem password', | ||
}), | ||
}; | ||
|
||
async run(): Promise<void> { | ||
const {args, flags} = await this.parse(SetHostExposure) | ||
|
||
const password = flags.password ?? process.env.VODAFONE_ROUTER_PASSWORD | ||
if (!password || password === '') { | ||
this.log( | ||
'You must provide a password either using -p or by setting the environment variable VODAFONE_ROUTER_PASSWORD' | ||
) | ||
this.exit() | ||
} | ||
try { | ||
const newSettingsJSON = await readFile(args.file, {encoding: 'utf8'}) | ||
const newSettings = JSON.parse(newSettingsJSON) as HostExposureSettings | ||
await setHostExposureSettings(newSettings, password!, this.logger) | ||
this.log("New host exposure settings set.") | ||
} | ||
catch (error) { | ||
this.error(error as Error, {message: 'Something went wrong.'}) | ||
} | ||
|
||
|
||
this.exit() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.