Skip to content

Instantly share code, notes, and snippets.

@Prashant446
Last active November 29, 2023 18:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Prashant446/d3d73ce1a443236395c9200b4b84810b to your computer and use it in GitHub Desktop.
Save Prashant446/d3d73ce1a443236395c9200b4b84810b to your computer and use it in GitHub Desktop.
IITK-VPN easy connect setup
0. Make sure you have expect or install using "sudo apt install expect"
1. Replace cc id(praskr) and password(xyzw) in setup.sh with your own credentials.
2. Run setup.sh
3. If everthing went well then you can use "iitkvpn_connect" command to connect to VPN
Note:
a. Scripts, by default, will be installed at: ~/scripts/
b. Forticlient software, by default, will be stored at: ~/Downloads/forticlientsslvpn/
c. Script folder is added into PATH by adding a line in .bashrc. Remove the line if you don't want that.
d. Your cc password is stored in ${script_folder}/iitkvpn_connect file!
e. If you don't want to scroll through the licsesnce, do: Ctrl+C then type "Y"/"Yes"
#!/bin/bash
# written for: Linux 64-bit
# Dependenies: wget, bash, expect
# useful link: https://www.iitk.ac.in/ccnew/index.php/13-network/99-how-to-use-ssl-vpn
# fill these:
cc_id='praskr'
cc_password='xyzw'
download_path=~/Downloads/
script_path=~/scripts/
software_url='https://www.iitk.ac.in/ccnew/images/VPN/forticlientsslvpn_linux_4.4.2317.tar'
if [[ !(-d $script_path) ]]; then
mkdir -p $script_path;
fi
if [[ !(-d $download_path) ]]; then
mkdir -p $download_path;
fi
cd $download_path
rm -rf forticlientsslvpn_linux_4.4.2317.tar forticlientsslvpn/
wget $software_url
tar -xf forticlientsslvpn_linux_4.4.2317.tar
./forticlientsslvpn/64bit/helper/setup.linux.sh
cd $script_path
printf "\n\nwriting scripts..."
cat <<EOF >vpn_connect.sh
#! /bin/bash
${download_path}/forticlientsslvpn/64bit/forticlientsslvpn_cli \
--server gateway.iitk.ac.in:443 \
--vpnuser ${cc_id} \
--keepalive
EOF
chmod +x vpn_connect.sh
cat <<EOF >iitkvpn_connect
#!/usr/bin/expect -f
#
# This Expect script was generated by autoexpect on Sun Feb 28 09:58:48 2021
# Expect and autoexpect were both written by Don Libes, NIST.
#
# Note that autoexpect does not guarantee a working script. It
# necessarily has to guess about certain things. Two reasons a script
# might fail are:
#
# 1) timing - A surprising number of programs (rn, ksh, zsh, telnet,
# etc.) and devices discard or ignore keystrokes that arrive "too
# quickly" after prompts. If you find your new script hanging up at
# one spot, try adding a short sleep just before the previous send.
# Setting "force_conservative" to 1 (see below) makes Expect do this
# automatically - pausing briefly before sending each character. This
# pacifies every program I know of. The -c flag makes the script do
# this in the first place. The -C flag allows you to define a
# character to toggle this mode off and on.
#
# 2) differing output - Some programs produce different output each time
# they run. The "date" command is an obvious example. Another is
# ftp, if it produces throughput statistics at the end of a file
# transfer. If this causes a problem, delete these patterns or replace
# them with wildcards. An alternative is to use the -p flag (for
# "prompt") which makes Expect only look for the last line of output
# (i.e., the prompt). The -P flag allows you to define a character to
# toggle this mode off and on.
#
# Read the man page for more info.
#
# -Don
set timeout -1
log_user 0
spawn vpn_connect.sh
match_max -d
expect -exact "Password for VPN:"
send -- "${cc_password}\r"
send_user "Entered Password\n"
expect -exact "Would you like to connect to this server? (Y/N)"
send -- "Y\r"
send_user -- "Connecting to VPN\n"
expect -exact "STATUS::Tunnel running"
send_user -- "Tunnel running\n"
expect_user "^c"
EOF
# To keep password stored in this file safe:
chmod 700 iitkvpn_connect
printf "\nscripts written, adding $script_path to PATH..."
cat <<EOF >>~/.bashrc
PATH=$PATH:$script_path
EOF
source ~/.bashrc
printf "\n\nDone! Use 'iitkvpn_connect' command to connect\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment