summaryrefslogtreecommitdiff
path: root/src/se/leap/leapclient/EIP.java
diff options
context:
space:
mode:
authorSean Leonard <meanderingcode@aetherislands.net>2013-06-09 04:09:03 -0600
committerSean Leonard <meanderingcode@aetherislands.net>2013-06-20 18:40:45 -0600
commit33338d43e0e83329a7c46807e096b8148e19aff7 (patch)
tree62eb9c0de87a2ef9ff66f0b79909429019dd0aae /src/se/leap/leapclient/EIP.java
parent9a9823f7e5bf0e46e360ba327ac6514ecd4bb320 (diff)
Quite basic staring and stopping of VPN
Diffstat (limited to 'src/se/leap/leapclient/EIP.java')
-rw-r--r--src/se/leap/leapclient/EIP.java58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/se/leap/leapclient/EIP.java b/src/se/leap/leapclient/EIP.java
index f86dd083..21cbdfd5 100644
--- a/src/se/leap/leapclient/EIP.java
+++ b/src/se/leap/leapclient/EIP.java
@@ -3,6 +3,7 @@ package se.leap.leapclient;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.NoSuchElementException;
import java.util.Vector;
import org.json.JSONArray;
@@ -11,6 +12,8 @@ import org.json.JSONObject;
import se.leap.openvpn.ConfigParser;
import se.leap.openvpn.ConfigParser.ConfigParseError;
+import se.leap.openvpn.LaunchVPN;
+import se.leap.openvpn.OpenVpnManagementThread;
import se.leap.openvpn.ProfileManager;
import se.leap.openvpn.VpnProfile;
import android.app.IntentService;
@@ -24,6 +27,8 @@ import android.util.Log;
*/
public final class EIP extends IntentService {
+ public final static String ACTION_START_EIP = "se.leap.leapclient.START_EIP";
+ public final static String ACTION_STOP_EIP = "se.leap.leapclient.STOP_EIP";
public final static String ACTION_UPDATE_EIP_SERVICE = "se.leap.leapclient.UPDATE_EIP_SERVICE";
private static Context context;
@@ -31,6 +36,8 @@ public final class EIP extends IntentService {
// Represents our Provider's eip-service.json
private static JSONObject eipDefinition = null;
+ // Our active gateway
+ private static OVPNGateway activeGateway = null;
public EIP(){
super("LEAPEIP");
@@ -58,6 +65,26 @@ public final class EIP extends IntentService {
if ( action == ACTION_UPDATE_EIP_SERVICE )
this.updateEIPService();
+ else if ( action == ACTION_START_EIP )
+ this.startEIP();
+ else if ( action == ACTION_STOP_EIP )
+ this.stopEIP();
+ }
+
+ private void startEIP() {
+ if (activeGateway==null)
+ activeGateway = selectGateway();
+
+ Intent intent = new Intent(this,LaunchVPN.class);
+ intent.setAction(Intent.ACTION_MAIN);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ intent.putExtra(LaunchVPN.EXTRA_KEY, activeGateway.mVpnProfile.getUUID().toString() );
+ intent.putExtra(LaunchVPN.EXTRA_NAME, activeGateway.mVpnProfile.getName() );
+ startActivity(intent);
+ }
+
+ private void stopEIP() {
+ OpenVpnManagementThread.stopOpenVPN();
}
private void updateEIPService() {
@@ -71,6 +98,11 @@ public final class EIP extends IntentService {
updateGateways();
}
+ private OVPNGateway selectGateway() {
+ // TODO Logic, yay!
+ return new OVPNGateway("first");
+ }
+
private void updateGateways(){
JSONArray gatewaysDefined = null;
@@ -122,6 +154,32 @@ public final class EIP extends IntentService {
private HashMap<String,Vector<Vector<String>>> options = new HashMap<String, Vector<Vector<String>>>();
+ // Constructor to load a gateway by name
+ private OVPNGateway(String name){
+ ProfileManager vpl = ProfileManager.getInstance(context);
+
+ try {
+
+ // FIXME ha, this got funny..it will get smart once i'm further...
+ if ( name == "first" ) {
+ name = vpl.getProfiles().iterator().next().mName;
+ }
+
+ mVpnProfile = vpl.getProfileByName(name);
+
+ } catch (NoSuchElementException e) {
+
+ // The gateway we were looking for is not in ProfileList!
+ updateEIPService();
+
+ // TODO prompt user to fix config error
+
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
// Constructor to create a gateway by definition
protected OVPNGateway(JSONObject gw){
// TODO We're going to build 1 profile per gateway, but eventually several