What's new

VPNMON VPNMON-R2 v2.65 -Jan 27, 2024- DISCONTINUED - Upgrade to VPNMON-R3 Available! (#3)

  • 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!

...
If you want to give more consistency, cleaner error handling, and simpler way of handling using "a case base" condition to the original edits I did to the _VPN_GetClientState_, I would suggest:

Bash:
_VPN_GetClientState_() {
    case "$1" in
        [1-5])
            local nvramVal="$($timeoutcmd$timeoutsec nvram get "vpn_client${1}_state")"
            case "$nvramVal" in
                [+/-][0-9])
                    echo "$nvramVal"
                    ;;
                "")
                    echo "${2:-0}"  # Use the provided default or default to 0
                    ;;
                *)
                    echo "WARNING: Unrecognized value in NVRAM: $nvramVal. Using default value." >&2
                    echo "${2:-0}"  # Use the provided default or default to 0
                    ;;
            esac
            return 0
            ;;
        *)
            echo "ERROR: Invalid client number. Please provide a number from 1 to 5." >&2
            return 1
            ;;
    esac
}
...
In your last code revision, the case pattern "[+/-][0-9]" for "$nvramVal" is incorrect because it causes the function to fail with valid values (e.g. "0" or "1") and to succeed with invalid values (e.g. "-1"), and that's because it requires a digit to have a preceding sign character (plus or minus) which is not required for valid values. The correct case pattern would be "[0-9]" for positive digits, making any negative values invalid (which is based on @Viktor Jaep's current code).

The other revisions look fine, although I still prefer to check for a "No arguments" error at the top of the function (just a minor defensive programming technique that I use in most functions for my own work - YCSMV*).
Bash:
if [ $# -lt 1 ] || [ -z "$1" ]
then
    echo "ERROR: No argument(s) provided." >&2
    return 1
fi

NOTE:
@Viktor Jaep, I don't know the actual range of positive values that are valid for the VPN client state so I just assumed "[0-9]" but you might want to adjust that based on what you know and have observed during your own testing.

*Your Coding Standards May Vary.
 
In your last code revision, the case pattern "[+/-][0-9]" for "$nvramVal" is incorrect because it causes the function to fail with valid values (e.g. "0" or "1") and to succeed with invalid values (e.g. "-1"), and that's because it requires a digit to have a preceding sign character (plus or minus) which is not required for valid values. The correct case pattern would be "[0-9]" for positive digits, making any negative values invalid (which is based on @Viktor Jaep's current code).

The other revisions look fine, although I still prefer to check for a "No arguments" error at the top of the function (just a minor defensive programming technique that I use in most functions for my own work - YCSMV*).
Bash:
if [ $# -lt 1 ] || [ -z "$1" ]
then
    echo "ERROR: No argument(s) provided." >&2
    return 1
fi

NOTE:
@Viktor Jaep, I don't know the actual range of positive values that are valid for the VPN client state so I just assumed "[0-9]" but you might want to adjust that based on what you know and have observed during your own testing.

*Your Coding Standards May Vary.
Yep, I figured. I put it to show the negative or positive variations could be considered with the "[+/-]", but I edited back to be more in line with your original.

Also, with the case based variations I gave "*" as a condition which considers both conditions of your defensive if statement provided either one hasn't been explicitly defined as a condition before hand without the need to check with an if statement.
Bash:
        *)
            echo "ERROR: Invalid client number. Please provide a number from 1 to 5." >&2
            return 1
            ;;
    esac
}
 
Last edited:
No problem, happy to test it out

I have the same result as @Ripshod - note:I did not perform a reboot on the router (not sure that would make a difference)
@TITAN @visortgw ... I have implemented the helpful changes suggested by @Martinski and @SomeWhereOverTheRainBow ... please give this version another shot! I've got a good feeling about this one! :)

Code:
curl --retry 3 "https://raw.githubusercontent.com/ViktorJp/VPNMON-R2/master/vpnmon-r2-2.63b1.sh" -o "/jffs/scripts/vpnmon-r2.sh" && chmod 755 "/jffs/scripts/vpnmon-r2.sh"

Still nothing in the logs unfortunately. Is there any way to increase the logging level? maybe that could indicate what/where the issue is?
Nothing really in the script that could generate any errors associated with this kind of event... Most of the logging is tied around connecting/disconnecting or errors related to some of the major functionality.
 
@TITAN @visortgw ... I have implemented the helpful changes suggested by @Martinski and @SomeWhereOverTheRainBow ... please give this version another shot! I've got a good feeling about this one! :)

Code:
curl --retry 3 "https://raw.githubusercontent.com/ViktorJp/VPNMON-R2/master/vpnmon-r2-2.63b1.sh" -o "/jffs/scripts/vpnmon-r2.sh" && chmod 755 "/jffs/scripts/vpnmon-r2.sh"


Nothing really in the script that could generate any errors associated with this kind of event... Most of the logging is tied around connecting/disconnecting or errors related to some of the major functionality.
I don't use VPNMON.
 
Minor revision today to nip the "unknown operand" errors in the bud... thanks again for your feedback and help with its continual improvements! :)

What's new?
v2.63 - (November 4, 2023)
- FIXED:
Thanks to @TITAN and @Ripshod for reporting back about unknown operand errors visible on the display when multiple VPN slots were not being used. This was due to some erroneous code that was not taking into consideration that some of these values may have been null. Much appreciation for @Martinski and @SomeWhereOverTheRainBow for their help and advice on creating a more optimized way of catching this!

Download link (or update directly within AMTM):
Code:
curl --retry 3 "https://raw.githubusercontent.com/ViktorJp/VPNMON-R2/master/vpnmon-r2-2.63.sh" -o "/jffs/scripts/vpnmon-r2.sh" && chmod 755 "/jffs/scripts/vpnmon-r2.sh"
 
Minor revision today to nip the "unknown operand" errors in the bud... thanks again for your feedback and help with its continual improvements! :)

What's new?
v2.63 - (November 4, 2023)
- FIXED:
Thanks to @TITAN and @Ripshod for reporting back about unknown operand errors visible on the display when multiple VPN slots were not being used. This was due to some erroneous code that was not taking into consideration that some of these values may have been null. Much appreciation for @Martinski and @SomeWhereOverTheRainBow for their help and advice on creating a more optimized way of catching this!

Download link (or update directly within AMTM):
Code:
curl --retry 3 "https://raw.githubusercontent.com/ViktorJp/VPNMON-R2/master/vpnmon-r2-2.63.sh" -o "/jffs/scripts/vpnmon-r2.sh" && chmod 755 "/jffs/scripts/vpnmon-r2.sh"
Thanks @Viktor Jaep - all good here too!
And, also thanks @Martinski and @SomeWhereOverTheRainBow
 
Hello @Viktor Jaep,

First, nice script, it is very helpful for me…

I have one question, is it possible to set the script to monitor two VPN connections, but in different countries (US and UK, for example)?

I use @Ranger802004 domain VPN routing, so I can access Netflix from US and BBC from England, but would love to configure your script to maintain the two connections…

I used ControlD before, but in my neck of the woods, the buffering I get is a downer….

Furthermore, I think vpnmgr was capable of doing that, but it has been years without updates.

Thanks
 
Hello @Viktor Jaep,

First, nice script, it is very helpful for me…

I have one question, is it possible to set the script to monitor two VPN connections, but in different countries (US and UK, for example)?

I use @Ranger802004 domain VPN routing, so I can access Netflix from US and BBC from England, but would love to configure your script to maintain the two connections…

I used ControlD before, but in my neck of the woods, the buffering I get is a downer….

Furthermore, I think vpnmgr was capable of doing that, but it has been years without updates.

Thanks
You're not the first one to ask. 😉 At the moment, the script can only monitor and fix one connection at a time. I do have plans in the works to build a new script that will monitor up to 5 different VPN connections. It's still in the works/design phase. Keep your eye out!
 
You're not the first one to ask. 😉 At the moment, the script can only monitor and fix one connection at a time. I do have plans in the works to build a new script that will monitor up to 5 different VPN connections. It's still in the works/design phase. Keep your eye out!
As always, you first must come up with a name.... What will it be.... VPNMON-RSWITCH ? or maybe... 5VPNMON-R2
 
Or VPNMON-R5. So much VPN action under the hood.
Aaaaaaannnndd... we're off. v0.0000001 beta. LOL Hey at least there's 2 VPNs running!

1700319075289.png
 
Progress...

1700454585341.png
 
My daily progress update... :p Things are coming along! Going with the minimalist @ColinTaylor color scheme...

1700533664621.png
 

Similar threads

Latest threads

Sign Up For SNBForums Daily Digest

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