Can I run a custom script when the WPS or WiFi button is pressed?

3 posts / 0 new
Last post
cue8chalk
cue8chalk's picture
Can I run a custom script when the WPS or WiFi button is pressed?

I'm trying to set up my router so that I can toggle my VPN client with the press of a button. I don't use the WPS or WiFi buttons at all, so I'm fine with using either (or both) to run a custom script to toggle the VPN client. I can easily write the script, but I just don't know how to attach it to the button press.

Can someone point me in the right direction?

cue8chalk
cue8chalk's picture
I'm positive this will break

I'm positive this will break with an update, but if anyone is curious, I found a way to do it.

First, I edited /etc/openvpn/ovpnclient-up.sh and /etc/openvpn/ovpnclient-down.sh to manage a file when the vpn client is up/down:

touch /tmp/openvpn-client-should-be-running # in up

rm -f /tmp/openvpn-client-should-be-running # in down

If you have a script monitoring the vpn client and automatically bringing it up (like /usr/bin/vpncmon.sh https://www.myopenrouter.com/article/how-set-openvpn-client-netgear-r780...), that needs to be edited so it won't try to revive your vpn client if it shouldn't be alive. The beginning of my /usr/bin/vpncmon.sh now looks like:

if [ ! -f /tmp/openvpn-client-should-be-running ]; then
    exit 0
fi

Finally, I settled on editing /sbin/wps_pbc to detect the WPS button press. At the very top, I added:

if [ "$1" = "pressed" ]; then
        if [ -f /tmp/openvpn-client-should-be-running ]; then
                /etc/init.d/openvpn-client stop
        else
                /etc/init.d/openvpn-client start
        fi
        exit 0
fi

if [ "$1" = "released" ]; then
        exit 0
fi

I have a feeling the last change will get overwritten when I upgrade, so it's not the best place to put it, but I couldn't find a better place for it. It seems like hotplug.d takes care of the logic for flashing the WPS light, but I couldn't find where I could cause it to replace the WPS button functinoality.

kamoj
kamoj's picture
Thank you for sharing this!

Thank you for sharing this!