Hardware Button GL-MT3000 Coding Help Toggle VPN

I have a GL-MT3000 that has a hardware toggle switch named as BTN_0. I was wondering what the code is to have it toggle on and off my wiregaurd vpn would be? This link isn't all that noob friendly so any help would be appreciated.

The link you referenced is the one I would have given you.

Where are you finding yourself stuck? The info in that page is correct, so it is probably mostly a matter of a different explanation for the section(s) you’re not grasping.

cat << "EOF" > /etc/rc.button/BTN_0
#!/bin/sh

[ "$ACTION" = "released" -a "$BUTTON" = "BTN_0" ] || exit 0

{
    wgiface="wg0" # wireguard interface name here
    if ifconfig | grep $wgiface; then
    ifdown $wgiface
    else
    ifup $wgiface
    fi
}

return 0
EOF

Make sure you have set the correct wireguard interface name.

There isn't a noob friendly way to handle the slider.

Depending on which position you want slider to activate the wg, you may need to monitor released or pressed events -- you need a script for that. Also if you want the wg status survive reboot, you'd need to create another script to poll slider status on boot and set wg interface accordingly.

I'd advise first create a script which polls the slider position when called and connects/disconnects wg interface, then call that script from both boot sequence (/etc/rc.local probably) and from the button hotplug script.

So it requires at least 3 scripts/files modifications to implement nicely.

It is also worth noting that starting a wireguard interface at boot can cause a race condition wherein the time has not yet synchronized as wireguard starts, making it impossible for wireguard to function properly and blocking all internet access.

There are a few ways to work around this, but keep this in mind (and read the forums for options) as you setup your scripts.