├── README.md ├── autovpn.sh └── killvpn.sh /README.md: -------------------------------------------------------------------------------- 1 | # AutoVPN 2 | Author: Bakhtiyar Syed 3 | 4 | This is an automatic VPN installer/runner for IIIT-H students. 5 | 6 | 7 | **Usage:** 8 | 9 | ```bash 10 | 1. After downloading the zip, extract it. 11 | 12 | 2. cd AutoVPN/ OR cd AutoVPN-master/ (depending on your mode of download via cloning or direct download.) 13 | 14 | 3. ./autovpn.sh 15 | ``` 16 | 17 | (Your official IIIT-H students/research email and password must be entered when prompted.) 18 | 19 | **Requirements:** 20 | > 21 | None (: 22 | 23 | **Constraints:** 24 | > 25 | Works only on Ubuntu(apt-get package) and Fedora (dnf package) related systems right now. 26 | You need to run the script with root access(sudo). 27 | 28 | **Troubleshooting** 29 | > 30 | The most common doubt everyone faces is how to proceed when they face a proxy error. This is not an error, it's just that you're no longer on the IIIT-H network and you need to unset your proxy environment variables. 31 | If you haven't yet unset your proxy variables, here's the way: 32 | 33 | ``` 34 | 1. Open your terminal and type: 35 | unset http_proxy ; unset https_proxy ; unset HTTP_PROXY ; unset HTTPS_PROXY 36 | 37 | 2. You have to go to network settings and change proxy to None. 38 | Just changing in the browser does not help. Pretty obvious but yeah. 39 | 40 | 3. Comment out everything there is in the file /etc/apt/apt.conf.d/99iiithproxy . 41 | If the file does not exist, ignore. 42 | 43 | 4. If you're still unable to connect, a restart of your PC might be needed. 44 | ``` 45 | 46 | 47 | 48 | *Pull requests and suggestions for improvement are most welcome.* 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /autovpn.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | #Author: Bakhtiyar Syed 4 | #Institution: IIIT Hyderabad 5 | #Date: 28 November 2016 6 | 7 | #interact 8 | 9 | chmod +x $0 10 | 11 | usr=$1; 12 | passwd=$2; 13 | 14 | # Run in root if not already running in it 15 | if [[ $(whoami) != "root" ]]; then 16 | xhost +SI:localuser:root 17 | sudo "$0" "$@" 18 | xhost -SI:localuser:root 19 | exit 20 | fi 21 | 22 | 23 | command -v zenity >/dev/null 2>&1 || { 24 | if command -v apt-get 2&>1; then 25 | apt-get update; apt-get install -y zenity; 26 | elif command -v dnf 2&>1; then 27 | dnf install -y zenity 28 | fi 29 | } 30 | 31 | 32 | 33 | 34 | #[ -z $usr ] && read -p "Enter username: " -a usr 35 | #[ -z $passwd ] && read -s -p "Enter password: " -a passwd 36 | 37 | 38 | [ -z $usr ] && usr="$(zenity --entry --height=160 --width=400 --text="Enter your IIIT-H email ID" --title=Authentication)" 39 | [ -z $passwd ] && passwd="$(zenity --password --height=160 --width=400 --text="Please enter your password" --title=Authentication)" 40 | cd; 41 | 42 | 43 | command -v openvpn >/dev/null 2>&1 || { 44 | if command -v apt-get 2&>1; then # Ubuntu based distros 45 | apt-get update; apt-get install -y openvpn; 46 | elif command -v dnf 2&>1; then # Fedora based distros 47 | dnf install -y openvpn 48 | fi 49 | } 50 | command -v expect >/dev/null 2>&1 || { 51 | if command -v apt-get 2&>1; then # Ubuntu based distros 52 | apt-get update; apt-get install -y expect; 53 | elif command -v dnf 2&>1; then # Fedora based distros 54 | dnf install -y expect 55 | fi 56 | } 57 | 58 | if grep -q "nameserver 10.4.20.204" "/etc/resolv.conf"; 59 | then 60 | sed -i '/nameserver 10.4.20.204/d' /etc/resolv.conf 61 | fi 62 | #apt-get update; 63 | 64 | 65 | 66 | cd /etc/openvpn; 67 | #rm -rf * 68 | if [ -e "ca.crt" ]; 69 | then 70 | rm -f ca.crt 71 | fi 72 | wget https://vpn.iiit.ac.in/ca.crt 73 | if [ -e "all.iiit.ac.in.crt" ] || [ -e "all.iiit.ac.in.crt.*" ]; 74 | then 75 | rm -f all.iiit.ac.in.crt; 76 | rm -f all.iiit.ac.in.crt.*; 77 | fi 78 | wget https://vpn.iiit.ac.in/all.iiit.ac.in.crt 79 | if [ -e "all.iiit.ac.in.key" ]; 80 | then 81 | rm all.iiit.ac.in.key 82 | fi 83 | 84 | curl -O --user "$usr":"$passwd" https://vpn.iiit.ac.in/secure/all.iiit.ac.in.key 85 | 86 | #fi 87 | 88 | chmod 600 all.iiit.ac.in.key; 89 | if [ -e "linux_client.conf" ]; 90 | then 91 | rm -f linux_client.conf; 92 | fi 93 | 94 | wget https://vpn.iiit.ac.in/linux_client.conf 95 | 96 | # Escape dollars in usr and passwd for expect's send 97 | usr=$(echo "$usr"| sed 's/\$/\\\$/g') 98 | passwd=$(echo "$passwd"| sed 's/\$/\\\$/g') 99 | 100 | #Remove newline chars 101 | #dt=${dt//$'\n'/} 102 | #dt=${dt//$'\n'/} 103 | usr="${usr//$'\\n'/}" 104 | passwd="${passwd//$'\\n'/}" 105 | #passwd="$(echo "$passwd" | sed -e 's/\n//g')" 106 | 107 | 108 | 109 | #echo $passwd 110 | expect <<- DONE 111 | 112 | spawn openvpn --config linux_client.conf; 113 | 114 | expect "Enter Auth Username:" { send "$usr\r" } 115 | 116 | expect "Enter Auth Password:" { send "$passwd\r" } 117 | 118 | expect "Initialization Sequence Completed" 119 | 120 | interact; 121 | DONE 122 | 123 | sleep 12; 124 | if grep -q "nameserver 10.4.20.204" "/etc/resolv.conf"; 125 | then 126 | echo "Nameserver already set. No need for further setting up"; 127 | else 128 | sed -i '1i\'"nameserver 10.4.20.204" /etc/resolv.conf; 129 | fi 130 | 131 | if ! ping -c1 moodle.iiit.ac.in &>/dev/null 132 | then 133 | zenity --error --height=100 --width=400 --title="An Error Occurred" --text="VPN failed to start. Contact the administrator or see troubleshooting on github.com/flyingcharge/AutoVPN" 134 | else 135 | zenity --info --title="SUCCESS" --text="VPN SUCCESSFULLY RUNNING!" 136 | fi 137 | sleep 3; 138 | #num=`history | tail -n 2 | head -n 1 | tr -s ' ' | cut -d ' ' -f 2`; 139 | 140 | #history -c; 141 | 142 | #export HISTFILE=/dev/null 143 | -------------------------------------------------------------------------------- /killvpn.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ $(whoami) != "root" ]]; then 4 | sudo "$0" "$@" 5 | exit 6 | fi 7 | 8 | pkill openvpn 9 | sed -i '/nameserver 10.4.20.204/d' /etc/resolv.conf 10 | --------------------------------------------------------------------------------