From what i read, --max-clients n limits the total number of clients simultaneously connected to the server, which would work if the server was built for only 1 client, but since i have multiple clients and only want to limit the number of connections per client, that option won't work.
After many days searching online for other info, i did finally find a post similar to my request here.
[url=
https://serverfault.com/questions/850599/permit-only-n-connection-for-a-user-config-in-openvpn/850889[/url]
Adding the following to the server.conf file
script-security 2
up /etc/openvpn/connectScript.sh
client-connect /etc/openvpn/connectScript.sh
client-disconnect /etc/openvpn/connectScript.sh
and then using the bash script Lacek detailed in the link above (i added a couple of echos to watch what the script is doing and when)
#!/bin/bash
PERSIST_DIR=/tmp/pDir
function handle_connect {
CLIENTFILE=$PERSIST_DIR/$common_name
echo Testing for the existance of the temp folder
if [ -d $PERSIST_DIR ] ; then
echo "Folder exists"
else
echo "Folder doens't exist, creating folder now"
mkdir $PERSIST_DIR
fi
if [ -e $CLIENTFILE ]; then
echo Client file exists
NUMCONN=$(cat $CLIENTFILE)
NEWCONN=$(expr $NUMCONN + 1)
if [ $NEWCONN -gt 3 ]; then exit 1; fi
echo $NEWCONN >$CLIENTFILE
else
echo 1 >"$CLIENTFILE"
fi
}
function handle_disconnect {
echo Starting disconnect for $common_name
CLIENTFILE=$PERSIST_DIR/$common_name
if [ -e "$CLIENTFILE" ]; then
echo File found, remove connection
NUMCONN=$(cat $CLIENTFILE)
NEWCONN=$(expr $NUMCONN - 1)
echo $NEWCONN >$CLIENTFILE
fi
echo Completed disconnect
}
case "$script_type" in
up)
rm -f $PERSIST_DIR/*
;;
client-connect)
"handle_connect"
;;
client-disconnect)
"handle_disconnect"
;;
esac
And now that works perfectly for what i needed! I did allow 3 connections per client because my tests shows a loss of internet connectivity by switching from wifi to cell data did not cause a disconnect notification to be sent to the server which then continued to use up 1 of the 2 connections allowed until the connection timeout kicked in.