Disconnect working
This commit is contained in:
@@ -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_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*"
|
||||||
|
CMD_DISCONNECT = "sudo nmcli device disconnect wlxf81a6719febb"
|
||||||
# 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'
|
||||||
|
|
||||||
@@ -37,17 +38,21 @@ def index():
|
|||||||
scan = scan_networks()
|
scan = scan_networks()
|
||||||
|
|
||||||
for network in scan:
|
for network in scan:
|
||||||
item = Network(
|
item = [
|
||||||
network.split(":")[0],
|
network.split(":")[0],
|
||||||
network.split(":")[1],
|
network.split(":")[1],
|
||||||
"Yes" if network.split(":")[2] == "*" else "",
|
"Yes" if network.split(":")[2] == "*" else "",
|
||||||
"None" if network.split(":")[3].strip() == "" else "WPA2",
|
"None" if network.split(":")[3].strip() == "" else "WPA2",
|
||||||
)
|
]
|
||||||
results.append(item)
|
results.append(item)
|
||||||
|
|
||||||
table = Networks(results)
|
# table = Networks(results)
|
||||||
table.border = True
|
# table.border = True
|
||||||
return render_template("index.html", table=table)
|
t = {}
|
||||||
|
for a in results:
|
||||||
|
t["ssid"] = a[0]
|
||||||
|
|
||||||
|
return render_template("index.html", index_table=results)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/login", methods=["GET", "POST"])
|
@app.route("/login", methods=["GET", "POST"])
|
||||||
@@ -95,4 +100,19 @@ def connect(ssid, security):
|
|||||||
return redirect(url_for("wpa", ssid=ssid))
|
return redirect(url_for("wpa", ssid=ssid))
|
||||||
|
|
||||||
cmd = CMD_JOIN.replace("*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)
|
||||||
|
|||||||
@@ -1,4 +1,65 @@
|
|||||||
<doctype html="">
|
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
|
||||||
<title>Networks</title>
|
<meta http-equiv="Pragma" content="no-cache" />
|
||||||
{{ table }}
|
<meta http-equiv="Expires" content="0" />
|
||||||
</doctype>
|
<style type="text/css">
|
||||||
|
.tg {
|
||||||
|
border-collapse: collapse;
|
||||||
|
border-spacing: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tg td {
|
||||||
|
border-color: black;
|
||||||
|
border-style: solid;
|
||||||
|
border-width: 1px;
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
font-size: 14px;
|
||||||
|
overflow: hidden;
|
||||||
|
padding: 10px 5px;
|
||||||
|
word-break: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tg th {
|
||||||
|
border-color: black;
|
||||||
|
border-style: solid;
|
||||||
|
border-width: 1px;
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: normal;
|
||||||
|
overflow: hidden;
|
||||||
|
padding: 10px 5px;
|
||||||
|
word-break: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tg .tg-0lax {
|
||||||
|
text-align: left;
|
||||||
|
vertical-align: top
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
{% block content %}
|
||||||
|
<h1>Networks</h1>
|
||||||
|
<table class="tg">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th class="tg-0lax">SSID</th>
|
||||||
|
<th class="tg-0lax">Signal Size</th>
|
||||||
|
<th class="tg-0lax">Connected</th>
|
||||||
|
<th class="tg-0lax">Security</th>
|
||||||
|
<th class="tg-0lax">Action</th>
|
||||||
|
</tr>
|
||||||
|
{%- for row in index_table %}
|
||||||
|
<tr>
|
||||||
|
<td>{{row[0]}}</td>
|
||||||
|
<td>{{row[1]}}</td>
|
||||||
|
<td>{{row[2]}}</td>
|
||||||
|
<td>{{row[3]}}</td>
|
||||||
|
{% if row[2] == "Yes" %}
|
||||||
|
{{ "User is logged in" if loggedin else "User is not logged in" }}
|
||||||
|
<td><a href={{"/disconnect/" + row[0] }}>Disconnect</a></td>
|
||||||
|
{% else %}
|
||||||
|
<td><a href={{"/connect/" + row[0] + "&" + row[3]}}>Connect</a></td>
|
||||||
|
{% endif %}
|
||||||
|
</tr>
|
||||||
|
{%- endfor %}
|
||||||
|
</thead>
|
||||||
|
</table>
|
||||||
|
{% endblock %}
|
||||||
Reference in New Issue
Block a user