vodafone-station-cli
Version:
Access your Vodafone Station from the comfort of the command line.
64 lines (63 loc) • 2.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getHostExposureSettings = getHostExposureSettings;
const tslib_1 = require("tslib");
const core_1 = require("@oclif/core");
const base_command_1 = tslib_1.__importStar(require("../../base-command"));
const discovery_1 = require("../../modem/discovery");
const factory_1 = require("../../modem/factory");
async function getHostExposureSettings(password, logger, discoveryOptions) {
const modemLocation = await (0, discovery_1.discoverModemLocation)(discoveryOptions);
const discoveredModem = await new discovery_1.ModemDiscovery(modemLocation, logger).discover();
const modem = (0, factory_1.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();
}
}
class GetHostExposure extends base_command_1.default {
static description = 'Get the current IPV6 host exposure settings';
static examples = [
`$ vodafone-station-cli host-exposure:get -p PASSWORD
{JSON data}
`,
`$ vodafone-station-cli host-exposure:get -p PASSWORD --ip 192.168.100.1
{JSON data}
`,
];
static flags = {
ip: (0, base_command_1.ipFlag)(),
password: core_1.Flags.string({
char: 'p',
description: 'router/modem password',
}),
};
async run() {
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');
return;
}
const discoveryOptions = {
ip: flags.ip,
};
try {
const settings = await getHostExposureSettings(password, this.logger, discoveryOptions);
const settingsJSON = JSON.stringify(settings, undefined, 4);
this.log(settingsJSON);
}
catch (error) {
this.error(error, { message: 'Something went wrong.' });
}
}
}
exports.default = GetHostExposure;