summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2013-09-27 22:57:30 +0200
committerArne Schwabe <arne@rfc2549.org>2013-09-27 22:57:30 +0200
commit911f3855f184ecdb1339c1d8383ea19e86fe918e (patch)
tree8799a9b78e0a7f5c7e4162a410ce256135f535f4
parent4d9f6e5358b97ab104bc6c26b862ab290161568f (diff)
Implement changing log level on the fly in the log window, still needs some UI design love
--HG-- extra : rebase_source : 207343cea3b74cd07ebdf00f8ef443465d12c966
-rw-r--r--res/layout/logwindow.xml81
-rw-r--r--res/menu/logmenu.xml55
-rw-r--r--src/de/blinkt/openvpn/LogDetailActionProvider.java61
-rw-r--r--src/de/blinkt/openvpn/LogWindow.java223
-rw-r--r--src/de/blinkt/openvpn/VpnProfile.java9
-rw-r--r--src/de/blinkt/openvpn/core/ConfigParser.java1
-rw-r--r--src/de/blinkt/openvpn/core/OpenVPNThread.java36
-rw-r--r--src/de/blinkt/openvpn/core/OpenVpnManagementThread.java16
-rw-r--r--src/de/blinkt/openvpn/core/VpnStatus.java41
-rw-r--r--vpndialogxposed/vpndialogxposed.iml6
10 files changed, 429 insertions, 100 deletions
diff --git a/res/layout/logwindow.xml b/res/layout/logwindow.xml
index 57ab5cb9..d7281346 100644
--- a/res/layout/logwindow.xml
+++ b/res/layout/logwindow.xml
@@ -1,18 +1,75 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical" >
-
- <TextView android:text="@string/speed_waiting"
- android:singleLine="true"
- android:id="@+id/speed"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"/>
- <ListView
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+ <LinearLayout
+ android:orientation="vertical"
+ android:id="@+id/logOptionsLayout"
+ android:visibility="gone"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
+
+ <TextView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/log_verbosity_level"/>
+
+ <SeekBar
+ android:id="@+id/LogLevelSlider"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:max="5"
+ android:indeterminate="false"/>
+
+ <TextView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="Timestamps"/>
+
+ <RadioGroup
+ android:id="@+id/timeFormatRadioGroup"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal">
+
+ <RadioButton
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="None"
+ android:id="@+id/radioNone"
+ />
+
+ <RadioButton
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Short"
+ android:id="@+id/radioShort"
+ />
+ <RadioButton
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="ISO"
+ android:id="@+id/radioISO"
+ />
+
+
+ </RadioGroup>
+ </LinearLayout>
+
+ <TextView
+ android:text="@string/speed_waiting"
+ android:singleLine="true"
+ android:id="@+id/speed"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"/>
+
+ <ListView
android:id="@android:id/list"
android:transcriptMode="normal"
android:layout_width="fill_parent"
- android:layout_height="fill_parent" />
-
+ android:layout_height="fill_parent"/>
+
</LinearLayout> \ No newline at end of file
diff --git a/res/menu/logmenu.xml b/res/menu/logmenu.xml
index 1c0551ed..d59dcf6f 100644
--- a/res/menu/logmenu.xml
+++ b/res/menu/logmenu.xml
@@ -1,35 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
-<menu xmlns:android="http://schemas.android.com/apk/res/android" >
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+
<item
- android:id="@+id/clearlog"
- android:icon="@drawable/ic_menu_trash_holo_light"
- android:showAsAction="ifRoom|withText"
- android:title="@string/clear_log"
- android:titleCondensed="@string/clear"/>
+ android:id="@+id/toggle_time"
+ android:alphabeticShortcut="t"
+ android:icon="@drawable/ic_clock"
+ android:showAsAction="withText|ifRoom"
+ android:title="@string/toggle_timestamps"/>
+
<item
- android:id="@+id/cancel"
- android:icon="@android:drawable/ic_menu_close_clear_cancel"
- android:showAsAction="ifRoom|withText"
- android:title="@string/cancel_connection_long"
- android:titleCondensed="@string/cancel_connection"/>
+ android:id="@+id/clearlog"
+ android:icon="@drawable/ic_menu_trash_holo_light"
+ android:showAsAction="ifRoom|withText"
+ android:title="@string/clear_log"
+ android:titleCondensed="@string/clear"/>
<item
- android:id="@+id/send"
- android:icon="@android:drawable/ic_menu_share"
- android:showAsAction="ifRoom|withText"
- android:title="@string/send_logfile"
- android:titleCondensed="@string/send"/>
+ android:id="@+id/send"
+ android:icon="@android:drawable/ic_menu_share"
+ android:showAsAction="ifRoom|withText"
+ android:title="@string/send_logfile"
+ android:titleCondensed="@string/send"/>
+
<item
- android:id="@+id/edit_vpn"
- android:alphabeticShortcut="e"
- android:icon="@android:drawable/ic_menu_edit"
- android:showAsAction="withText|ifRoom"
- android:title="@string/edit_vpn"/>
+ android:id="@+id/cancel"
+ android:icon="@android:drawable/ic_menu_close_clear_cancel"
+ android:showAsAction="ifRoom|withText"
+ android:title="@string/cancel_connection_long"
+ android:titleCondensed="@string/cancel_connection"/>
<item
- android:id="@+id/toggle_time"
- android:alphabeticShortcut="t"
- android:icon="@drawable/ic_clock"
- android:showAsAction="withText|ifRoom"
- android:title="@string/toggle_timestamps"/>
+ android:id="@+id/edit_vpn"
+ android:alphabeticShortcut="e"
+ android:icon="@android:drawable/ic_menu_edit"
+ android:showAsAction="withText|ifRoom"
+ android:title="@string/edit_vpn"/>
</menu> \ No newline at end of file
diff --git a/src/de/blinkt/openvpn/LogDetailActionProvider.java b/src/de/blinkt/openvpn/LogDetailActionProvider.java
new file mode 100644
index 00000000..697d5b3a
--- /dev/null
+++ b/src/de/blinkt/openvpn/LogDetailActionProvider.java
@@ -0,0 +1,61 @@
+package de.blinkt.openvpn;
+
+import android.annotation.TargetApi;
+import android.app.ActionBar;
+import android.content.Context;
+import android.graphics.drawable.Drawable;
+import android.os.Build;
+import android.view.*;
+import android.widget.SpinnerAdapter;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Created by arne on 22.09.13.
+ */
+public class LogDetailActionProvider extends ActionProvider {
+ /**
+ * Creates a new instance. ActionProvider classes should always implement a
+ * constructor that takes a single Context parameter for inflating from menu XML.
+ *
+ * @param context Context for accessing resources.
+ */
+ public LogDetailActionProvider(Context context) {
+ super(context);
+ }
+
+ @Override
+ public View onCreateActionView() {
+ return null;
+ }
+
+ @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
+ @Override
+ public View onCreateActionView(MenuItem forItem) {
+ return super.onCreateActionView(forItem);
+ }
+
+ @Override
+ public boolean hasSubMenu() {
+ return true;
+ }
+
+ @Override
+ public void onPrepareSubMenu(SubMenu subMenu) {
+ subMenu.add(1, Menu.NONE, Menu.NONE, "one");
+ subMenu.add(1, Menu.NONE, Menu.NONE, "two");
+ subMenu.add(1, Menu.NONE, Menu.NONE, "three");
+ subMenu.add(1, Menu.NONE, Menu.NONE, "four");
+
+ subMenu.add(2, Menu.NONE, Menu.NONE, "no");
+ subMenu.add(2, Menu.NONE, Menu.NONE, "short");
+ subMenu.add(2, Menu.NONE, Menu.NONE, "long");
+
+
+ }
+
+ @Override
+ public boolean onPerformDefaultAction() {
+ return super.onPerformDefaultAction();
+ }
+} \ No newline at end of file
diff --git a/src/de/blinkt/openvpn/LogWindow.java b/src/de/blinkt/openvpn/LogWindow.java
index ba6e79a1..e21c62b1 100644
--- a/src/de/blinkt/openvpn/LogWindow.java
+++ b/src/de/blinkt/openvpn/LogWindow.java
@@ -1,5 +1,9 @@
package de.blinkt.openvpn;
+import android.animation.Animator;
+import android.animation.AnimatorListenerAdapter;
+import android.animation.ObjectAnimator;
+import android.animation.ValueAnimator;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.*;
@@ -11,10 +15,12 @@ import android.os.Handler.Callback;
import android.os.IBinder;
import android.os.Message;
import android.text.SpannableString;
-import android.text.Spanned;
import android.text.format.DateFormat;
import android.text.style.ImageSpan;
import android.view.*;
+import android.view.animation.AccelerateInterpolator;
+import android.view.animation.Animation;
+import android.view.animation.TranslateAnimation;
import android.widget.*;
import android.widget.AdapterView.OnItemLongClickListener;
import de.blinkt.openvpn.core.VpnStatus;
@@ -32,14 +38,14 @@ import java.util.Date;
import java.util.Locale;
import java.util.Vector;
-public class LogWindow extends ListActivity implements StateListener {
+public class LogWindow extends ListActivity implements StateListener, SeekBar.OnSeekBarChangeListener, RadioGroup.OnCheckedChangeListener {
private static final String LOGTIMEFORMAT = "logtimeformat";
private static final int START_VPN_CONFIG = 0;
- protected OpenVpnService mService;
+ private static final String VERBOSITYLEVEL = "verbositylevel";
+ protected OpenVpnService mService;
private ServiceConnection mConnection = new ServiceConnection() {
-
@Override
public void onServiceConnected(ComponentName className,
IBinder service) {
@@ -54,27 +60,69 @@ public class LogWindow extends ListActivity implements StateListener {
}
};
+ private SeekBar mLogLevelSlider;
+ private LinearLayout mOptionsLayout;
+ private RadioGroup mTimeRadioGroup;
+
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+ ladapter.setLogLevel(progress+1);
+ Toast.makeText(this,"Loglevel set to " + ladapter.mLogLevel,Toast.LENGTH_SHORT).show();
+ }
+
+ @Override
+ public void onStartTrackingTouch(SeekBar seekBar) {
+
+ }
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar) {
+
+ }
+
+ @Override
+ public void onCheckedChanged(RadioGroup group, int checkedId) {
+ switch (checkedId) {
+ case R.id.radioISO:
+ ladapter.setTimeFormat(LogWindowListAdapter.TIME_FORMAT_ISO);
+ break;
+ case R.id.radioNone:
+ ladapter.setTimeFormat(LogWindowListAdapter.TIME_FORMAT_NONE);
+ break;
+ case R.id.radioShort:
+ ladapter.setTimeFormat(LogWindowListAdapter.TIME_FORMAT_SHORT);
+ break;
+
+ }
+ }
- class LogWindowListAdapter implements ListAdapter, LogListener, Callback {
+ class LogWindowListAdapter implements ListAdapter, LogListener, Callback {
- private static final int MESSAGE_NEWLOG = 0;
+ private static final int MESSAGE_NEWLOG = 0;
private static final int MESSAGE_CLEARLOG = 1;
-
- private static final int MESSAGE_NEWTS = 2;
- private Vector<LogItem> myEntries=new Vector<LogItem>();
+ private static final int MESSAGE_NEWTS = 2;
+ private static final int MESSAGE_NEWLOGLEVEL = 3;
+
+ public static final int TIME_FORMAT_NONE = 0;
+ public static final int TIME_FORMAT_SHORT = 1;
+ public static final int TIME_FORMAT_ISO = 2;
+
+ private Vector<LogItem> allEntries=new Vector<LogItem>();
+
+ private Vector<LogItem> currentLevelEntries=new Vector<LogItem>();
private Handler mHandler;
private Vector<DataSetObserver> observers=new Vector<DataSetObserver>();
private int mTimeFormat=0;
+ private int mLogLevel=3;
- public LogWindowListAdapter() {
+ public LogWindowListAdapter() {
initLogBuffer();
if (mHandler == null) {
mHandler = new Handler(this);
@@ -86,13 +134,14 @@ public class LogWindow extends ListActivity implements StateListener {
private void initLogBuffer() {
- myEntries.clear();
- Collections.addAll(myEntries, VpnStatus.getlogbuffer());
+ allEntries.clear();
+ Collections.addAll(allEntries, VpnStatus.getlogbuffer());
+ initCurrentMessages();
}
String getLogStr() {
String str = "";
- for(LogItem entry:myEntries) {
+ for(LogItem entry:allEntries) {
str+=entry.getString(LogWindow.this) + '\n';
}
return str;
@@ -120,17 +169,17 @@ public class LogWindow extends ListActivity implements StateListener {
@Override
public int getCount() {
- return myEntries.size();
+ return currentLevelEntries.size();
}
@Override
public Object getItem(int position) {
- return myEntries.get(position);
+ return currentLevelEntries.get(position);
}
@Override
public long getItemId(int position) {
- return position;
+ return currentLevelEntries.get(position).hashCode();
}
@Override
@@ -146,20 +195,20 @@ public class LogWindow extends ListActivity implements StateListener {
else
v = (TextView) convertView;
- LogItem le = myEntries.get(position);
+ LogItem le = currentLevelEntries.get(position);
String msg = le.getString(LogWindow.this);
String time ="";
- if (mTimeFormat != 0) {
+ if (mTimeFormat != TIME_FORMAT_NONE) {
Date d = new Date(le.getLogtime());
java.text.DateFormat timeformat;
- if (mTimeFormat==2)
+ if (mTimeFormat== TIME_FORMAT_ISO)
timeformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",Locale.getDefault());
else
timeformat = DateFormat.getTimeFormat(LogWindow.this);
time = timeformat.format(d);
}
- msg = time + " " + msg;
+ msg = time + " " + le.getVerbosityLevel() + " " + msg;
int spanStart = time.length();
@@ -210,7 +259,7 @@ public class LogWindow extends ListActivity implements StateListener {
@Override
public boolean isEmpty() {
- return myEntries.isEmpty();
+ return currentLevelEntries.isEmpty();
}
@@ -229,9 +278,9 @@ public class LogWindow extends ListActivity implements StateListener {
Message msg = Message.obtain();
assert (msg!=null);
msg.what=MESSAGE_NEWLOG;
- Bundle mbundle=new Bundle();
- mbundle.putParcelable("logmessage", logmessage);
- msg.setData(mbundle);
+ Bundle bundle=new Bundle();
+ bundle.putParcelable("logmessage", logmessage);
+ msg.setData(bundle);
mHandler.sendMessage(msg);
}
@@ -241,26 +290,55 @@ public class LogWindow extends ListActivity implements StateListener {
if(msg.what==MESSAGE_NEWLOG) {
LogItem logmessage = msg.getData().getParcelable("logmessage");
- myEntries.add(logmessage);
-
- for (DataSetObserver observer : observers) {
- observer.onChanged();
- }
- } else if (msg.what == MESSAGE_CLEARLOG) {
- initLogBuffer();
- for (DataSetObserver observer : observers) {
- observer.onInvalidated();
- }
+ if(addLogMessage(logmessage))
+ for (DataSetObserver observer : observers) {
+ observer.onChanged();
+ }
+ } else if (msg.what == MESSAGE_CLEARLOG) {
+ for (DataSetObserver observer : observers) {
+ observer.onInvalidated();
+ }
+ initLogBuffer();
} else if (msg.what == MESSAGE_NEWTS) {
for (DataSetObserver observer : observers) {
observer.onInvalidated();
}
- }
+ } else if (msg.what == MESSAGE_NEWLOGLEVEL) {
+ initCurrentMessages();
+
+ for (DataSetObserver observer: observers) {
+ observer.onChanged();
+ }
+
+ }
return true;
}
- void clearLog() {
+ private void initCurrentMessages() {
+ currentLevelEntries.clear();
+ for(LogItem li: allEntries) {
+ if (li.getVerbosityLevel() <= mLogLevel)
+ currentLevelEntries.add(li);
+ }
+ }
+
+ /**
+ *
+ * @param logmessage
+ * @return True if the current entries have changed
+ */
+ private boolean addLogMessage(LogItem logmessage) {
+ allEntries.add(logmessage);
+ if (logmessage.getVerbosityLevel() <= mLogLevel) {
+ currentLevelEntries.add(logmessage);
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ void clearLog() {
// Actually is probably called from GUI Thread as result of the user
// pressing a button. But better safe than sorry
VpnStatus.clearLog();
@@ -270,10 +348,15 @@ public class LogWindow extends ListActivity implements StateListener {
- public void nextTimeFormat() {
- mTimeFormat= (mTimeFormat+ 1) % 3;
+ public void setTimeFormat(int newTimeFormat) {
+ mTimeFormat= newTimeFormat;
mHandler.sendEmptyMessage(MESSAGE_NEWTS);
}
+
+ public void setLogLevel(int logLevel) {
+ mLogLevel = logLevel;
+ mHandler.sendEmptyMessage(MESSAGE_NEWLOGLEVEL);
+ }
}
@@ -322,7 +405,7 @@ public class LogWindow extends ListActivity implements StateListener {
Toast.makeText(this, R.string.log_no_last_vpn, Toast.LENGTH_LONG).show();
}
} else if(item.getItemId() == R.id.toggle_time) {
- ladapter.nextTimeFormat();
+ showHideOptionsPanel();
} else if(item.getItemId() == android.R.id.home) {
// This is called when the Home (Up) button is pressed
// in the Action Bar.
@@ -339,6 +422,36 @@ public class LogWindow extends ListActivity implements StateListener {
}
+ private void showHideOptionsPanel() {
+ boolean optionsVisible = (mOptionsLayout.getVisibility() != View.GONE);
+
+ ObjectAnimator anim;
+ if (optionsVisible) {
+ anim = ObjectAnimator.ofInt(mOptionsLayout,"alpha",0, mOptionsLayout.getHeight());
+ anim.addListener(collapseListener);
+
+ } else {
+ mOptionsLayout.setVisibility(View.VISIBLE);
+ anim = ObjectAnimator.ofInt(mOptionsLayout,"alpha", mOptionsLayout.getHeight(),0);
+ //anim = new TranslateAnimation(0.0f, 0.0f, mOptionsLayout.getHeight(), 0.0f);
+
+ }
+
+ //anim.setInterpolator(new AccelerateInterpolator(1.0f));
+ //anim.setDuration(300);
+ //mOptionsLayout.startAnimation(anim);
+ anim.start();
+
+ }
+
+ AnimatorListenerAdapter collapseListener = new AnimatorListenerAdapter() {
+ @Override
+ public void onAnimationEnd(Animator animator) {
+ mOptionsLayout.setVisibility(View.GONE);
+ }
+
+ };
+
@Override
public boolean onCreateOptionsMenu(Menu menu) {
@@ -408,7 +521,8 @@ public class LogWindow extends ListActivity implements StateListener {
super.onStop();
VpnStatus.removeStateListener(this);
unbindService(mConnection);
- getPreferences(0).edit().putInt(LOGTIMEFORMAT, ladapter.mTimeFormat).apply();
+ getPreferences(0).edit().putInt(LOGTIMEFORMAT, ladapter.mTimeFormat)
+ .putInt(VERBOSITYLEVEL, ladapter.mLogLevel).apply();
}
@@ -419,7 +533,10 @@ public class LogWindow extends ListActivity implements StateListener {
setContentView(R.layout.logwindow);
ListView lv = getListView();
- lv.setOnItemLongClickListener(new OnItemLongClickListener() {
+
+
+
+ lv.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view,
@@ -435,11 +552,33 @@ public class LogWindow extends ListActivity implements StateListener {
ladapter = new LogWindowListAdapter();
ladapter.mTimeFormat = getPreferences(0).getInt(LOGTIMEFORMAT, 0);
- lv.setAdapter(ladapter);
+ int loglevel = getPreferences(0).getInt(VERBOSITYLEVEL, 0);
+ ladapter.setLogLevel(loglevel);
+
+ lv.setAdapter(ladapter);
+
+ mTimeRadioGroup = (RadioGroup) findViewById(R.id.timeFormatRadioGroup);
+ mTimeRadioGroup.setOnCheckedChangeListener(this);
+
+ if(ladapter.mTimeFormat== LogWindowListAdapter.TIME_FORMAT_ISO) {
+ mTimeRadioGroup.check(R.id.radioISO);
+ } else if (ladapter.mTimeFormat == LogWindowListAdapter.TIME_FORMAT_NONE) {
+ mTimeRadioGroup.check(R.id.radioNone);
+ } else if (ladapter.mTimeFormat == LogWindowListAdapter.TIME_FORMAT_SHORT) {
+ mTimeRadioGroup.check(R.id.radioShort);
+ }
mSpeedView = (TextView) findViewById(R.id.speed);
getActionBar().setDisplayHomeAsUpEnabled(true);
+ mOptionsLayout = (LinearLayout) findViewById(R.id.logOptionsLayout);
+ mLogLevelSlider = (SeekBar) findViewById(R.id.LogLevelSlider);
+ mLogLevelSlider.setMax(VpnProfile.MAXLOGLEVEL-1);
+ mLogLevelSlider.setProgress(loglevel-1);
+
+ mLogLevelSlider.setOnSeekBarChangeListener(this);
+
+
}
diff --git a/src/de/blinkt/openvpn/VpnProfile.java b/src/de/blinkt/openvpn/VpnProfile.java
index cb186316..2368d3ce 100644
--- a/src/de/blinkt/openvpn/VpnProfile.java
+++ b/src/de/blinkt/openvpn/VpnProfile.java
@@ -51,6 +51,7 @@ public class VpnProfile implements Serializable {
public static final String MINIVPN = "miniopenvpn";
private static final long serialVersionUID = 7085688938959334563L;
private static final String OVPNCONFIGFILE = "android.conf";
+ static final int MAXLOGLEVEL = 4;
public static String DEFAULT_DNS1 = "8.8.8.8";
public static String DEFAULT_DNS2 = "8.8.4.4";
@@ -109,7 +110,7 @@ public class VpnProfile implements Serializable {
public boolean mUseFloat = false;
public boolean mUseCustomConfig = false;
public String mCustomConfigOptions = "";
- public String mVerb = "1";
+ public String mVerb = "1"; //ignored
public String mCipher = "";
public boolean mNobind = false;
public boolean mUseDefaultRoutev6 = true;
@@ -183,8 +184,7 @@ public class VpnProfile implements Serializable {
cfg += "management-hold\n\n";
cfg += getVersionEnvString(context);
- cfg += "# Log window is better readable this way\n";
- cfg += "suppress-timestamps\n";
+ cfg += "parsable-output\n";
boolean useTLSClient = (mAuthenticationType != TYPE_STATICKEYS);
@@ -197,7 +197,8 @@ public class VpnProfile implements Serializable {
cfg += "tls-client\n";
- cfg += "verb " + mVerb + "\n";
+ //cfg += "verb " + mVerb + "\n";
+ cfg += "verb " + MAXLOGLEVEL + "\n";
if (mConnectRetryMax == null) {
mConnectRetryMax = "5";
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;
diff --git a/vpndialogxposed/vpndialogxposed.iml b/vpndialogxposed/vpndialogxposed.iml
index b9f945d6..3de4565c 100644
--- a/vpndialogxposed/vpndialogxposed.iml
+++ b/vpndialogxposed/vpndialogxposed.iml
@@ -1,5 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" type="JAVA_MODULE" version="4">
+ <component name="FacetManager">
+ <facet type="android" name="Android">
+ <configuration />
+ </facet>
+ </component>
<component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/classes/debug" />
<exclude-output />
@@ -35,6 +40,7 @@
<sourceFolder url="file://$MODULE_DIR$/src/instrumentTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/instrumentTest/res" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/instrumentTest/resources" isTestSource="true" />
+ <sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/build/apk" />
<excludeFolder url="file://$MODULE_DIR$/build/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/bundles" />