-
-
Save akcoder/0cd5b3312fca5ca989a07078fd5e27be to your computer and use it in GitHub Desktop.
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
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