What's new
  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Which client is calling the openvpn-event script?

MelDavis

New Around Here
I have an openvpn-event script set up on an RT-N66U. If I understand it correctly, this same script is called for any and all of the openvpn clients. Is there a way to determine in the script which client is being referenced?

One of the openvpn variables available to the script is "config" name. Ideally, this would be "client1.ovpn", "client2.ovpn", etc. But the configurations for all the clients are named the same: "config.ovpn". Is there some way for the script to determine if it is being called for client1 or client2? An environment variable? Something to parse? Thanks.
 
I have an openvpn-event script set up on an RT-N66U. If I understand it correctly, this same script is called for any and all of the openvpn clients. Is there a way to determine in the script which client is being referenced?

One of the openvpn variables available to the script is "config" name. Ideally, this would be "client1.ovpn", "client2.ovpn", etc. But the configurations for all the clients are named the same: "config.ovpn". Is there some way for the script to determine if it is being called for client1 or client2? An environment variable? Something to parse? Thanks.

Something like this...

Code:
#!/bin/sh

PARAM=$*

logger -st "($(basename $0))"  $script_type "Starting......"[$@]

# Determine caller
P1=$1

logger -st "($(basename $0))"  "Debug Caller="$1

case "$P1" in
        "tun11")
                vpn_name="client1"
                ;;
        "tun12")
                vpn_name="client2"
                ;;
        "tun13")
                vpn_name="client3"
                ;;
        "tun14")
                vpn_name="client4"
                ;;
        "tun15")
                vpn_name="client5"
                ;;
        "tun21")
                vpn_name="server1"
                ;;
        "tun22")
                vpn_name="server2"
                ;;
        *)
                vpn_name=""
                ;;
esac

logger -s -t "($(basename $0))"  "VPN_name="$vpn_name ", detected for dev="$dev "and Script Type="$script_type

logger -s -t "($(basename $0))"  "Complete."

but check the OpenVPN docs for a complete list of the environment variables that may be referenced.
 
Last edited:
Thanks, Martineau. I did not realize that each client entry was hardwired to the device name. I falsely assumed that tun11 would be assigned to client5 if that was the only client started. This makes life easier. Thanks for replying so quickly.
 
Thanks, Martineau. I did not realize that each client entry was hardwired to the device name. I falsely assumed that tun11 would be assigned to client5 if that was the only client started. This makes life easier. Thanks for replying so quickly.

However be aware that even the seemingly trivial script above doesn't always work in identifying the client :eek:

Code:
RT-AC68U user.warn custom script: Running /jffs/scripts/openvpn-event (args: tun11 1500 1541 10.200.5.5 )
RT-AC68U user.warn (openvpn-event): route-up Starting......[tun11 1500 1541 10.200.5.5 ]
RT-AC68U user.warn (openvpn-event): Debug Caller=tun11 1500 1541 10.200.5.5
RT-AC68U user.warn (openvpn-event): VPN_name= , detected for dev=tun11 and Script Type=route-up


RT-AC68U user.warn custom script: Running /jffs/scripts/openvpn-event (args: tun12 1500 1541 10.200.5.19 255.255.252.0 init)
RT-AC68U user.warn (openvpn-event): up Starting......[tun12 1500 1541 10.200.5.19 255.255.252.0 init]
RT-AC68U user.warn (openvpn-event): Debug Caller=tun12
RT-AC68U user.warn (openvpn-event): VPN_name=client2 , detected for dev=tun12 and Script Type=up
 
Last edited:
I wonder if the openvpn variable "$dev" would report correctly, in the instance above?

Yes..in the script it is reported correctly.

My point is that this test-case version of openvpn-event should be examined to understand why/where it subtly fails! :mad:
 

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Back
Top