From 191722b843845ef301e9efd340b73d07a3a2e229 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Sat, 30 Mar 2019 14:26:06 +0100 Subject: [PATCH] Add a config parameter: enable log file mode (log/log-append) --- bin/ovpn_genconfig | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/bin/ovpn_genconfig b/bin/ovpn_genconfig index 321a7b2..50388be 100755 --- a/bin/ovpn_genconfig +++ b/bin/ovpn_genconfig @@ -104,10 +104,11 @@ usage() { echo " -t Use TAP device (instead of TUN device)" echo " -T Encrypt packets with the given cipher algorithm instead of the default one (tls-cipher)." echo " -z Enable comp-lzo compression." - echo " -S Change status folder. Default '/tmp'" + echo " -S Change status folder. Default '/tmp'." echo " -R Disable the reduce the OpenVPN daemon's privileges after initialization." - echo " -K Set a client config directory. Default Disable. Example: 'ccd'" + echo " -K Set a client config directory. Default Disable. Example: 'ccd'." echo " -V Enable the the record of client <-> virtual IP address (store in a config file)." + echo " -L Configure log mode: 'disable', 'enable', 'append'. Default 'disable'." } process_route_config() { @@ -175,12 +176,13 @@ OVPN_STATUS_PATH='/tmp' OVPN_DISABLE_REDUCE_DEAMON_S_PRIVILEGES=0 OVPN_CLIENT_CONFIG_DIR='' OVPN_ENABLE_KEEP_CLIENT_VIRTUAL_IP=0 +OVPN_LOG_MODE="disable" # Import existing configuration if present [ -r "$OVPN_ENV" ] && source "$OVPN_ENV" # Parse arguments -while getopts ":a:e:E:C:T:r:s:du:bcp:n:k:DNm:f:tz2S:RK:V" opt; do +while getopts ":a:e:E:C:T:r:s:du:bcp:n:k:DNm:f:tz2S:RK:VL:" opt; do case $opt in a) OVPN_AUTH="$OPTARG" @@ -273,6 +275,9 @@ while getopts ":a:e:E:C:T:r:s:du:bcp:n:k:DNm:f:tz2S:RK:V" opt; do V) OVPN_ENABLE_KEEP_CLIENT_VIRTUAL_IP=1 ;; + L) + OVPN_LOG_MODE="$OPTARG" + ;; \?) set +x echo "Invalid option: -$OPTARG" >&2 @@ -387,6 +392,16 @@ fi [ "$OVPN_ENABLE_KEEP_CLIENT_VIRTUAL_IP" == "1" ] && echo "ifconfig-pool-persist /etc/openvpn/client_vitual_ip.txt" >> "$conf" +if [ "${OVPN_LOG_MODE}" == "enable" ]; then + echo "log /var/log/openvpn/openvpn.log" >> "$conf" +else + if [ "${OVPN_LOG_MODE}" == "append" ]; then + echo "log-append /var/log/openvpn/openvpn.log" >> "$conf" + else + echo "Log file mode is disable" + fi +fi + [ -n "${OVPN_FRAGMENT:-}" ] && echo "fragment $OVPN_FRAGMENT" >> "$conf" # Append route commands