webhistory.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. const stripAnsi = require('strip-ansi')
  2. const { URL } = require('url')
  3. const iPhoneBackup = require('../util/iphone_backup.js').iPhoneBackup
  4. const normalizeCols = require('../util/normalize.js')
  5. module.exports.name = 'webhistory'
  6. module.exports.description = 'List all web history'
  7. module.exports.func = function (program, base) {
  8. if (!program.backup) {
  9. console.log('use -b or --backup <id> to specify backup.')
  10. process.exit(1)
  11. }
  12. // Grab the backup
  13. var backup = iPhoneBackup.fromID(program.backup, base)
  14. backup.getWebHistory(program.dump)
  15. .then((history) => {
  16. if (program.dump) {
  17. console.log(JSON.stringify(history, null, 4))
  18. return
  19. }
  20. var items = history.map(el => [
  21. el.XFORMATTEDDATESTRING + '' || '',
  22. new URL(el.url || '').origin || '',
  23. (el.title || '').substring(0, 64)
  24. ])
  25. items = [['Time', 'URL', 'Title'], ['-', '-', '-'], ...items]
  26. items = normalizeCols(items).map(el => el.join(' | ').replace(/\n/g, '')).join('\n')
  27. if (!program.color) { items = stripAnsi(items) }
  28. console.log(items)
  29. })
  30. .catch((e) => {
  31. console.log('[!] Encountered an Error:', e)
  32. })
  33. }