diff --git a/pwnagotchi/plugins/default/example.py b/pwnagotchi/plugins/default/example.py index 3f3e570..72087cf 100644 --- a/pwnagotchi/plugins/default/example.py +++ b/pwnagotchi/plugins/default/example.py @@ -14,6 +14,18 @@ import pwnagotchi.ui.fonts as fonts # Will be set with the options in config.yml config['main']['plugins'][__name__] OPTIONS = dict() +# called when :/plugins/ is opened +def on_webhook(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 when the plugin is loaded def on_loaded(): logging.warning("WARNING: plugin %s should be disabled!" % __name__) diff --git a/pwnagotchi/ui/web.py b/pwnagotchi/ui/web.py index c6b3ac6..021c37a 100644 --- a/pwnagotchi/ui/web.py +++ b/pwnagotchi/ui/web.py @@ -1,3 +1,4 @@ +import re import _thread from http.server import BaseHTTPRequestHandler, HTTPServer from threading import Lock @@ -5,6 +6,7 @@ import shutil import logging import pwnagotchi +from pwnagotchi import plugins frame_path = '/root/pwnagotchi.png' frame_format = 'PNG' @@ -159,6 +161,13 @@ class Handler(BaseHTTPRequestHandler): elif self.path.startswith('/ui'): self._image() + elif self.path.startswith('/plugins'): + plugin_from_path = re.match(r'\/plugins\/([^\/]+)(\/.*)?', self.path) + if plugin_from_path: + plugin_name = plugin_from_path.groups()[0] + right_path = plugin_from_path.groups()[1] if len(plugin_from_path.groups()) == 2 else None + if plugin_name in plugins.loaded and hasattr(plugins.loaded[plugin_name], 'on_webhook'): + plugins.loaded[plugin_name].on_webhook(self, right_path) else: self.send_response(404)