v0.1
This commit is contained in:
97
app_orig.py
Normal file
97
app_orig.py
Normal file
@@ -0,0 +1,97 @@
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
from flask import Flask
|
||||
from flask import request, redirect
|
||||
|
||||
CMD_SCAN = "sudo nmcli -t -f SSID,SIGNAL,IN-USE,SECURITY -e yes -m tab device wifi list ifname wlxf81a6719febb --rescan yes"
|
||||
scan = ["rpi:100: :WPA2", "Home:94:*:WPA2", "HOME2:48: :WPA2", "BT:23: :"]
|
||||
# scan = []
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
# sudo nmcli device wifi connect "Home" ifname wlxf81a6719febb password "password"
|
||||
# sudo nmcli -t -f SSID,SIGNAL,IN-USE,SECURITY -e yes -m tab device wifi list ifname wlxf81a6719febb --rescan yes
|
||||
|
||||
|
||||
def scan_wifi():
|
||||
global scan
|
||||
|
||||
scan = []
|
||||
temp = subprocess.run(CMD_SCAN.split(" "), stdout=subprocess.PIPE).stdout.decode("utf-8")
|
||||
for line in temp.splitlines():
|
||||
t = line.split(":")
|
||||
if t[0] != "":
|
||||
scan.append(line)
|
||||
|
||||
|
||||
@app.route("/connect")
|
||||
def connect():
|
||||
return "connect"
|
||||
|
||||
|
||||
@app.route("/passwd", methods=["GET", "POST"])
|
||||
def passwd():
|
||||
if request.method == "GET":
|
||||
html = """<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
|
||||
<h2>Enter Password</h2>
|
||||
|
||||
<form method="POST">
|
||||
<input type="text" id="passwd" name="passwd" value=""><br>
|
||||
<p><input type=submit value="Submit"></p>
|
||||
</form>
|
||||
|
||||
</body>
|
||||
</html>"""
|
||||
return html
|
||||
if request.method == "POST":
|
||||
# needs to pass password through... so probably not the way to do it..
|
||||
return redirect("/connect")
|
||||
|
||||
|
||||
@app.route("/", methods=["GET", "POST"])
|
||||
def main():
|
||||
if request.method == "GET":
|
||||
# scan_wifi()
|
||||
output = """<form method="POST"><table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Select</th>
|
||||
<th>SID</th>
|
||||
<th>Strength</th>
|
||||
<th>Connected</th>
|
||||
<th>Password</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
*DATA*
|
||||
</tbody>
|
||||
<p><input type=submit value=Connect></p></form>"""
|
||||
table = ""
|
||||
counter = 1
|
||||
for line in scan:
|
||||
line = line.split(":")
|
||||
table += '<tr><td><input value = "{}" id="type_radio_{}" name="type_radio" type="radio"</td><td>{}</td><td>{}</td><td>{}</td><td>{}</td></tr>'.format(
|
||||
counter,
|
||||
counter,
|
||||
line[0],
|
||||
line[1],
|
||||
"yes" if line[2].strip() == "*" else "",
|
||||
"None" if line[3].strip() == "" else line[3],
|
||||
)
|
||||
counter += 1
|
||||
output = output.replace("*DATA*", table)
|
||||
return output
|
||||
if request.method == "POST":
|
||||
try:
|
||||
line = scan[int(request.form.get("type_radio")) - 1]
|
||||
except:
|
||||
return redirect("/")
|
||||
|
||||
if line.split(":")[3] == "WPA2":
|
||||
return redirect("/passwd")
|
||||
|
||||
return redirect("/connect")
|
||||
Reference in New Issue
Block a user