vodafone-station-cli
Version:
Access your Vodafone Station from the comfort of the command line.
68 lines (67 loc) • 2.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.setHostExposureSettings = setHostExposureSettings;
const tslib_1 = require("tslib");
const core_1 = require("@oclif/core");
const promises_1 = require("node:fs/promises");
const base_command_1 = tslib_1.__importStar(require("../../base-command"));
const discovery_1 = require("../../modem/discovery");
const factory_1 = require("../../modem/factory");
async function setHostExposureSettings(settings, 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);
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();
}
}
class SetHostExposure extends base_command_1.default {
static args = {
file: core_1.Args.string({
description: 'input JSON file',
required: true,
}),
};
static description = 'Set the current IPV6 host exposure settings from a JSON file';
static examples = [
'$ vodafone-station-cli host-exposure:set -p PASSWORD <FILE>',
'$ vodafone-station-cli host-exposure:set -p PASSWORD --ip 192.168.100.1 <FILE>',
];
static flags = {
ip: (0, base_command_1.ipFlag)(),
password: core_1.Flags.string({
char: 'p',
description: 'router/modem password',
}),
};
async run() {
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');
return;
}
const discoveryOptions = {
ip: flags.ip,
};
try {
const newSettingsJSON = await (0, promises_1.readFile)(args.file, { encoding: 'utf8' });
const newSettings = JSON.parse(newSettingsJSON);
await setHostExposureSettings(newSettings, password, this.logger, discoveryOptions);
this.log('New host exposure settings set.');
}
catch (error) {
this.error(error, { message: 'Something went wrong.' });
}
}
}
exports.default = SetHostExposure;