Script to switch between VPN profiles (GL.iNet GL-MT300N-V2)

Hi Everyone,

just bought a GL-MT300N-V2 router, and am very happy with my order. To configure it I need some help, as I am new to this script. My goal is to switch between my VPN profiles. and I would like to get this done by the physical switch on this router(otherwise, I need to login to the router frontend, and switch it manually). I went through some other posts, to get the Button state "on" or "off", and enabling the vpn with startvpn etc.. but no where I found, how could I specify, which VPN profile it should use. By default, it is connecting to the last connected profile. Is there a way, that I could specify the profile name?

Would be helpfull, if there is any full working script already existing with my requirement.

regards,
Rakesh.

Hello vgaetera,

thank you for your response. But was not able to figure it out. What is the Instance? I have tried the ovpn file name and short name for that configuration. Both didn't work. The service was just restarted with same old VPN configuration.

regards,
Rakesh.

uci show openvpn | awk -F '[.=]' '/=openvpn$/{print $2}'

Thank you for your input. I figured out from my existing processes, the command to run.

/usr/sbin/openvpn --config /etc/openvpn/ovpnxx/xxxxxxxxxxxxx.ovpn

regards,
rakesh

If someone need more info,

the deafault settings for 'openvpn' are stored in "/etc/config/glconfig". Available params are enable, force, ovpn(filename), clientid etc... You can set those values by "uci set glconfig.openvpn.param='1'". After setting the needed ovpn, clientid, you can just restart the vpn by "/etc/init.d/startvpn restart".

Button switch action is stored in "/usr/bin/switchaction". bottom of that file, we can find an if else statement for left and right button positions. There you can put these "uci set glconfig.openvpn.params" and then restart the vpn. for ex.

if left 
	uci set glconfig.openvpn.enable='1'
	uci set glconfig.openvpn.force='1'
	uci set glconfig.openvpn.ovpn='/etc/openvpn/ovpn1/file1name.ovpn'
	uci set glconfig.openvpn.clientid='ovpn0'
	uci commit glconfig
	/etc/init.d/startvpn restart
else
	uci set glconfig.openvpn.enable='1'
	uci set glconfig.openvpn.force='1'
	uci set glconfig.openvpn.ovpn='/etc/openvpn/ovpn1/file2name.ovpn'
	uci set glconfig.openvpn.clientid='ovpn1'
	uci commit glconfig
	/etc/init.d/startvpn restart

Please keep in mind, in file "/usr/bin/switchaction", there are also many checks for WireGuard or OpenVpn connection, adjust accordingly(the above is only for OpenVPN).

hope that helps someone. cheers.

Edit - Please don't forget to enable the Button action in frontend, I wasted some minutes in finding why my changed code in 'switchaction' didn't work.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.