safari_open_tabs.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 database = fileHash('Library/Safari/BrowserState.db', 'AppDomain-com.apple.mobilesafari')
  10. module.exports.name = 'safari_open_tabs'
  11. module.exports.description = 'List open Safari tabs when backup was made'
  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. // Specify this only works for iOS 10+
  18. // If it is iOS-version specific, you can specify version information here.
  19. // You may provide a comma separated string such as ">=6.0,<11.0" to indicate ranges.
  20. module.exports.supportedVersions = '>=10.0'
  21. module.exports.func = function (program, backup, resolve, reject) {
  22. openTabsReport(backup)
  23. .then((items) => {
  24. var result = program.formatter.format(items, {
  25. program: program,
  26. columns: {
  27. 'Title': el => el.title,
  28. 'URL': el => el.url,
  29. 'Last Viewed Time': el => (new Date((el.last_viewed_time + 978307200) * 1000).toDateString()) + ' ' + (new Date((el.last_viewed_time + 978307200) * 1000).toTimeString())
  30. }
  31. })
  32. resolve(result)
  33. })
  34. .catch(reject)
  35. }
  36. const openTabsReport = (backup) => {
  37. return new Promise((resolve, reject) => {
  38. var browserStatedb = backup.getDatabase(database)
  39. try {
  40. const query = `
  41. select * from tabs
  42. order by last_viewed_time DESC
  43. `
  44. browserStatedb.all(query, async function (err, rows) {
  45. if (err) reject(err)
  46. resolve(rows)
  47. })
  48. } catch (e) {
  49. reject(e)
  50. }
  51. })
  52. }