parseConfig rejoins the class as _parseConfig

This commit is contained in:
mmcwilliams 2018-01-01 00:38:08 -05:00
parent 40a306c9e1
commit 0b5e4c47d3
1 changed files with 24 additions and 26 deletions

View File

@ -17,31 +17,6 @@ let _entry = null
let _ssid = null
let _cb = null
//helper functions
function parseConfig (str) {
const networks = []
const lines = str.split('\n')
let network = {}
for (let line of lines) {
if (line.substring(0, 9) === 'network={') {
network = {}
network.raw = line
} else if (network.raw && line.indexOf('ssid=') !== -1) {
network.ssid = line.replace('ssid=', '').trim().replace(quoteRe, '')
if (network.raw) {
network.raw += '\n' + line
}
} else if (network.raw && line.substring(0, 1) === '}') {
network.raw += '\n' + line
networks.push(network)
network = {}
} else if (network.raw) {
network.raw += '\n' + line
}
}
return networks
}
/** Class representing the wifi features */
class Wifi {
constructor () {
@ -88,7 +63,7 @@ class Wifi {
console.error(err)
return _cb(err)
}
parsed = parseConfig(data)
parsed = this._parseConfig(data)
current = parsed.find(network => {
return network.ssid === _ssid
})
@ -144,6 +119,29 @@ class Wifi {
_cb(null, { ssid : _ssid })
_cb = () => {}
}
_parseConfig (str) {
const networks = []
const lines = str.split('\n')
let network = {}
for (let line of lines) {
if (line.substring(0, 9) === 'network={') {
network = {}
network.raw = line
} else if (network.raw && line.indexOf('ssid=') !== -1) {
network.ssid = line.replace('ssid=', '').trim().replace(quoteRe, '')
if (network.raw) {
network.raw += '\n' + line
}
} else if (network.raw && line.substring(0, 1) === '}') {
network.raw += '\n' + line
networks.push(network)
network = {}
} else if (network.raw) {
network.raw += '\n' + line
}
}
return networks
}
/**
* Create sanitized wpa_supplicant.conf stanza for
* configuring wifi without storing plaintext passwords