2016-04-19 18:01:55 +00:00
|
|
|
#!/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 {
|
2016-05-01 03:37:27 +00:00
|
|
|
shift
|
|
|
|
$SUDO /opt/pivpn/makeOVPN.sh "$@"
|
2016-04-19 18:01:55 +00:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2016-12-08 16:43:30 +00:00
|
|
|
function listClientsFunc {
|
|
|
|
$SUDO /opt/pivpn/clientStat.sh
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2016-04-19 18:01:55 +00:00
|
|
|
function listOVPNFunc {
|
|
|
|
$SUDO /opt/pivpn/listOVPN.sh
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
function debugFunc {
|
2016-12-24 21:17:16 +00:00
|
|
|
noUFW=$(cat /etc/pivpn/NO_UFW)
|
2016-11-19 20:52:13 +00:00
|
|
|
echo "::: Generating Debug Output"
|
2017-01-27 22:46:34 +00:00
|
|
|
$SUDO /opt/pivpn/pivpnDebug.sh | tee /tmp/debug.txt
|
2016-11-19 20:52:13 +00:00
|
|
|
echo "::: "
|
|
|
|
echo "::: Debug output completed above."
|
|
|
|
echo "::: Copy saved to /tmp/debug.txt"
|
|
|
|
echo "::: "
|
2016-12-11 18:36:14 +00:00
|
|
|
if [[ ${noUFW} -eq 1 ]]; then
|
2017-01-27 22:46:34 +00:00
|
|
|
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'
|
2016-12-12 03:04:17 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
2016-12-11 18:36:14 +00:00
|
|
|
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
|
2016-12-12 03:04:17 +00:00
|
|
|
echo "::: Attempt at fix completed."
|
|
|
|
echo "::: Run 'pivpn debug' again to see if we detect issues."
|
2016-12-11 18:36:14 +00:00
|
|
|
fi
|
|
|
|
fi
|
2016-04-19 18:01:55 +00:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeOVPNFunc {
|
|
|
|
$SUDO /opt/pivpn/removeOVPN.sh
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
function uninstallFunc {
|
|
|
|
$SUDO /opt/pivpn/uninstall.sh
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2016-04-20 23:16:39 +00:00
|
|
|
function versionFunc {
|
2016-12-24 22:24:21 +00:00
|
|
|
printf "\e[1mVersion 1.9\e[0m\n"
|
2016-04-20 23:16:39 +00:00
|
|
|
}
|
|
|
|
|
2016-04-19 18:01:55 +00:00
|
|
|
function helpFunc {
|
|
|
|
echo "::: Control all PiVPN specific functions!"
|
|
|
|
echo ":::"
|
2016-05-01 03:37:27 +00:00
|
|
|
echo "::: Usage: pivpn <command> [option]"
|
2016-04-19 18:01:55 +00:00
|
|
|
echo ":::"
|
2016-05-01 03:37:27 +00:00
|
|
|
echo "::: Commands:"
|
|
|
|
echo "::: -a, add [nopass] Create a client ovpn profile, optional nopass"
|
2016-12-08 16:43:30 +00:00
|
|
|
echo "::: -c, clients List any connected clients to the server"
|
2016-04-19 18:01:55 +00:00
|
|
|
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
|
2016-05-01 03:37:27 +00:00
|
|
|
"-a" | "add" ) makeOVPNFunc "$@";;
|
2016-12-08 16:43:30 +00:00
|
|
|
"-c" | "clients" ) listClientsFunc;;
|
2016-04-19 18:01:55 +00:00
|
|
|
"-d" | "debug" ) debugFunc;;
|
|
|
|
"-l" | "list" ) listOVPNFunc;;
|
|
|
|
"-r" | "revoke" ) removeOVPNFunc;;
|
|
|
|
"-h" | "help" ) helpFunc;;
|
|
|
|
"-u" | "uninstall" ) uninstallFunc;;
|
2016-04-20 23:16:39 +00:00
|
|
|
"-v" ) versionFunc;;
|
2016-04-19 18:01:55 +00:00
|
|
|
* ) helpFunc;;
|
|
|
|
esac
|