summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2012-05-18 00:06:49 +0200
committerArne Schwabe <arne@rfc2549.org>2012-05-18 00:06:49 +0200
commit7ad69e645000fc66951a79104b0ce5ac3478b9f3 (patch)
treeabc5069ab0559e074436fcb58f5ac5bb6e7fc6ed
parent39e94d54313cf140929339a9f2613d79cbf734b0 (diff)
- Make Ipv6 support complete (minus tun-ipv6 warning)
- Implement byte counter support in the log window - Fix spelling of secret (closes issue #22) - Replace &quot;quot; with &quot;, no idea what went wrong there (closes issue #21)
-rw-r--r--openvpn/.gitignore1
-rw-r--r--openvpn/src/compat/#compat-basename.c#50
-rw-r--r--openvpn/src/compat/#compat-inet_ntop.c#76
-rw-r--r--openvpn/src/compat/#compat.h#68
-rw-r--r--openvpn/src/openvpn/console.c1
-rw-r--r--res/layout/logwindow.xml17
-rw-r--r--res/values/strings.xml10
-rw-r--r--res/xml/vpn_headers.xml14
-rw-r--r--res/xml/vpn_ipsettings.xml41
-rw-r--r--res/xml/vpn_routing.xml36
-rw-r--r--src/de/blinkt/openvpn/FileSelectionFragment.java3
-rw-r--r--src/de/blinkt/openvpn/LogWindow.java36
-rw-r--r--src/de/blinkt/openvpn/OpenVPN.java20
-rw-r--r--src/de/blinkt/openvpn/OpenVpnManagementThread.java40
-rw-r--r--src/de/blinkt/openvpn/Settings_IP.java19
-rw-r--r--src/de/blinkt/openvpn/Settings_Routing.java73
-rw-r--r--src/de/blinkt/openvpn/VpnProfile.java35
17 files changed, 279 insertions, 261 deletions
diff --git a/openvpn/.gitignore b/openvpn/.gitignore
index 60b9433c..324accf7 100644
--- a/openvpn/.gitignore
+++ b/openvpn/.gitignore
@@ -49,3 +49,4 @@ doc/openvpn.8.html
distro/rpm/openvpn.spec
tests/t_client.sh
src/openvpn/openvpn
+xcopenvpn
diff --git a/openvpn/src/compat/#compat-basename.c# b/openvpn/src/compat/#compat-basename.c#
deleted file mode 100644
index a0576919..00000000
--- a/openvpn/src/compat/#compat-basename.c#
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * OpenVPN -- An application to securely tunnel IP networks
- * over a single UDP port, with support for SSL/TLS-based
- * session authentication and key exchange,
- * packet encryption, packet authentication, and
- * packet compression.
- *
- * Copyright (C) 2011 - David Sommerseth <davids@redhat.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program (see the file COPYING included with this
- * distribution); if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#elif defined(_MSC_VER)
-#include "config-msvc.h"
-#endif
-
-#ifndef HAVE_BASENAME
-
-#include "compat.h"
-#include <string.h>
-
-/* Modified version based on glibc-2.14.1 by Roland McGrath <roland@gnu.org>
- * This version is extended to handle both / and \ in path names
- */
-char *
-basename (char *filename)
-{
- char *p = strrchr (filename, '/');
- if (!p) {
- /* If NULL, check for \ instead ... might be Windows a path */
- p = strrchr (filename, '\\');
- }
- return p ? p + 1 : (char *) filename;
-}
-
-#endif /* HAVE_BASENAME */
diff --git a/openvpn/src/compat/#compat-inet_ntop.c# b/openvpn/src/compat/#compat-inet_ntop.c#
deleted file mode 100644
index 0d521425..00000000
--- a/openvpn/src/compat/#compat-inet_ntop.c#
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * OpenVPN -- An application to securely tunnel IP networks
- * over a single UDP port, with support for SSL/TLS-based
- * session authentication and key exchange,
- * packet encryption, packet authentication, and
- * packet compression.
- *
- * Copyright (C) 2011 - David Sommerseth <davids@redhat.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program (see the file COPYING included with this
- * distribution); if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#elif defined(_MSC_VER)
-#include "config-msvc.h"
-#endif
-
-#ifndef HAVE_INET_NTOP
-
-#include "compat.h"
-
-#ifdef WIN32
-
-#include <windows.h>
-
-/*
- * inet_ntop() and inet_pton() wrap-implementations using
- * WSAAddressToString() and WSAStringToAddress() functions
- *
- * this is needed as long as we support running OpenVPN on WinXP
- */
-
-const char *
-inet_ntop(int af, const void *src, char *dst, socklen_t size)
-{
- struct sockaddr_storage ss;
- unsigned long s = size;
-
- ZeroMemory(&ss, sizeof(ss));
- ss.ss_family = af;
-
- switch(af) {
- case AF_INET:
- ((struct sockaddr_in *)&ss)->sin_addr = *(struct in_addr *)src;
- break;
- case AF_INET6:
- ((struct sockaddr_in6 *)&ss)->sin6_addr = *(struct in6_addr *)src;
- break;
- default:
- return NULL;
- }
- /* cannot direclty use &size because of strict aliasing rules */
- return (WSAAddressToString((struct sockaddr *)&ss, sizeof(ss), NULL, dst, &s) == 0)?
- dst : NULL;
-}
-
-#else
-
-#error no emulation for inet_ntop
-
-#endif
-
-#endif
diff --git a/openvpn/src/compat/#compat.h# b/openvpn/src/compat/#compat.h#
deleted file mode 100644
index 021573eb..00000000
--- a/openvpn/src/compat/#compat.h#
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * OpenVPN -- An application to securely tunnel IP networks
- * over a single UDP port, with support for SSL/TLS-based
- * session authentication and key exchange,
- * packet encryption, packet authentication, and
- * packet compression.
- *
- * Copyright (C) 2011 - David Sommerseth <davids@redhat.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program (see the file COPYING included with this
- * distribution); if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#ifndef COMPAT_H
-#define COMPAT_H
-
-#ifdef HAVE_WINSOCK2_H
-#include <winsock2.h>
-#endif
-
-#ifdef HAVE_WS2TCPIP_H
-#include <ws2tcpip.h>
-#endif
-
-#ifdef HAVE_SYS_TIME_H
-#include <sys/time.h>
-#endif
-
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-
-#ifndef HAVE_DIRNAME
-char * dirname(char *str);
-#endif /* HAVE_DIRNAME */
-
-#ifndef HAVE_BASENAME
-char * basename(char *str);
-#endif /* HAVE_BASENAME */
-
-#ifndef HAVE_GETTIMEOFDAY
-int gettimeofday (struct timeval *tv, void *tz);
-#endif
-
-#ifndef HAVE_DAEMON
-int daemon(int nochdir, int noclose);
-#endif
-
-#ifndef HAVE_INET_NTOP
-const char * inet_ntop(int af, const void *src, char *dst, socklen_t size);
-#endif
-
-#ifndef HAVE_INET_PTON
-int inet_pton(int af, const char *src, void *dst);
-#endif
-
-#endif /* COMPAT_H */
diff --git a/openvpn/src/openvpn/console.c b/openvpn/src/openvpn/console.c
index 2464e7e1..35372df7 100644
--- a/openvpn/src/openvpn/console.c
+++ b/openvpn/src/openvpn/console.c
@@ -232,6 +232,7 @@ get_console_input (const char *prompt, const bool echo, char *input, const int c
}
}
#else
+ msg (M_ERR, "Requiring input from console: %s", prompt);
msg (M_FATAL, "Sorry, but I can't get console input on this OS");
#endif
return ret;
diff --git a/res/layout/logwindow.xml b/res/layout/logwindow.xml
new file mode 100644
index 00000000..4051c92c
--- /dev/null
+++ b/res/layout/logwindow.xml
@@ -0,0 +1,17 @@
+<?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:id="@android:id/list"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent" />
+
+</LinearLayout> \ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 24332316..f0557545 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -125,7 +125,7 @@
<string name="check_remote_tlscert_title">Except TLS Server</string>
<string name="remote_tlscn_check_summary">Checks the Remote Server Certificate CN against a String</string>
<string name="remote_tlscn_check_title">Certificate Hostname Check</string>
- <string name="enter_tlscn_dialog">Enter the String against which the remote Server is checked. Openvpn will use prefix matching. &amp;quot;Server&amp;quot; matches &amp;quot;Server-1&amp;quot; and &amp;quot;Server-2&amp;quot;\\nLeave empty to check the CN against the server hostname.</string>
+ <string name="enter_tlscn_dialog">Enter the String against which the remote Server is checked. Openvpn will use prefix matching. &quot;Server&quot; matches &quot;Server-1&quot; and &quot;Server-2&quot;\\nLeave empty to check the CN against the server hostname.</string>
<string name="enter_tlscn_title">Remote Hostname(CN)</string>
<string name="tls_key_auth">Enables the TLS Key Authentication</string>
<string name="tls_auth_file">TLS Auth File</string>
@@ -145,7 +145,7 @@
<string name="ignore_routes_summary">Ignore routed pushed by the server.</string>
<string name="default_route_summary">Redirects all Traffic over the VPN</string>
<string name="use_default_title">Use default Route</string>
- <string name="custom_route_message">Enter custom routes. Only enter destination in CIDR format. &amp;quot;10.0.0.0/8 2002::/16&amp;quot; would direct the networks 10.0.0.0/8 and 2002::/16 over the VPN.</string>
+ <string name="custom_route_message">Enter custom routes. Only enter destination in CIDR format. &quot;10.0.0.0/8 2002::/16&quot; would direct the networks 10.0.0.0/8 and 2002::/16 over the VPN.</string>
<string name="custom_routes_title">Custom Routes</string>
<string name="log_verbosity_level">Log verbosity level</string>
<string name="float_summary">Allows authenticated packets from any IP</string>
@@ -216,5 +216,9 @@
<string name="faq_security">"As openvpn is security sensitive a few notes about security are sensible. All data on the sdcard is inherently unsecure. Every app can read it (for example this program requires no special sd card rights). The data of this application can only be read by the application itself. By using the import option for cacert/cert/key in the file dialog the data is stored in the vpn profile. The vpn profiles are only accessable by this application. (Do not forget to delte the copies on the sdcard afterwards). Even though accessible only by this application the data is stil unecrypted. By rooting the telephone or other exploits it may be possible to retrieve the data. Saved passwords are stored in plain text as well. For pkcs12 files it is highly recommended that you import them into the android keystore."</string>
<string name="import_vpn">Import</string>
<string name="broken_image_cert_title">Error showing certificate selection</string>
- <string name="broken_image_cert">Got an excption trying to show the Android 4.0+ certificate selction dialog. This should never happens as this a standard feature of Android 4.0+. Maybe your Android ROM support for certificate storage is broken</string>
+ <string name="broken_image_cert">Got an excption trying to show the Android 4.0+ certificate selction dialog. This should never happens as this a standard feature of Android 4.0+. Maybe your Android ROM support for certificate storage is broken</string>
+ <string name="ipv4">IPv4</string>
+ <string name="ipv6">IPv6</string>
+ <string name="use_default_titlev6">TODO</string>
+ <string name="speed_waiting">Waiting byte count message</string>
</resources>
diff --git a/res/xml/vpn_headers.xml b/res/xml/vpn_headers.xml
index c299d2a5..3762d445 100644
--- a/res/xml/vpn_headers.xml
+++ b/res/xml/vpn_headers.xml
@@ -2,27 +2,29 @@
<preference-headers xmlns:android="http://schemas.android.com/apk/res/android" >
<header
- android:tag="BasicSettings"
+ android:id="@+id/basicsettingsid"
android:fragment="de.blinkt.openvpn.Settings_Basic"
- android:title="Basic Settings"
- android:id="@+id/basicsettingsid"/>
+ android:tag="BasicSettings"
+ android:title="Basic Settings" />
<!-- android:icon="@drawable/ic_settings_applications" -->
<header
android:fragment="de.blinkt.openvpn.Settings_IP"
- android:summary="IP Address and Routing"
+ android:summary="IP Address"
android:title="IP Settings" />
<header
+ android:fragment="de.blinkt.openvpn.Settings_Routing"
+ android:title="Routing" />
+ <header
android:fragment="de.blinkt.openvpn.Settings_Authentication"
android:title="@string/settings_auth" />
<!-- android:icon="@drawable/ic_settings_display" -->
- <header
+ <header
android:fragment="de.blinkt.openvpn.Settings_Obscure"
android:summary="Obscure OpenVPN Settings. Normally not needed."
android:title="Obscure" >
</header>
-
<header
android:fragment="de.blinkt.openvpn.ShowConfigFragment"
android:summary="Shows the generated openvpn Configuration File"
diff --git a/res/xml/vpn_ipsettings.xml b/res/xml/vpn_ipsettings.xml
index fe55e8b4..e482f8f1 100644
--- a/res/xml/vpn_ipsettings.xml
+++ b/res/xml/vpn_ipsettings.xml
@@ -4,9 +4,9 @@
<SwitchPreference
android:disableDependentsState="true"
android:key="usePull"
- android:title="@string/use_pull"
+ android:summaryOff="@string/pull_off_summary"
android:summaryOn="@string/pull_on_summary"
- android:summaryOff="@string/pull_off_summary" />
+ android:title="@string/use_pull" />
<PreferenceCategory android:title="IP" >
<EditTextPreference
@@ -17,15 +17,15 @@
<EditTextPreference
android:dependency="usePull"
android:dialogMessage="@string/ipv6_dialog_tile"
+ android:enabled="false"
android:key="ipv6_address"
- android:title="@string/ipv6_address"
- android:enabled="false"/>
- <CheckBoxPreference
- android:title="@string/no_bind"
- android:summary="@string/nobind_summary"
- android:persistent="false"
- android:key="nobind" />
+ android:title="@string/ipv6_address" />
+ <CheckBoxPreference
+ android:key="nobind"
+ android:persistent="false"
+ android:summary="@string/nobind_summary"
+ android:title="@string/no_bind" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/dns" >
<CheckBoxPreference
@@ -37,32 +37,13 @@
android:key="searchdomain"
android:title="@string/searchdomain" />
<EditTextPreference
- android:key="dns1"
android:dialogMessage="@string/dns1_summary"
+ android:key="dns1"
android:title="@string/dns_server" />
<EditTextPreference
- android:key="dns2"
android:dialogMessage="@string/secondary_dns_message"
+ android:key="dns2"
android:title="@string/backup_dns" />
</PreferenceCategory>
- <PreferenceCategory android:title="Routing" >
- <CheckBoxPreference
- android:title="@string/ignored_pushed_routes"
- android:key="routenopull"
- android:summary="@string/ignore_routes_summary"
-
- />
- <CheckBoxPreference
- android:disableDependentsState="true"
- android:key="useDefaultRoute"
- android:summary="@string/default_route_summary"
- android:title="@string/use_default_title" />
-
- <EditTextPreference
- android:dependency="useDefaultRoute"
- android:dialogMessage="@string/custom_route_message"
- android:key="customRoutes"
- android:title="@string/custom_routes_title" />
- </PreferenceCategory>
</PreferenceScreen> \ No newline at end of file
diff --git a/res/xml/vpn_routing.xml b/res/xml/vpn_routing.xml
new file mode 100644
index 00000000..ce19a500
--- /dev/null
+++ b/res/xml/vpn_routing.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8"?>
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
+
+ <CheckBoxPreference
+ android:key="routenopull"
+ android:summary="@string/ignore_routes_summary"
+ android:title="@string/ignored_pushed_routes" />
+
+ <PreferenceCategory android:title="@string/ipv4" >
+ <CheckBoxPreference
+ android:disableDependentsState="true"
+ android:key="useDefaultRoute"
+ android:summary="@string/default_route_summary"
+ android:title="@string/use_default_title" />
+
+ <EditTextPreference
+ android:dependency="useDefaultRoute"
+ android:dialogMessage="@string/custom_route_message"
+ android:key="customRoutes"
+ android:title="@string/custom_routes_title" />
+ </PreferenceCategory>
+ <PreferenceCategory android:title="@string/ipv6" >
+ <CheckBoxPreference
+ android:disableDependentsState="true"
+ android:key="useDefaultRoutev6"
+ android:summary="@string/default_route_summary"
+ android:title="@string/use_default_title" />
+
+ <EditTextPreference
+ android:dependency="useDefaultRoutev6"
+ android:dialogMessage="@string/custom_route_message"
+ android:key="customRoutesv6"
+ android:title="@string/custom_routes_title" />
+ </PreferenceCategory>
+
+</PreferenceScreen> \ No newline at end of file
diff --git a/src/de/blinkt/openvpn/FileSelectionFragment.java b/src/de/blinkt/openvpn/FileSelectionFragment.java
index 41c7a1eb..c030bba0 100644
--- a/src/de/blinkt/openvpn/FileSelectionFragment.java
+++ b/src/de/blinkt/openvpn/FileSelectionFragment.java
@@ -29,9 +29,6 @@ public class FileSelectionFragment extends ListFragment {
private static final String ITEM_KEY = "key";
private static final String ITEM_IMAGE = "image";
private static final String ROOT = "/";
-
-
-
private List<String> path = null;
diff --git a/src/de/blinkt/openvpn/LogWindow.java b/src/de/blinkt/openvpn/LogWindow.java
index 3455e385..2e2612d3 100644
--- a/src/de/blinkt/openvpn/LogWindow.java
+++ b/src/de/blinkt/openvpn/LogWindow.java
@@ -28,8 +28,9 @@ import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import de.blinkt.openvpn.OpenVPN.LogListener;
+import de.blinkt.openvpn.OpenVPN.SpeedListener;
-public class LogWindow extends ListActivity {
+public class LogWindow extends ListActivity implements SpeedListener {
private String[] mBconfig=null;
@@ -190,6 +191,7 @@ public class LogWindow extends ListActivity {
private LogWindowListAdapter ladapter;
+ private TextView mSpeedView;
@Override
public boolean onOptionsItemSelected(MenuItem item) {
@@ -228,12 +230,23 @@ public class LogWindow extends ListActivity {
return true;
}
+ @Override
+ protected void onResume() {
+ super.onResume();
+ OpenVPN.addSpeedListener(this);
+ }
+ @Override
+ protected void onStop() {
+ super.onStop();
+ OpenVPN.removeSpeedListener(this);
+ }
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ setContentView(R.layout.logwindow);
ListView lv = getListView();
lv.setOnItemLongClickListener(new OnItemLongClickListener() {
@@ -249,12 +262,29 @@ public class LogWindow extends ListActivity {
return true;
}
});
- //lv.setTextFilterEnabled(true);
+
ladapter = new LogWindowListAdapter();
lv.setAdapter(ladapter);
+ mSpeedView = (TextView) findViewById(R.id.speed);
}
-
+ @Override
+ public void updateSpeed(final String logmessage) {
+ runOnUiThread(new Runnable() {
+
+ @Override
+ public void run() {
+ mSpeedView.setText(logmessage);
+ }
+ });
+
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ OpenVPN.removeLogListener(ladapter);
+ }
}
diff --git a/src/de/blinkt/openvpn/OpenVPN.java b/src/de/blinkt/openvpn/OpenVPN.java
index 24281d13..1d9eb6e0 100644
--- a/src/de/blinkt/openvpn/OpenVPN.java
+++ b/src/de/blinkt/openvpn/OpenVPN.java
@@ -10,12 +10,16 @@ public class OpenVPN {
public static LinkedList<String> logbuffer = new LinkedList<String>();
private static Vector<LogListener> logListener=new Vector<OpenVPN.LogListener>();
+ private static Vector<SpeedListener> speedListener=new Vector<OpenVPN.SpeedListener>();
private static String[] mBconfig;
public interface LogListener {
void newLog(String logmessage);
}
+ public interface SpeedListener {
+ void updateSpeed(String logmessage);
+ }
synchronized static void logMessage(int level,String prefix, String message)
{
@@ -41,6 +45,16 @@ public class OpenVPN {
logListener.remove(ll);
}
+
+ synchronized static void addSpeedListener(SpeedListener sl){
+ speedListener.add(sl);
+ }
+
+ synchronized static void removeSpeedListener(SpeedListener sl) {
+ speedListener.remove(sl);
+ }
+
+
synchronized public static String[] getlogbuffer() {
@@ -62,4 +76,10 @@ public class OpenVPN {
}
}
+
+ public static void updateSpeedString(String msg) {
+ for (SpeedListener sl : speedListener) {
+ sl.updateSpeed(msg);
+ }
+ }
}
diff --git a/src/de/blinkt/openvpn/OpenVpnManagementThread.java b/src/de/blinkt/openvpn/OpenVpnManagementThread.java
index 753cd98a..b568bd60 100644
--- a/src/de/blinkt/openvpn/OpenVpnManagementThread.java
+++ b/src/de/blinkt/openvpn/OpenVpnManagementThread.java
@@ -18,7 +18,10 @@ public class OpenVpnManagementThread implements Runnable {
private LocalSocket mSocket;
private VpnProfile mProfile;
private OpenVpnService mOpenVPNService;
- private LinkedList<FileDescriptor> mFDList=new LinkedList<FileDescriptor>();
+ private LinkedList<FileDescriptor> mFDList=new LinkedList<FileDescriptor>();
+ private int mBytecountinterval=2;
+ private long mLastIn=0;
+ private long mLastOut=0;
private static Vector<OpenVpnManagementThread> active=new Vector<OpenVpnManagementThread>();
@@ -157,9 +160,11 @@ public class OpenVpnManagementThread implements Runnable {
processPWCommand(argument);
} else if (cmd.equals("HOLD")) {
managmentCommand("hold release\n");
- //managmentCommand("log on\n");
+ managmentCommand("bytecount " + mBytecountinterval + "\n");
} else if (cmd.equals("NEED-OK")) {
processNeedCommand(argument);
+ } else if (cmd.equals("BYTECOUNT")){
+ processByteCount(argument);
} else if (cmd.equals("LOG")) {
String[] args = argument.split(",",3);
// 0 unix time stamp
@@ -178,6 +183,37 @@ public class OpenVpnManagementThread implements Runnable {
}
}
+ private void processByteCount(String argument) {
+ // >BYTECOUNT:{BYTES_IN},{BYTES_OUT}
+ int comma = argument.indexOf(',');
+ long in = Long.parseLong(argument.substring(0, comma));
+ long out = Long.parseLong(argument.substring(comma+1));
+
+ long diffin = in - mLastIn;
+ long diffout = out - mLastOut;
+
+ mLastIn=in;
+ mLastOut=out;
+
+ String netstat = String.format("In: %8s, %8s/s Out %8s, %8s/s ",
+ humanReadableByteCount(in, false),
+ humanReadableByteCount(diffin, false),
+ humanReadableByteCount(out, false),
+ humanReadableByteCount(diffout, false));
+ OpenVPN.updateSpeedString(netstat);
+
+
+ }
+
+ // From: http://stackoverflow.com/questions/3758606/how-to-convert-byte-size-into-human-readable-format-in-java
+ public static String humanReadableByteCount(long bytes, boolean si) {
+ int unit = si ? 1000 : 1024;
+ if (bytes < unit) return bytes + " B";
+ int exp = (int) (Math.log(bytes) / Math.log(unit));
+ String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp-1) + (si ? "" : "i");
+ return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
+ }
+
private void processNeedCommand(String argument) {
int p1 =argument.indexOf('\'');
int p2 = argument.indexOf('\'',p1+1);
diff --git a/src/de/blinkt/openvpn/Settings_IP.java b/src/de/blinkt/openvpn/Settings_IP.java
index dcdc10c0..f1e495c8 100644
--- a/src/de/blinkt/openvpn/Settings_IP.java
+++ b/src/de/blinkt/openvpn/Settings_IP.java
@@ -16,9 +16,6 @@ public class Settings_IP extends OpenVpnPreferencesFragment implements OnPrefere
private EditTextPreference mSearchdomain;
private EditTextPreference mDNS1;
private EditTextPreference mDNS2;
- private EditTextPreference mCustomRoutes;
- private CheckBoxPreference mUseDefaultRoute;
- private CheckBoxPreference mRouteNoPull;
private CheckBoxPreference mNobind;
@Override
@@ -41,9 +38,6 @@ public class Settings_IP extends OpenVpnPreferencesFragment implements OnPrefere
mSearchdomain =(EditTextPreference) findPreference("searchdomain");
mDNS1 = (EditTextPreference) findPreference("dns1");
mDNS2 = (EditTextPreference) findPreference("dns2");
- mCustomRoutes = (EditTextPreference) findPreference("customRoutes");
- mUseDefaultRoute = (CheckBoxPreference) findPreference("useDefaultRoute");
- mRouteNoPull = (CheckBoxPreference) findPreference("routenopull");
mNobind = (CheckBoxPreference) findPreference("nobind");
mIPv4.setOnPreferenceChangeListener(this);
@@ -53,7 +47,6 @@ public class Settings_IP extends OpenVpnPreferencesFragment implements OnPrefere
mUsePull.setOnPreferenceChangeListener(this);
mOverrideDNS.setOnPreferenceChangeListener(this);
mSearchdomain.setOnPreferenceChangeListener(this);
- mCustomRoutes.setOnPreferenceChangeListener(this);
loadSettings();
}
@@ -68,9 +61,6 @@ public class Settings_IP extends OpenVpnPreferencesFragment implements OnPrefere
mDNS2.setText(mProfile.mDNS2);
mOverrideDNS.setChecked(mProfile.mOverrideDNS);
mSearchdomain.setText(mProfile.mSearchDomain);
- mUseDefaultRoute.setChecked(mProfile.mUseDefaultRoute);
- mCustomRoutes.setText(mProfile.mCustomRoutes);
- mRouteNoPull.setChecked(mProfile.mRoutenopull);
mNobind.setChecked(mProfile.mNobind);
// Sets Summary
@@ -79,8 +69,7 @@ public class Settings_IP extends OpenVpnPreferencesFragment implements OnPrefere
onPreferenceChange(mDNS1, mDNS1.getText());
onPreferenceChange(mDNS2, mDNS2.getText());
onPreferenceChange(mSearchdomain, mSearchdomain.getText());
- onPreferenceChange(mCustomRoutes, mCustomRoutes.getText());
-
+
setDNSState();
}
@@ -94,9 +83,6 @@ public class Settings_IP extends OpenVpnPreferencesFragment implements OnPrefere
mProfile.mDNS2 = mDNS2.getText();
mProfile.mOverrideDNS = mOverrideDNS.isChecked();
mProfile.mSearchDomain = mSearchdomain.getText();
- mProfile.mUseDefaultRoute = mUseDefaultRoute.isChecked();
- mProfile.mCustomRoutes = mCustomRoutes.getText();
- mProfile.mRoutenopull = mRouteNoPull.isChecked();
mProfile.mNobind = mNobind.isChecked();
}
@@ -106,7 +92,7 @@ public class Settings_IP extends OpenVpnPreferencesFragment implements OnPrefere
Object newValue) {
if(preference==mIPv4 || preference == mIPv6
|| preference==mDNS1 || preference == mDNS2
- || preference == mSearchdomain || preference == mCustomRoutes
+ || preference == mSearchdomain
)
preference.setSummary((String)newValue);
@@ -125,7 +111,6 @@ public class Settings_IP extends OpenVpnPreferencesFragment implements OnPrefere
private void setDNSState() {
boolean enabled;
mOverrideDNS.setEnabled(mUsePull.isChecked());
- mRouteNoPull.setEnabled(mUsePull.isChecked());
if(!mUsePull.isChecked())
enabled =true;
else if (mOverrideDNS.isChecked())
diff --git a/src/de/blinkt/openvpn/Settings_Routing.java b/src/de/blinkt/openvpn/Settings_Routing.java
new file mode 100644
index 00000000..8305f4db
--- /dev/null
+++ b/src/de/blinkt/openvpn/Settings_Routing.java
@@ -0,0 +1,73 @@
+package de.blinkt.openvpn;
+import android.os.Bundle;
+import android.preference.CheckBoxPreference;
+import android.preference.EditTextPreference;
+import android.preference.Preference;
+import android.preference.Preference.OnPreferenceChangeListener;
+import android.preference.PreferenceManager;
+
+
+public class Settings_Routing extends OpenVpnPreferencesFragment implements OnPreferenceChangeListener {
+ private EditTextPreference mCustomRoutes;
+ private CheckBoxPreference mUseDefaultRoute;
+ private EditTextPreference mCustomRoutesv6;
+ private CheckBoxPreference mUseDefaultRoutev6;
+ private CheckBoxPreference mRouteNoPull;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ // Load the preferences from an XML resource
+ addPreferencesFromResource(R.xml.vpn_routing);
+ mCustomRoutes = (EditTextPreference) findPreference("customRoutes");
+ mUseDefaultRoute = (CheckBoxPreference) findPreference("useDefaultRoute");
+ mCustomRoutesv6 = (EditTextPreference) findPreference("customRoutesv6");
+ mUseDefaultRoutev6 = (CheckBoxPreference) findPreference("useDefaultRoutev6");
+ mRouteNoPull = (CheckBoxPreference) findPreference("routenopull");
+
+ mCustomRoutes.setOnPreferenceChangeListener(this);
+ mCustomRoutesv6.setOnPreferenceChangeListener(this);
+
+ loadSettings();
+ }
+
+ @Override
+ protected void loadSettings() {
+
+ mUseDefaultRoute.setChecked(mProfile.mUseDefaultRoute);
+ mUseDefaultRoutev6.setChecked(mProfile.mUseDefaultRoutev6);
+
+ mCustomRoutes.setText(mProfile.mCustomRoutes);
+ mCustomRoutesv6.setText(mProfile.mCustomRoutesv6);
+
+ mRouteNoPull.setChecked(mProfile.mRoutenopull);
+
+ // Sets Summary
+ onPreferenceChange(mCustomRoutes, mCustomRoutes.getText());
+ onPreferenceChange(mCustomRoutesv6, mCustomRoutesv6.getText());
+ mRouteNoPull.setEnabled(mProfile.mUsePull);
+ }
+
+
+ @Override
+ protected void saveSettings() {
+ mProfile.mUseDefaultRoute = mUseDefaultRoute.isChecked();
+ mProfile.mUseDefaultRoutev6 = mUseDefaultRoutev6.isChecked();
+ mProfile.mCustomRoutes = mCustomRoutes.getText();
+ mProfile.mCustomRoutesv6 = mCustomRoutesv6.getText();
+ mProfile.mRoutenopull = mRouteNoPull.isChecked();
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference,
+ Object newValue) {
+ if( preference == mCustomRoutes || preference == mCustomRoutesv6 )
+ preference.setSummary((String)newValue);
+
+ saveSettings();
+ return true;
+ }
+
+
+} \ No newline at end of file
diff --git a/src/de/blinkt/openvpn/VpnProfile.java b/src/de/blinkt/openvpn/VpnProfile.java
index a0f6db76..5cdff43d 100644
--- a/src/de/blinkt/openvpn/VpnProfile.java
+++ b/src/de/blinkt/openvpn/VpnProfile.java
@@ -91,6 +91,8 @@ public class VpnProfile implements Serializable{
public String mVerb="1";
public String mCipher="";
public boolean mNobind=false;
+ public boolean mUseDefaultRoutev6=true;
+ public String mCustomRoutesv6="";
public void clearDefaults() {
@@ -231,7 +233,7 @@ public class VpnProfile implements Serializable{
if(mUseTLSAuth) {
if(mAuthenticationType==TYPE_STATICKEYS)
- cfg+=insertFileData("scecret",mTLSAuthFilename);
+ cfg+=insertFileData("secret",mTLSAuthFilename);
else
cfg+=insertFileData("tls-auth",mTLSAuthFilename);
cfg+=" ";
@@ -243,9 +245,12 @@ public class VpnProfile implements Serializable{
cfg+="\n";
}
- // Basic Settings
if(!mUsePull ) {
- cfg +="ifconfig " + cidrToIPAndNetmask(mIPv4Address) + "\n";
+ if(nonNull(mIPv4Address))
+ cfg +="ifconfig " + cidrToIPAndNetmask(mIPv4Address) + "\n";
+
+ if(nonNull(mIPv6Address))
+ cfg +="ifconfig-ipv6 " + mIPv6Address + "\n";
}
if(mUsePull && mRoutenopull)
@@ -258,6 +263,13 @@ public class VpnProfile implements Serializable{
cfg += "route " + route + "\n";
}
+
+ if(mUseDefaultRoutev6)
+ cfg += "route-ipv6 ::/0\n";
+ else
+ for(String route:getCustomRoutesv6()) {
+ cfg += "route-ipv6 " + route + "\n";
+ }
if(mOverrideDNS || !mUsePull) {
if(!mDNS1.equals("") && mDNS1!=null)
@@ -346,6 +358,23 @@ public class VpnProfile implements Serializable{
return cidrRoutes;
}
+ private Collection<String> getCustomRoutesv6() {
+ Vector<String> cidrRoutes=new Vector<String>();
+ if(mCustomRoutesv6==null) {
+ // No routes set, return empty vector
+ return cidrRoutes;
+ }
+ for(String route:mCustomRoutesv6.split("[\n \t]")) {
+ if(!route.equals("")) {
+ cidrRoutes.add(route);
+ }
+ }
+
+ return cidrRoutes;
+ }
+
+
+
private String cidrToIPAndNetmask(String route) {
String[] parts = route.split("/");