From c300e737266dc97a9affc7e6ab4823526c77250c Mon Sep 17 00:00:00 2001 From: xenDE <daniel@mameso.com> Date: Thu, 26 Dec 2019 18:51:00 +0100 Subject: [PATCH 1/2] webgpsmap: add function for download the map as one html file with json-positions inside now it's possible to download the map as one Html file for local use on your pc or host somewhere for mobile use without your pownagotchi. uri: /plugins/webgpsmap/offlinemap --- pwnagotchi/plugins/default/webgpsmap.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/pwnagotchi/plugins/default/webgpsmap.py b/pwnagotchi/plugins/default/webgpsmap.py index 3d7ae4d..f033da4 100644 --- a/pwnagotchi/plugins/default/webgpsmap.py +++ b/pwnagotchi/plugins/default/webgpsmap.py @@ -22,7 +22,7 @@ from functools import lru_cache class Webgpsmap(plugins.Plugin): __author__ = 'https://github.com/xenDE and https://github.com/dadav' - __version__ = '1.3.0' + __version__ = '1.3.1' __name__ = 'webgpsmap' __license__ = 'GPL3' __description__ = 'a plugin for pwnagotchi that shows a openstreetmap with positions of ap-handshakes in your webbrowser' @@ -49,6 +49,7 @@ class Webgpsmap(plugins.Plugin): """ # defaults: response_header_contenttype = None + response_header_contentdisposition = None response_mimetype = "application/xhtml+xml" if not self.ready: try: @@ -89,6 +90,21 @@ class Webgpsmap(plugins.Plugin): except Exception as error: logging.error(f"[webgpsmap] error: {error}") return + elif path.startswith('offlinemap'): + # for download an all-in-one html file with positions.json inside + try: + self.ALREADY_SENT = list() + json_data = json.dumps(self.load_gps_from_dir(self.config['bettercap']['handshakes'])) + html_data = self.get_html() + html_data = html_data.replace('var positions = [];', 'var positions = ' + json_data + ';positionsLoaded=true;drawPositions();') + response_data = bytes(html_data, "utf-8") + response_status = 200 + response_mimetype = "application/xhtml+xml" + response_header_contenttype = 'text/html' + response_header_contentdisposition = 'attachment; filename=webgpsmap.html'; + except Exception as error: + logging.error(f"[webgpsmap] offlinemap: error: {error}") + return # elif path.startswith('/newest'): # # returns all positions newer then timestamp # response_data = bytes(json.dumps(self.load_gps_from_dir(self.config['bettercap']['handshakes']), newest_only=True), "utf-8") @@ -119,6 +135,8 @@ class Webgpsmap(plugins.Plugin): r = Response(response=response_data, status=response_status, mimetype=response_mimetype) if response_header_contenttype is not None: r.headers["Content-Type"] = response_header_contenttype + if response_header_contentdisposition is not None: + r.headers["Content-Disposition"] = response_header_contentdisposition return r except Exception as error: logging.error(f"[webgpsmap] error: {error}") From 4164e7c0673e8695e3adc2802d23454465ebc0c7 Mon Sep 17 00:00:00 2001 From: xenDE <daniel@mameso.com> Date: Sun, 29 Dec 2019 14:57:17 +0100 Subject: [PATCH 2/2] webgpsmap: get current position and set marker on map in interval (30s) used the browsers geolocation function to get the current location, show a marker and center the map there. on success (user allows usage of get-current-position) it gets position every 30s and reposition the marker without center the map to the marker. --- pwnagotchi/plugins/default/webgpsmap.html | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pwnagotchi/plugins/default/webgpsmap.html b/pwnagotchi/plugins/default/webgpsmap.html index 6c401ec..905a13c 100644 --- a/pwnagotchi/plugins/default/webgpsmap.html +++ b/pwnagotchi/plugins/default/webgpsmap.html @@ -270,5 +270,16 @@ positionsLoaded = true; drawPositions(); }); + // get current position and set marker in interval + var myLocationMarker = {}; + function onLocationFound(e) { + if (myLocationMarker != undefined) { + mymap.removeLayer(myLocationMarker); + }; + myLocationMarker = L.marker(e.latlng).addTo(mymap); + setTimeout(function(){ mymap.locate(); }, 30000); + } + mymap.on('locationfound', onLocationFound); + mymap.locate({setView: true}); </script> </body></html>