Refactoring provisioning script

Hi there! Hope it finds you well.

My VMis struggling to keep itself alive duo to constant overuse of it’s resources, such as RAM and Processor usage.

Any tips on how to improve this Provisioning script? Note that i made it out knowing nothing of javascript and i understand that there are way too many adjusts that need to be done, but, i don’t recognize them.

// Configs Checker ONTs Only \\
const now = Date.now();
const provisionado = declare("Tags.Provisionado", { value: 1 })?.value?.[0];
const bootstrap = args[0];
log(`provisionado: ${provisionado} || bootstrap: ${bootstrap}`);

if (provisionado && !bootstrap) {
  //Bind LAN1-LAN4 to WAN
  declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANPPPConnection.1.X_HW_LANBIND.Lan1Enable", { value: now }, { value: 1 });
  declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANPPPConnection.1.X_HW_LANBIND.Lan2Enable", { value: now }, { value: 1 });
  declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANPPPConnection.1.X_HW_LANBIND.Lan3Enable", { value: now }, { value: 1 });
  declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANPPPConnection.1.X_HW_LANBIND.Lan4Enable", { value: now }, { value: 1 });
  declare("InternetGatewayDevice.Layer3Forwarding.X_HW_policy_route.2.PhyPortName", { value: now }, { value: "LAN1,LAN2,LAN3,LAN4,SSID1,SSID5" });
  declare("InternetGatewayDevice.X_HW_Security.AclServices.AccessControl.List.*.ServicePort", { value: now }, { value: "HTTP,ICMP" });

  log("CPE está (supostamente) configurada, retornando...");
  return;
}

let username;

declare("InternetGatewayDevice", { value: now });
declare("InternetGatewayDevice.*", { value: now });
declare("InternetGatewayDevice.WANDevice.*", { value: now });
declare("InternetGatewayDevice.WANDevice.*.WANConnectionDevice.*", { value: now });

log("[1]");
refreshWlan();
log("[2]")
checkWAN();
log("[3]");
setupAdditionalConfigs();
updateTags();

log('>> Reiniciando CPE para finalizar configuração...');
declare("Reboot", null, { value: now });

function updateTags() {
  declare("Tags.Provisionado", null, { value: true });
}

function refreshWlan() {
  log('>> Refreshing WLAN...');
  declare("InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.*", { value: now });
  declare("InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.Enable", { value: now }, { value: true });
  declare("InternetGatewayDevice.LANDevice.1.WLANConfiguration.5.*", { value: now });
  declare("InternetGatewayDevice.LANDevice.1.WLANConfiguration.5.Enable", { value: now }, { value: true });
  declare("InternetGatewayDevice.LANDevice.1.WLANConfiguration.*.SSID", { value: now });
  declare("InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.X_HW_AttachConf.X_HW_AirtimeFairness", { value: now }, { value: true });
  declare("InternetGatewayDevice.LANDevice.1.WLANConfiguration.5.X_HW_AttachConf.X_HW_AirtimeFairness", { value: now }, { value: true });
}

function checkWAN() {
  declare("InternetGatewayDevice.WANDevice.*.WANConnectionDevice.*", { value: now });
  const nameWan1 = getWANName(1);
  const nameWan2 = getWANName(2);
  const nameWan3 = getWANName(3);

  if (!nameWan1 && !nameWan2) {
    setupBaseWanPppConnection(true, 1);
  } else if (nameWan1 && nameWan1.includes("internet")) {
    setupBaseWanPppConnection(false, 1);
  } else if (nameWan2 && nameWan2.includes("internet")) {
    setupBaseWanPppConnection(false, 2);
  } else if (nameWan3 && nameWan3.includes("internet")) {
    setupBaseWanPppConnection(false, 3);
  }
}

function getWANName(connectionDeviceNumber) {
  const name = declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${connectionDeviceNumber}.WANPPPConnection.1.Name`, { value: now })?.value?.[0];
  return name ? name.toLowerCase() : null;
}

function setupBaseWanPppConnection(createWan, WANConnectionDevicePATH) {

  if (createWan == true) {
    //Garantir que temos a instância WanPPPConnection
    const serial = declare('DeviceID.SerialNumber', { value: 1 }).value[0];
    const pppoe = ext("cpe-config", "GetPPPoE", serial);

    log('>> Criando instância WANPPPConnection...');
    declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANPPPConnection.*", null, { path: 1 });
    declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANPPPConnection.1.Username`, { value: now }, { value: pppoe.username });
    declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANPPPConnection.1.Password`, { value: now }, { value: pppoe.password });
  }

  //Common WanPPPConnection
  log('>> Atualizando valores WANPPP Base...');
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.*`, { value: now }); //Atualizar parâmetros
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.Enable`, { value: now }, { value: true });
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.MaxMTUSize`, { value: now }, { value: "1492" })
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.MaxMRUSize`, { value: now }, { value: "1492" });
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.CurrentMRUSize`, { value: now }, { value: "1492" });
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.DNSEnabled`, { value: now }, { value: true });
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.NATEnabled`, { value: now }, { value: true });
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.DNSServers`, { value: now });
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.Username`, { value: now });
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.Password`, { value: now });
  username = declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.Username`, { value: 1 }).value[0];

  //Huawei Ax2/Ax2S
  declare(`InternetGatewayDevice.WANDevice.1.WANCommonInterfaceConfig.EnabledForInternet`, { value: now }, { value: true });
  declare(`InternetGatewayDevice.WANDevice.1.WANCommonInterfaceConfig.WANAccessType`, { value: now }, { value: "Ethernet" });

  //Huawei EG8145X6/EG8145X6-10
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.X_HW_VLAN`, { value: now }, { value: 10 });
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.X_HW_NatType`, { value: now });
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.X_HW_NatType`, { value: now }, { value: 0 });
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.X_HW_IPv6Enable`, { value: now }, { value: true });
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.X_HW_IPv6.IPv6Address.[]`, { value: now }, { path: 0 }); // LIMPANDO ENTRADAS
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.X_HW_IPv6.IPv6Prefix.[]`, { value: now }, { path: 0 }); // LIMPANDO ENTRADAS  
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.X_HW_IPv6.IPv6Address.[]`, { value: now }, { path: 1 });
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.X_HW_IPv6.IPv6Address.1.Origin`, { value: now });
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.X_HW_IPv6.IPv6Address.1.Origin`, { value: now }, { value: "AutoConfigured" });
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.X_HW_IPv6.IPv6Prefix.[]`, { value: now }, { path: 1 });
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.X_HW_IPv6.IPv6Prefix.1.Origin`, { value: now });
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.X_HW_IPv6.IPv6Prefix.1.Origin`, { value: now }, { value: "PrefixDelegation" });
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.X_HW_LANBIND.*`, { value: now });
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.X_HW_LANBIND.SSID1Enable`, { value: now }, { value: 1 });
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.X_HW_LANBIND.SSID5Enable`, { value: now }, { value: 1 });
}

function setupAdditionalConfigs() {
  log('>> Finalizando configurações adicionais...');
  declare("InternetGatewayDevice.1", { value: now });
  declare("InternetGatewayDevice.*", { value: now });

  //Huawei ONT Ax6/Ax6-10
  declare("InternetGatewayDevice.X_HW_MainUPnP.Enable", { value: now }, { value: true });
  declare("InternetGatewayDevice.X_HW_SlvUPnP.Enable", { value: now }, { value: true });
  declare("InternetGatewayDevice.X_HW_Security.*", { value: now });
  declare("InternetGatewayDevice.X_HW_Security.*.*", { value: now });
  declare("InternetGatewayDevice.X_HW_Security.AclServices.AccessControl", { value: now });
  declare("InternetGatewayDevice.X_HW_Security.AclServices.AccessControl.*", { value: now });
  declare("InternetGatewayDevice.X_HW_Security.AclServices.AccessControl.AccessControlListEnable", { value: now }, { value: true });
  declare("InternetGatewayDevice.X_HW_Security.AclServices.AccessControl.AccessControlListNumberOfEntries", { value: now }, { value: 1 });
  declare("InternetGatewayDevice.X_HW_Security.AclServices.AccessControl.List", { value: now });
  declare("InternetGatewayDevice.X_HW_Security.AclServices.AccessControl.List.*", null, { path: 1 });
  declare("InternetGatewayDevice.X_HW_Security.AclServices.AccessControl.List.*.*", { value: now });
  declare("InternetGatewayDevice.X_HW_Security.AclServices.AccessControl.List.*.Mode", { value: now }, { value: 0 });
  declare("InternetGatewayDevice.X_HW_Security.AclServices.AccessControl.List.*.Priority", { value: now }, { value: 1 });
  declare("InternetGatewayDevice.X_HW_Security.AclServices.HTTPLanEnable", { value: now }, { value: true });
  declare("InternetGatewayDevice.X_HW_Security.AclServices.HTTPSLanEnable", { value: now }, { value: true });
  declare("InternetGatewayDevice.X_HW_Security.AclServices.SamBaLanEnable", { value: now }, { value: true });
  declare("InternetGatewayDevice.X_HW_Security.AclServices.WanAccess", { value: now });
  declare("InternetGatewayDevice.X_HW_Security.AclServices.WanAccess.*", null, { path: 1 });
  declare("InternetGatewayDevice.X_HW_Security.AclServices.WanAccess.*", { value: now });
  declare("InternetGatewayDevice.X_HW_Security.AclServices.WanAccess.*.*", { value: now });
  declare("InternetGatewayDevice.X_HW_Security.AclServices.WanAccess.1.Enable", { value: now }, { value: 1 });
  declare("InternetGatewayDevice.X_HW_Security.AclServices.AccessControl.List.*.ServicePort", { value: now }, { value: "HTTP,ICMP" });
  declare("InternetGatewayDevice.X_HW_Security.AclServices.AccessControl.List.*.SrcIp", { value: now }, { value: "0.0.0.0-0.0.0.0" });
  declare("InternetGatewayDevice.X_HW_Security.AclServices.AccessControl.List.*.SrcPortName", { value: now }, { value: "ALL" });
  declare("InternetGatewayDevice.X_HW_Security.AclServices.AccessControl.List.*.SrcPortType", { value: now }, { value: 2 });
  declare("InternetGatewayDevice.X_HW_AppRemoteManage.CurrentMgtURL", { value: now }, { value: "br-cloud.openlife.huawei.com" });
  declare("InternetGatewayDevice.X_HW_AppRemoteManage.CurrentPort", { value: now }, { value: "9002" });
  declare("InternetGatewayDevice.X_HW_AppRemoteManage.PhoneAppURL", { value: now }, { value: "br-cloud.openlife.huawei.com" });
  declare("InternetGatewayDevice.LANDevice.*", null, { path: 1 });
  declare("InternetGatewayDevice.LANDevice.*", { value: now });
  declare("InternetGatewayDevice.LANDevice.1.LANEthernetInterfaceConfig.*", null, { path: 4 });
  declare("InternetGatewayDevice.LANDevice.1.LANEthernetInterfaceConfig.*.X_HW_L3Enable", { value: now }, { value: true });
  declare("InternetGatewayDevice.Time.*", { value: now });
  declare("InternetGatewayDevice.Time.Enable", { value: now }, { value: true });
  declare("InternetGatewayDevice.Time.LocalTimeZone", { value: now }, { value: "-03:00" })
  declare("InternetGatewayDevice.Time.LocalTimeZoneName", { value: now }, { value: "Brasilia" })
  declare("InternetGatewayDevice.Time.NTPServer1", { value: now }, { value: "clock.fmt.he.net" });
  declare("InternetGatewayDevice.Time.NTPServer2", { value: now }, { value: "time.windows.com" });
  declare("InternetGatewayDevice.Time.X_HW_SynInterval", { value: now }, { value: "3600" });
  declare("InternetGatewayDevice.UserInterface.*", { value: now });
  declare("InternetGatewayDevice.UserInterface.X_HW_WebUserInfo.*", { value: now });
  declare("InternetGatewayDevice.UserInterface.X_HW_WebUserInfo.*.*", { value: now });
  declare("InternetGatewayDevice.UserInterface.X_HW_WebUserInfo.*.Enable", { value: now }, { value: true });
  declare("InternetGatewayDevice.X_HW_Security.Firewall.Enable", {value: now}, {value: true});
  
  const senhaONT = ext("cpe-config", "GetONTPassword", username);
  log(`>> Senha WebUser admin: ${senhaONT}`);

  declare("InternetGatewayDevice.UserInterface.X_HW_WebUserInfo.*", { value: now });
  declare("InternetGatewayDevice.UserInterface.X_HW_WebUserInfo.*.*", { value: now });
  declare("InternetGatewayDevice.UserInterface.X_HW_WebUserInfo.*.Enable", { value: now }, { value: true });
  declare("InternetGatewayDevice.UserInterface.X_HW_WebUserInfo.*.*", { value: now });
  declare("InternetGatewayDevice.UserInterface.X_HW_WebUserInfo.2.Password", { value: 1 }, { value: senhaONT });
}

Thanks in advance!

Remove these lines, its causing a lot of extra work that unnecessary.

declare("InternetGatewayDevice", { value: now });
declare("InternetGatewayDevice.*", { value: now });
declare("InternetGatewayDevice.WANDevice.*", { value: now });
declare("InternetGatewayDevice.WANDevice.*.WANConnectionDevice.*", { value: now });

...
    declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.*`, { value: now }); //Atualizar parâmetros
    declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.X_HW_LANBIND.*`, { value: now });

...

    declare("InternetGatewayDevice.1", { value: now });
    declare("InternetGatewayDevice.*", { value: now });

...
    declare("InternetGatewayDevice.X_HW_Security.*", { value: now });
    declare("InternetGatewayDevice.X_HW_Security.*.*", { value: now });
    declare("InternetGatewayDevice.X_HW_Security.AclServices.AccessControl", { value: now });
    declare("InternetGatewayDevice.X_HW_Security.AclServices.AccessControl.*", { value: now });
    declare("InternetGatewayDevice.X_HW_Security.AclServices.AccessControl.List.*.*", { value: now });
    declare("InternetGatewayDevice.X_HW_Security.AclServices.WanAccess.*", { value: now });
    declare("InternetGatewayDevice.X_HW_Security.AclServices.WanAccess.*.*", { value: now });

    declare("InternetGatewayDevice.LANDevice.*", null, { path: 1 });
    declare("InternetGatewayDevice.LANDevice.*", { value: now });
    declare("InternetGatewayDevice.Time.*", { value: now });
    declare("InternetGatewayDevice.UserInterface.*", { value: now });
    declare("InternetGatewayDevice.UserInterface.X_HW_WebUserInfo.*", { value: now });
    declare("InternetGatewayDevice.UserInterface.X_HW_WebUserInfo.*.*", { value: now });

...
    declare("InternetGatewayDevice.UserInterface.X_HW_WebUserInfo.*", { value: now });
    declare("InternetGatewayDevice.UserInterface.X_HW_WebUserInfo.*.*", { value: now });
    declare("InternetGatewayDevice.UserInterface.X_HW_WebUserInfo.*.*", { value: now });

HI, Akcoder! Thanks for replying.

Thank you so much! I even changed a bit of it’s logic to improve a little bit the semantic of it all, since i’m a little more used to javascript. Turned out like this:

// Configs Checker ONTs Only \\

const now = Date.now();
const provisionado = declare("Tags.Provisionado", { value: 1 })?.value?.[0];
const bootstrap = args[0];
log(`provisionado: ${provisionado} || bootstrap: ${bootstrap}`);

if (provisionado && !bootstrap) {
  bindLANToWAN();
  log("CPE está (supostamente) configurada, retornando...");
  return;
}

const serial = declare('DeviceID.SerialNumber', { value: 1 }).value[0];
const pppoe = ext("cpe-config", "GetPPPoE", serial);

log("[1]");
refreshWlan();
log("[2]");
checkWAN();
log("[3]");
setupAdditionalConfigs();
updateTags();

log('>> Reiniciando CPE para finalizar configuração...');
declare("Reboot", null, { value: now });

function updateTags() {
  declare("Tags.Provisionado", null, { value: true });
}

function refreshWlan() {
  log('>> Refreshing WLAN...');
  declareWLANConfiguration(1);
  declareWLANConfiguration(5);
}

function checkWAN() {
  const wanNames = [1, 2, 3].map(getWANName);

  if (!wanNames[0] && !wanNames[1]) {
    setupBaseWanPppConnection(true, 1);
  } else {
    for (let i = 0; i < wanNames.length; i++) {
      if (wanNames[i] && wanNames[i].includes("internet")) {
        setupBaseWanPppConnection(false, i + 1);
        break;
      }
    }
  }
}

function getWANName(connectionDeviceNumber) {
  const name = declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${connectionDeviceNumber}.WANPPPConnection.1.Name`, { value: now })?.value?.[0];
  return name ? name.toLowerCase() : null;
}

function setupBaseWanPppConnection(createWan, WANConnectionDevicePATH) {
  if (createWan) {
    log('>> Criando instância WANPPPConnection...');
    declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANPPPConnection.*", null, { path: 1 });
  } 
  declareWanPppConnection(WANConnectionDevicePATH, pppoe.username, pppoe.password);

  // Configurações adicionais para dispositivos Huawei
  huaweiOntX6AdditionalConfigs(WANConnectionDevicePATH);
}

function declareWanPppConnection(WANConnectionDevicePATH, username, password) {
  log('>> Atualizando valores WANPPP Base...');
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.Enable`, { value: now }, { value: true });
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.MaxMTUSize`, { value: now }, { value: "1492" });
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.MaxMRUSize`, { value: now }, { value: "1492" });
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.CurrentMRUSize`, { value: now }, { value: "1492" });
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.DNSEnabled`, { value: now }, { value: true });
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.NATEnabled`, { value: now }, { value: true });
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.DNSServers`, { value: now });
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.Username`, { value: now }, { value: username });
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.Password`, { value: now }, { value: password });
  
}

function huaweiOntX6AdditionalConfigs(WANConnectionDevicePATH) {
  declare(`InternetGatewayDevice.WANDevice.1.WANCommonInterfaceConfig.EnabledForInternet`, { value: now }, { value: true });
  declare(`InternetGatewayDevice.WANDevice.1.WANCommonInterfaceConfig.WANAccessType`, { value: now }, { value: "Ethernet" });
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.X_HW_VLAN`, { value: now }, { value: 10 });
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.X_HW_NatType`, { value: now }, { value: 0 });
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.X_HW_IPv6Enable`, { value: now }, { value: true });
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.X_HW_IPv6.IPv6Address.[]`, { value: now }, { path: 0 });
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.X_HW_IPv6.IPv6Prefix.[]`, { value: now }, { path: 0 });
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.X_HW_IPv6.IPv6Address.[]`, { value: now }, { path: 1 });
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.X_HW_IPv6.IPv6Address.1.Origin`, { value: now }, { value: "AutoConfigured" });
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.X_HW_IPv6.IPv6Prefix.[]`, { value: now }, { path: 1 });
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.X_HW_IPv6.IPv6Prefix.1.Origin`, { value: now }, { value: "PrefixDelegation" });
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.X_HW_LANBIND.SSID1Enable`, { value: now }, { value: 1 });
  declare(`InternetGatewayDevice.WANDevice.1.WANConnectionDevice.${WANConnectionDevicePATH}.WANPPPConnection.1.X_HW_LANBIND.SSID5Enable`, { value: now }, { value: 1 });
}

function setupAdditionalConfigs() {
  log('>> Finalizando configurações adicionais...');

  declare("InternetGatewayDevice.X_HW_MainUPnP.Enable", { value: now }, { value: true });
  declare("InternetGatewayDevice.X_HW_SlvUPnP.Enable", { value: now }, { value: true });
  declare("InternetGatewayDevice.X_HW_Security.AclServices.AccessControl.AccessControlListEnable", { value: now }, { value: true });
  declare("InternetGatewayDevice.X_HW_Security.AclServices.AccessControl.AccessControlListNumberOfEntries", { value: now }, { value: 1 });
  declare("InternetGatewayDevice.X_HW_Security.AclServices.AccessControl.List", { value: now });
  declare("InternetGatewayDevice.X_HW_Security.AclServices.AccessControl.List.*", null, { path: 1 });
  declare("InternetGatewayDevice.X_HW_Security.AclServices.AccessControl.List.*.Mode", { value: now }, { value: 0 });
  declare("InternetGatewayDevice.X_HW_Security.AclServices.AccessControl.List.*.Priority", { value: now }, { value: 1 });
  declare("InternetGatewayDevice.X_HW_Security.AclServices.HTTPLanEnable", { value: now }, { value: true });
  declare("InternetGatewayDevice.X_HW_Security.AclServices.HTTPSLanEnable", { value: now }, { value: true });
  declare("InternetGatewayDevice.X_HW_Security.AclServices.SamBaLanEnable", { value: now }, { value: true });
  declare("InternetGatewayDevice.X_HW_Security.AclServices.WanAccess", { value: now });
  declare("InternetGatewayDevice.X_HW_Security.AclServices.WanAccess.*", null, { path: 1 });
  declare("InternetGatewayDevice.X_HW_Security.AclServices.WanAccess.1.Enable", { value: now }, { value: 1 });
  declare("InternetGatewayDevice.X_HW_Security.AclServices.AccessControl.List.*.ServicePort", { value: now }, { value: "HTTP,ICMP" });
  declare("InternetGatewayDevice.X_HW_Security.AclServices.AccessControl.List.*.SrcIp", { value: now }, { value: "0.0.0.0-0.0.0.0" });
  declare("InternetGatewayDevice.X_HW_Security.AclServices.AccessControl.List.*.SrcPortName", { value: now }, { value: "ALL" });
  declare("InternetGatewayDevice.X_HW_Security.AclServices.AccessControl.List.*.SrcPortType", { value: now }, { value: 2 });
  declare("InternetGatewayDevice.X_HW_AppRemoteManage.CurrentMgtURL", { value: now }, { value: "br-cloud.openlife.huawei.com" });
  declare("InternetGatewayDevice.X_HW_AppRemoteManage.CurrentPort", { value: now }, { value: "9002" });
  declare("InternetGatewayDevice.X_HW_AppRemoteManage.PhoneAppURL", { value: now }, { value: "br-cloud.openlife.huawei.com" });
  declare("InternetGatewayDevice.LANDevice.1.LANEthernetInterfaceConfig.*", null, { path: 4 });
  declare("InternetGatewayDevice.LANDevice.1.LANEthernetInterfaceConfig.*.X_HW_L3Enable", { value: now }, { value: true });
  declare("InternetGatewayDevice.Time.Enable", { value: now }, { value: true });
  declare("InternetGatewayDevice.Time.LocalTimeZone", { value: now }, { value: "-03:00" });
  declare("InternetGatewayDevice.Time.LocalTimeZoneName", { value: now }, { value: "Brasilia" });
  declare("InternetGatewayDevice.Time.NTPServer1", { value: now }, { value: "clock.fmt.he.net" });
  declare("InternetGatewayDevice.Time.NTPServer2", { value: now }, { value: "time.windows.com" });
  declare("InternetGatewayDevice.Time.X_HW_SynInterval", { value: now }, { value: "3600" });
  declare("InternetGatewayDevice.X_HW_Security.Firewall.Enable", { value: now }, { value: true });

  const ont = ext("cpe-config", "GetONTPassword", pppoe.username);
  declare("InternetGatewayDevice.UserInterface.X_HW_WebUserInfo.*.Enable", { value: now }, { value: true });
  declare("InternetGatewayDevice.UserInterface.X_HW_WebUserInfo.2.Password", { value: 1 }, { value: ont.password });
}


function bindLANToWAN() {
  declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANPPPConnection.1.X_HW_LANBIND.Lan1Enable", { value: now }, { value: 1 });
  declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANPPPConnection.1.X_HW_LANBIND.Lan2Enable", { value: now }, { value: 1 });
  declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANPPPConnection.1.X_HW_LANBIND.Lan3Enable", { value: now }, { value: 1 });
  declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANPPPConnection.1.X_HW_LANBIND.Lan4Enable", { value: now }, { value: 1 });
  declare("InternetGatewayDevice.Layer3Forwarding.X_HW_policy_route.2.PhyPortName", { value: now }, { value: "LAN1,LAN2,LAN3,LAN4,SSID1,SSID5" });
  declare("InternetGatewayDevice.X_HW_Security.AclServices.AccessControl.List.*.ServicePort", { value: now }, { value: "HTTP,ICMP" });
}

function declareWLANConfiguration(configNumber) {
  declare(`InternetGatewayDevice.LANDevice.1.WLANConfiguration.${configNumber}.*`, { value: now });
  declare(`InternetGatewayDevice.LANDevice.1.WLANConfiguration.${configNumber}.Enable`, { value: now }, { value: true });
  declare(`InternetGatewayDevice.LANDevice.1.WLANConfiguration.${configNumber}.X_HW_AttachConf.X_HW_AirtimeFairness`, { value: now }, { value: true });
}