Re: Client history

Peter Davis via Openvpn-users <[email protected]>
Newsgroups gmane.network.openvpn.user
Message-ID <CsF-H7UnMb_CiAv5ywAoYMmSx9O-lqDm34c4zOkIGqngOyEQhpu7fYCOvr26KHm82IChP6uw2lf2U7oC24l7vPcstARumHYit7KwYkUYn30=@proton.me>
> On Monday, February 26th, 2024 at 12:05 AM, Bo Berglund <[email protected]> wrote:

> On Sun, 25 Feb 2024 10:50:05 +0000, Peter Davis via Openvpn-users
> [email protected] wrote:
> 
> > > Hello,
> > > I installed shellcheck and result is:
> > > 
> > > # shellcheck script-events.sh
> > > 
> > > In script-events.sh line 14:
> > > if [[ "$script_type" == "client-connect" ]]; then
> > > ^----------^ SC2154 (warning): script_type is referenced but not assigned.
> > > 
> > > In script-events.sh line 15:
> > > echo "$LOG_TIMESTAMP - $common_name connected with IP $trusted_ip" >> "$LOG_FILE"
> > > ^----------^ SC2154 (warning): common_name is referenced but not assigned.
> > > ^---------^ SC2154 (warning): trusted_ip is referenced but not assigned.
> > > 
> > > For more information:
> > > https://www.shellcheck.net/wiki/SC2154 -- common_name is referenced but not...
> 
> > Hi,
> > Thanks again.
> > But my problem is that the script doesn't work at all. How do I find the cause?
> 
> 
> I cannot help more in debugging your environment, but I suggest that you test
> the script itself without involving openvpn in the testing.
> 
> This can be done by creating a test script which will call the logging script
> like openvpn does and send the data as env vars like openvpn does in order to
> test the functions that way.
> 
> I have done trhis test now with my script and it works just fine:
> 
> Test script testlogging:
> -----------------------
> #!/bin/bash
> export script_type="client-connect"
> export common_name="CommonName"
> export trusted_ip="192.168.129.253"
> ./server-events.sh
> exit 0
> ------------------------
> 
> Script server-events.sh:
> ------------------------
> #!/bin/bash
> # shellcheck disable=SC2154
> # Log in local dir for testing
> LOG_FILE="server-events.log"
> # Log timestamp
> LOG_TIME=$(date "+%Y-%m-%d %H:%M:%S")
> # Log client connect or disconnect event with IP address
> if [ "$script_type" == "client-connect" ]; then
> echo "$LOG_TIME - $common_name connect IP $trusted_ip" >> "$LOG_FILE"
> 
> elif [ "$script_type" == "client-disconnect" ]; then
> echo "$LOG_TIME - $common_name disconnect IP $trusted_ip" >> "$LOG_FILE"
> 
> fi
> exit 0
> -------------------------
> 
> Place the scripts in the same test dir and execute ./testlogging
> Then there should be a logfile created in the same dir with the wanted data.
> 
> If that is the case then the logging script works as it should and you have to
> look elsewhere for a reason for failure in your environment.
> 
> 
> --
> Bo Berglund
> Developer in Sweden
> 
> 
> 
> _______________________________________________
> Openvpn-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/openvpn-users

Hi,
Thanks again.
I changed "LOG_FILE" to LOG_FILE="/tmp/Connections.log" and executed the script:

# ./script-events.sh
#
# cat /tmp/Connections.log 
2024-02-26 13:32:19 - CommonName connected with IP 192.168.129.253

The script worked, but where is the problem!
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.