[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [orbot/master] fixes geoip settings, and other small server config changes



commit a2d41e4f790ffc04fe65ab922fdcc6394924ddfa
Author: Nathan Freitas <nathan@xxxxxxxxxxx>
Date:   Fri Oct 28 00:29:57 2011 -0400

    fixes geoip settings, and other small server config changes
---
 .../android/service/TorBinaryInstaller.java        |   56 ++++++++-----------
 src/org/torproject/android/service/TorService.java |   56 ++++++++++----------
 .../android/service/TorServiceConstants.java       |    7 ++-
 .../android/service/TorServiceUtils.java           |   44 +++-------------
 .../torproject/android/service/TorTransProxy.java  |    6 +-
 5 files changed, 66 insertions(+), 103 deletions(-)

diff --git a/src/org/torproject/android/service/TorBinaryInstaller.java b/src/org/torproject/android/service/TorBinaryInstaller.java
index ba6ab3f..72f4ad3 100644
--- a/src/org/torproject/android/service/TorBinaryInstaller.java
+++ b/src/org/torproject/android/service/TorBinaryInstaller.java
@@ -13,6 +13,7 @@ import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
 
 import org.torproject.android.R;
+import org.torproject.android.TorConstants;
 
 import android.content.Context;
 import android.util.Log;
@@ -34,43 +35,34 @@ public class TorBinaryInstaller implements TorServiceConstants {
 	/*
 	 * Extract the Tor binary from the APK file using ZIP
 	 */
-	public boolean installFromRaw () 
+	public boolean installFromRaw () throws IOException
 	{
-		boolean result = false;
 		
-			
-		try
-		{
-			InputStream is;
-			
-			is = context.getResources().openRawResource(R.raw.toraa);			
-			streamToFile(is,installFolder, TOR_BINARY_ASSET_KEY, false);
-		
-			is = context.getResources().openRawResource(R.raw.torab);			
-			streamToFile(is,installFolder, TOR_BINARY_ASSET_KEY, true);
+		InputStream is;
 		
-			is = context.getResources().openRawResource(R.raw.torac);			
-			streamToFile(is,installFolder, TOR_BINARY_ASSET_KEY, true);
-		
-			is = context.getResources().openRawResource(R.raw.torad);			
-			streamToFile(is,installFolder, TOR_BINARY_ASSET_KEY, true);
-		
-			is = context.getResources().openRawResource(R.raw.torrc);			
-			streamToFile(is,installFolder, TORRC_ASSET_KEY, false);
+		is = context.getResources().openRawResource(R.raw.toraa);			
+		streamToFile(is,installFolder, TOR_BINARY_ASSET_KEY, false);
+	
+		is = context.getResources().openRawResource(R.raw.torab);			
+		streamToFile(is,installFolder, TOR_BINARY_ASSET_KEY, true);
 	
-			is = context.getResources().openRawResource(R.raw.privoxy);			
-			streamToFile(is,installFolder, PRIVOXY_ASSET_KEY, false);
+		is = context.getResources().openRawResource(R.raw.torac);			
+		streamToFile(is,installFolder, TOR_BINARY_ASSET_KEY, true);
 	
-			is = context.getResources().openRawResource(R.raw.privoxy_config);			
-			streamToFile(is,installFolder, PRIVOXYCONFIG_ASSET_KEY, false);
+		is = context.getResources().openRawResource(R.raw.torad);			
+		streamToFile(is,installFolder, TOR_BINARY_ASSET_KEY, true);
+	
+		is = context.getResources().openRawResource(R.raw.torrc);			
+		streamToFile(is,installFolder, TORRC_ASSET_KEY, false);
 
-		}
-		catch (IOException ioe)
-		{
-			Log.e(TAG, "unable to install tor binaries from raw", ioe);
-			return false;
-		}
-			
+		is = context.getResources().openRawResource(R.raw.privoxy);			
+		streamToFile(is,installFolder, PRIVOXY_ASSET_KEY, false);
+
+		is = context.getResources().openRawResource(R.raw.privoxy_config);			
+		streamToFile(is,installFolder, PRIVOXYCONFIG_ASSET_KEY, false);
+		
+		is = context.getResources().openRawResource(R.raw.geoip);			
+		streamToFile(is,installFolder, GEOIP_ASSET_KEY, false);
 	
 		return true;
 	}
@@ -132,7 +124,7 @@ public class TorBinaryInstaller implements TorServiceConstants {
 			
 			
 		} catch (IOException ex) {
-			Log.e(TAG, "error copying binary", ex);
+			Log.e(TorConstants.TAG, "error copying binary", ex);
 		}
 
 	}
diff --git a/src/org/torproject/android/service/TorService.java b/src/org/torproject/android/service/TorService.java
index 0f9cee3..70b7c9c 100644
--- a/src/org/torproject/android/service/TorService.java
+++ b/src/org/torproject/android/service/TorService.java
@@ -17,12 +17,12 @@ import net.freehaven.tor.control.ConfigEntry;
 import net.freehaven.tor.control.EventHandler;
 import net.freehaven.tor.control.TorControlConnection;
 
-import org.torproject.android.AppManager;
 import org.torproject.android.Orbot;
-import org.torproject.android.ProcessSettingsAsyncTask;
 import org.torproject.android.R;
 import org.torproject.android.TorConstants;
 import org.torproject.android.Utils;
+import org.torproject.android.settings.AppManager;
+import org.torproject.android.settings.ProcessSettingsAsyncTask;
 
 import android.app.AlertDialog;
 import android.app.Notification;
@@ -40,7 +40,7 @@ import android.os.RemoteException;
 import android.preference.PreferenceManager;
 import android.util.Log;
 
-public class TorService extends Service implements TorServiceConstants, Runnable, EventHandler
+public class TorService extends Service implements TorServiceConstants, TorConstants, Runnable, EventHandler
 {
 	
 	public static boolean ENABLE_DEBUG_LOG = false;
@@ -516,24 +516,14 @@ public class TorService extends Service implements TorServiceConstants, Runnable
     private boolean setupTransProxy (boolean activate) throws Exception
  	{
     	SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
- 		boolean hasRoot;
+    	
+ 		boolean hasRoot = prefs.getBoolean(PREF_HAS_ROOT,false);
  		
- 		if (prefs.contains("has_root"))
- 		{
- 			hasRoot = prefs.getBoolean("has_root",false);
- 		}
- 		else
+ 		if (!hasRoot)
  		{
- 			hasRoot = TorServiceUtils.checkRootAccess();
- 			Editor pEdit = prefs.edit();
- 			pEdit.putBoolean("has_root",hasRoot);
- 			pEdit.commit();
+ 			
  		}
- 		
- 		if (!hasRoot)
- 			return false;
- 		
-    	if (activate)
+ 		else if (activate)
     	{
 	 		
 	 		boolean enableTransparentProxy = prefs.getBoolean("pref_transparent", false);
@@ -748,7 +738,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
 				{
 					logNotice( "Connecting to control port: " + TOR_CONTROL_PORT);
 					
-					String baseMessage = getString(R.string.tor_process_connecting);
+					String baseMessage = getString(R.string.tor_process_starting);
 					sendCallbackStatusMessage(baseMessage);
 					
 					torConnSocket = new Socket(IP_LOCALHOST, TOR_CONTROL_PORT);
@@ -756,7 +746,6 @@ public class TorService extends Service implements TorServiceConstants, Runnable
 			        
 			      //  conn.authenticate(new byte[0]); // See section 3.2
 			        
-					sendCallbackStatusMessage(getString(R.string.tor_process_connecting_step2));
 
 					logNotice( "SUCCESS connected to control port");
 			        
@@ -772,7 +761,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
 				        		
 				        logNotice( "SUCCESS authenticated to control port");
 				        
-						sendCallbackStatusMessage(getString(R.string.tor_process_connecting_step2) + getString(R.string.tor_process_connecting_step3));
+						sendCallbackStatusMessage(getString(R.string.tor_process_starting) + ' ' + getString(R.string.tor_process_complete));
 	
 				        addEventHandler();
 				        
@@ -785,7 +774,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
 					conn = null;
 					Log.d(TAG,"Attempt: Error connecting to control port: " + ce.getLocalizedMessage(),ce);
 					
-					sendCallbackStatusMessage(getString(R.string.tor_process_connecting_step4));
+					sendCallbackStatusMessage(getString(R.string.tor_process_waiting));
 
 					Thread.sleep(1000);
 										
@@ -910,14 +899,14 @@ public class TorService extends Service implements TorServiceConstants, Runnable
           if (msg.indexOf(TOR_CONTROL_PORT_MSG_BOOTSTRAP_DONE)!=-1)
           {
         	  currentStatus = STATUS_ON;
+        	  showToolbarNotification (getString(R.string.status_activated),NOTIFY_ID,R.drawable.tornotificationon);
         	
 
    		   	getHiddenServiceHostname ();
    		   
           }
-          
-          
-    	  showToolbarNotification (getString(R.string.status_activated),NOTIFY_ID,R.drawable.tornotificationon);
+        
+      	
     		 
           sendCallbackStatusMessage (msg);
           
@@ -1273,7 +1262,6 @@ public class TorService extends Service implements TorServiceConstants, Runnable
     
     private boolean applyPreferences () throws RemoteException
     {
-    	
     	SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
 		
     	ENABLE_DEBUG_LOG = prefs.getBoolean("pref_enable_logging",false);
@@ -1284,9 +1272,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
 		//boolean autoUpdateBridges = prefs.getBoolean(TorConstants.PREF_BRIDGES_UPDATED, false);
 
         boolean becomeRelay = prefs.getBoolean(TorConstants.PREF_OR, false);
-
         boolean ReachableAddresses = prefs.getBoolean(TorConstants.PREF_REACHABLE_ADDRESSES,false);
-
         boolean enableHiddenServices = prefs.getBoolean("pref_hs_enable", false);
 
         boolean enableStrictNodes = prefs.getBoolean("pref_strict_nodes", false);
@@ -1294,6 +1280,18 @@ public class TorService extends Service implements TorServiceConstants, Runnable
         String exitNodes = prefs.getString("pref_exit_nodes", null);
         String excludeNodes = prefs.getString("pref_exclude_nodes", null);
         
+        String proxyType = prefs.getString("pref_proxy_type", null);
+        if (proxyType != null)
+        {
+        	String proxyHost = prefs.getString("pref_proxy_host", null);
+        	String proxyPort = prefs.getString("pref_proxy_port", null);
+        	
+        	if (proxyHost != null && proxyPort != null)
+        	{
+        		mBinder.updateConfiguration(proxyType + "Proxy", proxyHost + ':' + proxyPort, false);
+        	}
+        }
+        
         if (currentStatus == STATUS_ON)
         {
         	//reset iptables rules in active mode
@@ -1308,6 +1306,8 @@ public class TorService extends Service implements TorServiceConstants, Runnable
 			}
         }
         
+        File fileGeoIP = new File(appBinHome,"geoip");
+        mBinder.updateConfiguration("GeoIPFile", fileGeoIP.getAbsolutePath(), false);
         mBinder.updateConfiguration("EntryNodes", entranceNodes, false);
         mBinder.updateConfiguration("ExitNodes", exitNodes, false);
 		mBinder.updateConfiguration("ExcludeNodes", excludeNodes, false);
diff --git a/src/org/torproject/android/service/TorServiceConstants.java b/src/org/torproject/android/service/TorServiceConstants.java
index 4f58dde..759d0ce 100644
--- a/src/org/torproject/android/service/TorServiceConstants.java
+++ b/src/org/torproject/android/service/TorServiceConstants.java
@@ -4,11 +4,9 @@ package org.torproject.android.service;
 
 public interface TorServiceConstants {
 
-	public final static String TAG = "ORBOT";
 
 	public final static String TOR_APP_USERNAME = "org.torproject.android";
 	
-	public final static String ASSETS_BASE = "assets/";
 	
 	//home directory of Android application
 	
@@ -27,7 +25,10 @@ public interface TorServiceConstants {
 	
 	//privoxy.config
 	public final static String PRIVOXYCONFIG_ASSET_KEY = "privoxy.config";
-		
+	
+	//geoip data file asset key
+	public final static String GEOIP_ASSET_KEY = "geoip";
+	
 	//various console cmds
 	public final static String SHELL_CMD_CHMOD = "chmod";
 	public final static String SHELL_CMD_KILL = "kill -9";
diff --git a/src/org/torproject/android/service/TorServiceUtils.java b/src/org/torproject/android/service/TorServiceUtils.java
index 657d525..51d6378 100644
--- a/src/org/torproject/android/service/TorServiceUtils.java
+++ b/src/org/torproject/android/service/TorServiceUtils.java
@@ -9,47 +9,15 @@ import java.io.InputStreamReader;
 import java.io.OutputStreamWriter;
 import java.util.StringTokenizer;
 
+import org.torproject.android.TorConstants;
+
 import android.util.Log;
 
 public class TorServiceUtils implements TorServiceConstants {
 
-	/**
-	 * Check if we have root access
-	 * @return boolean true if we have root
-	 */
-	/*
-	  public static boolean checkRootAccess() {
-	 
-	
-
-		StringBuilder log = new StringBuilder();
-		
-		try {
-			
-			// Run an empty script just to check root access
-			String[] cmd = {"exit 0"};
-			int exitCode = TorServiceUtils.doShellCommand(cmd, log, true, true);
-			if (exitCode == 0) {
-				
-				return true;
-			}
-			
-		} catch (IOException e) {
-			//this means that there is no root to be had (normally) so we won't log anything
-			TorService.logException("Error checking for root access",e);
-			
-		}
-		catch (Exception e) {
-			TorService.logException("Error checking for root access",e);
-			//this means that there is no root to be had (normally)
-		}
-		
-		TorService.logMessage("Could not acquire root permissions");
-		return false;
-	}
-	*/
 	
-	public static boolean checkRootAccess(){
+	public static boolean isRootPossible()
+	{
 		
 		StringBuilder log = new StringBuilder();
 		
@@ -79,6 +47,8 @@ public class TorServiceUtils implements TorServiceConstants {
 		}
 		
 		TorService.logMessage("Could not acquire root permissions");
+		
+		
 		return false;
 	}
 	
@@ -102,7 +72,7 @@ public class TorServiceUtils implements TorServiceConstants {
 			}
 			catch (Exception e2)
 			{
-				Log.w(TAG,"Unable to get proc id for: " + command,e2);
+				Log.w(TorConstants.TAG,"Unable to get proc id for: " + command,e2);
 			}
 		}
 		
diff --git a/src/org/torproject/android/service/TorTransProxy.java b/src/org/torproject/android/service/TorTransProxy.java
index de8ea83..2c1119a 100644
--- a/src/org/torproject/android/service/TorTransProxy.java
+++ b/src/org/torproject/android/service/TorTransProxy.java
@@ -2,16 +2,16 @@ package org.torproject.android.service;
 
 import java.io.File;
 
-import org.torproject.android.TorifiedApp;
+import org.torproject.android.TorConstants;
+import org.torproject.android.settings.TorifiedApp;
 
 import android.content.Context;
 import android.util.Log;
 
 public class TorTransProxy implements TorServiceConstants {
 	
-	private final static String TAG = TorServiceConstants.TAG;
+	private final static String TAG = TorConstants.TAG;
 		
-
 	
 	public static int purgeIptables(Context context) throws Exception {
 		



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits