From e220a869e018a96b757e7415e8246d8aacfe397a Mon Sep 17 00:00:00 2001 From: Simone Margaritelli <evilsocket@gmail.com> Date: Fri, 18 Oct 2019 16:34:58 +0200 Subject: [PATCH] new: user config is now copied from /boot/config.yml --- pwnagotchi/utils.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/pwnagotchi/utils.py b/pwnagotchi/utils.py index 127761c..af6ea59 100644 --- a/pwnagotchi/utils.py +++ b/pwnagotchi/utils.py @@ -31,11 +31,18 @@ def load_config(args): ref_defaults_file = os.path.join(os.path.dirname(pwnagotchi.__file__), 'defaults.yml') ref_defaults_data = None - if not os.path.exists(args.config): + # check for a config.yml file on /boot/ + if os.path.exists("/boot/config.yml"): # logging not configured here yet + print("installing /boot/config.yml to %s ...", args.user_config) + os.rename("/boot/config.yml", args.user_config) + + # if not config is found, copy the defaults + if not os.path.exists(args.config): print("copying %s to %s ..." % (ref_defaults_file, args.config)) shutil.copy(ref_defaults_file, args.config) else: + # check if the user messed with the defaults with open(ref_defaults_file) as fp: ref_defaults_data = fp.read() @@ -46,9 +53,11 @@ def load_config(args): print("!!! file in %s is different than release defaults, overwriting !!!" % args.config) shutil.copy(ref_defaults_file, args.config) + # load the defaults with open(args.config) as fp: config = yaml.safe_load(fp) + # load the user config if os.path.exists(args.user_config): with open(args.user_config) as fp: user_config = yaml.safe_load(fp) @@ -131,6 +140,7 @@ def blink(times=1, delay=0.3): time.sleep(delay) led(True) + class WifiInfo(Enum): """ Fields you can extract from a pcap file @@ -141,6 +151,7 @@ class WifiInfo(Enum): CHANNEL = 3 RSSI = 4 + class FieldNotFoundError(Exception): pass @@ -172,7 +183,7 @@ def extract_from_pcap(path, fields): if hasattr(packet[Dot11], 'addr3'): results[field] = packet[Dot11].addr3 break - else: # magic + else: # magic raise FieldNotFoundError("Could not find field [BSSID]") except Exception: raise FieldNotFoundError("Could not find field [BSSID]") @@ -188,7 +199,7 @@ def extract_from_pcap(path, fields): if packet.haslayer(Dot11Elt) and hasattr(packet[Dot11Elt], 'info'): results[field] = packet[Dot11Elt].info.decode('utf-8') break - else: # magic + else: # magic raise FieldNotFoundError("Could not find field [ESSID]") except Exception: raise FieldNotFoundError("Could not find field [ESSID]") @@ -202,9 +213,9 @@ def extract_from_pcap(path, fields): if packet.haslayer(Dot11Beacon) and hasattr(packet[Dot11Beacon], 'network_stats'): stats = packet[Dot11Beacon].network_stats() if 'crypto' in stats: - results[field] = stats['crypto'] # set with encryption types + results[field] = stats['crypto'] # set with encryption types break - else: # magic + else: # magic raise FieldNotFoundError("Could not find field [ENCRYPTION]") except Exception: raise FieldNotFoundError("Could not find field [ENCRYPTION]")