diff options
author | Arne Schwabe <arne@rfc2549.org> | 2013-09-27 22:57:30 +0200 |
---|---|---|
committer | Arne Schwabe <arne@rfc2549.org> | 2013-09-27 22:57:30 +0200 |
commit | 911f3855f184ecdb1339c1d8383ea19e86fe918e (patch) | |
tree | 8799a9b78e0a7f5c7e4162a410ce256135f535f4 /src/de/blinkt/openvpn/core | |
parent | 4d9f6e5358b97ab104bc6c26b862ab290161568f (diff) |
Implement changing log level on the fly in the log window, still needs some UI design love
--HG--
extra : rebase_source : 207343cea3b74cd07ebdf00f8ef443465d12c966
Diffstat (limited to 'src/de/blinkt/openvpn/core')
-rw-r--r-- | src/de/blinkt/openvpn/core/ConfigParser.java | 1 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/core/OpenVPNThread.java | 36 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/core/OpenVpnManagementThread.java | 16 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/core/VpnStatus.java | 41 |
4 files changed, 78 insertions, 16 deletions
diff --git a/src/de/blinkt/openvpn/core/ConfigParser.java b/src/de/blinkt/openvpn/core/ConfigParser.java index 01a92bd7..dcbd636f 100644 --- a/src/de/blinkt/openvpn/core/ConfigParser.java +++ b/src/de/blinkt/openvpn/core/ConfigParser.java @@ -247,6 +247,7 @@ public class ConfigParser { "management", "management-query-passwords", "pause-exit", + "parsable-output", "persist-key", "register-dns", "route-delay", diff --git a/src/de/blinkt/openvpn/core/OpenVPNThread.java b/src/de/blinkt/openvpn/core/OpenVPNThread.java index 930d2614..0807b33d 100644 --- a/src/de/blinkt/openvpn/core/OpenVPNThread.java +++ b/src/de/blinkt/openvpn/core/OpenVPNThread.java @@ -10,11 +10,17 @@ import java.io.*; import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Map.Entry;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
public class OpenVPNThread implements Runnable {
- private static final String DUMP_PATH_STRING = "Dump path: ";
+ private static final String DUMP_PATH_STRING = "Dump path: ";
private static final String TAG = "OpenVPN";
- private String[] mArgv;
+ public static final int M_FATAL = (1 << 4);
+ public static final int M_NONFATAL = (1 << 5);
+ public static final int M_WARN = (1 << 6);
+ public static final int M_DEBUG = (1 << 7);
+ private String[] mArgv;
private Process mProcess;
private String mNativeDir;
private OpenVpnService mService;
@@ -111,7 +117,31 @@ public class OpenVPNThread implements Runnable { mDumpPath = logline.substring(DUMP_PATH_STRING.length());
- VpnStatus.logInfo("P:" + logline);
+ // 1380308330.240114 18000002 Send to HTTP proxy: 'X-Online-Host: bla.blabla.com'
+
+ Pattern p = Pattern.compile("(\\d+).(\\d+) ([0-9a-f])+ (.*)");
+ Matcher m = p.matcher(logline);
+ if(m.matches()) {
+ int flags = Integer.parseInt(m.group(3),16);
+ String msg = m.group(4);
+ int logLevel = flags & 0x0F;
+
+ VpnStatus.LogLevel logStatus = VpnStatus.LogLevel.INFO;
+
+ if ((flags & M_FATAL) != 0)
+ logStatus = VpnStatus.LogLevel.ERROR;
+ else if ((flags & M_NONFATAL)!=0)
+ logStatus = VpnStatus.LogLevel.WARNING;
+ else if ((flags & M_WARN)!=0)
+ logStatus = VpnStatus.LogLevel.WARNING;
+ else if ((flags & M_DEBUG)!=0)
+ logStatus = VpnStatus.LogLevel.VERBOSE;
+
+
+ VpnStatus.logMessageOpenVPN(logStatus,logLevel,msg);
+ } else {
+ VpnStatus.logInfo("P:" + logline);
+ }
}
diff --git a/src/de/blinkt/openvpn/core/OpenVpnManagementThread.java b/src/de/blinkt/openvpn/core/OpenVpnManagementThread.java index 23c6cff6..03b36144 100644 --- a/src/de/blinkt/openvpn/core/OpenVpnManagementThread.java +++ b/src/de/blinkt/openvpn/core/OpenVpnManagementThread.java @@ -202,7 +202,10 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement { private void processCommand(String command) {
- if (command.startsWith(">") && command.contains(":")) {
+ Log.i(TAG, "Line from managment" + command);
+
+
+ if (command.startsWith(">") && command.contains(":")) {
String[] parts = command.split(":",2);
String cmd = parts[0].substring(1);
String argument = parts[1];
@@ -241,7 +244,7 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement { }
private void processLogMessage(String argument) {
- String[] args = argument.split(",",3);
+ String[] args = argument.split(",",4);
// 0 unix time stamp
// 1 log level N,I,E etc.
/*
@@ -254,6 +257,8 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement { */
// 2 log message
+ Log.d("OpenVPN", argument);
+
VpnStatus.LogLevel level;
if (args[1].equals("I")) {
level = VpnStatus.LogLevel.INFO;
@@ -267,7 +272,9 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement { level = VpnStatus.LogLevel.INFO;
}
- VpnStatus.logMessage(level,"P:", args[2]);
+ int ovpnlevel = Integer.parseInt(args[2]) & 0x0F;
+
+ VpnStatus.logMessageOpenVPN(level,ovpnlevel, args[3]);
}
private void handleHold() {
@@ -294,7 +301,8 @@ public class OpenVpnManagementThread implements Runnable, OpenVPNManagement { mLastHoldRelease = System.currentTimeMillis();
managmentCommand("hold release\n");
managmentCommand("bytecount " + mBytecountInterval + "\n");
- managmentCommand("state on\n");
+ managmentCommand("state on\n");
+ //managmentCommand("log on all\n");
}
public void releaseHold() {
diff --git a/src/de/blinkt/openvpn/core/VpnStatus.java b/src/de/blinkt/openvpn/core/VpnStatus.java index c8e5a8b1..002b6fc9 100644 --- a/src/de/blinkt/openvpn/core/VpnStatus.java +++ b/src/de/blinkt/openvpn/core/VpnStatus.java @@ -42,6 +42,7 @@ public class VpnStatus { private static long mlastByteCount[]={0,0,0,0}; + public enum ConnectionStatus { LEVEL_CONNECTED, LEVEL_VPNPAUSED, @@ -55,10 +56,10 @@ public class VpnStatus { } public enum LogLevel { - INFO(1), - ERROR(2), - WARNING(3), - VERBOSE(4); + INFO(2), + ERROR(-2), + WARNING(1), + VERBOSE(3); protected int mValue; LogLevel(int value) { @@ -103,13 +104,20 @@ public class VpnStatus { // Default log priority LogLevel mLevel = LogLevel.INFO; private long logtime = System.currentTimeMillis(); + private int mVerbosityLevel = -1; private LogItem(int ressourceId, Object[] args) { mRessourceId = ressourceId; mArgs = args; } - @Override + public LogItem(LogLevel level, int verblevel, String message) { + mMessage=message; + mLevel = level; + mVerbosityLevel = verblevel; + } + + @Override public int describeContents() { return 0; } @@ -121,6 +129,8 @@ public class VpnStatus { dest.writeString(mMessage); dest.writeInt(mRessourceId); dest.writeInt(mLevel.getInt()); + dest.writeInt(mVerbosityLevel); + dest.writeLong(logtime); } @@ -129,6 +139,7 @@ public class VpnStatus { mMessage = in.readString(); mRessourceId = in.readInt(); mLevel = LogLevel.getEnumByValue(in.readInt()); + mVerbosityLevel = in.readInt(); logtime = in.readLong(); } @@ -247,7 +258,15 @@ public class VpnStatus { } - } + public int getVerbosityLevel() { + if (mVerbosityLevel==-1) { + // Hack: + // For message not from OpenVPN, report the status level as log level + return mLevel.getInt(); + } + return mVerbosityLevel; + } + } private static final int MAXLOGENTRIES = 500; @@ -278,8 +297,6 @@ public class VpnStatus { } private static void logInformation() { - - logInfo(R.string.mobile_info,Build.MODEL, Build.BOARD,Build.BRAND,Build.VERSION.SDK_INT); } @@ -452,7 +469,13 @@ public class VpnStatus { newLogItem(new LogItem(LogLevel.ERROR, resourceId, args)); } - public static synchronized void updateByteCount(long in, long out) { + public static void logMessageOpenVPN(LogLevel level, int ovpnlevel, String message) { + newLogItem(new LogItem(level, ovpnlevel, message)); + + } + + + public static synchronized void updateByteCount(long in, long out) { long lastIn = mlastByteCount[0]; long lastOut = mlastByteCount[1]; long diffIn = mlastByteCount[2] = in - lastIn; |