[Scripts] Improve VPN script
This commit is contained in:
		| @@ -1,59 +1,58 @@ | |||||||
| #!/usr/bin/env bash | #!/usr/bin/env bash | ||||||
|  |  | ||||||
| connect() { | connect() { | ||||||
| 	read -sp $'Please enter your Encryption Password:\n' encpass |     read -sp $'Please enter your Encryption Password: ' encpass | ||||||
| 	TOKEN=$(cat ~/.local/share/ethz-vpn-connect/ethzvpntoken.secret | openssl enc -aes-256-cbc -pbkdf2 -d -a -k $encpass) |     echo " ==> Connecting" | ||||||
| 	PASSWORD=$(cat ~/.local/share/ethz-vpn-connect/ethzvpnpass.secret | openssl enc -aes-256-cbc -pbkdf2 -d -a -k $encpass) |     TOKEN=$(cat ~/.local/share/ethz-vpn-connect/ethzvpntoken.secret | openssl enc -aes-256-cbc -pbkdf2 -d -a -k $encpass) | ||||||
| 	USERNAME=$(cat ~/.local/share/ethz-vpn-connect/ethzvpnusername.txt) |     PASSWORD=$(cat ~/.local/share/ethz-vpn-connect/ethzvpnpass.secret | openssl enc -aes-256-cbc -pbkdf2 -d -a -k $encpass) | ||||||
| 	echo $PASSWORD | sudo openconnect -b -u $USERNAME@student-net.ethz.ch -g student-net --useragent=AnyConnect --passwd-on-stdin --token-mode=totp --token-secret=sha1:base32:$TOKEN sslvpn.ethz.ch |     USERNAME=$(cat ~/.local/share/ethz-vpn-connect/ethzvpnusername.txt) | ||||||
| 	encpass="" |     echo $PASSWORD | sudo openconnect -b -u $USERNAME@student-net.ethz.ch -g student-net --useragent=AnyConnect --passwd-on-stdin --token-mode=totp --token-secret=sha1:base32:$TOKEN sslvpn.ethz.ch | ||||||
| 	PASSWORD="" |     encpass="" | ||||||
| 	TOKEN="" |     PASSWORD="" | ||||||
|  |     TOKEN="" | ||||||
| } | } | ||||||
|  |  | ||||||
| disconnect() { | disconnect() { | ||||||
| 	sudo killall -v -SIGINT openconnect #add -i option to ask for confirmation, usefull if running multible openconnect. |     sudo killall -v -SIGINT openconnect | ||||||
|  |     echo " ==> Disconnected" | ||||||
| } | } | ||||||
|  |  | ||||||
| setup() { | setup() { | ||||||
| 	echo 'You are about to overwrite your secrets. Press ctrl + C to cancel.' |     echo 'You are about to overwrite your secrets. Press ctrl + C to cancel.' | ||||||
| 	read -p $'Please enter your ETHZ-Username: ' USERNAME |     read -p $'Please enter your ETHZ-Username: ' USERNAME | ||||||
|     echo 'Ok!' |  | ||||||
|     read -sp $'Please choose and enter your Encryption Password (will be required when launching): ' encpass |     read -sp $'Please choose and enter your Encryption Password (will be required when launching): ' encpass | ||||||
|     echo 'Ok!' |  | ||||||
|     read -sp $'Please enter your ETHZ WLAN (= Radius) Password: ' PASSWORD |     read -sp $'Please enter your ETHZ WLAN (= Radius) Password: ' PASSWORD | ||||||
|     echo 'Ok!' |  | ||||||
|     read -sp $'Please enter your ETHZ OTP Secret: ' TOKEN |     read -sp $'Please enter your ETHZ OTP Secret: ' TOKEN | ||||||
| 	mkdir ~/.local/share/ethz-vpn-connect |     mkdir ~/.local/share/ethz-vpn-connect | ||||||
| 	echo $PASSWORD | openssl enc -aes-256-cbc -pbkdf2 -a -k $encpass >~/.local/share/ethz-vpn-connect/ethzvpnpass.secret |     echo $PASSWORD | openssl enc -aes-256-cbc -pbkdf2 -a -k $encpass >~/.local/share/ethz-vpn-connect/ethzvpnpass.secret | ||||||
| 	echo $TOKEN | openssl enc -aes-256-cbc -pbkdf2 -a -k $encpass >~/.local/share/ethz-vpn-connect/ethzvpntoken.secret |     echo $TOKEN | openssl enc -aes-256-cbc -pbkdf2 -a -k $encpass >~/.local/share/ethz-vpn-connect/ethzvpntoken.secret | ||||||
| 	echo $USERNAME >~/.local/share/ethz-vpn-connect/ethzvpnusername.txt |     echo $USERNAME >~/.local/share/ethz-vpn-connect/ethzvpnusername.txt | ||||||
| 	encpass="" |     encpass="" | ||||||
| 	PASSWORD="" |     PASSWORD="" | ||||||
| 	TOKEN="" |     TOKEN="" | ||||||
| 	echo $'Secrets set\n' |     echo $' ==> Secrets set <==\n' | ||||||
| } | } | ||||||
|  |  | ||||||
| case "$1" in | case "$1" in | ||||||
| 'connect') | 'connect') | ||||||
| 	connect |     connect | ||||||
| 	;; |     ;; | ||||||
| c) | c) | ||||||
| 	connect |     connect | ||||||
| 	;; |     ;; | ||||||
| 'disconnect') | 'disconnect') | ||||||
| 	disconnect |     disconnect | ||||||
| 	;; |     ;; | ||||||
| d) | d) | ||||||
| 	disconnect |     disconnect | ||||||
| 	;; |     ;; | ||||||
| dc) | dc) | ||||||
| 	disconnect |     disconnect | ||||||
| 	;; |     ;; | ||||||
| setup) | setup) | ||||||
| 	setup |     setup | ||||||
| 	;; |     ;; | ||||||
| *) | *) | ||||||
| 	echo -e 'Usage: ethz-vpn [Option] \n [Option]: \n       connect, c:             Connect VPN \n  disconnect, d, dc:      Disconnect VPN \n setup: set secrets and eth-Username.\n' |     echo -e 'Usage: ethz-vpn [Option] \n [Option]: \n       connect, c:             Connect VPN \n  disconnect, d, dc:      Disconnect VPN \n setup: set secrets and eth-Username.\n' | ||||||
| 	;; |     ;; | ||||||
| esac | esac | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user