Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stronger query params parser #8

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions wifi_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,13 @@ 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] if request_line else None
if path is None:
pass
elif path == '/':
self.handle_root()
elif url == 'configure':
elif path == '/configure':
self.handle_configure()
else:
self.handle_not_found()
Expand Down Expand Up @@ -217,10 +220,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 body else {}
if 'ssid' in params:
ssid = params['ssid']
password = params['password']
if len(ssid) == 0:
self.send_response("""
<p>SSID must be providaded!</p>
Expand Down