From 451a47487185e1e17626386e38381e5e8dba9fb8 Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Mon, 8 Dec 2014 13:07:28 +0100 Subject: Always use --remote when possible, fix connection block not accepting global options --HG-- extra : rebase_source : 725acc40a0c82171fab1536a14e22805b1322ed4 --- .../main/java/de/blinkt/openvpn/VpnProfile.java | 31 ++++++++++++++++++---- .../java/de/blinkt/openvpn/core/Connection.java | 4 +++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/main/src/main/java/de/blinkt/openvpn/VpnProfile.java b/main/src/main/java/de/blinkt/openvpn/VpnProfile.java index 606c563c..ed235373 100644 --- a/main/src/main/java/de/blinkt/openvpn/VpnProfile.java +++ b/main/src/main/java/de/blinkt/openvpn/VpnProfile.java @@ -299,16 +299,24 @@ public class VpnProfile implements Serializable, Cloneable { // We cannot use anything else than tun cfg += "dev tun\n"; + + boolean canUsePlainRemotes = true; + if (mConnections.length==1) { cfg += mConnections[0].getConnectionBlock(); } else { + for (Connection conn : mConnections) { + canUsePlainRemotes = canUsePlainRemotes && conn.isOnlyRemote(); + } + if (mRemoteRandom) cfg+="remote-random\n"; - for (Connection conn : mConnections) { - if (conn.mEnabled) { - cfg += "\n"; - cfg += conn.getConnectionBlock(); - cfg += "\n"; + + if (canUsePlainRemotes) { + for (Connection conn : mConnections) { + if (conn.mEnabled) { + cfg += conn.getConnectionBlock(); + } } } } @@ -501,6 +509,19 @@ public class VpnProfile implements Serializable, Cloneable { } + if (!canUsePlainRemotes) { + cfg += "# Connection Options are at the end to allow global options (and global custom options) to influence connection blocks\n" + for (Connection conn : mConnections) { + if (conn.mEnabled) { + cfg += "\n"; + cfg += conn.getConnectionBlock(); + cfg += "\n"; + } + } + } + + + return cfg; } diff --git a/main/src/main/java/de/blinkt/openvpn/core/Connection.java b/main/src/main/java/de/blinkt/openvpn/core/Connection.java index fd5c3761..a12dfcaf 100644 --- a/main/src/main/java/de/blinkt/openvpn/core/Connection.java +++ b/main/src/main/java/de/blinkt/openvpn/core/Connection.java @@ -44,4 +44,8 @@ public class Connection implements Serializable, Cloneable { public Connection clone() throws CloneNotSupportedException { return (Connection) super.clone(); } + + public boolean isOnlyRemote() { + return TextUtils.isEmpty(mCustomConfiguration) || !mUseCustomConfig; + } } -- cgit v1.2.3