small changes to naming of iptables methods
This commit is contained in:
		
							parent
							
								
									e206a241ab
								
							
						
					
					
						commit
						2b1969fea0
					
				| 
						 | 
				
			
			@ -10,6 +10,7 @@ import java.io.FileOutputStream;
 | 
			
		|||
import java.io.IOException;
 | 
			
		||||
import java.io.InputStream;
 | 
			
		||||
import java.io.OutputStream;
 | 
			
		||||
import java.util.zip.GZIPInputStream;
 | 
			
		||||
import java.util.zip.GZIPOutputStream;
 | 
			
		||||
import java.util.zip.ZipEntry;
 | 
			
		||||
import java.util.zip.ZipFile;
 | 
			
		||||
| 
						 | 
				
			
			@ -65,7 +66,20 @@ public class TorBinaryInstaller implements TorServiceConstants {
 | 
			
		|||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	private static void copyAssetFile(Context ctx, String asset, File file) throws IOException, InterruptedException
 | 
			
		||||
	{
 | 
			
		||||
    	
 | 
			
		||||
		DataOutputStream out = new DataOutputStream(new FileOutputStream(file));
 | 
			
		||||
		InputStream is = new GZIPInputStream(ctx.getAssets().open(asset));
 | 
			
		||||
		
 | 
			
		||||
		byte buf[] = new byte[8172];
 | 
			
		||||
		int len;
 | 
			
		||||
		while ((len = is.read(buf)) > 0) {
 | 
			
		||||
			out.write(buf, 0, len);
 | 
			
		||||
		}
 | 
			
		||||
		out.close();
 | 
			
		||||
		is.close();
 | 
			
		||||
	}
 | 
			
		||||
	/*
 | 
			
		||||
	 * Write the inputstream contents to the file
 | 
			
		||||
	 */
 | 
			
		||||
| 
						 | 
				
			
			@ -97,7 +111,7 @@ public class TorBinaryInstaller implements TorServiceConstants {
 | 
			
		|||
        }
 | 
			
		||||
 | 
			
		||||
        stmOut.close();
 | 
			
		||||
 | 
			
		||||
        stm.close();
 | 
			
		||||
        
 | 
			
		||||
        return true;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -275,7 +275,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
 | 
			
		|||
    		showToolbarNotification (getString(R.string.status_disabled),NOTIFY_ID,R.drawable.tornotificationoff);
 | 
			
		||||
    		sendCallbackStatusMessage(getString(R.string.status_disabled));
 | 
			
		||||
 | 
			
		||||
    		clearTransparentProxy();
 | 
			
		||||
    		disableTransparentProxy();
 | 
			
		||||
    	}
 | 
			
		||||
    	catch (Exception e)
 | 
			
		||||
    	{
 | 
			
		||||
| 
						 | 
				
			
			@ -597,7 +597,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
 | 
			
		|||
     * 
 | 
			
		||||
     * the idea is that if Tor is off then transproxy is off
 | 
			
		||||
     */
 | 
			
		||||
    private boolean clearTransparentProxy () throws Exception
 | 
			
		||||
    private boolean disableTransparentProxy () throws Exception
 | 
			
		||||
 	{
 | 
			
		||||
    	SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
 | 
			
		||||
    	
 | 
			
		||||
| 
						 | 
				
			
			@ -609,7 +609,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
 | 
			
		|||
	 		
 | 
			
		||||
	     	TorService.logMessage ("Clearing TransProxy rules");
 | 
			
		||||
	     	
 | 
			
		||||
	     	TorTransProxy.purgeIptables(this);
 | 
			
		||||
	     	TorTransProxy.flushIptables(this);
 | 
			
		||||
	     	
 | 
			
		||||
			showAlert(getString(R.string.status), getString(R.string.transproxy_rules_cleared));
 | 
			
		||||
	     	
 | 
			
		||||
| 
						 | 
				
			
			@ -1095,7 +1095,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
 | 
			
		|||
		        
 | 
			
		||||
					try
 | 
			
		||||
					{
 | 
			
		||||
						clearTransparentProxy();
 | 
			
		||||
						disableTransparentProxy();
 | 
			
		||||
			    		enableTransparentProxy();
 | 
			
		||||
					}
 | 
			
		||||
					catch (Exception e)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -24,13 +24,13 @@ public class TorServiceUtils implements TorServiceConstants {
 | 
			
		|||
		try {
 | 
			
		||||
			
 | 
			
		||||
			// Check if Superuser.apk exists
 | 
			
		||||
			File file = new File("/system/app/Superuser.apk");
 | 
			
		||||
			//File file = new File("/system/app/Superuser.apk");
 | 
			
		||||
			
 | 
			
		||||
			//Check for 'su' binary 
 | 
			
		||||
			String[] cmd = {"which su"};
 | 
			
		||||
			int exitCode = TorServiceUtils.doShellCommand(cmd, log, false, true);
 | 
			
		||||
			
 | 
			
		||||
			if (file.exists() && exitCode == 0) {
 | 
			
		||||
			if (exitCode == 0) {
 | 
			
		||||
				TorService.logMessage("Can acquire root permissions");
 | 
			
		||||
		    	 return true;
 | 
			
		||||
		     
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,7 +13,7 @@ public class TorTransProxy implements TorServiceConstants {
 | 
			
		|||
	private final static String TAG = TorConstants.TAG;
 | 
			
		||||
		
 | 
			
		||||
	
 | 
			
		||||
	public static int purgeIptables(Context context) throws Exception {
 | 
			
		||||
	public static int flushIptables(Context context) throws Exception {
 | 
			
		||||
		
 | 
			
		||||
	String ipTablesPath = new File(context.getDir("bin", 0),"iptables").getAbsolutePath();
 | 
			
		||||
		
 | 
			
		||||
| 
						 | 
				
			
			@ -22,7 +22,6 @@ public class TorTransProxy implements TorServiceConstants {
 | 
			
		|||
    	StringBuilder res = new StringBuilder();
 | 
			
		||||
    	int code = -1;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		script.append(ipTablesPath);
 | 
			
		||||
		script.append(" -t nat");
 | 
			
		||||
		script.append(" -F || exit\n");
 | 
			
		||||
| 
						 | 
				
			
			@ -177,7 +176,7 @@ public class TorTransProxy implements TorServiceConstants {
 | 
			
		|||
    	StringBuilder res = new StringBuilder();
 | 
			
		||||
    	int code = -1;
 | 
			
		||||
    	
 | 
			
		||||
    	purgeIptables(context);
 | 
			
		||||
    	flushIptables(context);
 | 
			
		||||
				
 | 
			
		||||
		//build up array of shell cmds to execute under one root context
 | 
			
		||||
		for (int i = 0; i < apps.length; i++)
 | 
			
		||||
| 
						 | 
				
			
			@ -276,7 +275,7 @@ public class TorTransProxy implements TorServiceConstants {
 | 
			
		|||
    	
 | 
			
		||||
    	StringBuilder res = new StringBuilder();
 | 
			
		||||
    	int code = -1;
 | 
			
		||||
    	purgeIptables(context);
 | 
			
		||||
    	flushIptables(context);
 | 
			
		||||
		
 | 
			
		||||
		//TCP
 | 
			
		||||
		//iptables -t nat -A PREROUTING -i eth0 -p tcp --dport $srcPortNumber -j REDIRECT --to-port $dstPortNumbe
 | 
			
		||||
| 
						 | 
				
			
			@ -375,7 +374,7 @@ public class TorTransProxy implements TorServiceConstants {
 | 
			
		|||
    	StringBuilder res = new StringBuilder();
 | 
			
		||||
    	int code = -1;
 | 
			
		||||
    	
 | 
			
		||||
    	purgeIptables(context);
 | 
			
		||||
    	flushIptables(context);
 | 
			
		||||
    	
 | 
			
		||||
    	int torUid = context.getApplicationInfo().uid;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue