Push dev work to master #2
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue