Try putting this line first:
declare('InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.PortMapping.[]', null, {path: 0});
This tells GenieACS to clear out any existing port mappings and just add the given one (if it doesn’t exist).
This is part of the script I use to manage port mappings. It takes in an array of objects. In production, this provision script makes a http call to our subscriber management server to get the values.
To call it, use something like this in your provision script:
const pf = [
{
ExternalPort:555,
ExternalPortEndRange:555,
InternalClient:"192.168.1.111",
InternalPort:55,
InternalPortEndRange:55,
PortMappingDescription:"port forward 1 - 555"
},
{
ExternalPort:8080,
ExternalPortEndRange:8080,
InternalClient:"192.168.1.111",
InternalPort:80,
InternalPortEndRange:80,
PortMappingDescription:"port forward 2 - 8080"
},
];
updatePortForwards(pf);
function updatePortForwards(portForwards)
{
let keys = [
'InternetGatewayDevice.WANDevice.*.WANConnectionDevice.*.WANPPPConnection.*.PortMapping',
'Device.NAT.PortMapping'
];
for (let basePath of keys) {
declare(basePath + '.[]', null, {path: 0});
for (let forward of portForwards) {
const path = basePath + '.[' + Object.keys(forward).map(key => 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');
}