list.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 !== '.DS_Store'))
  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. if (!el.manifest || !el.status) { return null }
  19. return {
  20. encrypted: el.manifest ? el.manifest.IsEncrypted
  21. ? chalk.green('encrypted')
  22. : chalk.red('not encrypted')
  23. : 'unknown encryption',
  24. device_name: el.manifest ? el.manifest.Lockdown.DeviceName : 'Unknown Device',
  25. device_id: el.id,
  26. serial: el.manifest.Lockdown.SerialNumber,
  27. iOSVersion: el.manifest.Lockdown.ProductVersion + '(' + el.manifest.Lockdown.BuildVersion + ')',
  28. backupVersion: el.status ? el.status.Version : '?',
  29. date: el.status ? new Date(el.status.Date).toLocaleString() : ''
  30. }
  31. })
  32. .filter(el => el != null)
  33. .map(el => [
  34. chalk.gray(el.device_id),
  35. el.encrypted,
  36. el.date,
  37. el.device_name,
  38. el.serial,
  39. el.iOSVersion,
  40. el.backupVersion
  41. ])
  42. items = [
  43. ['UDID', 'Encryption', 'Date', 'Device Name', 'Serial #', 'iOS Version', 'Backup Version'],
  44. ['-', '-', '-', '-', '-', '-', '-'],
  45. ...items
  46. ]
  47. items = normalizeCols(items)
  48. items = items.map(el => el.join(' | ')).join('\n')
  49. if (!program.color) { items = stripAnsi(items) }
  50. console.log(items)
  51. }