updated strings; modified iptables clear behavior;

This commit is contained in:
Nathan Freitas 2011-11-12 11:56:16 -05:00
parent 4dda90e480
commit 8e199a3e9c
2 changed files with 119 additions and 100 deletions

View File

@ -183,5 +183,21 @@
<string name="pref_proxy_port_title">Proxy Port</string> <string name="pref_proxy_port_title">Proxy Port</string>
<string name="pref_proxy_port_summary">Proxy server port</string> <string name="pref_proxy_port_summary">Proxy server port</string>
<string name="pref_proxy_port_dialog">Enter Proxy port</string> <string name="pref_proxy_port_dialog">Enter Proxy port</string>
<string name="status">Status</string>
<string name="setting_up_full_transparent_proxying_">Setting up full transparent proxying...</string>
<string name="setting_up_app_based_transparent_proxying_">Setting up app-based transparent proxying...</string>
<string name="transparent_proxying_enabled">Transparent proxying ENABLED</string>
<string name="transproxy_enabled_for_tethering_">TransProxy enabled for Tethering!</string>
<string name="warning_error_starting_transparent_proxying_">WARNING: error starting transparent proxying!</string>
<string name="transproxy_rules_cleared">TransProxy rules cleared</string>
<string name="couldn_t_start_tor_process_">"Couldn't start Tor process: "</string>
<string name="privoxy_is_running_on_port_">Privoxy is running on port: </string>
<string name="setting_up_port_based_transparent_proxying_">Setting up port-based transparent proxying...</string>
<string name="bridge_error">Bridge Error</string>
<string name="bridge_requires_ip">In order to use the bridge feature, you must enter at least one bridge IP address.</string>
<string name="send_email_for_bridges">Send an email to bridges@torproject.org with the line \"get bridges\" by itself in the body of the mail from a gmail account.</string>
<string name="error">Error</string>
<string name="your_reachableaddresses_settings_caused_an_exception_">Your ReachableAddresses settings caused an exception!</string>
<string name="your_relay_settings_caused_an_exception_">Your relay settings caused an exception!</string>
</resources> </resources>

View File

@ -275,7 +275,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
showToolbarNotification (getString(R.string.status_disabled),NOTIFY_ID,R.drawable.tornotificationoff); showToolbarNotification (getString(R.string.status_disabled),NOTIFY_ID,R.drawable.tornotificationoff);
sendCallbackStatusMessage(getString(R.string.status_disabled)); sendCallbackStatusMessage(getString(R.string.status_disabled));
setupTransProxy(false); clearTransparentProxy();
} }
catch (Exception e) catch (Exception e)
{ {
@ -495,7 +495,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
try { try {
setupTransProxy(true); enableTransparentProxy();
runTorShellCmd(); runTorShellCmd();
runPrivoxyShellCmd(); runPrivoxyShellCmd();
@ -513,20 +513,16 @@ public class TorService extends Service implements TorServiceConstants, TorConst
* *
* the idea is that if Tor is off then transproxy is off * the idea is that if Tor is off then transproxy is off
*/ */
private boolean setupTransProxy (boolean activate) throws Exception private boolean enableTransparentProxy () throws Exception
{ {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean hasRoot = prefs.getBoolean(PREF_HAS_ROOT,false); boolean hasRoot = prefs.getBoolean(PREF_HAS_ROOT,false);
boolean enableTransparentProxy = prefs.getBoolean("pref_transparent", false);
if (!hasRoot) if (hasRoot && enableTransparentProxy)
{
}
else if (activate)
{ {
boolean enableTransparentProxy = prefs.getBoolean("pref_transparent", false);
boolean transProxyAll = prefs.getBoolean("pref_transparent_all", false); boolean transProxyAll = prefs.getBoolean("pref_transparent_all", false);
boolean transProxyPortFallback = prefs.getBoolean("pref_transparent_port_fallback", false); boolean transProxyPortFallback = prefs.getBoolean("pref_transparent_port_fallback", false);
boolean transProxyTethering = prefs.getBoolean("pref_transparent_tethering", false); boolean transProxyTethering = prefs.getBoolean("pref_transparent_tethering", false);
@ -535,83 +531,92 @@ public class TorService extends Service implements TorServiceConstants, TorConst
String portProxyList = prefs.getString("pref_port_list", ""); String portProxyList = prefs.getString("pref_port_list", "");
if (enableTransparentProxy)
{ //TODO: Find a nice place for the next (commented) line
//TODO: Find a nice place for the next (commented) line //TorTransProxy.setDNSProxying();
//TorTransProxy.setDNSProxying();
int code = 0; // Default state is "okay"
int code = 0; // Default state is "okay" if(transProxyPortFallback)
{
if(transProxyPortFallback) showAlert(getString(R.string.status), getString(R.string.setting_up_port_based_transparent_proxying_));
StringTokenizer st = new StringTokenizer(portProxyList, ",");
int status = code;
while (st.hasMoreTokens())
{ {
showAlert("Status", "Setting up port-based transparent proxying..."); status = TorTransProxy.setTransparentProxyingByPort(this, Integer.parseInt(st.nextToken()));
StringTokenizer st = new StringTokenizer(portProxyList, ","); if(status != 0)
int status = code; code = status;
while (st.hasMoreTokens()) }
{ }
status = TorTransProxy.setTransparentProxyingByPort(this, Integer.parseInt(st.nextToken())); else
if(status != 0) {
code = status; if(transProxyAll)
} {
showAlert(getString(R.string.status), getString(R.string.setting_up_full_transparent_proxying_));
code = TorTransProxy.setTransparentProxyingAll(this);
} }
else else
{ {
if(transProxyAll) showAlert(getString(R.string.status), getString(R.string.setting_up_app_based_transparent_proxying_));
{ code = TorTransProxy.setTransparentProxyingByApp(this,AppManager.getApps(this));
showAlert("Status", "Setting up full transparent proxying...");
code = TorTransProxy.setTransparentProxyingAll(this);
}
else
{
showAlert("Status", "Setting up app-based transparent proxying...");
code = TorTransProxy.setTransparentProxyingByApp(this,AppManager.getApps(this));
}
} }
}
TorService.logMessage ("TorTransProxy resp code: " + code);
TorService.logMessage ("TorTransProxy resp code: " + code); if (code == 0)
{
showAlert(getString(R.string.status), getString(R.string.transparent_proxying_enabled));
if (code == 0)
if (transProxyTethering)
{ {
showAlert("Status", "Transparent proxying ENABLED"); showAlert(getString(R.string.status), getString(R.string.transproxy_enabled_for_tethering_));
TorTransProxy.enableTetheringRules(this);
if (transProxyTethering)
{
showAlert("Status", "TransProxy enabled for Tethering!");
TorTransProxy.enableTetheringRules(this);
// mBinder.updateConfiguration("TransListenAddress", "0.0.0.0", false);
// mBinder.updateConfiguration("DNSListenAddress", "0.0.0.0", false);
}
} }
else }
{ else
showAlert("Status", "WARNING: error starting transparent proxying!"); {
} showAlert(getString(R.string.status), getString(R.string.warning_error_starting_transparent_proxying_));
}
return true;
return true;
}
else
{
TorTransProxy.purgeIptables(this);
showAlert("Status", "Transparent proxying: DISABLED");
}
}
else
{
TorTransProxy.purgeIptables(this);
showAlert("Status", "Transparent proxying: DISABLED");
} }
else
return false;
}
/*
* activate means whether to apply the users preferences
* or clear them out
*
* the idea is that if Tor is off then transproxy is off
*/
private boolean clearTransparentProxy () throws Exception
{
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
return true; boolean hasRoot = prefs.getBoolean(PREF_HAS_ROOT,false);
boolean enableTransparentProxy = prefs.getBoolean("pref_transparent", false);
if (hasRoot && enableTransparentProxy)
{
TorService.logMessage ("Clearing TransProxy rules");
TorTransProxy.purgeIptables(this);
showAlert(getString(R.string.status), getString(R.string.transproxy_rules_cleared));
return true;
}
else
return false;
} }
private void runTorShellCmd() throws Exception private void runTorShellCmd() throws Exception
@ -657,7 +662,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
if (procId == -1) if (procId == -1)
{ {
sendCallbackStatusMessage("Couldn't start Tor process.\nretrying..." + log.toString()); sendCallbackStatusMessage(getString(R.string.couldn_t_start_tor_process_) + log.toString());
Thread.sleep(torRetryWaitTimeMS); Thread.sleep(torRetryWaitTimeMS);
attempts++; attempts++;
} }
@ -723,7 +728,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
logNotice(log.toString()); logNotice(log.toString());
} }
sendCallbackLogMessage("Privoxy is running on port: " + PORT_HTTP); sendCallbackLogMessage(getString(R.string.privoxy_is_running_on_port_) + PORT_HTTP);
logNotice("Privoxy process id=" + privoxyProcId); logNotice("Privoxy process id=" + privoxyProcId);
@ -926,13 +931,6 @@ public class TorService extends Service implements TorServiceConstants, TorConst
private void showAlert(String title, String msg) private void showAlert(String title, String msg)
{ {
/*
new AlertDialog.Builder(this)
.setTitle(title)
.setMessage(msg)
.setPositiveButton(android.R.string.ok, null)
.show();
*/
showToolbarNotification(msg, NOTIFY_ID, R.drawable.tornotification); showToolbarNotification(msg, NOTIFY_ID, R.drawable.tornotification);
} }
@ -1088,6 +1086,25 @@ public class TorService extends Service implements TorServiceConstants, TorConst
try { try {
applyPreferences(); applyPreferences();
if (currentStatus == STATUS_ON)
{
//reset iptables rules in active mode
try
{
clearTransparentProxy();
enableTransparentProxy();
}
catch (Exception e)
{
logException("unable to setup transproxy",e);
}
}
} catch (RemoteException e) { } catch (RemoteException e) {
logException ("error applying prefs",e); logException ("error applying prefs",e);
} }
@ -1304,20 +1321,6 @@ public class TorService extends Service implements TorServiceConstants, TorConst
} }
} }
if (currentStatus == STATUS_ON)
{
//reset iptables rules in active mode
try
{
setupTransProxy(true);
}
catch (Exception e)
{
logException("unable to setup transproxy",e);
}
}
File fileGeoIP = new File(appBinHome,"geoip"); File fileGeoIP = new File(appBinHome,"geoip");
mBinder.updateConfiguration("GeoIPFile", fileGeoIP.getAbsolutePath(), false); mBinder.updateConfiguration("GeoIPFile", fileGeoIP.getAbsolutePath(), false);
mBinder.updateConfiguration("EntryNodes", entranceNodes, false); mBinder.updateConfiguration("EntryNodes", entranceNodes, false);
@ -1332,8 +1335,8 @@ public class TorService extends Service implements TorServiceConstants, TorConst
if (bridgeList == null || bridgeList.length() == 0) if (bridgeList == null || bridgeList.length() == 0)
{ {
showAlert("Bridge Error","In order to use the bridge feature, you must enter at least one bridge IP address." + showAlert(getString(R.string.bridge_error),getString(R.string.bridge_requires_ip) +
"Send an email to bridges@torproject.org with the line \"get bridges\" by itself in the body of the mail from a gmail account."); getString(R.string.send_email_for_bridges));
return false; return false;
@ -1383,7 +1386,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
} }
catch (Exception e) catch (Exception e)
{ {
showAlert("Config Error","Your ReachableAddresses settings caused an exception!"); showAlert(getString(R.string.error),getString(R.string.your_reachableaddresses_settings_caused_an_exception_));
return false; return false;
} }
@ -1409,7 +1412,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
} }
catch (Exception e) catch (Exception e)
{ {
showAlert("Uh-oh!","Your relay settings caused an exception!"); showAlert(getString(R.string.error),getString(R.string.your_relay_settings_caused_an_exception_));
return false; return false;
} }