Skip to content

Commit

Permalink
Merge pull request #443 from nodogsplash/4.2.1beta
Browse files Browse the repository at this point in the history
BinAuth: Limit log size and write to syslog
  • Loading branch information
bluewavenet committed Oct 4, 2019
2 parents 5595680 + d58592f commit 0f01c23
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions forward_authentication_service/binauth/binauth_log.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,28 @@
# 3. FAS
#

# Get the current Date/Time for the log
date=$(date)
# functions:

write_log () {
logfile="/tmp/binauth.log"
min_freespace_to_log_ratio=10
datetime=$(date)

if [ ! -f $logfile ]; then
echo "$datetime, New log file created" > $logfile
fi

ndspid=$(ps | grep nodogsplash | awk -F ' ' 'NR==2 {print $1}')
filesize=$(ls -s -1 $logfile | awk -F' ' '{print $1}')
available=$(df |grep /tmp | awk -F ' ' '{print $4}')
sizeratio=$(($available/$filesize))

if [ $sizeratio -ge $min_freespace_to_log_ratio ]; then
echo "$datetime, $log_entry" >> $logfile
else
echo "BinAuth - log file too big, please archive contents" | logger -p "daemon.err" -s -t "nodogsplash[$ndspid]: "
fi
}

#
# Get the action method from NDS ie the first command line argument.
Expand Down Expand Up @@ -59,13 +79,13 @@ if [ $action == "auth_client" ]; then
useragent_enc=$6
useragent=$(printf "${useragent_enc//%/\\x}")

# Append to the log.

echo "$date, method=$1, clientmac=$2, clientip=$7, username=$3, password=$4, redir=$redir, useragent=$useragent" >> /tmp/binauth.log
log_entry="method=$1, clientmac=$2, clientip=$7, username=$3, password=$4, redir=$redir, useragent=$useragent"
else
echo "$date, method=$1, clientmac=$2, bytes_incoming=$3, bytes_outgoing=$4, session_start=$5, session_end=$6" >> /tmp/binauth.log
log_entry="method=$1, clientmac=$2, bytes_incoming=$3, bytes_outgoing=$4, session_start=$5, session_end=$6"
fi

# Append to the log.
write_log

# Set length of session in seconds (eg 24 hours is 86400 seconds - if set to 0 then defaults to global sessiontimeout value):
session_length=0
Expand Down

0 comments on commit 0f01c23

Please sign in to comment.