Intent Script to Connect and Disconnect OpenVPN

Solved
DM
Daniel Maniera
OPAL Associates GmbH (Germany)

Dear Support Community,

i'm not fimilar with Android Intents. I tried to figure it out how they work to get out a script but i'm out of ideas.

I tried to build my script by using different informations.

These might be the best:

CONNECT WITH PROFLE

Intent openVPN = new Intent("net.openvpn.openvpn.CONNECT"); openVPN.setPackage("net.openvpn.openvpn"); openVPN.setClassName("net.openvpn.openvpn", "net.openvpn.unified.MainActivity"); openVPN.putExtra("net.openvpn.openvpn.AUTOSTART_PROFILE_NAME", "PC MYPROFILENAME "); openVPN.putExtra("net.openvpn.openvpn.AUTOCONNECT", true); openVPN.putExtra("net.openvpn.openvpn.APP_SECTION", "PC"); if (openVPN.resolveActivity(getActivity().getPackageManager()) != null) { startActivity(openVPN); }

DISCONNECT

Intent openVPN = new Intent("net.openvpn.openvpn.DISCONNECT"); openVPN.setPackage("net.openvpn.openvpn"); openVPN.setClassName("net.openvpn.openvpn", "net.openvpn.unified.MainActivity"); openVPN.putExtra("net.openvpn.openvpn.STOP", true); if (openVPN.resolveActivity(getActivity().getPackageManager()) != null) { startActivityForResult(openVPN, 0); }

I tried the disconnect first because it seamed to be the easier part and came up with different scripts but none of them worked:

sendintent -a "intent:#Intent;action=net.openvpn.openvpn.DISCONNECT;component=net.openvpn.openvpn;B.STOP=true;end;"

or

sendintent -a "intent:#Intent;action=net.openvpn.openvpn.DISCONNECT;B.STOP=true;end;"

or

sendintent -a "intent:#Intent;action=net.openvpn.openvpn.DISCONNECT;B.net.openvpn.openvpn.extra.STOP=true;end;"

I guess i've tried them all but unforunately none of them worked.

Hope you can help!

2 years ago
Android Scripting
ANSWERS
DM
Daniel Maniera
2 years ago

For those who are interested in the solution i figured out with one of our partners:

sendintent -a "intent:#Intent;action=net.openvpn.openvpn.CONNECT;component=net.openvpn.openvpn/net.openvpn.unified.MainActivity;B.net.openvpn.openvpn.AUTOCONNECT=true;S.net.openvpn.openvpn.AUTOSTART_PROFILE_ID="PUT_YOUR_PROFILE_ID_HERE";end"

sendintent -a "intent:#Intent;action=net.openvpn.openvpn.DISCONNECT;component=net.openvpn.openvpn/net.openvpn.unified.MainActivity;B.net.openvpn.openvpn.STOP=true;end"

That's the solution.

Kind regards,

Daniel

Solution
RC
Raymond Chan Diamond Contributor
2 years ago

Did you manage to get any documentation or reply from OpenVPN developer on whether they have implemented any Android intent?   And if so, what are the support parameters and related details (e.g. data type, support arguments, etc.)?

If there is any documentation in hand, please provide the details or URL download link. 

DM
Daniel Maniera
2 years ago

Hi Raymond,

yes, they implemented something.

The Informations i found are from here:

https://forums.openvpn.net/viewtopic.php?t=25845 (at the bottom)

and here

https://openvpn.net/faq/how-do-i-use-tasker-with-openvpn-connect-for-android/

and here

https://forums.openvpn.net/viewtopic.php?t=13122

i even figured out how to disconnect a session with a SOTI Script:

sendintent -a "intent:#Intent;action=net.openvpn.openvpn.DISCONNECT;component=net.openvpn.openvpn/net.openvpn.unified.MainActivity;B.net.openvpn.openvpn.extra.STOP=true;end"

the only issue i do have with this script is that in the application it looks like it with initialise a connection but the connection in fact is closed.

Kind regards,

Daniel

RC
Raymond Chan Diamond Contributor
2 years ago

If you have reasonable test results to suspect that your script did initialize a connection but the connection in fact closed, then you probably should contact the support team/developers of OpenVPN to see if they can confirm that the problem is related to the intent arguments you passed or related to their implementation on connection management. 

G
GPMOD@SOTI
2 years ago

Hi Daniel, 

Thanks for posting on SOTI Pulse and thanks Raymond for responding to the post.

I would request you check with OpenVPN support if your configuration is correct.

Furthermore, you can open a support case here and someone from Technical Support Team can help you to reach out to SOTI Professional services for advanced configurations.  

Thank you. 

Kind regards,

Technical Support | SOTI Inc. |1.905.624.9828 | support@soti.net | www.soti.net |