From b7380018f16326e4188e23751879b90eb8ef50c4 Mon Sep 17 00:00:00 2001 From: dadav <33197631+dadav@users.noreply.github.com> Date: Thu, 7 Nov 2019 07:33:40 +0100 Subject: [PATCH] Changed webhook arguments and add exception handling --- pwnagotchi/plugins/default/example.py | 17 +++-------------- pwnagotchi/ui/web/handler.py | 16 ++++++---------- 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/pwnagotchi/plugins/default/example.py b/pwnagotchi/plugins/default/example.py index 5a13651..2a02e63 100644 --- a/pwnagotchi/plugins/default/example.py +++ b/pwnagotchi/plugins/default/example.py @@ -16,26 +16,15 @@ class Example(plugins.Plugin): logging.debug("example plugin created") # called when http://:/plugins// is called - # must return a response - def on_webhook(self, path, args, req_method): + # must return a html page + # IMPORTANT: If you use "POST"s, add a csrf-token (via csrf_token() and render_template_string) + def on_webhook(self, path, request): pass # called when the plugin is loaded def on_loaded(self): logging.warning("WARNING: this plugin should be disabled! options = " % self.options) - # called when :/plugins/ is opened - def on_webhook(self, response, path): - res = "Hook triggered" - response.send_response(200) - response.send_header('Content-type', 'text/html') - response.end_headers() - - try: - response.wfile.write(bytes(res, "utf-8")) - except Exception as ex: - logging.error(ex) - # called in manual mode when there's internet connectivity def on_internet_available(self, agent): pass diff --git a/pwnagotchi/ui/web/handler.py b/pwnagotchi/ui/web/handler.py index 8284e59..97fa259 100644 --- a/pwnagotchi/ui/web/handler.py +++ b/pwnagotchi/ui/web/handler.py @@ -40,17 +40,13 @@ class Handler: # show plugins overview abort(404) else: - - # call plugin on_webhook - arguments = request.args - req_method = request.method - - # need to return something here if name in plugins.loaded and hasattr(plugins.loaded[name], 'on_webhook'): - return render_template_string( - plugins.loaded[name].on_webhook(subpath, args=arguments, req_method=req_method)) - - abort(500) + try: + return plugins.loaded[name].on_webhook(subpath, request) + except Exception: + abort(500) + else: + abort(404) # serve a message and shuts down the unit def shutdown(self):