From 7c7acb1a490e2808165d0d1b6ee41d998f2d6dfc Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Sun, 3 Mar 2013 12:33:53 +0100 Subject: - Increase version to 0.5.34a for JB 4.1 only - When importing OpenVPN Access profiles import username and name --- AndroidManifest.xml | 11 ++-- res/menu/import_menu.xml | 14 ++--- src/de/blinkt/openvpn/ConfigConverter.java | 4 ++ src/de/blinkt/openvpn/ConfigParser.java | 89 +++++++++++++++++++----------- 4 files changed, 74 insertions(+), 44 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index f92ec38a..b7c382b9 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -18,8 +18,8 @@ + android:versionCode="62" + android:versionName="0.5.34a" > @@ -30,7 +30,8 @@ @@ -153,7 +155,6 @@ android:targetActivity=".LaunchVPN" > - @@ -166,4 +167,4 @@ tools:ignore="ExportedContentProvider" /> - \ No newline at end of file + diff --git a/res/menu/import_menu.xml b/res/menu/import_menu.xml index c29db10e..1bed5a6b 100644 --- a/res/menu/import_menu.xml +++ b/res/menu/import_menu.xml @@ -1,12 +1,5 @@ - - + + \ No newline at end of file diff --git a/src/de/blinkt/openvpn/ConfigConverter.java b/src/de/blinkt/openvpn/ConfigConverter.java index 5065436c..d715e8b7 100644 --- a/src/de/blinkt/openvpn/ConfigConverter.java +++ b/src/de/blinkt/openvpn/ConfigConverter.java @@ -194,6 +194,10 @@ public class ConfigConverter extends ListActivity { String newname = mPossibleName; + // Default to + if(mResult.mName!=null && !ConfigParser.CONVERTED_PROFILE.equals(mResult.mName)) + newname=mResult.mName; + while(vpl.getProfileByName(newname)!=null) { i++; if(i==1) diff --git a/src/de/blinkt/openvpn/ConfigParser.java b/src/de/blinkt/openvpn/ConfigParser.java index 724772eb..9e286312 100644 --- a/src/de/blinkt/openvpn/ConfigParser.java +++ b/src/de/blinkt/openvpn/ConfigParser.java @@ -16,24 +16,31 @@ import java.util.Vector; public class ConfigParser { + public static final String CONVERTED_PROFILE = "converted Profile"; private HashMap>> options = new HashMap>>(); - + private HashMap> meta = new HashMap>(); + + private boolean extraRemotesAsCustom=false; - + public void parseConfig(Reader reader) throws IOException, ConfigParseError { - - BufferedReader br =new BufferedReader(reader); - @SuppressWarnings("unused") - int lineno=0; + BufferedReader br =new BufferedReader(reader); while (true){ String line = br.readLine(); if(line==null) break; - lineno++; - Vector args = parseline(line); + + // Check for OpenVPN Access Server Meta information + if (line.startsWith("# OVPN_ACCESS_SERVER_")) { + Vector metaarg = parsemeta(line); + meta.put(metaarg.get(0),metaarg); + continue; + } + Vector args = parseline(line); + if(args.size() ==0) continue; @@ -51,6 +58,16 @@ public class ConfigParser { } } + private Vector parsemeta(String line) { + String meta = line.split("#\\sOVPN_ACCESS_SERVER_", 2)[1]; + String[] parts = meta.split("=",2); + Vector rval = new Vector(); + for(String p:parts) + rval.add(p); + return rval; + + } + private void checkinlinefile(Vector args, BufferedReader br) throws IOException, ConfigParseError { String arg0 = args.get(0); // CHeck for @@ -241,12 +258,12 @@ public class ConfigParser { "topology", "win-sys", }; - - + + // This method is far too long public VpnProfile convertProfile() throws ConfigParseError{ boolean noauthtypeset=true; - VpnProfile np = new VpnProfile("converted Profile"); + VpnProfile np = new VpnProfile(CONVERTED_PROFILE); // Pull, client, tls-client np.clearDefaults(); @@ -255,7 +272,7 @@ public class ConfigParser { options.remove("pull"); options.remove("client"); } - + Vector secret = getOption("secret", 1, 2); if(secret!=null) { @@ -265,9 +282,9 @@ public class ConfigParser { np.mTLSAuthFilename=secret.get(1); if(secret.size()==3) np.mTLSAuthDirection=secret.get(2); - + } - + Vector> routes = getAllOption("route", 1, 4); if(routes!=null) { String routeopt = ""; @@ -284,7 +301,7 @@ public class ConfigParser { } catch (NumberFormatException ne) { throw new ConfigParseError("Could not parse netmask of route " + netmask); } - + } np.mCustomRoutes=routeopt; } @@ -304,7 +321,7 @@ public class ConfigParser { } } } - + Vector direction = getOption("key-direction", 1, 1); if(direction!=null) np.mTLSAuthDirection=direction.get(1); @@ -331,12 +348,12 @@ public class ConfigParser { if(!mode.get(1).equals("p2p")) throw new ConfigParseError("Invalid mode for --mode specified, need p2p"); } - + Vector port = getOption("port", 1,1); if(port!=null){ np.mServerPort = port.get(1); } - + Vector proto = getOption("proto", 1,1); if(proto!=null){ np.mUseUdp=isUdpProto(proto.get(1));; @@ -356,7 +373,7 @@ public class ConfigParser { np.mServerName = remote.get(1); } } - + Vector> dhcpoptions = getAllOption("dhcp-option", 2, 2); @@ -381,7 +398,7 @@ public class ConfigParser { CIDRIP cidr = new CIDRIP(ifconfig.get(1), ifconfig.get(2)); np.mIPv4Address=cidr.toString(); } - + if(getOption("remote-random-hostname", 0, 0)!=null) np.mUseRandomHostname=true; @@ -399,7 +416,7 @@ public class ConfigParser { if(auth!=null) np.mAuth = auth.get(1); - + Vector ca = getOption("ca",1,1); if(ca!=null){ np.mCaFilename = ca.get(1); @@ -433,28 +450,28 @@ public class ConfigParser { np.mVerb=verb.get(1); } - + if(getOption("nobind", 0, 0) != null) np.mNobind=true; - + if(getOption("persist-tun", 0,0) != null) np.mPersistTun=true; - + Vector connectretry = getOption("connect-retry", 1, 1); if(connectretry!=null) np.mConnectRetry =connectretry.get(1); - + Vector connectretrymax = getOption("connect-retry-max", 1, 1); if(connectretrymax!=null) np.mConnectRetryMax =connectretrymax.get(1); - + Vector> remotetls = getAllOption("remote-cert-tls", 1, 1); if(remotetls!=null) if(remotetls.get(0).get(1).equals("server")) np.mExpectTLSCert=true; else options.put("remotetls",remotetls); - + Vector authuser = getOption("auth-user-pass",0,1); if(authuser !=null){ if(noauthtypeset) { @@ -465,15 +482,23 @@ public class ConfigParser { np.mAuthenticationType=VpnProfile.TYPE_USERPASS_KEYSTORE; } if(authuser.size()>1) { - // Set option value to password get to get canche to embed later. + // Set option value to password get to get cance to embed later. np.mUsername=null; np.mPassword=authuser.get(1); useEmbbedUserAuth(np,authuser.get(1)); } - } - + // Parse OpenVPN Access Server extra + Vector friendlyname = meta.get("FRIENDLY_NAME"); + if(friendlyname !=null && friendlyname.size() > 1) + np.mName=friendlyname.get(1); + + + Vector ocusername = meta.get("USERNAME"); + if(ocusername !=null && ocusername.size() > 1) + np.mUsername=ocusername.get(1); + // Check the other options if(remotes !=null && remotes.size()>1 && extraRemotesAsCustom) { // first is already added @@ -487,7 +512,7 @@ public class ConfigParser { return np; } - + public void useExtraRemotesAsCustom(boolean b) { this.extraRemotesAsCustom = b; } @@ -505,7 +530,7 @@ public class ConfigParser { throw new ConfigParseError("Unsupported option to --proto " + proto); return isudp; } - + static public void useEmbbedUserAuth(VpnProfile np,String inlinedata) { String data = inlinedata.replace(VpnProfile.INLINE_TAG, ""); -- cgit v1.2.3