parseConfig moved out of class
This commit is contained in:
parent
15ded20735
commit
781f6046e5
|
@ -17,6 +17,31 @@ let _entry = null
|
||||||
let _ssid = null
|
let _ssid = null
|
||||||
let _cb = 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 representing the wifi features */
|
||||||
class Wifi {
|
class Wifi {
|
||||||
constructor () {
|
constructor () {
|
||||||
|
@ -63,7 +88,7 @@ class Wifi {
|
||||||
return _cb(err)
|
return _cb(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
parsed = this._parseConfig(data)
|
parsed = parseConfig(data)
|
||||||
console.dir(parsed)
|
console.dir(parsed)
|
||||||
console.log(data)
|
console.log(data)
|
||||||
console.log(data.search(networkPattern))
|
console.log(data.search(networkPattern))
|
||||||
|
@ -122,29 +147,6 @@ class Wifi {
|
||||||
//this._callback(null, { ssid : ssid, pwd : pwd.length })
|
//this._callback(null, { ssid : ssid, pwd : pwd.length })
|
||||||
_cb = () => {}
|
_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
|
* Create sanitized wpa_supplicant.conf stanza for
|
||||||
* configuring wifi without storing plaintext passwords
|
* configuring wifi without storing plaintext passwords
|
||||||
|
|
Loading…
Reference in New Issue