Disconnect working

This commit is contained in:
Rich
2021-07-04 15:00:08 +01:00
parent 6ce91e5c84
commit 9310e15f64
3 changed files with 92 additions and 11 deletions

View File

@@ -12,6 +12,7 @@ from config import debug
CMD_SCAN = "sudo nmcli -t -f SSID,SIGNAL,IN-USE,SECURITY -e yes -m tab device wifi list ifname wlxf81a6719febb --rescan yes"
CMD_JOIN = "sudo nmcli device wifi connect *SSID* ifname wlxf81a6719febb"
CMD_JOINPW = "sudo nmcli device wifi connect *SSID* ifname wlxf81a6719febb password *PASSWORD*"
CMD_DISCONNECT = "sudo nmcli device disconnect wlxf81a6719febb"
# Error: Connection activation failed: (7) Secrets were required, but not provided.
# Device 'wlxf81a6719febb' successfully activated with '11111-1111-11111-111111-11111111'
@@ -37,17 +38,21 @@ def index():
scan = scan_networks()
for network in scan:
item = Network(
item = [
network.split(":")[0],
network.split(":")[1],
"Yes" if network.split(":")[2] == "*" else "",
"None" if network.split(":")[3].strip() == "" else "WPA2",
)
]
results.append(item)
table = Networks(results)
table.border = True
return render_template("index.html", table=table)
# table = Networks(results)
# table.border = True
t = {}
for a in results:
t["ssid"] = a[0]
return render_template("index.html", index_table=results)
@app.route("/login", methods=["GET", "POST"])
@@ -95,4 +100,19 @@ def connect(ssid, security):
return redirect(url_for("wpa", ssid=ssid))
cmd = CMD_JOIN.replace("*SSID*", ssid)
return cmd
output = subprocess.run(cmd.split(" "), stdout=subprocess.PIPE, stderr=subprocess.PIPE).stdout.decode("utf-8")
if output.find("Error") == -1:
return "Successfully connected to {}".format(ssid)
return "Failed to connect to {}".format(ssid)
@app.route("/disconnect/<string:ssid>", methods=["GET", "POST"])
@login_required
def disconnect(ssid):
output = subprocess.run(CMD_DISCONNECT.split(" "), stdout=subprocess.PIPE, stderr=subprocess.PIPE).stdout.decode("utf-8")
if output.find("successfully disconnected") != -1:
return "Successfully Disconnected from {}".format(ssid)
return "Failed to Disconnect from {}".format(ssid)