From d640e083d48b78456e8e0f76e31134a2864cf228 Mon Sep 17 00:00:00 2001 From: albert-lopez Date: Thu, 9 Jun 2016 15:58:53 +0200 Subject: [PATCH] Remove android/src --- .../openoverlayrouter/noroot/ConfigTools.java | 240 ------ .../noroot/MultiSelectionSpinner.java | 208 ------ .../noroot/Notifications.java | 61 -- .../src/org/openoverlayrouter/noroot/OOR.java | 350 --------- .../noroot/OORVPNService.java | 257 ------- .../org/openoverlayrouter/noroot/OOR_JNI.java | 65 -- .../noroot/confActivity.java | 71 -- .../openoverlayrouter/noroot/logActivity.java | 143 ---- .../noroot/updateConfActivity.java | 699 ------------------ 9 files changed, 2094 deletions(-) delete mode 100644 android/src/org/openoverlayrouter/noroot/ConfigTools.java delete mode 100644 android/src/org/openoverlayrouter/noroot/MultiSelectionSpinner.java delete mode 100644 android/src/org/openoverlayrouter/noroot/Notifications.java delete mode 100644 android/src/org/openoverlayrouter/noroot/OOR.java delete mode 100644 android/src/org/openoverlayrouter/noroot/OORVPNService.java delete mode 100644 android/src/org/openoverlayrouter/noroot/OOR_JNI.java delete mode 100644 android/src/org/openoverlayrouter/noroot/confActivity.java delete mode 100644 android/src/org/openoverlayrouter/noroot/logActivity.java delete mode 100644 android/src/org/openoverlayrouter/noroot/updateConfActivity.java diff --git a/android/src/org/openoverlayrouter/noroot/ConfigTools.java b/android/src/org/openoverlayrouter/noroot/ConfigTools.java deleted file mode 100644 index eb96e00..0000000 --- a/android/src/org/openoverlayrouter/noroot/ConfigTools.java +++ /dev/null @@ -1,240 +0,0 @@ -/* - * - * Copyright (C) 2011, 2015 Cisco Systems, Inc. - * Copyright (C) 2015 CBA research group, Technical University of Catalonia. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - - -package org.openoverlayrouter.noroot; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; -import java.net.NetworkInterface; -import java.net.SocketException; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import android.os.Environment; -import android.util.Log; - -public class ConfigTools { - - public static final String confFile = "oor.conf"; - - public static List getEIDs() throws FileNotFoundException - { - File sdcardDir = Environment.getExternalStorageDirectory(); - File file = new File(sdcardDir, confFile); - - if (!file.exists()){ - Log.w("OOR", "Configuration file not exist"); - throw new FileNotFoundException(); - } - - List eids = new ArrayList(); - - try { - - BufferedReader br = new BufferedReader(new FileReader(file)); - String line = br.readLine(); - String sub_line = null; - - while ( line != null ) { - if (line.startsWith("#")){ - line = br.readLine(); - continue; - } - line = line.toLowerCase(); - line = line.replaceAll("\\s", ""); - - if (line.contains("database-mapping")){ - do{ - sub_line = br.readLine(); - if (sub_line.startsWith("#")){ - sub_line = br.readLine(); - continue; - } - sub_line = sub_line.toLowerCase(); - sub_line = sub_line.replaceAll("\\s", ""); - - if (sub_line.contains("eid-prefix")){ - String[] tmp = sub_line.split("="); - if (tmp.length < 2) - continue; - String[] tmp_1 = tmp[1].split("/"); - if (tmp_1.length < 2) - continue; - if (validate_IP_Address(tmp_1[0])){ - eids.add(tmp_1[0]); - } - } - }while (!sub_line.contains("}")); - } - line = br.readLine(); - } - } - catch (IOException e) { - ; - } - - return eids; - } - - public static List getDNS() throws FileNotFoundException - { - File sdcardDir = Environment.getExternalStorageDirectory(); - File file = new File(sdcardDir, confFile); - boolean overrideDNS = false; - - - if (!file.exists()){ - Log.w("OOR", "Configuration file not exist"); - throw new FileNotFoundException(); - } - - List dns_servers = new ArrayList(); - - try { - - BufferedReader br = new BufferedReader(new FileReader(file)); - String line = br.readLine(); - - while ( line != null ) { - if (line.startsWith("#")){ - line = br.readLine(); - continue; - } - line = line.toLowerCase(); - line = line.replaceAll("\\s", ""); - - - if (line.contains("override-dns=")) { - String[] tmp = line.split("="); - if(tmp.length > 1 ){ - String overrideDNS_aux = tmp[1]; - if (overrideDNS_aux.equals("on") || overrideDNS_aux.equals("true")){ - overrideDNS = true; - }else{ - overrideDNS = false; - } - } - }else if (line.contains("override-dns-primary=")) { - String[] tmp = line.split("="); - if (tmp.length > 1){ - if (validate_IP_Address(tmp[1])){ - dns_servers.add(tmp[1]); - } - } - } else if (line.contains("override-dns-secondary=")) { - String[] tmp = line.split("="); - if (tmp.length > 1){ - if (validate_IP_Address(tmp[1])){ - dns_servers.add(tmp[1]); - } - } - } - - line = br.readLine(); - } - } - catch (IOException e) { - ; - } - if (overrideDNS){ - return (dns_servers); - }else{ - return (null); - } - } - - - - - public static boolean validate_IP_Address(String ip) - { - String ipv4Pattern = "(([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.){3}([01]?\\d\\d?|2[0-4]\\d|25[0-5])"; - String ipv6Pattern = "([0-9a-fA-F]{1,4}:){7}([0-9a-fA-F]){1,4}"; - String ipv6Patter_com = "\\A((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)::((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)\\z"; - - - Pattern VALID_IPV4_PATTERN = null; - Pattern VALID_IPV6_PATTERN = null; - Pattern VALID_IPV6_COMP_PATTERN = null; - try { - VALID_IPV4_PATTERN = Pattern.compile(ipv4Pattern, Pattern.CASE_INSENSITIVE); - VALID_IPV6_PATTERN = Pattern.compile(ipv6Pattern, Pattern.CASE_INSENSITIVE); - VALID_IPV6_COMP_PATTERN = Pattern.compile(ipv6Patter_com, Pattern.CASE_INSENSITIVE); - } catch (Exception e) { - //logger.severe("Unable to compile pattern", e); - } - - Matcher m1 = VALID_IPV4_PATTERN.matcher(ip); - if (m1.matches()) { - return true; - } - Matcher m2 = VALID_IPV6_PATTERN.matcher(ip); - if (m2.matches()){ - return true; - } - Matcher m3 = VALID_IPV6_COMP_PATTERN.matcher(ip); - return m3.matches(); - } - - /* - * Convination of two technics to get the list of interfaces. - * getNetworkInterfaces: in some devices it doesn't return down interfaces - * /proc/net/xt_qtaguid/iface_stat_all is not used in all versions of android - */ - public static List get_ifaces_list() - { - - List iface_list = new ArrayList(); - try { - Enumeration en = NetworkInterface.getNetworkInterfaces(); - while (en.hasMoreElements()) - { - NetworkInterface intf = en.nextElement(); - iface_list.add(intf.getName()); - } - - try{ - FileReader reader = new FileReader("/proc/net/xt_qtaguid/iface_stat_all"); - BufferedReader in = new BufferedReader(reader); - String line = null; - String device; - while( (line = in.readLine()) != null) { - device = line.substring(0,line.indexOf(" ")); - if (!iface_list.contains(device)){ - iface_list.add(device); - } - } - reader.close(); - }catch (Exception e){e.printStackTrace();}; - } catch (SocketException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - return (iface_list); - } - -} diff --git a/android/src/org/openoverlayrouter/noroot/MultiSelectionSpinner.java b/android/src/org/openoverlayrouter/noroot/MultiSelectionSpinner.java deleted file mode 100644 index 4f356c1..0000000 --- a/android/src/org/openoverlayrouter/noroot/MultiSelectionSpinner.java +++ /dev/null @@ -1,208 +0,0 @@ -/* - * - * Copyright (C) 2011, 2015 Cisco Systems, Inc. - * Copyright (C) 2015 CBA research group, Technical University of Catalonia. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - - -package org.openoverlayrouter.noroot; - -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; - -import android.app.AlertDialog; -import android.content.Context; -import android.content.DialogInterface; -import android.content.DialogInterface.OnMultiChoiceClickListener; -import android.util.AttributeSet; -import android.widget.ArrayAdapter; -import android.widget.Spinner; -import android.widget.SpinnerAdapter; - -public class MultiSelectionSpinner extends Spinner implements - OnMultiChoiceClickListener { - String[] _items = null; - boolean[] mSelection = null; - - ArrayAdapter simple_adapter; - - public MultiSelectionSpinner(Context context) { - super(context); - - simple_adapter = new ArrayAdapter(context, - android.R.layout.simple_spinner_item); - super.setAdapter(simple_adapter); - } - - public MultiSelectionSpinner(Context context, AttributeSet attrs) { - super(context, attrs); - - simple_adapter = new ArrayAdapter(context, - android.R.layout.simple_spinner_item); - super.setAdapter(simple_adapter); - } - - public void onClick(DialogInterface dialog, int which, boolean isChecked) { - if (mSelection != null && which < mSelection.length) { - mSelection[which] = isChecked; - - simple_adapter.clear(); - simple_adapter.add(buildSelectedItemString()); - } else { - throw new IllegalArgumentException( - "Argument 'which' is out of bounds."); - } - } - - @Override - public boolean performClick() { - AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); - builder.setMultiChoiceItems(_items, mSelection, this); - builder.show(); - return true; - } - - @Override - public void setAdapter(SpinnerAdapter adapter) { - throw new RuntimeException( - "setAdapter is not supported by MultiSelectSpinner."); - } - - public void setItems(String[] items) { - _items = items; - mSelection = new boolean[_items.length]; - simple_adapter.clear(); - simple_adapter.add(_items[0]); - Arrays.fill(mSelection, false); - } - - public void setItems(List items) { - _items = items.toArray(new String[items.size()]); - mSelection = new boolean[_items.length]; - simple_adapter.clear(); - simple_adapter.add(_items[0]); - Arrays.fill(mSelection, false); - } - - public void setSelection(String[] selection) { - for (String cell : selection) { - for (int j = 0; j < _items.length; ++j) { - if (_items[j].equals(cell)) { - mSelection[j] = true; - } - } - } - } - - public void setSelection(List selection) { - for (int i = 0; i < mSelection.length; i++) { - mSelection[i] = false; - } - for (String sel : selection) { - for (int j = 0; j < _items.length; ++j) { - if (_items[j].equals(sel)) { - mSelection[j] = true; - } - } - } - simple_adapter.clear(); - simple_adapter.add(buildSelectedItemString()); - } - - public void setSelection(int index) { - for (int i = 0; i < mSelection.length; i++) { - mSelection[i] = false; - } - if (index >= 0 && index < mSelection.length) { - mSelection[index] = true; - } else { - throw new IllegalArgumentException("Index " + index - + " is out of bounds."); - } - simple_adapter.clear(); - simple_adapter.add(buildSelectedItemString()); - } - - public void setSelection(int[] selectedIndicies) { - for (int i = 0; i < mSelection.length; i++) { - mSelection[i] = false; - } - for (int index : selectedIndicies) { - if (index >= 0 && index < mSelection.length) { - mSelection[index] = true; - } else { - throw new IllegalArgumentException("Index " + index - + " is out of bounds."); - } - } - simple_adapter.clear(); - simple_adapter.add(buildSelectedItemString()); - } - - public List getSelectedStrings() { - List selection = new LinkedList(); - for (int i = 0; i < _items.length; ++i) { - if (mSelection[i]) { - selection.add(_items[i]); - } - } - return selection; - } - - public List getSelectedIndicies() { - List selection = new LinkedList(); - for (int i = 0; i < _items.length; ++i) { - if (mSelection[i]) { - selection.add(i); - } - } - return selection; - } - - private String buildSelectedItemString() { - StringBuilder sb = new StringBuilder(); - boolean foundOne = false; - - for (int i = 0; i < _items.length; ++i) { - if (mSelection[i]) { - if (foundOne) { - sb.append(", "); - } - foundOne = true; - - sb.append(_items[i]); - } - } - return sb.toString(); - } - - public String getSelectedItemsAsString() { - StringBuilder sb = new StringBuilder(); - boolean foundOne = false; - - for (int i = 0; i < _items.length; ++i) { - if (mSelection[i]) { - if (foundOne) { - sb.append(", "); - } - foundOne = true; - sb.append(_items[i]); - } - } - return sb.toString(); - } -} \ No newline at end of file diff --git a/android/src/org/openoverlayrouter/noroot/Notifications.java b/android/src/org/openoverlayrouter/noroot/Notifications.java deleted file mode 100644 index 7944a45..0000000 --- a/android/src/org/openoverlayrouter/noroot/Notifications.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * - * Copyright (C) 2011, 2015 Cisco Systems, Inc. - * Copyright (C) 2015 CBA research group, Technical University of Catalonia. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.openoverlayrouter.noroot; - -import android.app.Notification; -import android.app.NotificationManager; -import android.app.PendingIntent; -import android.content.Context; -import android.content.Intent; -import android.media.RingtoneManager; -import android.net.Uri; - -public class Notifications{ - - private Context context; - - public Notifications(Context context){ - this.context = context; - } - - public void notify_msg(String log_msg) - { - NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); - // Intent to be call when pushing the notification. - Intent startIntent = new Intent(context, OOR.class); - PendingIntent contentIntent = PendingIntent.getActivity(context,0,startIntent,PendingIntent.FLAG_CANCEL_CURRENT); - - // Allways overwriting same notification. - int notification_id = 1; - - Notification.Builder notify_b = new Notification.Builder(context); - notify_b.setContentTitle("OOR Alert"); - notify_b.setContentText(log_msg); - notify_b.setSmallIcon(R.drawable.oor_logo_small); - notify_b.setWhen(System.currentTimeMillis()); - notify_b.setContentIntent(contentIntent); - notify_b.setAutoCancel(true); - Uri uri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); - notify_b.setSound(uri); - - Notification notify_msg = notify_b.getNotification(); - notificationManager.notify(notification_id,notify_msg); - } -} diff --git a/android/src/org/openoverlayrouter/noroot/OOR.java b/android/src/org/openoverlayrouter/noroot/OOR.java deleted file mode 100644 index 6533c1d..0000000 --- a/android/src/org/openoverlayrouter/noroot/OOR.java +++ /dev/null @@ -1,350 +0,0 @@ -/* - * - * Copyright (C) 2011, 2015 Cisco Systems, Inc. - * Copyright (C) 2015 CBA research group, Technical University of Catalonia. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.openoverlayrouter.noroot; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.Timer; -import java.util.TimerTask; - -import org.openoverlayrouter.noroot.R; - -import android.annotation.TargetApi; -import android.app.Activity; -import android.app.AlertDialog; -import android.location.Location; -import android.net.VpnService; -import android.os.Build; -import android.os.Bundle; -import android.os.Handler; -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.res.Resources; -import android.graphics.Color; -import android.widget.CheckBox; -import android.widget.Button; -import android.widget.TextView; -import android.util.Log; -import android.view.View; -import android.view.View.OnClickListener; - -@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) -public class OOR extends Activity implements OnClickListener { - - public static String oor_path = null; - private static String system_dns[] = new String[2]; - private boolean oorWasRunning = false; - private static boolean oorRunning = false; - private static boolean err_msg_detected = false; - private static boolean startVPN = false; - private Intent vpn_intent = null; - private static final int CONF_ACT = 1; - private static final int VPN_SER = 2; - - private Handler handler; - private Runnable doUpdateView; - - - - /** Called when the activity is first created. */ - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.main); - - //shell = new SuShell(); - - /* Get the directory of the executable */ - - try{ - oor_path = getPackageManager().getApplicationInfo("org.openoverlayrouter.noroot", 0).nativeLibraryDir; - - }catch(Exception e) - { - e.printStackTrace(); - }; - - /* - * Set up the button handlers - */ - CheckBox oorCheckBox = (CheckBox)findViewById(R.id.startStopCheckbox); - oorCheckBox.setOnClickListener(this); - handler = new Handler(); - doUpdateView = new Runnable() { - public void run() { - updateStatus(); - } - }; - - Button log = (Button) findViewById(R.id.showLogButton); - log.setOnClickListener(new View.OnClickListener() { - public void onClick(View view) { - Intent myIntent = new Intent(view.getContext(), logActivity.class); - startActivity(myIntent); - } - } - ); - Button conf = (Button) findViewById(R.id.showConfButton); - conf.setOnClickListener(new View.OnClickListener() { - public void onClick(View view) { - Intent myIntent = new Intent(view.getContext(), confActivity.class); - startActivity(myIntent); - } - } - ); - - Button updateconf = (Button) findViewById(R.id.updateConfButton); - updateconf.setOnClickListener(new View.OnClickListener() { - public void onClick(View view) { - Intent myIntent = new Intent(view.getContext(), updateConfActivity.class); - startActivityForResult(myIntent, CONF_ACT); - - } - } - ); - - //system_dns = get_dns_servers(); - - } - - - Location lastLocation; - - Timer mUpdateTimer = null; - @Override - protected void onPause() { - Log.v("OOR", "Pausing.."); - super.onPause(); - - // Stop all timers - mUpdateTimer.cancel(); - } - - @Override - protected void onStop() { - Log.v("OOR", "Stopping..."); - super.onStop(); - // Stop all timers - mUpdateTimer.cancel(); - } - - @Override - protected void onResume() { - Log.v("OOR", "Resuming..."); - super.onResume(); - - // Rebuild the timer - if (mUpdateTimer != null) { - mUpdateTimer.cancel(); - } - mUpdateTimer = new Timer(); - mUpdateTimer.scheduleAtFixedRate(new statusTask(), 0, 1000); - } - - static public String runTask(String command, String args, boolean ignoreOutput) { - StringBuffer output = new StringBuffer(); - Process process = null; - try { - process = new ProcessBuilder() - .command(command, args) - .redirectErrorStream(true) - .start(); - InputStream in = process.getInputStream(); - BufferedReader reader = new BufferedReader(new InputStreamReader(in)); - String line; - process.waitFor(); - if (!ignoreOutput) { - while ((line = reader.readLine()) != null) { - output.append(line); - output.append('\n'); - } - } - } catch (IOException e1) { - System.out.println("OOR: Command Failed."); - e1.printStackTrace(); - return("Command Failed."); - } catch (InterruptedException e) { - e.printStackTrace(); - } - return(output.toString()); - } - - - public void updateStatus() { - final CheckBox oorCheckBox = (CheckBox) findViewById(R.id.startStopCheckbox); - final TextView oorCheckBoxLabel = (TextView) findViewById(R.id.startStopCheckboxLabel); - final TextView statusView = (TextView) findViewById(R.id.infoView); - - - oorRunning = OORVPNService.vpn_running; - - if (OORVPNService.vpn_running) { - oorCheckBoxLabel.setText(R.string.oorRunning); - oorCheckBoxLabel.setTextColor(Color.WHITE); - oorCheckBox.setChecked(true); - //updateInfoView(); - statusView.setText(""); - oorWasRunning = true; - } else if (oorWasRunning) { - oorCheckBoxLabel.setText("OOR has exited, click to restart."); - oorCheckBoxLabel.setTextColor(Color.RED); - oorCheckBox.setChecked(false); - //updateInfoView(); - statusView.setText(""); - } else { - oorCheckBoxLabel.setText(R.string.oorNotRunning); - oorCheckBoxLabel.setTextColor(Color.WHITE); - oorCheckBox.setChecked(false); - //updateInfoView(); - statusView.setText(""); - } - - if (!err_msg_detected && OORVPNService.err_msg_code != 0){ - err_msg_detected = true; - Resources res = getResources(); - String[] err_msg = res.getStringArray(R.array.ErrMsgArray); - showMessage(err_msg[OORVPNService.err_msg_code], - false, new Runnable() { public void run() { - OORVPNService.err_msg_code =0; - err_msg_detected = false; - } - }); - } - - } - - - - public final class statusTask extends TimerTask { - public void run() { - handler.post(doUpdateView); - } - } - - public void showMessage(String message, boolean cancelAble, final Runnable task) { - - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle("Attention:"); - builder.setMessage(message) - .setCancelable(cancelAble) - .setPositiveButton("Ok", new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - if (task != null) { - task.run(); - } else { - dialog.dismiss(); - } - } - }); - if (cancelAble) { - builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - dialog.dismiss(); - } - }); - } - AlertDialog alert = builder.create(); - alert.show(); - } - - - void restartOOR(){ - System.out.println("OOR: Restarting oor"); - stopVPN(); - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - startVPN(); - } - - public void startVPN(){ - startVPN = true; - Intent intent = VpnService.prepare(this); - if (intent != null) { - startActivityForResult(intent, VPN_SER); - } else { - onActivityResult(VPN_SER, RESULT_OK, null); - } - } - - public void stopVPN(){ - startVPN = false; - - Intent intent = VpnService.prepare(this); - if (intent == null) { - onActivityResult(VPN_SER, RESULT_OK, null); - } - } - - - public void onActivityResult(int request, int result, Intent data) { - switch (request){ - case CONF_ACT: - if (result == updateConfActivity.CONFIG_UPDATED){ - if (OORVPNService.vpn_running){ - restartOOR(); - } - } - break; - case VPN_SER: - String prefix = getPackageName(); - if (result == RESULT_OK) { - if (startVPN == true){ - vpn_intent = new Intent(this, OORVPNService.class); - vpn_intent.putExtra(prefix+".START", true); - startService(vpn_intent); - - }else{ - vpn_intent = new Intent(this, OORVPNService.class); - vpn_intent.putExtra(prefix+".START", false); - startService(vpn_intent); - } - } - break; - default: - break; - } - } - - public void onClick(View V) { - CheckBox oorCheckBox = (CheckBox)findViewById(R.id.startStopCheckbox); - if (V == findViewById(R.id.startStopCheckbox)) { - if (oorCheckBox.isChecked()) { - startVPN(); - return; - } - showMessage(this.getString(R.string.askStopServiceString), - true, new Runnable() { public void run() { - stopVPN(); - oorWasRunning = false; - } - }); - } - } -} - diff --git a/android/src/org/openoverlayrouter/noroot/OORVPNService.java b/android/src/org/openoverlayrouter/noroot/OORVPNService.java deleted file mode 100644 index ca6f6cf..0000000 --- a/android/src/org/openoverlayrouter/noroot/OORVPNService.java +++ /dev/null @@ -1,257 +0,0 @@ -/* - * - * Copyright (C) 2011, 2015 Cisco Systems, Inc. - * Copyright (C) 2015 CBA research group, Technical University of Catalonia. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.openoverlayrouter.noroot; - -import android.app.Notification; -import android.app.NotificationManager; -import android.app.PendingIntent; - -import android.content.Intent; -import android.net.VpnService; -import android.os.Environment; -import android.os.Handler; -import android.os.Message; -import android.os.ParcelFileDescriptor; -import android.util.Log; -import android.widget.Toast; - -import java.io.FileNotFoundException; -import java.util.Iterator; -import java.util.List; - - - - -public class OORVPNService extends VpnService implements Handler.Callback, Runnable { - private static final String TAG = "OORVPNService"; - - private PendingIntent mConfigureIntent = null; - - private static Thread mThread = null; - - private static ParcelFileDescriptor mInterface = null; - - public static boolean vpn_running = false; - public static int err_msg_code = 0; - - public OOR_JNI jni = null; - - - - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - - String prefix = getPackageName(); - boolean start; - - if (intent != null){ - start = intent.getBooleanExtra(prefix + ".START",true); - }else{ - Log.i(TAG, "OOR VPN service stopped and it has been reestarted"); - start = true; - } - - - if (start == true){ - if (mThread != null){ - if (mInterface == null){ - Log.i(TAG, "Error"); - } - Log.i(TAG, "Service already running"); - //return (START_STICKY); - vpn_running = true; - }else{ - mThread = new Thread(this, "OORVpnThread"); - mThread.start(); - - } - }else{ - this.onDestroy(); - } - - /* - * START_STICKY tells the OS to recreate the service after it has enough memory and call - * onStartCommand() again with a null intent. START_NOT_STICKY tells the OS to not bother - * recreating the service again - */ - if (start == true){ - //return (START_STICKY); - return (START_NOT_STICKY); - }else{ - return (START_NOT_STICKY); - } - } - - @Override - public void onDestroy() { - if (vpn_running == true){ - vpn_running = false; - jni.oor_exit(); - } - - Log.d(TAG, "Destroying VPN Service thread"); - if (mThread != null) { - mThread.interrupt(); - } - mInterface = null; - mThread = null; - - } - - @Override - public boolean handleMessage(Message message) { - if (message != null) { - Toast.makeText(this, message.what, Toast.LENGTH_SHORT).show(); - } - return true; - } - - public synchronized void run(){ - - String storage_path = Environment.getExternalStorageDirectory().getAbsolutePath()+"/"; - jni = new OOR_JNI(this); - - try { - // Create a DatagramChannel as the VPN tunnel. - this.configure(); - int tunfd = mInterface.detachFd(); - - vpn_running = true; - - if (jni.oor_start(tunfd, storage_path) != 1){ - Log.e(TAG, "OOR error, check configuration file"); - this.onDestroy(); - return; - } - - System.out.println("====> Starting OOR event loop "); - jni.oor_loop(); - System.out.println(" ************************** END ******************************************************************* "); - - // We keep forwarding packets till something goes wrong. - - }catch(IllegalArgumentException e){ - Log.e(TAG, e.getMessage()); - }catch (Exception e) { - e.printStackTrace(); - }finally{ - if (vpn_running == true){ - vpn_running = false; - jni.oor_exit(); - } - mThread = null; - vpn_running = false; - } - - return; - } - - private void configure() throws Exception { - Iterator eids = null; - String eid = null; - List dns_list = null; - Iterator dns_servers = null; - String dns = null; - boolean ipv4_eids = false; - boolean ipv6_eids = false; - - // Configure a builder while parsing the parameters. - Builder builder = new Builder(); - - - try { - eids = ConfigTools.getEIDs().iterator(); - while(eids.hasNext()){ - eid = eids.next(); - Log.i(TAG, "Assigning EID "+eid+" to the TUN interface"); - if (eid.contains(":")){ - if (ipv6_eids == false){ - builder.addAddress(eid, 128); - ipv6_eids = true; - } - }else{ - if (ipv4_eids == false){ - builder.addAddress(eid, 32); - ipv4_eids = true; - } - } - } - if (ipv4_eids == false && ipv6_eids == false){ - throw new Exception("At least one EID is required"); - } - dns_list = ConfigTools.getDNS(); - if (dns_list != null){ - dns_servers = dns_list.iterator(); - while(dns_servers.hasNext()){ - dns = dns_servers.next(); - builder.addDnsServer(dns); - } - } - - if (ipv4_eids){ - Log.i(TAG, "ADD IPV4 ROUTES"); - builder.addRoute("0.0.0.0",1); - builder.addRoute("128.0.0.0",1); - } - if (ipv6_eids){ - Log.i(TAG, "ADD IPV6 ROUTES"); - builder.addRoute("::",1); - builder.addRoute("8000::",1); - } - builder.setMtu(1440); - }catch (FileNotFoundException e){ - OORVPNService.err_msg_code = 1; - throw new IllegalArgumentException("Configuration file not exist"); - }catch (Exception e) { - OORVPNService.err_msg_code = 2; - throw new IllegalArgumentException("Wrong configuration"); - } - - // Create a new interface using the builder and save the parameters. - mInterface = builder.setSession("OOR") - .setConfigureIntent(mConfigureIntent) - .establish(); - Log.i(TAG, "Tun interface configured"); - } - - - public void notify_msg(String log_msg) - { - NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); - Intent startIntent = new Intent(this, OOR.class); - PendingIntent contentIntent = PendingIntent.getActivity(this,0,startIntent,PendingIntent.FLAG_CANCEL_CURRENT); - - // Allways overwriting same notification. - int notification_id = 1; - - Notification.Builder notify_b = new Notification.Builder(this); - notify_b.setContentTitle("OOR Alert"); - notify_b.setContentText(log_msg); - notify_b.setSmallIcon(R.drawable.oor_logo_small); - notify_b.setWhen(System.currentTimeMillis()); - notify_b.setContentIntent(contentIntent); - notify_b.setAutoCancel(true); - - Notification notify_msg = notify_b.getNotification(); - notificationManager.notify(notification_id,notify_msg); - - } -} \ No newline at end of file diff --git a/android/src/org/openoverlayrouter/noroot/OOR_JNI.java b/android/src/org/openoverlayrouter/noroot/OOR_JNI.java deleted file mode 100644 index 167a45a..0000000 --- a/android/src/org/openoverlayrouter/noroot/OOR_JNI.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * - * Copyright (C) 2011, 2015 Cisco Systems, Inc. - * Copyright (C) 2015 CBA research group, Technical University of Catalonia. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.openoverlayrouter.noroot; - -public class OOR_JNI { - - static { - System.loadLibrary("oor"); - } - - public OORVPNService lm_vpn_service = null; - - public OOR_JNI (OORVPNService vpn_service){ - this.lm_vpn_service = vpn_service; - } - - public native int oor_start(int tunFD, String storage_path); - - public native void oor_loop(); - - public native void oor_exit(); - - public void jni_protect_socket(int socket) - { - boolean sock_protect = false; - - if (socket >= 0){ - int retry = 0; - while (!sock_protect && retry < 30){ - if (!lm_vpn_service.protect(socket)) { - retry++; - try { - Thread.sleep(200); - } catch (InterruptedException e) { - e.printStackTrace(); - } - }else{ - sock_protect = true; - System.out.println("OOR: The socket "+socket+" has been protected (VPN Service)"); - } - } - } - if (sock_protect == false){ - System.out.println("OOR: Couldn't protect the socket "+socket); - } - } - -} diff --git a/android/src/org/openoverlayrouter/noroot/confActivity.java b/android/src/org/openoverlayrouter/noroot/confActivity.java deleted file mode 100644 index 0212cb1..0000000 --- a/android/src/org/openoverlayrouter/noroot/confActivity.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * - * Copyright (C) 2011, 2015 Cisco Systems, Inc. - * Copyright (C) 2015 CBA research group, Technical University of Catalonia. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.openoverlayrouter.noroot; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; - -import android.app.Activity; -import android.os.Bundle; -import android.os.Environment; -import android.widget.TextView; - -public class confActivity extends Activity { - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.conf); - refresh(); - } - - private static final String confFile = "oor.conf"; - - private void refresh() { - final TextView statusView = (TextView) findViewById(R.id.confView); - File sdcardDir = Environment.getExternalStorageDirectory(); - File infoFile = new File(sdcardDir, confFile); - BufferedReader reader; - - - try { - reader = new BufferedReader(new FileReader(infoFile)); - } catch (FileNotFoundException e) { - statusView.setText("Configuration file missing.\nPlease Go To \"Update OOR Configuration\" screen to create configuration.\n"); - return; - } - String line; - StringBuffer output = new StringBuffer(); - - try { - while ((line = reader.readLine()) != null) { - output.append(line); - output.append("\n"); - } - } catch (IOException e) { - statusView.setText("Configuration file read error."); - return; - } - statusView.setText(output.toString()); - } - -} diff --git a/android/src/org/openoverlayrouter/noroot/logActivity.java b/android/src/org/openoverlayrouter/noroot/logActivity.java deleted file mode 100644 index f7fac5d..0000000 --- a/android/src/org/openoverlayrouter/noroot/logActivity.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * - * Copyright (C) 2011, 2015 Cisco Systems, Inc. - * Copyright (C) 2015 CBA research group, Technical University of Catalonia. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - - -package org.openoverlayrouter.noroot; - -import android.app.Activity; -import android.app.ProgressDialog; -import android.content.res.Configuration; -import android.os.Bundle; -import android.os.Environment; -import android.os.Handler; -import android.view.View; -import android.widget.TextView; -import android.widget.ScrollView; - -import java.io.*; - -public class logActivity extends Activity { - - - private ProgressDialog myDialog = null; - private Handler mHandler = new Handler(); - - - private static File log_file = null; - public static final int maxReadBytes = 200000; - - - public void onConfigurationChanged(Configuration newConfig) { - super.onConfigurationChanged(newConfig); - setContentView(R.layout.log); - if (myDialog == null){ - myDialog = ProgressDialog.show( logActivity.this, null, null,true ); - } - new Thread(new Runnable() { - public void run() { - refresh(); - } - }).start(); - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - File sdcardDir = Environment.getExternalStorageDirectory(); - log_file = new File(sdcardDir, "oor.log"); - - setContentView(R.layout.log); - //myDialog = ProgressDialog.show( logActivity.this, " " , " Loading. Please wait ... ", true); - myDialog = ProgressDialog.show( logActivity.this, null, null,true ); - - new Thread(new Runnable() { - public void run() { - refresh(); - } - }).start(); - } - public void refresh() { - - StringBuffer contents = new StringBuffer(); - - final StringBuffer fixedContents = contents; - - try { - RandomAccessFile logFile = new RandomAccessFile(log_file, "r"); - if (logFile.length() > maxReadBytes) { - logFile.seek(logFile.length() - maxReadBytes); - } - String currentLine = logFile.readLine(); - while (currentLine != null) { - - if (currentLine != null) { - contents.append(currentLine); - contents.append('\n'); - } - currentLine = logFile.readLine(); - } - try { - if (logFile != null) { - logFile.close(); - } - } catch (IOException e) { - e.printStackTrace(); - } - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } finally { - - } - - mHandler.post(new Runnable() { public void run() { - - - // Put the file contents into the TextView - TextView log = (TextView) findViewById(R.id.logView); - log.setText(fixedContents); - - // Auto scroll to the bottom - final ScrollView scroll = (ScrollView) findViewById(R.id.scrollView1); - scroll.post(new Runnable() { - public void run() { - scroll.fullScroll(View.FOCUS_DOWN); - } - }); - if (myDialog != null){ - myDialog.dismiss(); - myDialog = null; - } - } - } - ); - } - - public void refreshClicked(View v) { - myDialog = ProgressDialog.show( logActivity.this, null, null ); - - new Thread(new Runnable() { - public void run() { - refresh(); - } - }).start(); - } -} diff --git a/android/src/org/openoverlayrouter/noroot/updateConfActivity.java b/android/src/org/openoverlayrouter/noroot/updateConfActivity.java deleted file mode 100644 index ce7aa7c..0000000 --- a/android/src/org/openoverlayrouter/noroot/updateConfActivity.java +++ /dev/null @@ -1,699 +0,0 @@ -/* - * - * Copyright (C) 2011, 2015 Cisco Systems, Inc. - * Copyright (C) 2015 CBA research group, Technical University of Catalonia. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.openoverlayrouter.noroot; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.net.NetworkInterface; -import java.net.SocketException; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import android.app.Activity; -import android.app.AlertDialog; -import android.os.Bundle; -import android.os.Environment; -import android.view.View; -import android.content.DialogInterface; -import android.content.Intent; -import android.widget.CheckBox; -import android.widget.EditText; -import android.widget.Spinner; -import android.widget.ArrayAdapter; - - -public class updateConfActivity extends Activity { - - public static final String confFile = "oor.conf"; - - public static String eidIPv4 = ""; - public static String eidIPv6 = ""; - public static List ifaces = null; - public static String MR = ""; - public static String MS = ""; - public static String MSKey = "password"; - public static String proxyETR = ""; - public static String DNS1 = ""; - public static String DNS2 = ""; - public static boolean overrideDNS = false; - public static boolean nat_aware = false; - public static int rloc_prob_interval = 30; - public static int rloc_prob_retries = 2; - public static int rloc_prob_retries_interval = 5; - public static String logLevel = "1"; - public static final int CONFIG_UPDATED = 1; - public static File conf_file = null; - public static List iface_list = null; - - @Override - public void onCreate(Bundle savedInstanceState) { - - super.onCreate(savedInstanceState); - setContentView(R.layout.updateconf); - - File sdcardDir = Environment.getExternalStorageDirectory(); - conf_file = new File(sdcardDir, confFile); - - - iface_list = ConfigTools.get_ifaces_list(); - - - //Spinner spinner = (Spinner) findViewById(R.id.IfaceNameSpinner); - MultiSelectionSpinner spinner = (MultiSelectionSpinner) findViewById(R.id.IfaceNameSpinner); - ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_spinner_item,iface_list); - // Specify the layout to use when the list of choices appears - adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - // Apply the adapter to the spinner - //spinner.setAdapter(adapter); - spinner.setItems(iface_list); - - Spinner logSpinner = (Spinner) findViewById(R.id.LogSpinner); - ArrayAdapter logAdapter = ArrayAdapter.createFromResource(this,R.array.LogLevelArray, android.R.layout.simple_spinner_item); - logSpinner.setAdapter(logAdapter); - - if ( !conf_file.exists() ) { - createConfFile(); - } - - readConfFileAndFillParameters(); - - } - - - - public void readConfFileAndFillParameters() - { - - try { - - BufferedReader br = new BufferedReader(new FileReader(conf_file)); - String line = br.readLine(); - String sub_line = null; - String sub_line_1 = null; - ifaces = new ArrayList(); - - while ( line != null ) { - if (line.startsWith("#")){ - line = br.readLine(); - continue; - } - line = line.toLowerCase(); - line = line.replaceAll("\\s", ""); - - if (line.contains("database-mapping")){ - do{ - sub_line = br.readLine(); - if (sub_line.startsWith("#")){ - sub_line = br.readLine(); - continue; - } - sub_line = sub_line.toLowerCase(); - sub_line = sub_line.replaceAll("\\s", ""); - - if (sub_line.contains("eid-prefix")){ - String[] tmp = sub_line.split("="); - if (tmp.length < 2) - continue; - String[] tmp_1 = tmp[1].split("/"); - if (tmp_1.length < 2) - continue; - if (tmp_1[0].contains(":")){ - eidIPv6 = tmp_1[0]; - EditText e = (EditText) findViewById(R.id.updateConfeid6Text); - e.setText(eidIPv6); - }else if (tmp_1[0].contains(".")){ - eidIPv4 = tmp_1[0]; - EditText e = (EditText) findViewById(R.id.updateConfeid4Text); - e.setText(eidIPv4); - } - } - if (sub_line.contains("rloc-iface")){ - sub_line = br.readLine(); - if (sub_line.startsWith("#")){ - sub_line = br.readLine(); - continue; - } - sub_line = sub_line.toLowerCase(); - sub_line = sub_line.replaceAll("\\s", ""); - - if (sub_line.contains("interface")){ - String[] tmp = sub_line.split("="); - if (tmp.length < 2) - continue; - String iface_name = tmp[1]; - - Iterator iface_it = iface_list.iterator(); - while (iface_it.hasNext()) - { - if (iface_it.next().equals(iface_name)){ - if (!ifaces.contains(iface_name)){ - ifaces.add(iface_name); - } - break; - } - } - } - - } - }while (!sub_line.contains("}")); - }else if (line.contains("map-resolver")) { - sub_line = br.readLine(); - if (sub_line.startsWith("#")){ - sub_line = br.readLine(); - continue; - } - sub_line = sub_line.replaceAll("\\s", ""); - - if (sub_line.contains(",")){ - String[] tmp = sub_line.split(","); - if (tmp.length!=0){ - MR = tmp[0]; - } - }else { - MR = sub_line; - } - - EditText e = (EditText) findViewById(R.id.updateConfMRText); - e.setText(MR); - } else if (line.contains("nat-traversal") && !line.startsWith("#")) { - do { - sub_line = br.readLine(); - if (sub_line.startsWith("#")){ - sub_line = br.readLine(); - continue; - } - sub_line = sub_line.toLowerCase(); - sub_line = sub_line.replaceAll("\\s", ""); - - if (sub_line.contains("nat_aware")) { - String[] tmp = sub_line.split("="); - if(tmp.length < 2) - continue; - String nat_aware_aux = tmp[1]; - if (nat_aware_aux.equals("on") || nat_aware_aux.equals("true")){ - nat_aware = true; - }else{ - nat_aware = false; - } - } - }while (!sub_line.contains("}")); - CheckBox c = (CheckBox)findViewById(R.id.updateConf_NAT_aware); - c.setChecked(nat_aware); - } else if (line.contains("map-server")) { - do { - sub_line = br.readLine(); - if (sub_line.startsWith("#")){ - sub_line = br.readLine(); - continue; - } - sub_line_1 = sub_line; // Not lose uppercase in password - sub_line = sub_line.toLowerCase(); - sub_line = sub_line.replaceAll("\\s", ""); - - if (sub_line.contains("address")) { - String[] tmp = sub_line.split("="); - if (tmp.length>1){ - MS = tmp[1]; - } - } else if (sub_line.contains("key")) { - String[] tmp = sub_line_1.split("="); - if (tmp.length>1){ - MSKey = tmp[1]; - } - } - } while (!sub_line.contains("}")); - - EditText e = (EditText) findViewById(R.id.updateConfMSText); - e.setText(MS); - - EditText et = (EditText) findViewById(R.id.updateConfMSKeyText); - et.setText(MSKey); - } else if (line.contains("proxy-etr")) { - do { - sub_line = br.readLine(); - if (sub_line.startsWith("#")){ - sub_line = br.readLine(); - continue; - } - sub_line = sub_line.toLowerCase(); - sub_line = sub_line.replaceAll("\\s", ""); - - if (sub_line.contains("address")) { - String[] tmp = sub_line.split("="); - if (tmp.length > 1){ - proxyETR = tmp[1]; - } - } - } while (!sub_line.contains("}")); - - EditText e = (EditText) findViewById(R.id.updateConf_proxy_etr); - e.setText(proxyETR); - - }else if (line.contains("override-dns=")) { - String[] tmp = line.split("="); - if(tmp.length > 1 ){ - String overrideDNS_aux = tmp[1]; - if (overrideDNS_aux.equals("on") || overrideDNS_aux.equals("true")){ - overrideDNS = true; - }else{ - overrideDNS = false; - } - } - - CheckBox c = (CheckBox)findViewById(R.id.updateConfDNSCheck); - c.setChecked(overrideDNS); - }else if (line.contains("override-dns-primary=")) { - String[] tmp = line.split("="); - if (tmp.length > 1){ - if (ConfigTools.validate_IP_Address(tmp[1])){ - DNS1 = tmp[1]; - } - } - EditText e = (EditText)findViewById(R.id.updateConfDNS1Text); - e.setText(DNS1); - } else if (line.contains("override-dns-secondary=")) { - String[] tmp = line.split("="); - if (tmp.length > 1){ - if (ConfigTools.validate_IP_Address(tmp[1])){ - DNS2 = tmp[1]; - } - } - EditText e = (EditText)findViewById(R.id.updateConfDNS2Text); - e.setText(DNS2); - } - else if (line.contains("debug=")) { - String[] tmp = line.split("="); - if (tmp.length > 1){ - logLevel = tmp[1]; - } - Spinner log_spinner = (Spinner) findViewById(R.id.LogSpinner); - log_spinner.setSelection(new Integer(logLevel).intValue()); - } - - line = br.readLine(); - } - MultiSelectionSpinner spinner = (MultiSelectionSpinner) findViewById(R.id.IfaceNameSpinner); - spinner.setSelection(ifaces); - - EditText e = (EditText)findViewById(R.id.updateConfDNS1Text); - e.setEnabled(overrideDNS); - e = (EditText)findViewById(R.id.updateConfDNS2Text); - e.setEnabled(overrideDNS); - - } - catch (IOException e) { - ; - } - - } - - public void createConfFile() - { - /* - * If a configuration file is not found, a default configuration file is created. - * */ - try { - String defText; - defText = new StringBuilder() - .append("# *** OOR EXAMPLE CONFIG FILE ***\n\n\n") - .append("# General configuration\n") - .append("# debug: Debug levels [0..3]\n") - .append("# map-request-retries: Additional Map-Requests to send per map cache miss\n\n") - .append("debug = "+logLevel+"\n") - .append("map-request-retries = 2\n\n\n") - .append("#\n") - .append("# operating mode can be any of:\n") - .append("# xTR, RTR, MN, MS\n") - .append("#\n\n") - .append("operating-mode = MN\n") - .append("# RLOC Probing configuration\n") - .append("# rloc-probe-interval: interval at which periodic RLOC probes are sent\n") - .append("# (seconds). A value of 0 disables RLOC Probing\n") - .append("# rloc-probe-retries: RLOC Probe retries before setting the locator with\n") - .append("# status down. [0..5]\n") - .append("# rloc-probe-retries-interval: interval at which RLOC probes retries are\n") - .append("# sent (seconds) [1..#rloc-probe-interval]\n\n") - .append("rloc-probing {\n") - .append(" rloc-probe-interval = "+rloc_prob_interval+"\n") - .append(" rloc-probe-retries = "+rloc_prob_retries+"\n") - .append(" rloc-probe-retries-interval = "+rloc_prob_retries_interval+"\n") - .append("}\n\n\n") - .append("# NAT Traversal configuration. \n") - .append("# nat_aware: check if the node is behind NAT\n") - .append("# site_ID: 64 bits to identify the site which the node is connected to. In\n") - .append("# hexadecimal\n") - .append("# xTR_ID: 128 bits to identify the xTR inside the site. In hexadecimal\n\n") - .append("nat-traversal {\n") - .append(" nat_aware = off\n") - .append(" site_ID = 0000000000000001 #In doubt, keep the default value\n") - .append(" xTR_ID = 00000000000000000000000000000001 #In doubt, keep the default value\n") - .append("}\n\n\n") - .append("# Encapsulated Map-Requests are sent to this map-resolver\n") - .append("# You can define several map-resolvers. Encapsulated Map-Request messages will\n") - .append("# be sent to only one.\n") - .append("# address: IPv4 or IPv6 address of the map resolver\n") - .append("map-resolver = {\n") - .append(" "+MR+",\n") - .append("}\n\n\n") - .append("# Map-Registers are sent to this map-server\n") - .append("# You can define several map-servers. Map-Register messages will be sent to all\n") - .append("# of them.\n") - .append("# address: IPv4 or IPv6 address of the map-server\n") - .append("# key-type: Only 1 supported (HMAC-SHA-1-96)\n") - .append("# key: password to authenticate with the map-server\n") - .append("# proxy-reply [on/off]: Configure map-server to Map-Reply on behalf of the xTR\n\n") - .append("map-server {\n") - .append(" address = "+MS+"\n") - .append(" key-type = 1\n") - .append(" key = "+MSKey+"\n") - .append(" proxy-reply = on\n") - .append("}\n\n\n") - .append("# Packets addressed to non-LISP sites will be encapsulated to this Proxy-ETR\n") - .append("# You can define several Proxy-ETR. Traffic will be balanced according to\n") - .append("# priority and weight.\n") - .append("# address: IPv4 or IPv6 address of the Proxy-ETR\n") - .append("# priority [0-255]: Proxy-ETR with lower values are more preferable.\n") - .append("# weight [0-255]: When priorities are the same for multiple Proxy-ETRs,\n") - .append("# the Weight indicates how to balance unicast traffic between them.\n") - .append("proxy-etr {\n") - .append(" address = "+proxyETR+"\n") - .append(" priority = 1\n") - .append(" weight = 100\n") - .append("}\n\n\n") - .append("# List of PITRs to SMR on handover\n") - .append("# address: IPv4 or IPv6 address of the Proxy-ITR\n") - .append("# Current LISP beta-network (lisp4.net/lisp6.net) PITR addresses\n\n") - .append("proxy-itrs = {\n") - .append(" 69.31.31.98,\n") - .append(" 149.20.48.60,\n") - .append(" 198.6.255.37,\n") - .append(" 173.36.193.25,\n") - .append(" 129.250.1.63,\n") - .append(" 217.8.98.33,\n") - .append(" 217.8.98.35,\n") - .append(" 193.162.145.46,\n") - .append(" 193.34.30.222,\n") - .append(" 193.34.31.222,\n") - .append(" 147.83.131.33,\n") - .append(" 158.38.1.92,\n") - .append(" 203.181.249.172,\n") - .append(" 202.51.247.10\n") - .append("}\n\n\n") - .append("# IPv4 / IPv6 EID of the node.\n") - .append("# Two kind of rlocs can be defined:\n") - .append("# -> rloc-address: Specifies directly the rloc of the interface\n") - .append("# -> rloc-iface: Specifies the interface associated with the RLOC\n") - .append("#\n") - .append("# eid-prefix: EID prefix (IPvX/mask) of the mapping\n") - .append("# address: IPv4 or IPv6 address of the rloc. Address should exist and\n") - .append("# be assigned to an UP interface during starting process otherwise\n") - .append("# it is discarded\n") - .append("# interface: interface containing the RLOCs associated to this mapping\n") - .append("# afi: 4 to use IPv4 address of the interface and 6 to use IPv6 address\n") - .append("# of the interface\n") - .append("# priority [0-255]: Priority for the IPvX RLOC of the interface. Locators\n") - .append("# with lower values are more preferable. This is used for both incoming\n") - .append("# policy announcements and outcoming traffic policy management.\n") - .append("# weight [0-255]: When priorities are the same for multiple RLOCs, the Weight\n") - .append("# indicates how to balance unicast traffic between them.\n") - .toString(); - if (ifaces != null){ - if (!eidIPv4.equals("")){ - defText= defText.concat(createEIDConFile(eidIPv4+"/32")); - } - if (!eidIPv6.equals("")){ - defText= defText.concat(createEIDConFile(eidIPv6+"/128")); - } - } - - - defText= defText.concat("override-dns = "+overrideDNS+"\n"); - if (!DNS1.equals("")) - defText= defText.concat("override-dns-primary = "+DNS1+"\n"); - if (!DNS2.equals("")) - defText= defText.concat("override-dns-secondary = "+DNS2+"\n"); - - FileWriter fstream = new FileWriter(conf_file); - BufferedWriter out = new BufferedWriter(fstream); - out.write(defText); - out.close(); - - } catch (Exception e) { - displayMessage("Error while writing Default Conf file to sdcard!!", false, null); - } - } - - private String createEIDConFile(String eid) - { - String eid_statement = new String(); - eid_statement= eid_statement.concat("database-mapping {\n") - .concat(" eid-prefix = "+eid+"\n"); - Iterator it = ifaces.iterator(); - while (it.hasNext()){ - String iface_name = it.next(); - eid_statement= eid_statement.concat(" rloc-iface{\n") - .concat(" interface = "+iface_name+"\n") - .concat(" ip_version = 4\n") - .concat(" priority = 1\n") - .concat(" weight = 100\n") - .concat(" }\n\n"); - if (nat_aware == false){ - eid_statement= eid_statement.concat(" rloc-iface{\n") - .concat(" interface = "+iface_name+"\n") - .concat(" ip_version = 6\n") - .concat(" priority = 1\n") - .concat(" weight = 100\n") - .concat(" }\n\n"); - } - - } - eid_statement= eid_statement.concat("}\n"); - return (eid_statement); - } - - - public void displayMessage(String message, boolean cancelAble, final Runnable task) - { - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle("Attention"); - builder.setMessage(message); - builder.setCancelable(cancelAble); - builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { - public void onClick( DialogInterface dialog, int id ) { - if ( task != null ) { - task.run(); - } else { - dialog.dismiss(); - } - } - } ); - - if ( cancelAble ) { - builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - dialog.dismiss(); - } - } ); - } - - AlertDialog alert = builder.create(); - alert.show(); - - } - - - public boolean get_and_validate_parameters(){ - EditText e; - CheckBox c; - MultiSelectionSpinner multi_spinner; - Spinner spinner; - String eidv4 = ""; - String eidv6 = ""; - String mapResolver = ""; - String mapServer = ""; - String mapServerKey = "password"; - String pETR = ""; - String DNS_1 = ""; - String DNS_2 = ""; - boolean overrideDNS_bool = false; - boolean nat_aware_bool = false; - - - String message = "ERROR: The following fields are not valid: \n"; - String error = ""; - - - e = (EditText) findViewById(R.id.updateConfeid4Text); - eidv4 = e.getText().toString(); - - e = (EditText) findViewById(R.id.updateConfeid6Text); - eidv6 = e.getText().toString(); - - c = (CheckBox)findViewById(R.id.updateConf_NAT_aware); - nat_aware_bool = c.isChecked(); - - e = (EditText) findViewById(R.id.updateConfMRText); - mapResolver = e.getText().toString(); - - e = (EditText) findViewById(R.id.updateConfMSText); - mapServer = e.getText().toString(); - - e = (EditText) findViewById(R.id.updateConfMSKeyText); - mapServerKey = e.getText().toString(); - - e = (EditText) findViewById(R.id.updateConf_proxy_etr); - pETR = e.getText().toString(); - - c = (CheckBox)findViewById(R.id.updateConfDNSCheck); - overrideDNS_bool = c.isChecked(); - - e = (EditText) findViewById(R.id.updateConfDNS1Text); - DNS_1 = e.getText().toString(); - - e = (EditText) findViewById(R.id.updateConfDNS2Text); - DNS_2 = e.getText().toString(); - - multi_spinner = (MultiSelectionSpinner)findViewById(R.id.IfaceNameSpinner); - ifaces = multi_spinner.getSelectedStrings(); - - spinner = (Spinner)findViewById(R.id.LogSpinner); - logLevel = spinner.getSelectedItem().toString(); - - - - if (!eidv4.equals("") && !ConfigTools.validate_IP_Address(eidv4)){ - error = error.concat(" - EID-IPv4\n"); - } - if (!eidv6.equals("") && !ConfigTools.validate_IP_Address(eidv6)){ - error = error.concat(" - EID-IPv6\n"); - } - if (!ConfigTools.validate_IP_Address(mapResolver)){ - error = error.concat(" - Map-Resolver\n"); - } - if (!ConfigTools.validate_IP_Address(mapServer)){ - error = error.concat(" - Map-Server\n"); - } - if (!ConfigTools.validate_IP_Address(pETR)){ - error = error.concat(" - Proxy ETR\n"); - } - if (overrideDNS_bool && ( DNS_1.equals("") || !ConfigTools.validate_IP_Address(DNS_1))){ - error = error.concat(" - Primary DNS\n"); - } - if ((overrideDNS_bool && !DNS_2.equals("") && !ConfigTools.validate_IP_Address(DNS_2))){ - error = error.concat(" - Secondary DNS\n"); - } - if (nat_aware_bool == true && !eidv4.equals("") && !eidv6.equals("")){ - error = error.concat(" - Only one EID is supported\n"); - } - - - - - if (!error.equals("")){ - displayMessage(message+error, false, null); - return (false); - } - if (eidv4.equals("") && eidv6.equals("")){ - displayMessage("ERROR: At least one EID should be supplied", false, null); - return (false); - } - - eidIPv4 = eidv4; - eidIPv6 = eidv6; - MR = mapResolver; - MS = mapServer; - MSKey = mapServerKey; - proxyETR = pETR; - DNS1 = DNS_1; - DNS2 = DNS_2; - overrideDNS = overrideDNS_bool; - nat_aware = nat_aware_bool; - - return (true); - } - - public void updateConfFile() - { - if (get_and_validate_parameters() == true){ - createConfFile(); - setResult(CONFIG_UPDATED); - finish(); - } - } - - public void updateConfDNSClicked(View v) - { - CheckBox c = (CheckBox)v; - if (c.isChecked()) { - overrideDNS = true; - - EditText e = (EditText)findViewById(R.id.updateConfDNS1Text); - e.setEnabled(true); - - e = (EditText)findViewById(R.id.updateConfDNS2Text); - e.setEnabled(true); - } else { - overrideDNS = false; - EditText e = (EditText)findViewById(R.id.updateConfDNS1Text); - e.setEnabled(false); - - e = (EditText)findViewById(R.id.updateConfDNS2Text); - e.setEnabled(false); - } - } - - public void updateConfNATAwareClicked(View v) - { - CheckBox c = (CheckBox)v; - if (c.isChecked()) { - nat_aware = true; - } else { - nat_aware = false; - } - } - - public void updateConfClicked(View v) - { - displayMessage("This will overwrite the existing configuration.\nDo you want to Continue?", true, new Runnable() { public void run() { - updateConfFile(); - } - }); - } - - public static boolean isOverrideDNS(){ - return(overrideDNS); - } - - public static String[] getNewDNS(){ - String[] dns = {DNS1, DNS2}; - return (dns); - } - -}