From 52af8391317bfb655b0c934988b6c2a2afbe548b Mon Sep 17 00:00:00 2001
From: Simone Margaritelli <evilsocket@gmail.com>
Date: Mon, 7 Oct 2019 17:04:06 +0200
Subject: [PATCH] new: exclude option for the grid plugin

---
 docs/configure.md                  | 15 ++++++++++++++-
 pwnagotchi/defaults.yml            |  2 ++
 pwnagotchi/plugins/default/grid.py | 10 +++++++++-
 3 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/docs/configure.md b/docs/configure.md
index 47fe042..dfc33ae 100644
--- a/docs/configure.md
+++ b/docs/configure.md
@@ -76,7 +76,20 @@ main:
         report: true # full-opt in
 ```
 
-If you prefer to completely opt-out by also disabling signaling:
+Even if fully opted-in, you can still disable reporting for specific networks, for instance if you don't want your home network to be in the system:
+
+```yaml
+main:
+    plugins:
+      grid:
+        enabled: true
+        report: true
+        exclude:
+          - MyHomeNetwork
+          - de:ad:be:ef:de:ad # both ESSIDs and BSSIDs are supported
+```
+
+If instead you prefer to completely opt-out by also disabling signaling:
 
 ```yaml
 main:
diff --git a/pwnagotchi/defaults.yml b/pwnagotchi/defaults.yml
index 7d4d92b..330218f 100644
--- a/pwnagotchi/defaults.yml
+++ b/pwnagotchi/defaults.yml
@@ -9,6 +9,8 @@ main:
       grid:
         enabled: true
         report: false # don't report pwned networks by default!
+        exclude: # do not report the following networks (accepts both ESSIDs and BSSIDs)
+          - YourHomeNetworkHere
       auto-update:
         enabled: false
         interval: 1 # every day
diff --git a/pwnagotchi/plugins/default/grid.py b/pwnagotchi/plugins/default/grid.py
index 09ee08a..6c151b3 100644
--- a/pwnagotchi/plugins/default/grid.py
+++ b/pwnagotchi/plugins/default/grid.py
@@ -154,7 +154,15 @@ def on_internet_available(ui, keys, config, log):
             if OPTIONS['report']:
                 for pcap_file in pcap_files:
                     net_id = os.path.basename(pcap_file).replace('.pcap', '')
-                    if net_id not in reported:
+                    do_skip = False
+                    for skip in OPTIONS['exclude']:
+                        skip = skip.lower()
+                        net = net_id.lower()
+                        if skip in net or skip.replace(':', '') in net:
+                            do_skip = True
+                            break
+
+                    if net_id not in reported and not do_skip:
                         essid, bssid = parse_pcap(pcap_file)
                         if bssid:
                             if api_report_ap(log, keys, token, essid, bssid):