speed_dial.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. const log = require('../util/log')
  2. const path = require('path')
  3. const sqlite3 = require('sqlite3')
  4. const bplist = require('bplist-parser')
  5. const fs = require('fs')
  6. const plist = require('plist')
  7. // Derive filenames based on domain + file path
  8. const fileHash = require('../util/backup_filehash')
  9. const file = fileHash('Library/Preferences/com.apple.mobilephone.speeddial.plist')
  10. module.exports.name = 'speed_dial'
  11. module.exports.description = 'Show Speed dial contact information'
  12. // Specify this reporter requires a backup.
  13. // The second parameter to func() is now a backup instead of the path to one.
  14. module.exports.requiresBackup = true
  15. // Specify this reporter supports the promises API for allowing chaining of reports.
  16. module.exports.usesPromises = true
  17. module.exports.func = function (program, backup, resolve, reject) {
  18. speedDialReport(backup)
  19. .then((items) => {
  20. var result = program.formatter.format(items, {
  21. program: program,
  22. columns: {
  23. 'Action Type': el => el.ActionType ? el.ActionType.indexOf('ActionType') !== -1 ? el.ActionType.split('ActionType')[0] : el.ActionType : 'N/A',
  24. 'Contact Name': el => el.Name,
  25. 'Value': el => el.Value
  26. }
  27. })
  28. resolve(result)
  29. })
  30. .catch(reject)
  31. }
  32. const speedDialReport = (backup) => {
  33. return new Promise((resolve, reject) => {
  34. var filename = backup.getFileName(file)
  35. try {
  36. let speeddialPlist = bplist.parseBuffer(fs.readFileSync(filename))[0]
  37. resolve(speeddialPlist)
  38. } catch (e) {
  39. reject(e)
  40. }
  41. })
  42. }