diff --git a/pwnagotchi/plugins/__init__.py b/pwnagotchi/plugins/__init__.py index d0805311..cb58323d 100644 --- a/pwnagotchi/plugins/__init__.py +++ b/pwnagotchi/plugins/__init__.py @@ -16,7 +16,19 @@ def on(event_name, *args, **kwargs): cb_name = 'on_%s' % event_name for plugin_name, plugin in loaded.items(): if cb_name in plugin.__dict__: - # print("calling %s %s(%s)" %(cb_name, args, kwargs)) + try: + plugin.__dict__[cb_name](*args, **kwargs) + except Exception as e: + logging.error("error while running %s.%s : %s" % (plugin_name, cb_name, e)) + logging.error(e, exc_info=True) + + +def one(plugin_name, event_name, *args, **kwargs): + global loaded + if plugin_name in loaded: + plugin = loaded[plugin_name] + cb_name = 'on_%s' % event_name + if cb_name in plugin.__dict__: try: plugin.__dict__[cb_name](*args, **kwargs) except Exception as e: diff --git a/pwnagotchi/ui/web.py b/pwnagotchi/ui/web.py index 82af2693..e5432717 100644 --- a/pwnagotchi/ui/web.py +++ b/pwnagotchi/ui/web.py @@ -166,8 +166,7 @@ class Handler(BaseHTTPRequestHandler): 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) + plugins.one(plugin_name, 'webhook', right_path) else: self.send_response(404)