From ecb7b4321d1e781027082fbb60dbcb44138107c8 Mon Sep 17 00:00:00 2001 From: Someone Date: Mon, 5 Sep 2022 22:11:39 +0200 Subject: [PATCH] core/MMBot.py --- core/MMBot.py | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/core/MMBot.py b/core/MMBot.py index c2fa396..3ece80a 100644 --- a/core/MMBot.py +++ b/core/MMBot.py @@ -461,6 +461,18 @@ class MMBot(): self.handled = False data = None + if self.headers["Content-Type"] == "application/x-www-form-urlencoded": + data = urllib.parse.parse_qs(self.rfile.read(int(self.headers["Content-Length"])).decode("utf-8"), keep_blank_values=True) + # only accept first occurence + data = {k: v[0] for k, v in data.items()} + + elif self.headers["Content-Type"] == "application/json": + data = json.loads(self.rfile.read(int(self.headers["Content-Length"])).decode("utf-8")) + +# else: +# self.respond_public(415) +# return + logger.debug("do_public_POST(): request incomming.") try: module = 'not yet known' @@ -473,8 +485,8 @@ class MMBot(): else: # Invalid command/unknown command logger.error("do_public_POST(): Invalid command/unknown command") - self.bot.debug_chan("do_public_POST(): Invalid command/unknown command.\n# :boom::boom::boom::boom::boom:\n```\n"+self.path+"\n```") - self.respond_cmd_err("Invalid command/unknown command") + #self.bot.debug_chan("do_public_POST(): Invalid command/unknown command.\n# :boom::boom::boom::boom::boom:\n```\n"+self.path+"\n```") + self.respond_public(400, {"error":"Invalid command/unknown command"} ,if_nonzero_secondary='ignore') # always try to fail to retain userinput. If previously responded to, nothing will happen. self.respond_public(400, if_nonzero_secondary='ignore') @@ -489,6 +501,18 @@ class MMBot(): self.handled = False data = None + if self.headers["Content-Type"] == "application/x-www-form-urlencoded": + data = urllib.parse.parse_qs(self.rfile.read(int(self.headers["Content-Length"])).decode("utf-8"), keep_blank_values=True) + # only accept first occurence + data = {k: v[0] for k, v in data.items()} + + elif self.headers["Content-Type"] == "application/json": + data = json.loads(self.rfile.read(int(self.headers["Content-Length"])).decode("utf-8")) + +# else: +# self.respond_public(415) +# return + logger.debug("do_public_GET(): request incomming.") try: module = 'not yet known' @@ -501,7 +525,7 @@ class MMBot(): else: # Invalid command/unknown command logger.error("do_public_GET(): Invalid command/unknown command") - self.bot.debug_chan("do_public_GET(): Invalid command/unknown command.\n# :boom::boom::boom::boom::boom:\n```\n"+self.path+"\n```") + #self.bot.debug_chan("do_public_GET(): Invalid command/unknown command.\n# :boom::boom::boom::boom::boom:\n```\n"+self.path+"\n```") self.respond_public(400, {"error":"Invalid command/unknown command"} ,if_nonzero_secondary='ignore') # always try to fail to retain userinput. If previously responded to, nothing will happen. -- 2.43.0