diff options
author | Arne Schwabe <arne@rfc2549.org> | 2012-04-21 18:36:35 +0200 |
---|---|---|
committer | Arne Schwabe <arne@rfc2549.org> | 2012-04-21 18:36:35 +0200 |
commit | 488a41cc60636298581c2b44b4706b259fc98a36 (patch) | |
tree | ba247a01a310ca7b68343e655e0d7b550597de46 /src/de/blinkt/openvpn | |
parent | 89369d1e8651514ad295b11e6e1f5ee00a402168 (diff) |
wip
Diffstat (limited to 'src/de/blinkt/openvpn')
-rw-r--r-- | src/de/blinkt/openvpn/OpenVPNClient.java | 28 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/OpenVpnService.java | 23 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/VPNConfigPreference.java | 15 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/VPNPreferences.java | 138 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/VPNProfileList.java | 22 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/VpnProfile.java | 4 |
6 files changed, 222 insertions, 8 deletions
diff --git a/src/de/blinkt/openvpn/OpenVPNClient.java b/src/de/blinkt/openvpn/OpenVPNClient.java index 27073459..f1a32b63 100644 --- a/src/de/blinkt/openvpn/OpenVPNClient.java +++ b/src/de/blinkt/openvpn/OpenVPNClient.java @@ -52,6 +52,7 @@ import android.widget.AdapterView.OnItemSelectedListener; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; +import android.widget.EditText; import android.widget.Spinner; import android.widget.TextView; import android.widget.ToggleButton; @@ -103,6 +104,12 @@ public class OpenVPNClient extends Activity implements View.OnClickListener, OnI private Spinner mTLSDirection; + + private EditText mUserName; + + + private EditText mPassword; + @Override protected void onStop(){ super.onStop(); @@ -264,7 +271,8 @@ public class OpenVPNClient extends Activity implements View.OnClickListener, OnI mShowAdvanced = (CheckBox) findViewById(R.id.show_advanced); mTlsFile = (FileSelectLayout) findViewById(R.id.tlsAuth); - + mUserName = (EditText) findViewById(R.id.auth_username); + mPassword = (EditText) findViewById(R.id.auth_password); addFileSelectLayout(mCaCert); @@ -304,7 +312,7 @@ public class OpenVPNClient extends Activity implements View.OnClickListener, OnI // hide everything findViewById(R.id.pkcs12).setVisibility(View.GONE); findViewById(R.id.certs).setVisibility(View.GONE); - findViewById(R.id.commonsecret).setVisibility(View.GONE); + findViewById(R.id.statickeys).setVisibility(View.GONE); findViewById(R.id.keystore).setVisibility(View.GONE); switch(type) { @@ -314,12 +322,15 @@ public class OpenVPNClient extends Activity implements View.OnClickListener, OnI case VpnProfile.TYPE_PKCS12: findViewById(R.id.pkcs12).setVisibility(View.VISIBLE); break; - case VpnProfile.COMMON_SECRET: - findViewById(R.id.commonsecret).setVisibility(View.VISIBLE); + case VpnProfile.TYPE_STATICKEYS: + findViewById(R.id.statickeys).setVisibility(View.VISIBLE); break; case VpnProfile.TYPE_KEYSTORE: findViewById(R.id.keystore).setVisibility(View.VISIBLE); break; + + case VpnProfile.TYPE_USERPASS: + findViewById(R.id.userpassword).setVisibility(View.VISIBLE); } @@ -477,7 +488,8 @@ public class OpenVPNClient extends Activity implements View.OnClickListener, OnI onActivityResult(START_OPENVPN, RESULT_OK, null); } } else if (v == findViewById(R.id.about)) { - Intent intent = new Intent(getBaseContext(),AboutActivity.class); + //Intent intent = new Intent(getBaseContext(),AboutActivity.class); + Intent intent = new Intent(getBaseContext(),VPNPreferences.class); startActivity(intent); } else if (v == findViewById(R.id.select_keystore_button)) { showCertDialog(); @@ -500,7 +512,11 @@ public class OpenVPNClient extends Activity implements View.OnClickListener, OnI String pkcs12pw = savePKCS12(); intent.putExtra(prefix + ".PKCS12PASS", pkcs12pw); } - + + if(mType.getSelectedItemPosition() == VpnProfile.TYPE_USERPASS) { + intent.putExtra(prefix + ".USERNAME", mUserName.getText().toString()); + intent.putExtra(prefix + ".PASSWORD", mPassword.getText().toString()); + } startService(intent); Intent startLW = new Intent(getBaseContext(),LogWindow.class); diff --git a/src/de/blinkt/openvpn/OpenVpnService.java b/src/de/blinkt/openvpn/OpenVpnService.java index e8174bcb..4aad9318 100644 --- a/src/de/blinkt/openvpn/OpenVpnService.java +++ b/src/de/blinkt/openvpn/OpenVpnService.java @@ -117,13 +117,34 @@ public class OpenVpnService extends VpnService implements Handler.Callback, Runn } } + if(intent.hasExtra(prefix +".USERNAME")) + { + try { + String user = managmentEscape(intent.getStringExtra(prefix +".USERNAME")); + String pw = managmentEscape(intent.getStringExtra(prefix +".PASSWORD")); + Thread.sleep(3000); + + + managmentCommand("username 'Auth' " + user+ "\n" + + "password 'Auth' " + pw + "\n"); + } catch (InterruptedException e) { + } + } return START_STICKY; } - @Override + private String managmentEscape(String unescape) { + String escapedString = unescape.replace("\\", "\\\\"); + escapedString = escapedString.replace("\"","\\\""); + escapedString = escapedString.replace("\n","\\n"); + return '"' + escapedString + '"'; + } + + + @Override public void onDestroy() { if (mThread != null) { managmentCommand("signal SIGINT\n"); diff --git a/src/de/blinkt/openvpn/VPNConfigPreference.java b/src/de/blinkt/openvpn/VPNConfigPreference.java new file mode 100644 index 00000000..3afcfccb --- /dev/null +++ b/src/de/blinkt/openvpn/VPNConfigPreference.java @@ -0,0 +1,15 @@ +package de.blinkt.openvpn; + +import android.content.Context; +import android.preference.CheckBoxPreference; +import android.preference.Preference; +import android.util.AttributeSet; + +public class VPNConfigPreference extends Preference { + + public VPNConfigPreference(Context context, AttributeSet attrs) { + super(context, attrs); + setWidgetLayoutResource(R.layout.vpn_preference_layout); + } + +} diff --git a/src/de/blinkt/openvpn/VPNPreferences.java b/src/de/blinkt/openvpn/VPNPreferences.java new file mode 100644 index 00000000..69485efd --- /dev/null +++ b/src/de/blinkt/openvpn/VPNPreferences.java @@ -0,0 +1,138 @@ +package de.blinkt.openvpn; + +import java.util.List; + +import android.os.Bundle; +import android.preference.CheckBoxPreference; +import android.preference.EditTextPreference; +import android.preference.Preference; +import android.preference.Preference.OnPreferenceChangeListener; +import android.preference.PreferenceActivity; +import android.preference.PreferenceFragment; +import android.preference.PreferenceManager; +import android.preference.SwitchPreference; +import android.widget.Button; + + +public class VPNPreferences extends PreferenceActivity { + + public VPNPreferences() { + super(); + } + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + if (hasHeaders()) { + Button button = new Button(this); + button.setText("Some action"); + setListFooter(button); + } + } + @Override + public void onBuildHeaders(List<Header> target) { + loadHeadersFromResource(R.xml.vpn_headers, target); + } + + public static class IP_Settings extends PreferenceFragment implements OnPreferenceChangeListener { + private EditTextPreference mIPv4; + private EditTextPreference mIPv6; + private SwitchPreference mUsePull; + private CheckBoxPreference mOverrideDNS; + private Preference mSearchdomain; + private Preference mDNS1; + private Preference mDNS2; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // Make sure default values are applied. In a real app, you would + // want this in a shared function that is used to retrieve the + // SharedPreferences wherever they are needed. + PreferenceManager.setDefaultValues(getActivity(), + R.xml.vpn_ipsettings, false); + + // Load the preferences from an XML resource + addPreferencesFromResource(R.xml.vpn_ipsettings); + mIPv4 = (EditTextPreference) findPreference("ipv4_address"); + mIPv6 = (EditTextPreference) findPreference("ipv6_address"); + mUsePull = (SwitchPreference) findPreference("usePull"); + mOverrideDNS = (CheckBoxPreference) findPreference("overrideDNS"); + mSearchdomain =findPreference("searchdomain"); + mDNS1 = findPreference("dns1"); + mDNS2 = findPreference("dns2"); + + mIPv4.setOnPreferenceChangeListener(this); + mIPv6.setOnPreferenceChangeListener(this); + mDNS1.setOnPreferenceChangeListener(this); + mDNS2.setOnPreferenceChangeListener(this); + mUsePull.setOnPreferenceChangeListener(this); + mOverrideDNS.setOnPreferenceChangeListener(this); + setDNSState(); + + } + + @Override + public boolean onPreferenceChange(Preference preference, + Object newValue) { + if(preference==mIPv4 || preference == mIPv6 || + preference==mDNS1 || preference == mDNS2) + preference.setSummary((String)newValue); + + if(preference== mUsePull || preference == mOverrideDNS) + setDNSState(); + + return true; + } + + private void setDNSState() { + boolean enabled; + mOverrideDNS.setEnabled(mUsePull.isChecked()); + if(!mUsePull.isChecked()) + enabled =true; + else if (mOverrideDNS.isChecked()) + enabled = true; + else + enabled = false; + + mDNS1.setEnabled(enabled); + mDNS2.setEnabled(enabled); + mSearchdomain.setEnabled(enabled); + + } + + + } + public static class Authentication extends PreferenceFragment { + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // Make sure default values are applied. In a real app, you would + // want this in a shared function that is used to retrieve the + // SharedPreferences wherever they are needed. + PreferenceManager.setDefaultValues(getActivity(), + R.xml.vpn_authentification, false); + + // Load the preferences from an XML resource + addPreferencesFromResource(R.xml.vpn_authentification); + } + } + public static class Obscure extends PreferenceFragment { + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // Make sure default values are applied. In a real app, you would + // want this in a shared function that is used to retrieve the + // SharedPreferences wherever they are needed. + PreferenceManager.setDefaultValues(getActivity(), + R.xml.vpn_ipsettings, false); + + // Load the preferences from an XML resource + addPreferencesFromResource(R.xml.vpn_obscure); + } + } +} + diff --git a/src/de/blinkt/openvpn/VPNProfileList.java b/src/de/blinkt/openvpn/VPNProfileList.java new file mode 100644 index 00000000..fb7af280 --- /dev/null +++ b/src/de/blinkt/openvpn/VPNProfileList.java @@ -0,0 +1,22 @@ +package de.blinkt.openvpn; + +import android.os.Bundle; +import android.preference.PreferenceActivity; + + +import android.app.ProfileManager; + +public class VPNProfileList extends PreferenceActivity { + private ProfileManager mProfileManager; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + if (getPreferenceManager() != null) { + addPreferencesFromResource(R.xml.profiles_settings); + mProfileManager = (ProfileManager) getActivity().getSystemService(PROFILE_SERVICE); + + } + } +} diff --git a/src/de/blinkt/openvpn/VpnProfile.java b/src/de/blinkt/openvpn/VpnProfile.java index d01b1104..8d5fbe32 100644 --- a/src/de/blinkt/openvpn/VpnProfile.java +++ b/src/de/blinkt/openvpn/VpnProfile.java @@ -3,6 +3,8 @@ package de.blinkt.openvpn; public class VpnProfile { static final int TYPE_CERTIFICATES=0; static final int TYPE_PKCS12=1; - static final int COMMON_SECRET=3; static final int TYPE_KEYSTORE=2; + public static final int TYPE_USERPASS = 3; + public static final int TYPE_STATICKEYS = 4; + } |