diff options
author | Arne Schwabe <arne@rfc2549.org> | 2012-05-06 20:06:30 +0200 |
---|---|---|
committer | Arne Schwabe <arne@rfc2549.org> | 2012-05-06 20:06:30 +0200 |
commit | 36121acf0b12a90387f71b79b1538acf95842158 (patch) | |
tree | facfc2f5cb82f36207862882d103111d1b936bab /src | |
parent | ef4fd36f5d38e82ba6165be2468d985d62f1d32f (diff) |
- Ability to copy single log entries (issue #9)
- Remove dependency on JNI for all but early logging and opening tun
Diffstat (limited to 'src')
-rw-r--r-- | src/de/blinkt/openvpn/LogWindow.java | 26 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/OpenVPN.java | 16 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/OpenVpnManagementThread.java | 46 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/OpenVpnService.java | 11 |
4 files changed, 62 insertions, 37 deletions
diff --git a/src/de/blinkt/openvpn/LogWindow.java b/src/de/blinkt/openvpn/LogWindow.java index f3809e2..3455e38 100644 --- a/src/de/blinkt/openvpn/LogWindow.java +++ b/src/de/blinkt/openvpn/LogWindow.java @@ -1,19 +1,17 @@ package de.blinkt.openvpn; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.nio.charset.Charset; import java.util.Vector; import android.app.AlertDialog; import android.app.AlertDialog.Builder; import android.app.ListActivity; +import android.content.ClipData; +import android.content.ClipboardManager; +import android.content.Context; import android.content.DialogInterface; -import android.content.Intent; import android.content.DialogInterface.OnClickListener; +import android.content.Intent; import android.database.DataSetObserver; -import android.net.Uri; import android.os.Bundle; import android.os.Handler; import android.os.Handler.Callback; @@ -23,6 +21,8 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.AdapterView.OnItemLongClickListener; import android.widget.ListAdapter; import android.widget.ListView; import android.widget.TextView; @@ -235,6 +235,20 @@ public class LogWindow extends ListActivity { super.onCreate(savedInstanceState); ListView lv = getListView(); + + lv.setOnItemLongClickListener(new OnItemLongClickListener() { + + @Override + public boolean onItemLongClick(AdapterView<?> parent, View view, + int position, long id) { + ClipboardManager clipboard = (ClipboardManager) + getSystemService(Context.CLIPBOARD_SERVICE); + ClipData clip = ClipData.newPlainText("Log Entry",((TextView) view).getText()); + clipboard.setPrimaryClip(clip); + Toast.makeText(getBaseContext(), R.string.copied_entry, Toast.LENGTH_SHORT).show(); + return true; + } + }); //lv.setTextFilterEnabled(true); ladapter = new LogWindowListAdapter(); lv.setAdapter(ladapter); diff --git a/src/de/blinkt/openvpn/OpenVPN.java b/src/de/blinkt/openvpn/OpenVPN.java index 8dad6af..cc827aa 100644 --- a/src/de/blinkt/openvpn/OpenVPN.java +++ b/src/de/blinkt/openvpn/OpenVPN.java @@ -67,22 +67,6 @@ public class OpenVPN { } - static void addInterfaceInfo(int mtu, String local, String netmask) - { - Log.i("openvpn","Got interface info M" + mtu + " L: " + local + "NM: " + netmask); - mOpenVpnService.setLocalIP(local,netmask); - } - - static void addDns(String dns) { - Log.i("openvpn","Got DNS Server: " + dns); - mOpenVpnService.addDNS(dns); - } - - - static void addDomain(String domain) { - Log.i("openvpn","Got DNS Domain: " + domain); - mOpenVpnService.setDomain(domain); - } public static void setCallback(OpenVpnService openVpnService) { diff --git a/src/de/blinkt/openvpn/OpenVpnManagementThread.java b/src/de/blinkt/openvpn/OpenVpnManagementThread.java index 4162d31..450cd53 100644 --- a/src/de/blinkt/openvpn/OpenVpnManagementThread.java +++ b/src/de/blinkt/openvpn/OpenVpnManagementThread.java @@ -5,9 +5,7 @@ import java.io.IOException; import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.net.DatagramSocket;
import java.util.LinkedList;
-import java.util.List;
import java.util.Vector;
import android.net.LocalSocket;
@@ -146,7 +144,7 @@ public class OpenVpnManagementThread implements Runnable { } else if (cmd.equals("HOLD")) {
managmentCommand("hold release\n");
} else if (cmd.equals("NEED-OK")) {
- processPWCommand(argument);
+ processNeedCommand(argument);
} else {
Log.i(TAG, "Got unrecognized command" + command);
}
@@ -154,6 +152,37 @@ public class OpenVpnManagementThread implements Runnable { Log.i(TAG, "Got unrecognized line from managment" + command);
}
}
+
+ private void processNeedCommand(String argument) {
+ int p1 =argument.indexOf('\'');
+ int p2 = argument.indexOf('\'',p1+1);
+
+ String needed = argument.substring(p1+1, p2);
+ String extra = argument.split(":",2)[1];
+
+ if (needed.equals("PROTECTFD")) {
+ FileDescriptor fdtoprotect = mFDList.pollFirst();
+ protectFileDescriptor(fdtoprotect);
+ } else if (needed.equals("DNSSERVER")) {
+ mOpenVPNService.addDNS(extra);
+ }else if (needed.equals("DNSDOMAIN")){
+ mOpenVPNService.setDomain(extra);
+ } else if (needed.equals("ROUTE")) {
+ String[] routeparts = extra.split(" ");
+ mOpenVPNService.addRoute(routeparts[0], routeparts[1]);
+ } else if (needed.equals("IFCONFIG")) {
+ String[] ifconfigparts = extra.split(" ");
+ int mtu = Integer.parseInt(ifconfigparts[0]);
+ mOpenVPNService.setLocalIP(ifconfigparts[0], ifconfigparts[1],mtu);
+
+ } else {
+ Log.e(TAG,"Unkown needok command " + argument);
+ return;
+ }
+
+ String cmd = String.format("needok '%s' %s\n", needed, "ok");
+ managmentCommand(cmd);
+ }
private void processPWCommand(String argument) {
//argument has the form Need 'Private Key' password
@@ -163,7 +192,7 @@ public class OpenVpnManagementThread implements Runnable { String needed = argument.substring(p1+1, p2);
String pw=null;
- String response="password";
+
if(needed.equals("Private Key")) {
pw = mProfile.getPasswordPrivateKey();
@@ -172,14 +201,9 @@ public class OpenVpnManagementThread implements Runnable { needed, VpnProfile.openVpnEscape(mProfile.mUsername));
managmentCommand(usercmd);
pw = mProfile.getPasswordAuth();
- } else if (needed.equals("PROTECTFD")) {
- FileDescriptor fdtoprotect = mFDList.pollFirst();
- protectFileDescriptor(fdtoprotect);
- pw = "ok";
- response="needok";
- }
+ }
if(pw!=null) {
- String cmd = String.format("%s '%s' %s\n",response, needed, VpnProfile.openVpnEscape(pw));
+ String cmd = String.format("password '%s' %s\n", needed, VpnProfile.openVpnEscape(pw));
managmentCommand(cmd);
}
diff --git a/src/de/blinkt/openvpn/OpenVpnService.java b/src/de/blinkt/openvpn/OpenVpnService.java index e6e69ab..5937f48 100644 --- a/src/de/blinkt/openvpn/OpenVpnService.java +++ b/src/de/blinkt/openvpn/OpenVpnService.java @@ -46,6 +46,7 @@ public class OpenVpnService extends VpnService implements Handler.Callback { private OpenVpnManagementThread mSocketManager; private Thread mSocketManagerThread; + private int mMtu; @@ -220,6 +221,8 @@ public class OpenVpnService extends VpnService implements Handler.Callback { for (String dns : mDnslist ) { builder.addDnsServer(dns); } + + builder.setMtu(mMtu); for (CIDRIP route:mRoutes) { @@ -236,7 +239,7 @@ public class OpenVpnService extends VpnService implements Handler.Callback { String bconfig[] = new String[5]; bconfig[0]= getString(R.string.last_openvpn_tun_config); - bconfig[1] = String.format(getString(R.string.local_ip_info,mLocalIP.mIp,mLocalIP.len)); + bconfig[1] = String.format(getString(R.string.local_ip_info,mLocalIP.mIp,mLocalIP.len,mMtu)); bconfig[2] = String.format(getString(R.string.dns_server_info, joinString(mDnslist))); bconfig[3] = String.format(getString(R.string.dns_domain_info, mDomain)); bconfig[4] = String.format(getString(R.string.routes_info, joinString(mRoutes))); @@ -249,8 +252,6 @@ public class OpenVpnService extends VpnService implements Handler.Callback { builder.setSession(mProfile.mName + " - " + mLocalIP); - - // Let the configure Button show the Log Intent intent = new Intent(getBaseContext(),LogWindow.class); @@ -310,8 +311,10 @@ public class OpenVpnService extends VpnService implements Handler.Callback { } - public void setLocalIP(String local, String netmask) { + public void setLocalIP(String local, String netmask,int mtu) { mLocalIP = new CIDRIP(local, netmask); + mMtu = mtu; + if(mLocalIP.len == 32 && !netmask.equals("255.255.255.255")) { OpenVPN.logMessage(0, "", String.format(getString(R.string.ip_not_cidr, local,netmask))); } |