wifi.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. const plist = require('../../util/plist')
  2. const fs = require('fs')
  3. // Normalize mac addresses in wifi output
  4. const macParse = require('../../util/mac_address_parse')
  5. // Derive filenames based on domain + file path
  6. const fileHash = require('../../util/backup_filehash')
  7. const WIFI_PLIST = fileHash('SystemConfiguration/com.apple.wifi.plist', 'SystemPreferencesDomain')
  8. module.exports = {
  9. version: 4,
  10. name: 'system.wifi',
  11. description: `List associated wifi networks and their usage information`,
  12. requiresBackup: true,
  13. // Run on a v3 lib / backup object.
  14. run (lib, { backup }) {
  15. return new Promise((resolve, reject) => {
  16. try {
  17. // Get the fifi file
  18. var filename = backup.getFileName(WIFI_PLIST)
  19. // Attempt to parse it
  20. let wifiList = plist.parseFile(filename)
  21. let result = wifiList['List of known networks']
  22. .map(el => {
  23. if (el.BSSID) {
  24. el.BSSID = macParse.pad_zeros(el.BSSID) + ''
  25. }
  26. return el
  27. })
  28. resolve(result)
  29. } catch (e) {
  30. reject(e)
  31. }
  32. })
  33. },
  34. // Wifi Report Fields.
  35. output: {
  36. lastJoined: el => el.lastJoined,
  37. lastAutoJoined: el => el.lastAutoJoined || '',
  38. ssid: el => el.SSID_STR,
  39. bssid: el => el.BSSID,
  40. security: el => el.SecurityMode || '',
  41. hidden: el => !!el.HIDDEN_NETWORK,
  42. enabled: el => !!el.enabled
  43. }
  44. }