diff options
author | Arne Schwabe <arne@rfc2549.org> | 2013-06-05 14:39:48 +0200 |
---|---|---|
committer | Arne Schwabe <arne@rfc2549.org> | 2013-06-05 14:39:48 +0200 |
commit | 1e57ad0ef473917864ea1f5983e2ca79932b30c6 (patch) | |
tree | 7694f21563e50f95a75704758ea8752e69fabdb0 | |
parent | 1c900c0ee6de4af5d5fb46ebdaf7ed1929804f5a (diff) |
Add support for asking username/password if none is set (closes issue #174)
-rw-r--r-- | icsopenvpn.iml | 71 | ||||
-rw-r--r-- | res/layout/userpass.xml | 39 | ||||
-rwxr-xr-x | res/values/strings.xml | 2 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/LaunchVPN.java | 57 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/VpnProfile.java | 7 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/core/DeviceStateReceiver.java | 1 |
6 files changed, 153 insertions, 24 deletions
diff --git a/icsopenvpn.iml b/icsopenvpn.iml new file mode 100644 index 00000000..922231a6 --- /dev/null +++ b/icsopenvpn.iml @@ -0,0 +1,71 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module external.linked.project.path="$MODULE_DIR$/build.gradle" external.system.id="GRADLE" type="JAVA_MODULE" version="4"> + <component name="FacetManager"> + <facet type="android" name="Android"> + <configuration> + <option name="SELECTED_BUILD_VARIANT" value="debug" /> + <option name="ASSEMBLE_TASK_NAME" value="assembleDebug" /> + <option name="ALLOW_USER_CONFIGURATION" value="false" /> + </configuration> + </facet> + <facet type="android-gradle" name="Android-Gradle"> + <configuration> + <option name="GRADLE_PROJECT_PATH" value=":" /> + <option name="PROJECT_ABSOLUTE_PATH" value="$MODULE_DIR$" /> + <option name="GRADLE_HOME_DIR_PATH" /> + </configuration> + </facet> + </component> + <component name="NewModuleRootManager" inherit-compiler-output="true"> + <exclude-output /> + <content url="file://$MODULE_DIR$"> + <sourceFolder url="file://$MODULE_DIR$/build/source/r/debug" isTestSource="false" /> + <sourceFolder url="file://$MODULE_DIR$/build/source/aidl/debug" isTestSource="false" /> + <sourceFolder url="file://$MODULE_DIR$/build/source/rs/debug" isTestSource="false" /> + <sourceFolder url="file://$MODULE_DIR$/build/source/buildConfig/debug" isTestSource="false" /> + <sourceFolder url="file://$MODULE_DIR$/build/res/rs/debug" isTestSource="false" /> + <sourceFolder url="file://$MODULE_DIR$/build/source/r/test" isTestSource="true" /> + <sourceFolder url="file://$MODULE_DIR$/build/source/aidl/test" isTestSource="true" /> + <sourceFolder url="file://$MODULE_DIR$/build/source/rs/test" isTestSource="true" /> + <sourceFolder url="file://$MODULE_DIR$/build/source/buildConfig/test" isTestSource="true" /> + <sourceFolder url="file://$MODULE_DIR$/build/res/rs/test" isTestSource="true" /> + <sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" /> + <sourceFolder url="file://$MODULE_DIR$/src/debug/assets" isTestSource="false" /> + <sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" /> + <sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" /> + <sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" /> + <sourceFolder url="file://$MODULE_DIR$/src/debug/res" isTestSource="false" /> + <sourceFolder url="file://$MODULE_DIR$/src/debug/resources" isTestSource="false" /> + <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> + <sourceFolder url="file://$MODULE_DIR$/assets" isTestSource="false" /> + <sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" /> + <sourceFolder url="file://$MODULE_DIR$/res" isTestSource="false" /> + <sourceFolder url="file://$MODULE_DIR$/tests/aidl" isTestSource="true" /> + <sourceFolder url="file://$MODULE_DIR$/tests/assets" isTestSource="true" /> + <sourceFolder url="file://$MODULE_DIR$/tests/java" isTestSource="true" /> + <sourceFolder url="file://$MODULE_DIR$/tests/jni" isTestSource="true" /> + <sourceFolder url="file://$MODULE_DIR$/tests/rs" isTestSource="true" /> + <sourceFolder url="file://$MODULE_DIR$/tests/res" isTestSource="true" /> + <sourceFolder url="file://$MODULE_DIR$/tests/resources" isTestSource="true" /> + <excludeFolder url="file://$MODULE_DIR$/.gradle" /> + <excludeFolder url="file://$MODULE_DIR$/.hg" /> + <excludeFolder url="file://$MODULE_DIR$/.hgcheck" /> + <excludeFolder url="file://$MODULE_DIR$/.idea" /> + <excludeFolder url="file://$MODULE_DIR$/.settings" /> + <excludeFolder url="file://$MODULE_DIR$/build/apk" /> + <excludeFolder url="file://$MODULE_DIR$/build/assets" /> + <excludeFolder url="file://$MODULE_DIR$/build/bundles" /> + <excludeFolder url="file://$MODULE_DIR$/build/classes" /> + <excludeFolder url="file://$MODULE_DIR$/build/dependency-cache" /> + <excludeFolder url="file://$MODULE_DIR$/build/exploded-bundles" /> + <excludeFolder url="file://$MODULE_DIR$/build/incremental" /> + <excludeFolder url="file://$MODULE_DIR$/build/libs" /> + <excludeFolder url="file://$MODULE_DIR$/build/manifests" /> + <excludeFolder url="file://$MODULE_DIR$/build/symbols" /> + <excludeFolder url="file://$MODULE_DIR$/build/tmp" /> + </content> + <orderEntry type="jdk" jdkName="Android 4.2.2" jdkType="Android SDK" /> + <orderEntry type="sourceFolder" forTests="false" /> + </component> +</module> + diff --git a/res/layout/userpass.xml b/res/layout/userpass.xml new file mode 100644 index 00000000..d13953c6 --- /dev/null +++ b/res/layout/userpass.xml @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="utf-8"?> + +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:orientation="vertical" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <EditText + android:id="@+id/username" + android:inputType="textEmailAddress" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginTop="16dp" + android:layout_marginLeft="4dp" + android:layout_marginRight="4dp" + android:layout_marginBottom="4dp" + android:hint="@string/auth_username" /> + <EditText + android:id="@+id/password" + android:inputType="textPassword" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginTop="4dp" + android:layout_marginLeft="4dp" + android:layout_marginRight="4dp" + android:layout_marginBottom="4dp" + android:hint="@string/password"/> + + <CheckBox + android:id="@+id/save_password" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginTop="4dp" + android:layout_marginLeft="4dp" + android:text="@string/save_password" + android:layout_marginRight="4dp" + android:layout_marginBottom="16dp"/> + +</LinearLayout>
\ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index b7589271..c77f079c 100755 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -155,7 +155,6 @@ <string name="converted_profile_i">imported profile %d</string> <string name="broken_images">Broken Images</string> <string name="broken_images_faq"><p>Official HTC images are known to have a strange routing problem causing traffic not to flow through the tunnel (See also <a href=\"http://code.google.com/p/ics-openvpn/issues/detail?id=18\">Issue 18</a> in the bug tracker.)</p><p>The official SONY images from Xperia arc S and Xperia Ray have been reported to be missing the VPNService completely from the image. Other Sony images may be affected as well. (See also <a href=\"http://code.google.com/p/ics-openvpn/issues/detail?id=29\">Issue 29</a> in the bug tracker.)</p><p>On custom build images the tun module might be missing or the rights of /dev/tun might be wrong. Some CM9 images need the fix ownership option under general settings.</p><p>Most important: If you have a broken image, report it to your vendor. The more people report the issue to the vendor the more likely you will get a fix.</p></string> - <string name="error_empty_username">The username must not be empty.</string> <string name="pkcs12_file_encryption_key">PKCS12 File Encryption Key</string> <string name="private_key_password">Private Key Password</string> <string name="password">Password</string> @@ -282,5 +281,6 @@ <string name="screenoff_title">Pause VPN connection after screen off</string> <string name="screenoff_pause">Pausing connection in screen off state: less than %1$s in %2$ss</string> <string name="screen_nopersistenttun">Warning: Persistent tun not enabled for this VPN. Traffic will use the normal Internet connection when the screen is off.</string> + <string name="save_password">Save Password</string> </resources>
\ No newline at end of file diff --git a/src/de/blinkt/openvpn/LaunchVPN.java b/src/de/blinkt/openvpn/LaunchVPN.java index 80075086..074bd235 100644 --- a/src/de/blinkt/openvpn/LaunchVPN.java +++ b/src/de/blinkt/openvpn/LaunchVPN.java @@ -17,12 +17,16 @@ import android.os.Bundle; import android.os.Parcelable; import android.preference.PreferenceManager; import android.text.InputType; +import android.text.Layout; +import android.text.TextUtils; import android.text.method.PasswordTransformationMethod; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; +import android.widget.CheckBox; import android.widget.EditText; +import android.widget.LinearLayout; import android.widget.ListView; import android.widget.TextView; import de.blinkt.openvpn.core.OpenVPN; @@ -207,6 +211,8 @@ public class LaunchVPN extends ListActivity implements OnItemClickListener { private void askForPW(final int type) { final EditText entry = new EditText(this); + final View userpwlayout = getLayoutInflater().inflate(R.layout.userpass, null); + entry.setSingleLine(); entry.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); entry.setTransformationMethod(new PasswordTransformationMethod()); @@ -214,24 +220,41 @@ public class LaunchVPN extends ListActivity implements OnItemClickListener { AlertDialog.Builder dialog = new AlertDialog.Builder(this); dialog.setTitle("Need " + getString(type)); dialog.setMessage("Enter the password for profile " + mSelectedProfile.mName); - dialog.setView(entry); - - dialog.setPositiveButton(android.R.string.ok, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - String pw = entry.getText().toString(); - if(type == R.string.password) { - mSelectedProfile.mTransientPW = pw; - } else { - mSelectedProfile.mTransientPCKS12PW = pw; - } - onActivityResult(START_VPN_PROFILE, Activity.RESULT_OK, null); - } - - }); - dialog.setNegativeButton(android.R.string.cancel, + if (type == R.string.password) { + ((EditText)userpwlayout.findViewById(R.id.username)).setText(mSelectedProfile.mUsername); + ((EditText)userpwlayout.findViewById(R.id.password)).setText(mSelectedProfile.mPassword); + dialog.setView(userpwlayout); + } else { + dialog.setView(entry); + } + + AlertDialog.Builder builder = dialog.setPositiveButton(android.R.string.ok, + new OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + + if (type == R.string.password) { + String pw = ((EditText) userpwlayout.findViewById(R.id.password)).getText().toString(); + String username = ((EditText) userpwlayout.findViewById(R.id.username)).getText().toString(); + mSelectedProfile.mUsername = username; + if (((CheckBox) userpwlayout.findViewById(R.id.save_password)).isChecked()) { + if (pw !=null && !("".equals(pw))) + mSelectedProfile.mPassword=pw; + } else { + mSelectedProfile.mPassword=null; + mSelectedProfile.mTransientPW = pw; + } + } else { + String pw = entry.getText().toString(); + mSelectedProfile.mTransientPCKS12PW = pw; + } + onActivityResult(START_VPN_PROFILE, Activity.RESULT_OK, null); + + } + + }); + dialog.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { diff --git a/src/de/blinkt/openvpn/VpnProfile.java b/src/de/blinkt/openvpn/VpnProfile.java index 03fcbc1b..dcca334c 100644 --- a/src/de/blinkt/openvpn/VpnProfile.java +++ b/src/de/blinkt/openvpn/VpnProfile.java @@ -659,9 +659,6 @@ public class VpnProfile implements Serializable{ if(mIPv4Address == null || cidrToIPAndNetmask(mIPv4Address) == null) return R.string.ipv4_format_error; } - if(isUserPWAuth() && !nonNull(mUsername)) { - return R.string.error_empty_username; - } if(!mUseDefaultRoute && getCustomRoutes()==null) return R.string.custom_route_format_error; @@ -757,10 +754,8 @@ public class VpnProfile implements Serializable{ } } - if(isUserPWAuth() && (mPassword.equals("") || mPassword == null)) { - if(mTransientPW==null) + if (isUserPWAuth() && !(nonNull(mUsername) && (nonNull(mPassword) || mTransientPW!=null))) { return R.string.password; - } return 0; } diff --git a/src/de/blinkt/openvpn/core/DeviceStateReceiver.java b/src/de/blinkt/openvpn/core/DeviceStateReceiver.java index 7d6e80db..b27ea00f 100644 --- a/src/de/blinkt/openvpn/core/DeviceStateReceiver.java +++ b/src/de/blinkt/openvpn/core/DeviceStateReceiver.java @@ -70,6 +70,7 @@ public class DeviceStateReceiver extends BroadcastReceiver implements ByteCountL screen = connectState.DISCONNECTED;
OpenVPN.logInfo(R.string.screenoff_pause,
OpenVpnService.humanReadableByteCount(TRAFFIC_LIMIT, false), TRAFFIC_WINDOW);
+
mManangement.pause();
}
Log.i("OpenVPN", String.format("State: %s %s total %d last %d time %d",network.name(), screen.name(),windowtraffic/1024,
|