dotfiles/.local/bin/dmenuvpn

24 lines
1.1 KiB
Plaintext
Raw Normal View History

2020-10-23 14:45:02 +02:00
#!/bin/bash
PASS_DIR=Misc/SaferVPN
USER='alexander@bocken.org'
ETH_user="abocken@student-net.ethz.ch"
ETH_password_path="ETH/VPN"
2024-01-19 14:22:04 +01:00
ETH_OTP_path="OTP/nETHz"
2020-10-23 14:45:02 +02:00
2021-01-21 11:29:06 +01:00
choice="$(ls "${XDG_CONFIG_HOME}/openvpn/cfgs" | sed 's/\.ovpn//' | awk 'BEGIN {print "ETH"}; {print $0}' | dmenu -i -p 'connect with which vpn server?' -l 10)"
2020-11-07 23:43:31 +01:00
[ -z "$choice" ] && exit
if [ "$choice" = "ETH" ]; then
if [ $(pgrep -c openconnect) -eq 0 ]; then
2024-01-19 14:22:04 +01:00
printf "%s\n%s\n" "$(pass "$ETH_password_path")" "$(pass otp "$ETH_OTP_path")" | sudo openconnect --useragent=AnyConnect -g student-net -u "$ETH_user" --passwd-on-stdin sslvpn.ethz.ch &
2023-10-12 15:12:12 +02:00
if ping -c 3 -W 3 -q webprint.ethz.ch ;then
notify-send "ETH VPN" "ETH VPN connected"
fi
elif ping -c 1 -W 2 -q webprint.ethz.ch ;then
2020-11-07 23:43:31 +01:00
sudo pkill openconnect && notify-send "ETH VPN" "ETH VPN disconnected"
2020-10-23 14:45:02 +02:00
fi
2020-11-07 23:43:31 +01:00
else
printf '%s\n%s\n' "$USER" "$(pass $PASS_DIR)" > /tmp/tmp_pass
2021-06-12 18:27:40 +02:00
[ -n "$choice" ] && st -t "openVPN" sudo openvpn --config "${XDG_CONFIG_HOME}/openvpn/cfgs/${choice}.ovpn" --mute-replay-warnings --auth-user-pass /tmp/tmp_pass & pkill -RTMIN+9 dwmblocks; sleep 2; rm -f /tmp/tmp_pass
2020-10-23 14:45:02 +02:00
fi
pkill -RTMIN+9 dwmblocks