diff --git a/lib/wifi/index.js b/lib/wifi/index.js index 8f1c4b3..7b643d7 100644 --- a/lib/wifi/index.js +++ b/lib/wifi/index.js @@ -17,6 +17,31 @@ 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.indexOf('network={') !== -1) { + network = {} + network.raw = line + } else if (line.indexOf('ssid=') !== -1) { + network.ssid = line.replace('ssid=', '').trim().replace(quoteRe, '') + if (network.raw) { + network.raw += '\n' + line + } + } else if (line.indexOf('}') !== -1) { + network.raw += '\n' + line + networks.push(network) + network = {} + } else if (network.ssid) { + network.raw += '\n' + line + } + } + return networks +} + /** Class representing the wifi features */ class Wifi { constructor () { @@ -63,7 +88,7 @@ class Wifi { return _cb(err) } - parsed = this._parseConfig(data) + parsed = parseConfig(data) console.dir(parsed) console.log(data) console.log(data.search(networkPattern)) @@ -122,29 +147,6 @@ class Wifi { //this._callback(null, { ssid : ssid, pwd : pwd.length }) _cb = () => {} } - _parseConfig (str) { - const networks = [] - const lines = str.split('\n') - let network = {} - for (let line of lines) { - if (line.indexOf('network={') !== -1) { - network = {} - network.raw = line - } else if (line.indexOf('ssid=') !== -1) { - network.ssid = line.replace('ssid=', '').trim().replace(quoteRe, '') - if (network.raw) { - network.raw += '\n' + line - } - } else if (line.indexOf('}') !== -1) { - network.raw += '\n' + line - networks.push(network) - network = {} - } else if (network.ssid) { - network.raw += '\n' + line - } - } - return networks - } /** * Create sanitized wpa_supplicant.conf stanza for * configuring wifi without storing plaintext passwords