Description:
This script, assigned to a network, overrides a specific WiFi networks SSID and Preshared Key with the variables
context.vars.SSID
context.vars.WPAKey
The selected WiFi that will be overridden is SSID_TO_CHANGE
.
List of used variables:
Variable | Description |
---|---|
Add-in code:
/** // Step 1: obtain _single_ ssid reference var ssid = context.network.ssids["SSID_TO_CHANGE"]; if (!ssid) { config.abort("SSID missing"); } if (!context.vars.SSID) { config.abort("variable SSID not set"); } if (!context.vars.WPAKey) { config.abort("variable WPAKey not set"); } // Step 2: collect iface numbers var ifcNumbers = []; for (var i = 0; i < ssid.ifcNumber.length; i++) { ifcNumbers.push(ssid.ifcNumber[i]); } // Step 3: change wifi/pass using collected iface numbers var wlantable = config.getTableByOid("1.2.23.20.1"); var encrtable = config.getTableByOid("1.2.23.20.3"); for (var i = 0; i < ifcNumbers.length; i++) { var rowWlan = wlantable.getFirstRowByOid("1", ifcNumbers[i]); if (rowWlan) { rowWlan.setByOid("2", context.vars.SSID); wlantable.addOrMerge(rowWlan); } var rowEncr = encrtable.getFirstRowByOid("1", ifcNumbers[i]); if (rowEncr) { rowEncr.setByOid("6", "" + context.vars.WPAKey); encrtable.addOrMerge(rowEncr); } } }; |
---|
Add-in as JSON file: