diff --git a/app/routes.py b/app/routes.py index b658be7..06931a9 100644 --- a/app/routes.py +++ b/app/routes.py @@ -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/", 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) diff --git a/app/templates/index.html b/app/templates/index.html index f5c6c2a..64ec4a6 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -1,4 +1,65 @@ - - Networks - {{ table }} - \ No newline at end of file + + + + +{% block content %} +

Networks

+ + + + + + + + + + {%- for row in index_table %} + + + + + + {% if row[2] == "Yes" %} + {{ "User is logged in" if loggedin else "User is not logged in" }} + + {% else %} + + {% endif %} + + {%- endfor %} + +
SSIDSignal SizeConnectedSecurityAction
{{row[0]}}{{row[1]}}{{row[2]}}{{row[3]}}DisconnectConnect
+{% endblock %} \ No newline at end of file diff --git a/config.py b/config.py index 8d63d90..54b5512 100644 --- a/config.py +++ b/config.py @@ -2,7 +2,7 @@ import os basedir = os.path.abspath(os.path.dirname(__file__)) -debug = True +debug = False class Config(object):