Skip to content

Commit

Permalink
Add client connection status information on stdout.
Browse files Browse the repository at this point in the history
OpenVPN daemon logs are redirected to stderr from now on.
  • Loading branch information
pieterlange committed Apr 24, 2017
1 parent 0c1956e commit 6534a21
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ ADD ./bin /usr/local/bin
RUN chmod a+x /usr/local/bin/*

# Initialisation scripts and default template
COPY entrypoint.sh /sbin/entrypoint.sh
COPY watch-portmapping.sh /sbin/watch-portmapping.sh
COPY *.sh /sbin/
COPY openvpn.tmpl $OVPN_TEMPLATE

# Add support for OTP authentication using a PAM module
Expand Down
7 changes: 6 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,15 @@ if [ -n "${OVPN_MANAGEMENT_PORT}" ]; then
addArg "--management" "127.0.0.1 ${OVPN_MANAGEMENT_PORT}"
fi

if [ -n "${OVPN_STATUS}" ]; then
addArg "--status" "${OVPN_STATUS}"
/sbin/print-status.sh ${OVPN_STATUS} &
fi

if [ $DEBUG ]; then
echo "openvpn.conf:"
cat $OVPN_CONFIG
fi

echo "$(date "+%a %b %d %H:%M:%S %Y") Running 'openvpn ${ARGS[@]} ${USER_ARGS[@]}'"
exec openvpn ${ARGS[@]} ${USER_ARGS[@]}
exec openvpn ${ARGS[@]} ${USER_ARGS[@]} 1> /dev/stderr 2> /dev/stderr
1 change: 0 additions & 1 deletion openvpn.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ tls-cipher ${OVPN_TLS_CIPHER}
# Rely on scheduler to do port mapping, internally always 1194
port 1194
dev tun0
status /tmp/openvpn-status.log

user nobody
group nogroup
Expand Down
19 changes: 19 additions & 0 deletions print-status.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

statusfile=$1

while true; do
sleep 60
if [ ! -r $statusfile ]; then
echo "Cannot read statusfile at $statusfile"
break
fi
while read line; do
IFS=',' read -r -a client <<< $line

# Opportunistic filtering, only the client section has 5 fields
if [ ! -z "${client[4]}" -a "${client[0]}" != "Common Name" ]; then
echo -e "{ \"common_name\": \"${client[0]}\", \"bytes_received\": ${client[2]}, \"bytes_sent\": ${client[3]}, \"connected_since\": \"${client[4]}\" }"
fi
done < $statusfile
done

0 comments on commit 6534a21

Please sign in to comment.