webgpsmap: better logging informations for easy user debugging

This commit is contained in:
xenDE 2020-01-18 16:52:52 +01:00 committed by GitHub
parent 0764304be9
commit a28c9a1176
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -9,21 +9,22 @@ from functools import lru_cache
from dateutil.parser import parse from dateutil.parser import parse
''' '''
2do: webgpsmap shows existing position data stored in your /handshakes/ directory
- make+test the cache handling multiple clients
- cleanup the javascript in a class and handle "/newest" additions the plugin does the following:
- create map filters (only cracked APs, only last xx days, between 2 days with slider) - search for *.pcap files in your /handshakes/ dir
http://www.gistechsolutions.com/leaflet/DEMO/filter/filter.html - for every found .pcap file it looks for a .geo.json or .gps.json or .paw-gps.json file with
https://gis.stackexchange.com/questions/312737/filtering-interactive-leaflet-map-with-dropdown-menu latitude+longitude data inside and shows this position on the map
https://blogs.kent.ac.uk/websolutions/2015/01/29/filtering-map-markers-with-leaflet-js-a-brief-technical-overview/ - if also an .cracked file with a plaintext password inside exist, it reads the content and shows the
http://www.digital-geography.com/filter-leaflet-maps-slider/ position as green instead of red and the password inside the infopox of the position
http://bl.ocks.org/zross/47760925fcb1643b4225 special:
- you can save the html-map as one file for offline use or host on your own webspace with "/plugins/webgpsmap/offlinemap"
''' '''
class Webgpsmap(plugins.Plugin): class Webgpsmap(plugins.Plugin):
__author__ = 'https://github.com/xenDE and https://github.com/dadav' __author__ = 'https://github.com/xenDE and https://github.com/dadav'
__version__ = '1.3.1' __version__ = '1.4.0'
__name__ = 'webgpsmap' __name__ = 'webgpsmap'
__license__ = 'GPL3' __license__ = 'GPL3'
__description__ = 'a plugin for pwnagotchi that shows a openstreetmap with positions of ap-handshakes in your webbrowser' __description__ = 'a plugin for pwnagotchi that shows a openstreetmap with positions of ap-handshakes in your webbrowser'
@ -65,7 +66,7 @@ class Webgpsmap(plugins.Plugin):
response_mimetype = "application/xhtml+xml" response_mimetype = "application/xhtml+xml"
response_header_contenttype = 'text/html' response_header_contenttype = 'text/html'
except Exception as error: except Exception as error:
logging.error(f"[webgpsmap] error: {error}") logging.error(f"[webgpsmap] on_webhook NOT_READY error: {error}")
return return
else: else:
if request.method == "GET": if request.method == "GET":
@ -75,7 +76,7 @@ class Webgpsmap(plugins.Plugin):
try: try:
response_data = bytes(self.get_html(), "utf-8") response_data = bytes(self.get_html(), "utf-8")
except Exception as error: except Exception as error:
logging.error(f"[webgpsmap] error: {error}") logging.error(f"[webgpsmap] on_webhook / error: {error}")
return return
response_status = 200 response_status = 200
response_mimetype = "application/xhtml+xml" response_mimetype = "application/xhtml+xml"
@ -89,7 +90,7 @@ class Webgpsmap(plugins.Plugin):
response_mimetype = "application/json" response_mimetype = "application/json"
response_header_contenttype = 'application/json' response_header_contenttype = 'application/json'
except Exception as error: except Exception as error:
logging.error(f"[webgpsmap] error: {error}") logging.error(f"[webgpsmap] on_webhook all error: {error}")
return return
elif path.startswith('offlinemap'): elif path.startswith('offlinemap'):
# for download an all-in-one html file with positions.json inside # for download an all-in-one html file with positions.json inside
@ -104,7 +105,7 @@ class Webgpsmap(plugins.Plugin):
response_header_contenttype = 'text/html' response_header_contenttype = 'text/html'
response_header_contentdisposition = 'attachment; filename=webgpsmap.html'; response_header_contentdisposition = 'attachment; filename=webgpsmap.html';
except Exception as error: except Exception as error:
logging.error(f"[webgpsmap] offlinemap: error: {error}") logging.error(f"[webgpsmap] on_webhook offlinemap: error: {error}")
return return
# elif path.startswith('/newest'): # elif path.startswith('/newest'):
# # returns all positions newer then timestamp # # returns all positions newer then timestamp
@ -140,7 +141,7 @@ class Webgpsmap(plugins.Plugin):
r.headers["Content-Disposition"] = response_header_contentdisposition r.headers["Content-Disposition"] = response_header_contentdisposition
return r return r
except Exception as error: except Exception as error:
logging.error(f"[webgpsmap] error: {error}") logging.error(f"[webgpsmap] on_webhook CREATING_RESPONSE error: {error}")
return return
# cache 2048 items # cache 2048 items
@ -236,15 +237,15 @@ class Webgpsmap(plugins.Plugin):
self.ALREADY_SENT += pos_file self.ALREADY_SENT += pos_file
except json.JSONDecodeError as error: except json.JSONDecodeError as error:
self.SKIP += pos_file self.SKIP += pos_file
logging.error(f"[webgpsmap] JSONDecodeError in: {error}") logging.error(f"[webgpsmap] JSONDecodeError in: {pos_file} - error: {error}")
continue continue
except ValueError as error: except ValueError as error:
self.SKIP += pos_file self.SKIP += pos_file
logging.error(f"[webgpsmap] ValueError: {error}") logging.error(f"[webgpsmap] ValueError: {pos_file} - error: {error}")
continue continue
except OSError as error: except OSError as error:
self.SKIP += pos_file self.SKIP += pos_file
logging.error(f"[webgpsmap] OSError: {error}") logging.error(f"[webgpsmap] OSError: {pos_file} - error: {error}")
continue continue
logging.info(f"[webgpsmap] loaded {len(gps_data)} positions") logging.info(f"[webgpsmap] loaded {len(gps_data)} positions")
return gps_data return gps_data
@ -343,9 +344,9 @@ class PositionFile:
return_pass = password_file.read() return_pass = password_file.read()
password_file.close() password_file.close()
except OSError as error: except OSError as error:
logging.error(f"[webgpsmap] OS error: {format(error)}") logging.error(f"[webgpsmap] OS error loading password: {password_file_path} - error: {format(error)}")
except: except:
logging.error(f"[webgpsmap] Unexpected error: {sys.exc_info()[0]}") logging.error(f"[webgpsmap] Unexpected error loading password: {password_file_path} - error: {sys.exc_info()[0]}")
raise raise
return return_pass return return_pass