-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopen_connection
More file actions
executable file
·121 lines (105 loc) · 2.51 KB
/
Copy pathopen_connection
File metadata and controls
executable file
·121 lines (105 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# /bin/bash
#This Script Sets Up VPN and SSH connection back to home machines
#Usage Information
usage() {
echo "Usage: [PROGRAM_NAME] [OPTION]"
echo "Usage: OPTIONS: [ -h | --your_home ] [ -f | --other_host ]"
}
#Exit Function
exit_func () {
if [ $1 == 1 ]; then
echo "Exit 1 --> Incorrect Number Of Arguments."
exit 1
elif [ $1 == 2 ]; then
echo "Exit 2 --> VPN Connection Could Not Be Established"
exit 2
elif [ $1 == 3 ]; then
echo "Exit 3 --> Unable To Break Connection"
exit 3
elif [ $1 == 0 ]; then
echo "Exit 0 --> Success!"
exit 0
fi
}
#Method To Open Connection
establish_connection () {
#Open Terminal and OpenVPN Into
gnome-terminal -e "openvpn --config /path/to/your/.ovpn/file"
#Check If Connection Was Successful
if [ !"$(check_connection)" ]; then
echo "Connection Status --> Failure."
usage
exit_func 2
elif [ "$(check_connection)" ]; then
echo "Connection Status --> Success!"
return 0
fi
}
#Check Connection Pings A Host I Know To Be On Network To Check If I Am On VPN
check_connection () {
for i in 1 2
do
ping -c3 "IP on Your Network"
res=$?
if [ $res == 0 ]; then
return $res
else
continue
fi
done
}
#Kills All OpenVPN Connections
break_connection () {
killall openvpn
return 0
}
#If Number Of Arguments Is Correct
if [ $# -eq 1 ]; then
while [ "$1" != "" ]; do
#Check On The Arguments Passed In
case $1 in
#Based On Argument, Connect To VPN, Else Print Usage And Exit
-h | --your_home ) if [ "$(establish_connection)" ]; then
ssh user@your_home
break_connection
exit_func 0
elif [ !"$(establish_connection)" ]; then
usage
exit_func 2
fi
;;
-f | --other_user ) if [ "$(establish_connection)" ]; then
ssh user@other_user
break_connection
exit_func 0
elif [ !"$(establish_connection)" ]; then
usage
exit_func 2
fi
;;
-ff | --other-files ) if [ "$(establish_connection)" ]; then
sftp user@other_user
break_connection
exit_func 0
elif [ !"$(establish_connection)" ]; then
usage
exit_func 2
fi
;;
-hf | --home-files ) if [ "$(establish_connection)" ]; then
sftp user@your_home
break_connection
exit_func 0
elif [ "$(establish_connection)" ]; then
usage
exit_func 2
fi
;;
* ) usage
exit_func 2
esac
done
else
usage
exit_func 1
fi