From a28c9a1176f4b364acf67e81f2436db85dd697fa Mon Sep 17 00:00:00 2001
From: xenDE <daniel@mameso.com>
Date: Sat, 18 Jan 2020 16:52:52 +0100
Subject: [PATCH] webgpsmap: better logging informations for easy user
 debugging

---
 pwnagotchi/plugins/default/webgpsmap.py | 43 +++++++++++++------------
 1 file changed, 22 insertions(+), 21 deletions(-)

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