Start and stop a service while pushing wps button

hi i need functionality for start and stop a service while pushing wps button for 2 second for openvpn service

service openvpn start
service openvpn stop

https://openwrt.org/docs/guide-user/base-system/hotplug

thank you i see these topic but i'm not expert and want simple solution

if you're lucky someone's already done it, and posted a script, if not, too bad ...

Try placing this script at "/etc/rc.button/wps":

#!/bin/sh

if [ "${BUTTON}" != "wps" ]; then
	logger WDS: Not WPS
	return 0
fi

if [ "${ACTION}" != "released" ]; then
	logger WDS: Not released
	return 0
fi

if [ "${SEEN}" -lt 2 ]; then
	logger WDS: Not pressed long enough
	return 0
fi

if [ "`service openvpn status`" = "runing" ]; then
	logger WDS: OpenVPN is running
	service openvpn stop
else
	logger WDS: OpenVPN is not running
	service openvpn start
fi

return 0

I haven't even tested... it can do what you need, or it can burn your whole house down; look at the logs for clues.

4 Likes

Probably want to spell "running" properly, but I think that is a great start!

2 Likes

nice :slight_smile: :slight_smile: :slight_smile:

1 Like

Could still kill your dog though...

2 Likes

Only if

dog is runing

:wink:

1 Like

i see log something happen but vpn not affected i use this script in tomato and work great can someone edit this to work with openwrt

[ $(pidof vpnclient1; echo $?) -ne 0 ] && service vpnclient1 start || service vpnclient1 stop
#[ $1 -le 2 ] && telnetd #...

Quite impossible, since telnet hasn't been available in OpenWRT for a very long time.

What's wrong with the one @eduperez posted ?

And I guess you will not tell us what you see on the logs... will you?

in log say openvpn stop but in openvpn page connection still running i use openwrt 19.07 i press for 5 6 seconds

Sorry, but "openvpn stop" is not a message that comes from my script; it must be either "WDS: OpenVPN is running" or "WDS: OpenVPN is not running", followed by the messages from OpenVPN stopping or starting.

Could you please copy-and-paste the exact messages that appear on the log?

in log there is 3 message
OpenVPN is not running
Not released
Not pressed long enough

and never say OpenVPN is running
noting happen in openvpn page

When it says "not pressed long enough", it means you did not hold the button for more that two seconds, and the script does nothing else.

When it says "OpenVPN is not running" it will immediately launch the "service openvpn start" command. Does it work when you execute it from the command line?

hi yes when i enter service openvpn start or service openvpn stop from ssh it connect and disconnect vpn

Sorry, but I am out of ideas now...

1 Like

any idea someone can test this itself and find out what is problem

maybe try with
/etc/init.d/openvpn stop

i haved problems in past using 'service' inside scripts
/etc/init.d/xxxx [start|stop] work as expected

1 Like