Add 'pivpn clients' command to show list of connected clients

This commit is contained in:
Kaladin Light 2016-12-08 11:43:30 -05:00
parent 43a8a706e2
commit da5facecbc
5 changed files with 34 additions and 4 deletions

View file

@ -459,7 +459,7 @@ checkForDependencies() {
echo ":::"
echo "::: Checking dependencies:"
dependencies=( openvpn git dhcpcd5 tar wget iptables-persistent dnsutils expect whiptail )
dependencies=( openvpn git dhcpcd5 tar wget grep iptables-persistent dnsutils expect whiptail )
for i in "${dependencies[@]}"; do
echo -n "::: Checking for $i..."
if [ "$(dpkg-query -W -f='${Status}' "$i" 2>/dev/null | grep -c "ok installed")" -eq 0 ]; then

9
pivpn
View file

@ -16,6 +16,11 @@ function makeOVPNFunc {
exit 1
}
function listClientsFunc {
$SUDO /opt/pivpn/clientStat.sh
exit 1
}
function listOVPNFunc {
$SUDO /opt/pivpn/listOVPN.sh
exit 1
@ -42,7 +47,7 @@ function uninstallFunc {
}
function versionFunc {
printf "\e[1mVersion 1.7\e[0m\n"
printf "\e[1mVersion 1.8\e[0m\n"
}
function helpFunc {
@ -52,6 +57,7 @@ function helpFunc {
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"
@ -67,6 +73,7 @@ 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;;

View file

@ -4,8 +4,8 @@ _pivpn()
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
dashopts="-a -d -l -r -h -u"
opts="debug add list revoke uninstall help"
dashopts="-a -c -d -l -r -h -u"
opts="debug add clients list revoke uninstall help"
if [ "${#COMP_WORDS[@]}" -eq 2 ]
then
if [[ ${cur} == -* ]] ; then

22
scripts/clientStat.sh Normal file
View file

@ -0,0 +1,22 @@
#!/usr/bin/env bash
# PiVPN: client status script
STATUS_LOG="/var/log/openvpn-status.log"
printf "\n"
if [ ! -f "${STATUS_LOG}" ]; then
echo "The file: $STATUS_LOG was not found!"
exit 1
fi
printf ": NOTE : The output below is NOT real-time!\n"
printf ": : It may be off by a few minutes.\n"
printf "\n"
printf "\e[1m::: Client Status List :::\e[0m\n"
printf "\t\t\t\t\t\t\tBytes\t\tBytes\t\n"
printf "\e[4mName\e[0m\t\t\e[4mRemote IP\e[0m\t\t\e[4mVirtual IP\e[0m\t\e[4mReceived\e[0m\t\e[4mSent\e[0m\t\t\e[4mConnected Since\e[0m \n"
if grep -q "^CLIENT_LIST" "${STATUS_LOG}"; then
awk -F' ' -v s='CLIENT_LIST' '$1 == s {print $2"\t\t"$3"\t"$4"\t"$5"\t\t"$6"\t\t"$8" "$9" "$11" -- "$10}' ${STATUS_LOG}
else
printf "\nNo Clients Connected!\n"
fi
printf "\n"

View file

@ -36,6 +36,7 @@ persist-key
persist-tun
#crl-verify /etc/openvpn/crl.pem
status /var/log/openvpn-status.log 20
status-version 3
log /var/log/openvpn.log
verb 1
# Generated for use by PiVPN.io