list.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. const stripAnsi = require('strip-ansi')
  2. const iPhoneBackup = require('../util/iphone_backup.js').iPhoneBackup
  3. const normalizeCols = require('../util/normalize.js')
  4. const chalk = require('chalk')
  5. const fs = require('fs-extra')
  6. module.exports.name = 'list'
  7. module.exports.description = 'List of all backups. alias for -l'
  8. module.exports.func = function (program, base) {
  9. var items = fs.readdirSync(base, { encoding: 'utf8' })
  10. .filter(el => (el.length === 40))
  11. .map(file => iPhoneBackup.fromID(file, base))
  12. // Possibly dump output
  13. if (program.dump) {
  14. console.log(JSON.stringify(items, null, 4))
  15. return
  16. }
  17. items = items.map(el => {
  18. return {
  19. encrypted: el.manifest ? el.manifest.IsEncrypted
  20. ? chalk.green('encrypted')
  21. : chalk.red('not encrypted')
  22. : 'unknown encryption',
  23. device_name: el.manifest ? el.manifest.Lockdown.DeviceName : 'Unknown Device',
  24. device_id: el.id,
  25. serial: el.manifest.Lockdown.SerialNumber,
  26. iOSVersion: el.manifest.Lockdown.ProductVersion + '(' + el.manifest.Lockdown.BuildVersion + ')',
  27. backupVersion: el.status ? el.status.Version : '?',
  28. date: el.status ? new Date(el.status.Date).toLocaleString() : ''
  29. }
  30. })
  31. .map(el => [
  32. chalk.gray(el.device_id),
  33. el.encrypted,
  34. el.date,
  35. el.device_name,
  36. el.serial,
  37. el.iOSVersion,
  38. el.backupVersion
  39. ])
  40. items = [
  41. ['UDID', 'Encryption', 'Date', 'Device Name', 'Serial #', 'iOS Version', 'Backup Version'],
  42. ['-', '-', '-', '-', '-', '-', '-'],
  43. ...items
  44. ]
  45. items = normalizeCols(items)
  46. items = items.map(el => el.join(' | ')).join('\n')
  47. if (!program.color) { items = stripAnsi(items) }
  48. console.log(items)
  49. }