Merge pull request #299 from dadav/feature/web-hook-for-plugins

Implement webhook for plugins
This commit is contained in:
evilsocket 2019-10-20 22:11:04 +02:00 committed by GitHub
commit 020be7185c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -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 <host>:<port>/plugins/<pluginname> is opened
def on_webhook(response, path):
res = "<html><body><a>Hook triggered</a></body></html>"
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__)

View File

@ -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)