Opal - Change LED Color on VPN Connection

My goal is to change the LED on my Opal to `gl_led both’ when openvpn is active and the toggle switch is in the ON position (with VPN enable as the action in settings).

I found a script for the mt1300 and adjusted it for the Opal and it works fine by adding it to rc.local. Looking at /usr/bin/switchaction, I see a lock file listed at /var/lock/switch.lock, but do not see the lock file in that directory when the switch is toggled and also, the LED is not staying at `gl_led both daemon’ and is alternating back to white solid.

Is there a way to make the LED stay “both solid” when the VPN is active?

Also, I want to add the script to the OVPN section at line 122 of usr/bin/switchaction with a way to exit/quit the script if the lock file is not present. Is there another lock file created by the switch other than the following? The script repeats every 10 seconds, so having it run when the switch is on and exit the script when the switch is toggled off (lock file removed) should be just adding the same to the VPN LED script, but I have not been successful. I do not see any change in the /var/lock directory when toggling the switch.

LOCK=/var/lock/switch.lock
        if [ -f "$LOCK" ];then
                exit 0
#!/bin/sh

ip="9.9.9.9"
count="1"
timeout="1"
gl_led off
gl_led white daemon

while true; do

status=$(ping -q -c "$count" -W "$timeout" "$ip"  > /dev/null 2>&1 && echo "ok" || echo "fail")

if [ "$status" = "ok" ]; then
	if [ -d /sys/class/net/tun* ]; then    
		gl_led both daemon   
	else    
		gl_led white_breath daemon      
	fi
else
	gl_led blue_flash fast daemon
fi

sleep 10

done

Any input is appreciated on how to execute/quit the script based on the toggle switch position and also on how to keep the LED “solid both” when the ping is successful. It changes the LED every 10 seconds with the script in rc.local when the VPN is active, so that may be the best I can do.

The script will show “both solid” when the VPN is connected, “white breath” when the VPN is off and modem/WAN is connected and “blue_flash fast” if the modem/WAN is not connected and the VPN is trying to connect.

I think you can take a look at the /etc/rc.button/BTN_1 file and replace the switch trigger script with your own.

Thanks! I’ll look into that file. It may just be easier to add another conditional to look at PIDs and if present, run the LED routine and if not, do nothing.

Is there any way to override the default LED behavior (solid white on connectivity)? The default GL connectivity script looks like it replaces any LED changes every 10 seconds as well. I find it useful to know when the VPN is active w/o changing the script to run every 2 seconds.

Also, I would like to see an LED option in the 4.x firmwares to display solid white with normal connectivity and “both” when VPN/WG/Tor is active. And adding one RGB LED on all the newer double LED models to expand on the white/blue notification lights would be cool.

I may have been spoiled by the Spitz and being able to change one of the lights to VPN status since I don’t use the travel routers on the WAN port much.

3.X firmware cannot obtain VPN connection events. Therefore, only polling can be used to check the status. In 4.X firmware, you can add actions you want in the /etc/hotplug.d/wireguard or /etc/hotplug.d/iface directory

2 Likes

Cool! Thank you for the information on the 4.x firmwares!

just messing with this… not elegant but works…

stop led automatically changing by disabling led service…
service led disable

run script to detect internet connectivity… blue when wireguard, white when internet, flashing white when no internet

while :
do

ping -c1 -W1 -q 8.8.8.8 > /dev/null 2>&1
status=$?;
if [ $status -eq 0 ]; then
        ping -I wg0 -c1 -W1 -q 8.8.8.8 > /dev/null 2>&1
        status=$?;
        if [ $status -eq 0 ]; then
            gl_led blue daemon
        else
            gl_led white daemon
        fi
else
    gl_led white_flash medium daemon
fi

Oh cool! I didn’t even think about disabling the LED service. I decided to wait for the 4.x stable and add it to the hotplug events since I mainly use the toggle switch for VPN.

I’m still hoping they add a single RGB LED to the newer models backpanel that have a single status light for a wider range of colors when VPN is connected or for activity/service status. I’ve been using my Spitz lately but may try your enhancements with the LED service off next time I put the Opal in my bag.

Thanks!

ah that’s cool…

i altered my script a bit to flash if no internet, white if internet, blue if wireguard connected (breathing if adguardhome enabled)… fw4 uses gl_i2c_led instead, and has 3 services to disable (can’t remember which ones now… just grep services for led…).

i build a modified firmware with the initial password, network setting, updated adblockhome and wireguard settings built in (love uci-defaults!) so if i mess things up when on the road can reset it back to my known working state… tend to mess around with things when i shouldn’t (and have ended up with a base reset router when my configs would have been good on more than one time on holidays)!!!

by the way… if using adguard, don’t forget to add the dns forwarding in the service start, and remove on end (good to block kids devices as you can actually see the ip address instead of localhost!)
iptables -t nat -A PREROUTING -p tcp --dport 53 -j DNAT --to MYIP:3053
iptables -t nat -A PREROUTING -p udp --dport 53 -j DNAT --to MYIP:3053

need to be able to disable for captive portals and handy to be able to do it from the gl.inet frontend…

tried building adguardhome gl-agh-stats package for fw4 opal (to get gl.inet frontend), but got frustrated and gave up with missing dependencies! will give fw4 a skip until it is officially released and monitor which packages are available as well!

Oh, probably can tell… but I am new to linux scripting, so am sure the script is all over the place… but it works!

#!/bin/sh

currentMode=“”
newMode=“”

while :
do

ping -c1 -W3 -q 8.8.8.8 > /dev/null 2>&1
internetConnected=$?;
if [ $internetConnected -eq 0 ]; then
adguardRunning=$(ps | grep -i adguardhome | wc -l)

ping -I wg0 -c1 -W3 -q 8.8.8.8 > /dev/null 2>&1
wireguardConnected=$?;

if [ $wireguardConnected -eq 0 ]; then
    if [ $adguardRunning -eq 1 ]; then
        newMode="gl_led blue"
    else
        newMode="gl_led blue_breath"
    fi
else
    if [ $adguardRunning -eq 1 ]; then
        newMode="gl_led white"
    else
        newMode="gl_led white_breath"
    fi
fi

else
newMode=“gl_led white_flash normal”
fi

if [ “$currentMode” != “$newMode” ]; then
currentMode=$newMode
$($newMode)
fi

sleep 5
done

1 Like