From c4c3b4d492c175a8b033e8c490d30881b647abf9 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Tue, 4 Feb 2025 11:51:09 +0100 Subject: [PATCH] bin: vpn scripts --- .local/bin/scripts/nv | 5 ++++- .local/bin/scripts/vpn | 28 +++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/.local/bin/scripts/nv b/.local/bin/scripts/nv index 00f5763..c8fb7bb 100755 --- a/.local/bin/scripts/nv +++ b/.local/bin/scripts/nv @@ -1,3 +1,6 @@ #!/bin/sh -e # Toggle NordVPN -nordvpn status | grep --color=never Disconnected && nordvpn connect de || nordvpn disconnect; nordvpn status +if test $# -gt 0 +then nordvpn connect "$@" +else nordvpn status | grep --color=never Disconnected && nordvpn connect de || nordvpn disconnect; nordvpn status +fi diff --git a/.local/bin/scripts/vpn b/.local/bin/scripts/vpn index 521120d..707ae76 100755 --- a/.local/bin/scripts/vpn +++ b/.local/bin/scripts/vpn @@ -1,3 +1,29 @@ #!/bin/sh -e test -f "$1" || cd "$XDG_DATA_HOME/openvpn" -tmux new-session -s "$@" "sudo openvpn $@ || read" +case "$1" in + ("") tmux new-session -s "vpn" "tmux ls; $SHELL";; + (forti) + if ip route | grep -q ppp0 + then echo "Device ppp0 already in use!" + else sudo tmux new-session -s "$1" ' + set -x + route="$(ip route | grep default | sort | head -1)" + # Start openfortivpn in the background + openfortivpn & + VPN_PID=$! + # Wait a little for the VPN to establish the connection + sleep 5 +# TODO Loop + # Delete the default route set by openfortivpn (ppp0) + ip route del default dev ppp0 + # Add the default route via the local network + eval "ip route add $route" + ip route add 134.245.0.0/16 dev ppp0; + ip route + wait $VPN_PID + echo "VPN has disconnected." + ' + fi + ;; + (*) tmux new-session -s "$@" "sudo openvpn $@ || read";; +esac