This commit is contained in:
Rich
2021-08-05 16:54:25 +01:00
parent 34464fd461
commit 9933954deb
3 changed files with 65 additions and 10 deletions

View File

@@ -1,5 +1,6 @@
import re
import subprocess
import time
from config import ClientInterface
@@ -27,9 +28,12 @@ ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
"""
def run_subprocess(cmd, check=True):
def run_subprocess(cmd, check=True, delay=0):
cmd_split = cmd.split(" ")
return subprocess.run(cmd_split, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=check).stdout.decode("utf-8")
output = subprocess.run(cmd_split, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=check).stdout.decode("utf-8")
if delay > 0:
time.sleep(delay)
return output
def run_subprocess_interface(cmd, check=True):
@@ -173,3 +177,21 @@ def vpn_disconnect():
if run_subprocess("nordvpn d").find("You are disconnected from NordVPN") != -1:
return True
return False
def killswitch_status():
if run_subprocess("nordvpn settings").find("Kill Switch: disabled") != -1:
return False
return True
def killswich_enable():
if run_subprocess("nordvpn set killswitch on", delay=2).find("Kill Switch is set to 'enabled' successfully") != -1:
return True
return False
def killswich_disaable():
if run_subprocess("nordvpn set killswitch off", delay=2).find("Kill Switch is set to 'disabled' successfully") != -1:
return True
return False

View File

@@ -4,14 +4,24 @@ from flask_login import current_user, login_required, login_user, logout_user
from app import app
from app.forms import LoginForm, WPAForm
from app.models import ConfigTable, Passwords, User
from app.network_utils import connect_network, disconnect_network, scan_networks, vpn_connect, vpn_connected, vpn_disconnect
from app.network_utils import (
connect_network,
disconnect_network,
killswich_disaable,
killswich_enable,
killswitch_status,
scan_networks,
vpn_connect,
vpn_connected,
vpn_disconnect,
)
@app.route("/")
@app.route("/index")
@login_required
def index():
return render_template("index.html", networks=scan_networks(), vpn=vpn_connected())
return render_template("index.html", networks=scan_networks(), vpn=vpn_connected(), killswitch=killswitch_status())
@app.route("/login", methods=["GET", "POST"])
@@ -87,3 +97,21 @@ def vpndisconnect():
return render_template("message.html", message="Sucessfully disconnected from VPN")
return render_template("message.html", message="Failed to disconnect from VPN")
@app.route("/ksenable/", methods=["GET", "POST"])
@login_required
def ksenable():
if killswich_enable():
return render_template("message.html", message="Sucessfully Enabled KillSwitch")
return render_template("message.html", message="Failed to Enable KillSwitch")
@app.route("/ksdisable/", methods=["GET", "POST"])
@login_required
def ksdisable():
if killswich_disaable():
return render_template("message.html", message="Sucessfully Disabled KillSwitch")
return render_template("message.html", message="Failed to Disable KillSwitch")

View File

@@ -46,12 +46,17 @@
<a href="{{ url_for('index') }}">Home</a>
{% if not current_user.is_anonymous %}
<a href="{{ url_for('logout') }}">Logout</a>
{% endif %}
{% if vpn %}
<a href="{{ url_for('vpndisconnect') }}">Disconnect from VPN</a>
{% else %}
<a href="{{ url_for('vpnconnect') }}">Connect to VPN</a>
{% endif %}
{% if killswitch %}
<a href="{{ url_for('ksdisable') }}">Disable KillSwitch</a>
{% else %}
<a href="{{ url_for('ksenable') }}">Enable KillSwitch</a>
{% endif %}
{% endif %}
</div>
<hr>
{% block content %}{% endblock %}