summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2012-05-06 18:13:09 +0200
committerArne Schwabe <arne@rfc2549.org>2012-05-06 18:13:09 +0200
commit7c020349d214a942293047954ce45aab04cc6420 (patch)
tree8cd65adb7b37b6c968f39112ba03c3fe5e2f5c3a
parent581062c8b9629a5d52b555d13b573b12394fafda (diff)
Add ability to send the log (closes issue #9)
protect fd over unix socket
-rw-r--r--openvpn/src/openvpn/jniglue.c17
-rw-r--r--openvpn/src/openvpn/jniglue.h2
-rw-r--r--openvpn/src/openvpn/tun.c4
-rw-r--r--res/menu/logmenu.xml9
-rw-r--r--res/values/strings.xml6
-rw-r--r--src/de/blinkt/openvpn/LogWindow.java25
-rw-r--r--src/de/blinkt/openvpn/OpenVpnManagementThread.java12
-rw-r--r--src/de/blinkt/openvpn/VpnProfile.java19
8 files changed, 56 insertions, 38 deletions
diff --git a/openvpn/src/openvpn/jniglue.c b/openvpn/src/openvpn/jniglue.c
index b7167051..d49fe353 100644
--- a/openvpn/src/openvpn/jniglue.c
+++ b/openvpn/src/openvpn/jniglue.c
@@ -137,14 +137,6 @@ int android_open_tun () {
}
-unsigned char android_protect_socket(int sockfd) {
- jmethodID aMethodID = (*openvpnjenv)->GetStaticMethodID(openvpnjenv, openvpnclass, "protectSocket",
- "(I)Z");
- return (*openvpnjenv)->CallStaticBooleanMethod(openvpnjenv,openvpnclass,aMethodID,sockfd);
-
-}
-
-
void android_set_dns(const char* dns) {
jmethodID aMethodID = (*openvpnjenv)->GetStaticMethodID(openvpnjenv, openvpnclass, "addDns",
"(Ljava/lang/String;)V");
@@ -154,15 +146,6 @@ void android_set_dns(const char* dns) {
}
-void android_set_domain(const char* domain) {
- jmethodID aMethodID = (*openvpnjenv)->GetStaticMethodID(openvpnjenv, openvpnclass, "addDomain",
- "(Ljava/lang/String;)V");
- jstring jdomain = (*openvpnjenv)->NewStringUTF(openvpnjenv,domain);
- (*openvpnjenv)->CallStaticVoidMethod(openvpnjenv,openvpnclass,aMethodID,jdomain);
-
-
-}
-
void addRouteInformation(const char* dest, const char* mask, const char* gw) {
jstring jmask = (*openvpnjenv)->NewStringUTF(openvpnjenv, mask);
diff --git a/openvpn/src/openvpn/jniglue.h b/openvpn/src/openvpn/jniglue.h
index 7c723ef5..ea60a718 100644
--- a/openvpn/src/openvpn/jniglue.h
+++ b/openvpn/src/openvpn/jniglue.h
@@ -15,6 +15,4 @@ void addInterfaceInformation(int mtu,const char* ifconfig_local, const char* ifc
void android_openvpn_log(int level,const char* prefix,const char* prefix_sep,const char* m1);
void android_openvpn_exit(int status);
void android_set_dns(const char* dns);
-void android_set_domain(const char* domain);
-
#endif
diff --git a/openvpn/src/openvpn/tun.c b/openvpn/src/openvpn/tun.c
index 238d9fba..844d596e 100644
--- a/openvpn/src/openvpn/tun.c
+++ b/openvpn/src/openvpn/tun.c
@@ -1384,8 +1384,10 @@ open_tun (const char *dev, const char *dev_type, const char *dev_node, struct tu
android_set_dns(print_in_addr_t(tt->options.dns[i], 0, &gc));
}
+
+
if(tt->options.domain)
- android_set_domain(tt->options.domain);
+ management_query_user_pass(management, &up , "DNSDOMAIN", GET_USER_PASS_NEED_OK,(void*) 0);
if((tt->fd = android_open_tun())< 0){
msg (M_ERR, "ERROR: Cannot open TUN");
diff --git a/res/menu/logmenu.xml b/res/menu/logmenu.xml
index b8fd286b..1ab982d8 100644
--- a/res/menu/logmenu.xml
+++ b/res/menu/logmenu.xml
@@ -19,4 +19,11 @@
android:showAsAction="ifRoom|withText"
android:title="@string/show_connection_details"
android:titleCondensed="@string/info"/>
- </menu> \ No newline at end of file
+ <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"/>
+
+</menu> \ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 5b635ff9..b6411a8e 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -167,5 +167,9 @@
<string name="route_not_cidr">Cannot make sense of %1$s and %2$s as IP route with CIDR netmask, using /32 as netmask.</string>
<string name="route_not_netip">Corrected route %1$s/%2$s to %3$s/%2$s</string>
<string name="keychain_access">Cannot accces the Android Keychain Certificates. If you restored a backup of the app reselect the certificate</string>
- <string name="version_info">Version: %s</string>
+ <string name="version_info">Version: %s</string>
+ <string name="could_not_write_log">Could not write log contents to file</string>
+ <string name="send_logfile">Send Logfile</string>
+ <string name="send">Send</string>
+ <string name="ics_openvpn_log_file">ICS Openvpn log file</string>
</resources>
diff --git a/src/de/blinkt/openvpn/LogWindow.java b/src/de/blinkt/openvpn/LogWindow.java
index 65e8c66c..f3809e27 100644
--- a/src/de/blinkt/openvpn/LogWindow.java
+++ b/src/de/blinkt/openvpn/LogWindow.java
@@ -1,13 +1,19 @@
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.DialogInterface;
+import android.content.Intent;
import android.content.DialogInterface.OnClickListener;
import android.database.DataSetObserver;
+import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Handler.Callback;
@@ -20,6 +26,7 @@ import android.view.ViewGroup;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
+import android.widget.Toast;
import de.blinkt.openvpn.OpenVPN.LogListener;
public class LogWindow extends ListActivity {
@@ -56,6 +63,22 @@ public class LogWindow extends ListActivity {
}
}
+ String getLogStr() {
+ String str = "";
+ for(String entry:myEntries) {
+ str+=entry + '\n';
+ }
+ return str;
+ }
+
+ private void shareLog() {
+ Intent shareIntent = new Intent(Intent.ACTION_SEND);
+ shareIntent.putExtra(Intent.EXTRA_TEXT, getLogStr());
+ shareIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.ics_openvpn_log_file));
+ shareIntent.setType("text/plain");
+ startActivity(Intent.createChooser(shareIntent, "Send Logfile"));
+ }
+
@Override
public void registerDataSetObserver(DataSetObserver observer) {
observers.add(observer);
@@ -190,6 +213,8 @@ public class LogWindow extends ListActivity {
} else if(item.getItemId()==R.id.info) {
if(mBconfig==null)
OpenVPN.triggerLogBuilderConfig();
+ } else if(item.getItemId()==R.id.send) {
+ ladapter.shareLog();
}
return super.onOptionsItemSelected(item);
diff --git a/src/de/blinkt/openvpn/OpenVpnManagementThread.java b/src/de/blinkt/openvpn/OpenVpnManagementThread.java
index 2bae9e5e..4162d315 100644
--- a/src/de/blinkt/openvpn/OpenVpnManagementThread.java
+++ b/src/de/blinkt/openvpn/OpenVpnManagementThread.java
@@ -31,14 +31,6 @@ public class OpenVpnManagementThread implements Runnable {
}
- private String managmentEscape(String unescape) {
- String escapedString = unescape.replace("\\", "\\\\");
- escapedString = escapedString.replace("\"","\\\"");
- escapedString = escapedString.replace("\n","\\n");
- return '"' + escapedString + '"';
- }
-
-
public void managmentCommand(String cmd) {
try {
mSocket.getOutputStream().write(cmd.getBytes());
@@ -177,7 +169,7 @@ public class OpenVpnManagementThread implements Runnable {
pw = mProfile.getPasswordPrivateKey();
} else if (needed.equals("Auth")) {
String usercmd = String.format("username '%s' %s\n",
- needed, managmentEscape(mProfile.mUsername));
+ needed, VpnProfile.openVpnEscape(mProfile.mUsername));
managmentCommand(usercmd);
pw = mProfile.getPasswordAuth();
} else if (needed.equals("PROTECTFD")) {
@@ -187,7 +179,7 @@ public class OpenVpnManagementThread implements Runnable {
response="needok";
}
if(pw!=null) {
- String cmd = String.format("%s '%s' %s\n",response, needed, managmentEscape(pw));
+ String cmd = String.format("%s '%s' %s\n",response, needed, VpnProfile.openVpnEscape(pw));
managmentCommand(cmd);
}
diff --git a/src/de/blinkt/openvpn/VpnProfile.java b/src/de/blinkt/openvpn/VpnProfile.java
index 572c0c2d..75f0235d 100644
--- a/src/de/blinkt/openvpn/VpnProfile.java
+++ b/src/de/blinkt/openvpn/VpnProfile.java
@@ -148,6 +148,13 @@ public class VpnProfile implements Serializable{
}
};
+ public static String openVpnEscape(String unescape) {
+ String escapedString = unescape.replace("\\", "\\\\");
+ escapedString = escapedString.replace("\"","\\\"");
+ escapedString = escapedString.replace("\n","\\n");
+ return '"' + escapedString + '"';
+ }
+
static final String OVPNCONFIGPKCS12 = "android.pkcs12";
@@ -231,22 +238,22 @@ public class VpnProfile implements Serializable{
case VpnProfile.TYPE_CERTIFICATES:
// Ca
cfg+="ca ";
- cfg+=mCaFilename;
+ cfg+=openVpnEscape(mCaFilename);
cfg+="\n";
// Client Cert + Key
cfg+="key ";
- cfg+=mClientKeyFilename;
+ cfg+=openVpnEscape(mClientKeyFilename);
cfg+="\n";
cfg+="cert ";
- cfg+=mClientCertFilename;
+ cfg+=openVpnEscape(mClientCertFilename);
cfg+="\n";
break;
case VpnProfile.TYPE_USERPASS_PKCS12:
cfg+="auth-user-pass\n";
case VpnProfile.TYPE_PKCS12:
cfg+="pkcs12 ";
- cfg+=mPKCS12Filename;
+ cfg+=openVpnEscape(mPKCS12Filename);
cfg+="\n";
cfg+="management-query-passwords\n";
break;
@@ -262,7 +269,7 @@ public class VpnProfile implements Serializable{
case VpnProfile.TYPE_USERPASS:
cfg+="auth-user-pass\n";
cfg+="management-query-passwords\n";
- cfg+="ca " + mCaFilename +"\n";
+ cfg+="ca " +openVpnEscape(mCaFilename) +"\n";
}
if(mUseLzo) {
@@ -274,7 +281,7 @@ public class VpnProfile implements Serializable{
cfg+="secret ";
else
cfg+="tls-auth ";
- cfg+=mTLSAuthFilename;
+ cfg+=openVpnEscape(mTLSAuthFilename);
cfg+=" ";
cfg+= mTLSAuthDirection;
cfg+="\n";