From b50acd364c730ab33ed8e0504d2a26f860025ca3 Mon Sep 17 00:00:00 2001 From: dadav <33197631+dadav@users.noreply.github.com> Date: Thu, 7 Nov 2019 07:28:32 +0100 Subject: [PATCH] Add webcfg --- pwnagotchi/defaults.yml | 3 +- pwnagotchi/plugins/default/webcfg.py | 511 +++++++++++++++++++++++++++ 2 files changed, 513 insertions(+), 1 deletion(-) create mode 100644 pwnagotchi/plugins/default/webcfg.py diff --git a/pwnagotchi/defaults.yml b/pwnagotchi/defaults.yml index 0acce4d..f083270 100644 --- a/pwnagotchi/defaults.yml +++ b/pwnagotchi/defaults.yml @@ -109,7 +109,8 @@ main: epoch: 'oo oo oo oo oo oo oo' peer_detected: 'oo oo oo oo oo oo oo' peer_lost: 'oo oo oo oo oo oo oo' - + webcfg: + enabled: false # monitor interface to use iface: mon0 # command to run to bring the mon interface up in case it's not up already diff --git a/pwnagotchi/plugins/default/webcfg.py b/pwnagotchi/plugins/default/webcfg.py new file mode 100644 index 0000000..52532f2 --- /dev/null +++ b/pwnagotchi/plugins/default/webcfg.py @@ -0,0 +1,511 @@ +import logging +import json +import yaml +import _thread +import pwnagotchi.plugins as plugins +from pwnagotchi import restart +from flask import abort +from flask import render_template_string + + +INDEX = """ + + + + + webcfg + + + + +
+ + + +
+
+ + + + +""" + +def serializer(obj): + if isinstance(obj, set): + return list(obj) + raise TypeError + +class WebConfig(plugins.Plugin): + __author__ = '33197631+dadav@users.noreply.github.com' + __version__ = '1.0.0' + __license__ = 'GPL3' + __description__ = 'This plugin allows the user to make runtime changes.' + + def __init__(self): + self.ready = False + + def on_ready(self, agent): + self.config = agent.config() + self.mode = "MANU" if agent.mode == "manual" else "AUTO" + self.ready = True + + def on_internet_available(self, agent): + self.config = agent.config() + self.mode = "MANU" if agent.mode == "manual" else "AUTO" + self.ready = True + + def on_loaded(self): + """ + Gets called when the plugin gets loaded + """ + logging.info("webcfg: Plugin loaded.") + + + def on_webhook(self, path, request): + """ + Serves the current configuration + """ + if not self.ready: + return "Plugin not ready" + + if request.method == "GET": + if path == "/" or not path: + return render_template_string(INDEX) + elif path == "get-config": + # send configuration + return json.dumps(self.config, default=serializer) + else: + abort(404) + elif request.method == "POST": + if path == "save-config": + try: + with open('/etc/pwnagotchi/config.yml', 'w') as config_file: + yaml.safe_dump(request.get_json(), config_file, encoding='utf-8', + allow_unicode=True, default_flow_style=False) + + _thread.start_new_thread(restart, (self.mode,)) + return "success" + except yaml.YAMLError as yaml_ex: + return "config error" + abort(404)