Skip to content

Instantly share code, notes, and snippets.

@akcoder
Created Oct 16, 2019
Embed
What would you like to do?
log("PortForwards");
const now = Date.now();
let provisioned = declare("Tags.UpdatePortForwards", {value: 1});
if (provisioned.value === undefined) {
log('PortForwards - PortForwards (allegedly) have been updated, returning');
return;
}
let serialNumber = declare("DeviceID.SerialNumber", {value: 1}).value[0];
let productClass = declare("DeviceID.ProductClass", {value: 1}).value[0];
let oui = declare("DeviceID.OUI", {value: 1}).value[0];
let args = {serial: serialNumber, productClass: productClass, oui: oui};
//Get the PortForwards
let portForwards = ext('cpe-config', 'portForwards', JSON.stringify(args));
if (!portForwards) {
log('PortForwards - Empty response from port forward API');
return;
}
let basePath = "InternetGatewayDevice.WANDevice.*.WANConnectionDevice.1.WANPPPConnection.*.PortMapping";
declare(basePath + ".[]", null, {path: 0});
for (let forward of portForwards) {
const path = basePath + '.[' + Object.keys(forward).map(function (key) { return key + ':' + forward[key]; }).join(',') + ']';
log("\r\n\r\nPortForwards - Updating - " + path + "\r\n\r\n", forward);
for (let key of Object.keys(forward)) {
declare(path, {path: 1}, {path: 1});
}
}
log('PortForwards - Done');
declare("Tags.UpdatePortForwards", null, {value: false});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment