From 11d5d41cffe8ff03dfad2e36d0ac9d470c2837c3 Mon Sep 17 00:00:00 2001 From: yamenk-gribaudo <102967309+yamenk-gribaudo@users.noreply.github.com> Date: Thu, 29 Jun 2023 17:55:47 -0300 Subject: [PATCH 1/3] Stronger query params parser --- wifi_manager.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/wifi_manager.py b/wifi_manager.py index 6eb63af..4cb3def 100644 --- a/wifi_manager.py +++ b/wifi_manager.py @@ -217,10 +217,11 @@ def handle_root(self): def handle_configure(self): - match = re.search('ssid=([^&]*)&password=(.*)', self.url_decode(self.request)) - if match: - ssid = match.group(1).decode('utf-8') - password = match.group(2).decode('utf-8') + body = self.url_decode(self.request).decode('utf-8').split('\r\n').pop() + params = {x[0] : x[1] for x in [x.split("=") for x in body.split("&") ]} + if 'ssid' in params: + ssid = params['ssid'] + password = params['password'] if len(ssid) == 0: self.send_response("""
SSID must be providaded!
From e06f23b2dff4c38a3de3f67bd76964edb16f3078 Mon Sep 17 00:00:00 2001 From: yamenk-gribaudo <102967309+yamenk-gribaudo@users.noreply.github.com> Date: Fri, 30 Jun 2023 10:39:25 -0300 Subject: [PATCH 2/3] Update wifi_manager.py --- wifi_manager.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/wifi_manager.py b/wifi_manager.py index 4cb3def..5d044a9 100644 --- a/wifi_manager.py +++ b/wifi_manager.py @@ -146,10 +146,11 @@ def web_server(self): if self.request: if self.debug: print(self.url_decode(self.request)) - url = re.search('(?:GET|POST) /(.*?)(?:\\?.*?)? HTTP', self.request).group(1).decode('utf-8').rstrip('/') - if url == '': + request_line = self.request.decode('utf-8').split('\r\n').pop(0) + path = request_line.split()[1].strip("/") if request_line else "" + if path == '': self.handle_root() - elif url == 'configure': + elif path == 'configure': self.handle_configure() else: self.handle_not_found() @@ -218,7 +219,7 @@ def handle_root(self): def handle_configure(self): body = self.url_decode(self.request).decode('utf-8').split('\r\n').pop() - params = {x[0] : x[1] for x in [x.split("=") for x in body.split("&") ]} + params = {x[0] : x[1] for x in [x.split("=") for x in body.split("&") ]} if body else {} if 'ssid' in params: ssid = params['ssid'] password = params['password'] From 75ac6526c9481d7d7b339809593c6b9ddeac4983 Mon Sep 17 00:00:00 2001 From: yamenk-gribaudo <102967309+yamenk-gribaudo@users.noreply.github.com> Date: Fri, 30 Jun 2023 18:05:48 -0300 Subject: [PATCH 3/3] Update wifi_manager.py --- wifi_manager.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/wifi_manager.py b/wifi_manager.py index 5d044a9..c063582 100644 --- a/wifi_manager.py +++ b/wifi_manager.py @@ -147,10 +147,12 @@ def web_server(self): if self.debug: print(self.url_decode(self.request)) request_line = self.request.decode('utf-8').split('\r\n').pop(0) - path = request_line.split()[1].strip("/") if request_line else "" - if path == '': + path = request_line.split()[1] if request_line else None + if path is None: + pass + elif path == '/': self.handle_root() - elif path == 'configure': + elif path == '/configure': self.handle_configure() else: self.handle_not_found()