kopia lustrzana https://github.com/tayfunulu/WiFiManager
commit
a1f955b338
30
wifimgr.py
30
wifimgr.py
|
@ -3,6 +3,7 @@ import socket
|
||||||
import ure
|
import ure
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
|
||||||
ap_ssid = "WifiManager"
|
ap_ssid = "WifiManager"
|
||||||
ap_password = "tayfunulu"
|
ap_password = "tayfunulu"
|
||||||
ap_authmode = 3 # WPA2
|
ap_authmode = 3 # WPA2
|
||||||
|
@ -99,22 +100,31 @@ def do_connect(ssid, password):
|
||||||
return connected
|
return connected
|
||||||
|
|
||||||
|
|
||||||
def send_response(client, payload, status_code=200):
|
def send_header(client, status_code=200, content_length=None ):
|
||||||
client.sendall("HTTP/1.0 {} OK\r\n".format(status_code))
|
client.sendall("HTTP/1.0 {} OK\r\n".format(status_code))
|
||||||
client.sendall("Content-Type: text/html\r\n")
|
client.sendall("Content-Type: text/html\r\n")
|
||||||
client.sendall("Content-Length: {}\r\n".format(len(payload)))
|
if content_length is not None:
|
||||||
|
client.sendall("Content-Length: {}\r\n".format(content_length))
|
||||||
|
|
||||||
client.sendall("\r\n")
|
client.sendall("\r\n")
|
||||||
|
|
||||||
if len(payload) > 0:
|
def send_response(client, payload, status_code=200):
|
||||||
|
content_length = len(payload)
|
||||||
|
|
||||||
|
send_header(client, status_code, content_length)
|
||||||
|
|
||||||
|
if content_length > 0:
|
||||||
client.sendall(payload)
|
client.sendall(payload)
|
||||||
|
|
||||||
|
client.close()
|
||||||
|
|
||||||
def handle_root(client):
|
def handle_root(client):
|
||||||
wlan_sta.active(True)
|
wlan_sta.active(True)
|
||||||
ssids = sorted(ssid.decode('utf-8') for ssid, *_ in wlan_sta.scan())
|
ssids = sorted(ssid.decode('utf-8') for ssid, *_ in wlan_sta.scan())
|
||||||
|
|
||||||
response = []
|
send_header(client)
|
||||||
response.append("""\
|
|
||||||
|
client.sendall("""\
|
||||||
<html>
|
<html>
|
||||||
<h1 style="color: #5e9ca0; text-align: center;">
|
<h1 style="color: #5e9ca0; text-align: center;">
|
||||||
<span style="color: #ff0000;">
|
<span style="color: #ff0000;">
|
||||||
|
@ -126,8 +136,10 @@ def handle_root(client):
|
||||||
<tbody>
|
<tbody>
|
||||||
""")
|
""")
|
||||||
|
|
||||||
for ssid in ssids:
|
while len(ssids):
|
||||||
response.append("""\
|
ssid = ssids.pop(0)
|
||||||
|
|
||||||
|
client.sendall("""\
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="2">
|
<td colspan="2">
|
||||||
<input type="radio" name="ssid" value="{0}" />{0}
|
<input type="radio" name="ssid" value="{0}" />{0}
|
||||||
|
@ -135,7 +147,7 @@ def handle_root(client):
|
||||||
</tr>
|
</tr>
|
||||||
""".format(ssid))
|
""".format(ssid))
|
||||||
|
|
||||||
response.append("""\
|
client.sendall("""\
|
||||||
<tr>
|
<tr>
|
||||||
<td>Password:</td>
|
<td>Password:</td>
|
||||||
<td><input name="password" type="password" /></td>
|
<td><input name="password" type="password" /></td>
|
||||||
|
@ -171,8 +183,8 @@ def handle_root(client):
|
||||||
</ul>
|
</ul>
|
||||||
</html>
|
</html>
|
||||||
""" % dict(filename=NETWORK_PROFILES))
|
""" % dict(filename=NETWORK_PROFILES))
|
||||||
send_response(client, "\n".join(response))
|
|
||||||
|
|
||||||
|
client.close()
|
||||||
|
|
||||||
def handle_configure(client, request):
|
def handle_configure(client, request):
|
||||||
match = ure.search("ssid=([^&]*)&password=(.*)", request)
|
match = ure.search("ssid=([^&]*)&password=(.*)", request)
|
||||||
|
|
Ładowanie…
Reference in New Issue