geofences.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. const fileHash = require('../../util/backup_filehash')
  2. const apple_timestamp = require('../../util/apple_timestamp')
  3. const GEO_DB = fileHash('Library/Caches/locationd/consolidated.db', 'RootDomain')
  4. module.exports = {
  5. version: 4,
  6. name: 'system.geofences',
  7. description: `List local geofences used for triggers`,
  8. requiresBackup: true,
  9. // Run on a v3 lib / backup object.
  10. run (lib, { backup }) {
  11. return getGeoFences(backup)
  12. },
  13. // Wifi Report Fields.
  14. output: {
  15. date: el => el.XFORMATTEDDATESTRING,
  16. latitude: el => el.Latitude,
  17. longitude: el => el.Longitude,
  18. distance: el => el.Distance
  19. }
  20. }
  21. function getGeoFences (backup) {
  22. return new Promise((resolve, reject) => {
  23. backup.openDatabase(GEO_DB)
  24. .then(db => {
  25. db.all(`SELECT ${apple_timestamp.parse('Timestamp')} AS XFORMATTEDDATESTRING, Latitude, Longitude, Distance FROM Fences ORDER BY Timestamp ASC`, async function (err, rows) {
  26. if (err) reject(err)
  27. resolve(rows)
  28. })
  29. })
  30. .catch(reject)
  31. })
  32. }