forked from pivpn/pivpn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pivpn
102 lines (91 loc) · 2.85 KB
/
pivpn
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
#!/bin/bash
# Must be root to use this tool
if [[ ! $EUID -eq 0 ]];then
if [[ $(dpkg-query -s sudo) ]];then
export SUDO="sudo"
else
echo "::: Please install sudo or run this as root."
exit 1
fi
fi
function makeOVPNFunc {
shift
$SUDO /opt/pivpn/makeOVPN.sh "$@"
exit 1
}
function listClientsFunc {
$SUDO /opt/pivpn/clientStat.sh
exit 1
}
function listOVPNFunc {
$SUDO /opt/pivpn/listOVPN.sh
exit 1
}
function debugFunc {
noUFW=$(cat /etc/pivpn/NO_UFW)
echo "::: Generating Debug Output"
$SUDO /opt/pivpn/pivpnDebug.sh | tee /tmp/debug.txt
echo "::: "
echo "::: Debug output completed above."
echo "::: Copy saved to /tmp/debug.txt"
echo "::: "
if [[ ${noUFW} -eq 1 ]]; then
IPTABLES_FIX=`$SUDO iptables -t nat -L -n -v | grep -c 'MASQUERADE.*10.8.0.0\/24'`
$SUDO iptables -t nat -L -n -v | grep -q 'MASQUERADE.*10.8.0.0\/24'
if [ $? -ne 0 ]; then
IPTABLES_FIX=2
fi
if [[ ${IPTABLES_FIX} -gt 1 ]]; then
echo "::: We detected some potential issues with your iptables."
read -p "::: Would you like us to try to fix this? [y/n]: " -n 1 -r
echo
if [[ ${REPLY} =~ ^[Yy]$ ]]; then
$SUDO /opt/pivpn/fix_iptables.sh
fi
echo "::: Attempt at fix completed."
echo "::: Run 'pivpn debug' again to see if we detect issues."
fi
fi
exit 1
}
function removeOVPNFunc {
$SUDO /opt/pivpn/removeOVPN.sh
exit 1
}
function uninstallFunc {
$SUDO /opt/pivpn/uninstall.sh
exit 1
}
function versionFunc {
printf "\e[1mVersion 1.9\e[0m\n"
}
function helpFunc {
echo "::: Control all PiVPN specific functions!"
echo ":::"
echo "::: Usage: pivpn <command> [option]"
echo ":::"
echo "::: Commands:"
echo "::: -a, add [nopass] Create a client ovpn profile, optional nopass"
echo "::: -c, clients List any connected clients to the server"
echo "::: -d, debug Start a debugging session if having trouble"
echo "::: -l, list List all valid and revoked certificates"
echo "::: -r, revoke Revoke a client ovpn profile"
echo "::: -h, help Show this help dialog"
echo "::: -u, uninstall Uninstall PiVPN from your system!"
exit 1
}
if [[ $# = 0 ]]; then
helpFunc
fi
# Handle redirecting to specific functions based on arguments
case "$1" in
"-a" | "add" ) makeOVPNFunc "$@";;
"-c" | "clients" ) listClientsFunc;;
"-d" | "debug" ) debugFunc;;
"-l" | "list" ) listOVPNFunc;;
"-r" | "revoke" ) removeOVPNFunc;;
"-h" | "help" ) helpFunc;;
"-u" | "uninstall" ) uninstallFunc;;
"-v" ) versionFunc;;
* ) helpFunc;;
esac