Working before disconnect

This commit is contained in:
Rich
2021-07-04 10:50:38 +01:00
parent 673d823599
commit 6645650610
2 changed files with 7 additions and 6 deletions

View File

@@ -10,8 +10,8 @@ from app.models import Network, Networks, User
from config import debug 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_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_JOIN = "sudo nmcli device wifi connect *SSID* ifname wlxf81a6719febb"
CMD_JOINPW = 'sudo nmcli device wifi connect "*SSID*" ifname wlxf81a6719febb password "*PASSWORD*"' CMD_JOINPW = "sudo nmcli device wifi connect *SSID* ifname wlxf81a6719febb password *PASSWORD*"
# Error: Connection activation failed: (7) Secrets were required, but not provided. # Error: Connection activation failed: (7) Secrets were required, but not provided.
# Device 'wlxf81a6719febb' successfully activated with '11111-1111-11111-111111-11111111' # Device 'wlxf81a6719febb' successfully activated with '11111-1111-11111-111111-11111111'
@@ -23,6 +23,7 @@ def scan_networks():
t = line.split(":") t = line.split(":")
if t[0] != "": if t[0] != "":
scan.append(line) scan.append(line)
return scan return scan
@@ -78,11 +79,11 @@ def wpa(ssid):
cmd = CMD_JOINPW.replace("*SSID*", ssid) cmd = CMD_JOINPW.replace("*SSID*", ssid)
cmd = cmd.replace("*PASSWORD*", form.password.data) cmd = cmd.replace("*PASSWORD*", form.password.data)
output = subprocess.run(cmd.split(" "), stdout=subprocess.PIPE).stdout.decode("utf-8") output = subprocess.run(cmd.split(" "), stdout=subprocess.PIPE, stderr=subprocess.PIPE).stdout.decode("utf-8")
if output.find("Error") == "-1": if output.find("Error") == -1:
return "Successfully connected to {}".format(ssid) return "Successfully connected to {}".format(ssid)
return "Failed to connect to {} {} {}".format(ssid, pformat(cmd.split(" ")), cmd) return "Failed to connect to {}".format(ssid)
return render_template("wpa.html", title="WPA Password", form=form) return render_template("wpa.html", title="WPA Password", form=form)

View File

@@ -2,7 +2,7 @@ import os
basedir = os.path.abspath(os.path.dirname(__file__)) basedir = os.path.abspath(os.path.dirname(__file__))
debug = False debug = True
class Config(object): class Config(object):