diff --git a/app/network_utils.py b/app/network_utils.py index b95df11..378c825 100644 --- a/app/network_utils.py +++ b/app/network_utils.py @@ -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 diff --git a/app/routes2.py b/app/routes2.py index 7912894..5b83e5b 100644 --- a/app/routes2.py +++ b/app/routes2.py @@ -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") diff --git a/app/templates/base.html b/app/templates/base.html index cba92ca..b23ea67 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -45,12 +45,17 @@ Travel Router: Home {% if not current_user.is_anonymous %} - Logout - {% endif %} - {% if vpn %} - Disconnect from VPN - {% else %} - Connect to VPN + Logout + {% if vpn %} + Disconnect from VPN + {% else %} + Connect to VPN + {% endif %} + {% if killswitch %} + Disable KillSwitch + {% else %} + Enable KillSwitch + {% endif %} {% endif %}