Skip to content

Commit

Permalink
Add 'pivpn clients' command to show list of connected clients
Browse files Browse the repository at this point in the history
  • Loading branch information
0-kaladin committed Dec 8, 2016
1 parent 43a8a70 commit da5face
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
2 changes: 1 addition & 1 deletion auto_install/install.sh
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion pivpn
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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"
Expand All @@ -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;;
Expand Down
4 changes: 2 additions & 2 deletions scripts/bash-completion
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions scripts/clientStat.sh
@@ -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"
1 change: 1 addition & 0 deletions server_config.txt
Expand Up @@ -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

0 comments on commit da5face

Please sign in to comment.