Skip to content

Instantly share code, notes, and snippets.

@akcoder
Last active June 27, 2022 21:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akcoder/0cd5b3312fca5ca989a07078fd5e27be to your computer and use it in GitHub Desktop.
Save akcoder/0cd5b3312fca5ca989a07078fd5e27be to your computer and use it in GitHub Desktop.
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);
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