Created
August 22, 2023 14:38
-
-
Save korylprince/169284d5e4444af15cfb8c5f69ed07db to your computer and use it in GitHub Desktop.
MicroMDM Webhook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, request, abort | |
import base64 | |
import plistlib | |
import json | |
app = Flask(__name__) | |
def clean_json(obj): | |
if isinstance(obj, dict): | |
new = dict() | |
for k, v in obj.items(): | |
new[clean_json(k)] = clean_json(v) | |
return new | |
elif isinstance(obj, list): | |
return [clean_json(i) for i in obj] | |
elif isinstance(obj, tuple): | |
return tuple([clean_json(i) for i in obj]) | |
elif isinstance(obj, bytes): | |
try: | |
return obj.decode("utf-8") | |
except: | |
return repr(obj) | |
else: | |
return obj | |
@app.route("/", methods=["POST"]) | |
def webhook(): | |
r = request.json | |
if "acknowledge_event" in r: | |
payload = base64.b64decode(r["acknowledge_event"]["raw_payload"]) | |
del r["acknowledge_event"]["raw_payload"] | |
r["acknowledge_event"]["payload"] = plistlib.loads(payload) | |
if "checkin_event" in r: | |
payload = base64.b64decode(r["checkin_event"]["raw_payload"]) | |
del r["checkin_event"]["raw_payload"] | |
r["checkin_event"]["payload"] = plistlib.loads(payload) | |
try: | |
print(json.dumps(clean_json(r), indent=4)) | |
except: | |
print(repr(clean_json(r))) | |
return "" | |
app.run(host="0.0.0.0", port=3636) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment