Skip to content

Commit 6534a21

Browse files
committed
Add client connection status information on stdout.
OpenVPN daemon logs are redirected to stderr from now on.
1 parent 0c1956e commit 6534a21

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ ADD ./bin /usr/local/bin
3333
RUN chmod a+x /usr/local/bin/*
3434

3535
# Initialisation scripts and default template
36-
COPY entrypoint.sh /sbin/entrypoint.sh
37-
COPY watch-portmapping.sh /sbin/watch-portmapping.sh
36+
COPY *.sh /sbin/
3837
COPY openvpn.tmpl $OVPN_TEMPLATE
3938

4039
# Add support for OTP authentication using a PAM module

entrypoint.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,15 @@ if [ -n "${OVPN_MANAGEMENT_PORT}" ]; then
100100
addArg "--management" "127.0.0.1 ${OVPN_MANAGEMENT_PORT}"
101101
fi
102102

103+
if [ -n "${OVPN_STATUS}" ]; then
104+
addArg "--status" "${OVPN_STATUS}"
105+
/sbin/print-status.sh ${OVPN_STATUS} &
106+
fi
107+
103108
if [ $DEBUG ]; then
104109
echo "openvpn.conf:"
105110
cat $OVPN_CONFIG
106111
fi
107112

108113
echo "$(date "+%a %b %d %H:%M:%S %Y") Running 'openvpn ${ARGS[@]} ${USER_ARGS[@]}'"
109-
exec openvpn ${ARGS[@]} ${USER_ARGS[@]}
114+
exec openvpn ${ARGS[@]} ${USER_ARGS[@]} 1> /dev/stderr 2> /dev/stderr

openvpn.tmpl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ tls-cipher ${OVPN_TLS_CIPHER}
2222
# Rely on scheduler to do port mapping, internally always 1194
2323
port 1194
2424
dev tun0
25-
status /tmp/openvpn-status.log
2625

2726
user nobody
2827
group nogroup

print-status.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
statusfile=$1
4+
5+
while true; do
6+
sleep 60
7+
if [ ! -r $statusfile ]; then
8+
echo "Cannot read statusfile at $statusfile"
9+
break
10+
fi
11+
while read line; do
12+
IFS=',' read -r -a client <<< $line
13+
14+
# Opportunistic filtering, only the client section has 5 fields
15+
if [ ! -z "${client[4]}" -a "${client[0]}" != "Common Name" ]; then
16+
echo -e "{ \"common_name\": \"${client[0]}\", \"bytes_received\": ${client[2]}, \"bytes_sent\": ${client[3]}, \"connected_since\": \"${client[4]}\" }"
17+
fi
18+
done < $statusfile
19+
done

0 commit comments

Comments
 (0)