henrichg / PhoneProfilesPlus

Profile manager for Android - event triggered
Apache License 2.0
417 stars 32 forks source link

[Feature request] Add support for toggling WireGuard tunnels #87

Closed balporig closed 2 years ago

balporig commented 2 years ago

The WireGuard VPN android app exposes toggling ON/OFF tunnels from external apps. An example implementation can be seen by Easer. Options to include:

henrichg commented 2 years ago

In source code of Easer: (https://github.com/renyuneyun/Easer/blob/master/app/src/main/java/ryey/easer/skills/operation/wireguard/WireguardLoader.java) https://github.com/renyuneyun/Easer/blob/master/app/src/main/java/ryey/easer/skills/operation/wireguard/WireguardOperationSkill.java

I'm found also this: https://www.reddit.com/r/tasker/comments/fn6wou/wireguard_now_supports_control_by_remote_apps/

Result: will be implemented. Will be added new profile parameter "VPN". In it will be OpenVPN support (currently in "Run application, shortcut, intent" as predefined intents) and added WireGuard. ;-)

henrichg commented 2 years ago

Impleneted. If you want, install and test it. Added is profile parameter "VPN" in "Radios" section. https://drive.google.com/file/d/1CR4y2u3V8PCwQK9sw1P88JrlpSdA2Ou4/view?usp=drivesdk

balporig commented 2 years ago

Does not seem to work:

1_img

The UI is good one suggestion, when you select OpenVpn hide the Wireguard text field and vice versa.

henrichg commented 2 years ago
balporig commented 2 years ago

You granted permission for WireGuard? It is required. PPP notifies it, when you activate profile. Tunnel name is correct?

Yep, its all correct

"OpenVPN profile name" is disabled, when you set WireGuard in "VPN apllication:".

It is, but makes not sense to be show if not being used. At least if it's being kept, change the textbox placeholder to be more visible to users.

Activity log is only for information, not for detailed log, what was wrong. And in Activity log are only some errors loged. Not all.

Again, it will be nice to have the option to view the access log if desired. For example now I could have given better feedback if there was obvious exception in there instead of saying this does not work. If there was a beta version, you can have that one enabled by default.

Beta releases in izzyDroid repo: sorry not. Beta release is not for all users, only for users, which send me e-mail with errors, suggestions, ... Beta = developer version. It is my internal naming.

If the beta is closed, yes, but doesn't have to be. Many projects release open beta/nightly versions, like the famous Firefox Nightly. The more users and the easier it is to test and report, the better. Here's an example of open beta: https://apt.izzysoft.de/fdroid/index/apk/dev.patrickgold.florisboard.beta

henrichg commented 2 years ago
henrichg commented 2 years ago

I'm found bug. Mixed call of activaty and broadcast. :-( Fixed. Fixed version: https://drive.google.com/file/d/1CR4y2u3V8PCwQK9sw1P88JrlpSdA2Ou4/view?usp=drivesdk

balporig commented 2 years ago

There is progress. Disabling now works. Enabling does not let you save the config, and it is not detected as change.

henrichg commented 2 years ago

But "Enable VPN" does not setup tunnel configuration. It only set it ON. You must configure tunnel in WireGuard.

From Easer:

    static final String INTENT_STATE_UP = "com.wireguard.android.action.SET_TUNNEL_UP";
    static final String INTENT_STATE_DOWN = "com.wireguard.android.action.SET_TUNNEL_DOWN";

    static final String EXTRA_TUNNEL_NAME = "tunnel";

    static final String WIREGUARD_APP = "com.wireguard.android";

public void _load(@NonNull WireguardOperationData data, @NonNull OnResultCallback callback) {
        Intent intent = new Intent(data.tunnel_state ? INTENT_STATE_UP : INTENT_STATE_DOWN);
        intent.setPackage(WireguardOperationSkill.WIREGUARD_APP);
        intent.putExtra(EXTRA_TUNNEL_NAME, data.tunnel_name);
        context.sendBroadcast(intent);
        callback.onResult(true);
    }

The similar code is in PPP:

intent = new Intent(enableVPN ? "com.wireguard.android.action.SET_TUNNEL_UP" : "com.wireguard.android.action.SET_TUNNEL_DOWN");
intent.setPackage("com.wireguard.android");
intent.putExtra("tunnel", tunnelName);
context.sendBroadcast(intent);
balporig commented 2 years ago

Don't mean to setup tunnel configuration, this is done, but to enable the tunnel. PPP cannot save it's configuration when set to Enable.

henrichg commented 2 years ago

What you means "cannot save"? It is all by WireGuard. If WireGuard do not starts tunnel, then must be bug in your WireGuard configuration. Maybe must be enabled remote control in WireGuard applicaiton or only in tunnel configuration. I do not using it, then I do not know.

balporig commented 2 years ago

Wireguard is working fine. In the new VPN PPP mode you can do 2 things Enable/Disable, any of those changes need to be saved at the end to be set. If you set to Disable, PPP display there are profile changes and let you save them and works as expectd, but for Enable it does not, thus you cannot enable the Tunnel.

henrichg commented 2 years ago

Ach so! Currently I uderstand. PPP do not detect changes in VPN parameter configuration. OK will be fixed soon. Thanks.

henrichg commented 2 years ago

Fixed: https://drive.google.com/file/d/1CR4y2u3V8PCwQK9sw1P88JrlpSdA2Ou4/view?usp=drivesdk

balporig commented 2 years ago

Can verify now works as intended. Thank you again for the effort!

henrichg commented 2 years ago

;-)

henrichg commented 2 years ago

Implemented.