fix: safer call to webhook
This commit is contained in:
parent
4aa29f1b79
commit
c0252c9830
pwnagotchi
@ -16,7 +16,19 @@ def on(event_name, *args, **kwargs):
|
|||||||
cb_name = 'on_%s' % event_name
|
cb_name = 'on_%s' % event_name
|
||||||
for plugin_name, plugin in loaded.items():
|
for plugin_name, plugin in loaded.items():
|
||||||
if cb_name in plugin.__dict__:
|
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:
|
try:
|
||||||
plugin.__dict__[cb_name](*args, **kwargs)
|
plugin.__dict__[cb_name](*args, **kwargs)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -166,8 +166,7 @@ class Handler(BaseHTTPRequestHandler):
|
|||||||
if plugin_from_path:
|
if plugin_from_path:
|
||||||
plugin_name = plugin_from_path.groups()[0]
|
plugin_name = plugin_from_path.groups()[0]
|
||||||
right_path = plugin_from_path.groups()[1] if len(plugin_from_path.groups()) == 2 else None
|
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.one(plugin_name, 'webhook', right_path)
|
||||||
plugins.loaded[plugin_name].on_webhook(self, right_path)
|
|
||||||
else:
|
else:
|
||||||
self.send_response(404)
|
self.send_response(404)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user