[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r15441: Implement "Test Settings" button in the proxy preferences wi (in torbutton/trunk/src: chrome/content chrome/locale/en-US components defaults/preferences)
Author: mikeperry
Date: 2008-06-24 02:11:08 -0400 (Tue, 24 Jun 2008)
New Revision: 15441
Modified:
torbutton/trunk/src/chrome/content/preferences.js
torbutton/trunk/src/chrome/content/preferences.xul
torbutton/trunk/src/chrome/content/torbutton.js
torbutton/trunk/src/chrome/content/torbutton_util.js
torbutton/trunk/src/chrome/locale/en-US/torbutton.dtd
torbutton/trunk/src/chrome/locale/en-US/torbutton.properties
torbutton/trunk/src/components/torbutton-logger.js
torbutton/trunk/src/defaults/preferences/preferences.js
Log:
Implement "Test Settings" button in the proxy preferences
window. No automated checks yet.. we'll see how this works
out for a release or so. Also, new strings and "Restore
Defaults" tweaks.
Modified: torbutton/trunk/src/chrome/content/preferences.js
===================================================================
--- torbutton/trunk/src/chrome/content/preferences.js 2008-06-23 21:40:36 UTC (rev 15440)
+++ torbutton/trunk/src/chrome/content/preferences.js 2008-06-24 06:11:08 UTC (rev 15441)
@@ -358,6 +358,59 @@
if (tor_enabled) torbutton_activate_tor_settings();
}
+function torbutton_prefs_test_settings() {
+
+ // Reset Tor state to disabled.
+ var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
+ .getService(Components.interfaces.nsIWindowMediator);
+ var chrome = wm.getMostRecentWindow("navigator:browser");
+
+ var strings = torbutton_get_stringbundle();
+ if(chrome.m_tb_ff3) {
+ // FIXME: This is kind of ghetto.. can we make a progress
+ // bar or a window that updates itself?
+ var warning = strings.GetStringFromName("torbutton.popup.test.ff3_notice");
+ window.alert(warning);
+ }
+ var ret = chrome.torbutton_test_settings();
+ // Strange errors are not worth translating. Our english users will
+ // tell us they happen and we will (presumably) make them not happen.
+ if(ret < 0) {
+ ret = -ret;
+ window.alert("Tor proxy test: HTTP error for check.torproject.org: "+ret);
+ return;
+ }
+
+ switch(ret) {
+ case 0:
+ window.alert("Tor proxy test: Internal error");
+ break;
+ case 1:
+ window.alert("Tor proxy test: Result not mimetype text/xml");
+ break;
+ case 3: // Can't seem to happen
+ window.alert("Tor proxy test: Can't find result target!");
+ break;
+ case 2:
+ window.alert("Tor proxy test: No TorCheckResult id found (response not valid XHTML)");
+ break;
+ case 4:
+ var warning = strings.GetStringFromName("torbutton.popup.test.success");
+ window.alert(warning);
+ break;
+ case 5:
+ var warning = strings.GetStringFromName("torbutton.popup.test.failure");
+ window.alert(warning);
+ break;
+ case 6:
+ window.alert("Tor proxy test: TorDNSEL failure. Results unknown.");
+ break;
+ case 7:
+ window.alert("Tor proxy test: check.torproject.org returned bad result");
+ break;
+ }
+}
+
function torbutton_prefs_reset_defaults() {
var o_torprefs = torbutton_get_prefbranch('extensions.torbutton.');
var o_proxyprefs = torbutton_get_prefbranch('network.proxy.');
@@ -366,7 +419,7 @@
var i;
var was_enabled = false;
var loglevel = o_torprefs.getIntPref("loglevel");
- var loglmthd = o_torprefs.getIntPref("logmethod");
+ var logmthd = o_torprefs.getIntPref("logmethod");
torbutton_log(3, "Starting Pref reset");
@@ -414,7 +467,7 @@
// Reset browser prefs that torbutton touches just in case
// they get horked. Better everything gets set back to default
- // than some arcane pref gets wedged with no clear way to do it.
+ // than some arcane pref gets wedged with no clear way to fix it.
// Technical users who tuned these by themselves will be able to fix it.
// It's the non-technical ones we should make it easy for
torbutton_reset_browser_prefs();
@@ -429,7 +482,7 @@
torbutton_log(4, "Tor still enabled after reset. Attempting to restore sanity");
chrome.torbutton_set_status();
} else {
- chrome.torbutton_enable_tor();
+ chrome.torbutton_enable_tor(true);
}
}
Modified: torbutton/trunk/src/chrome/content/preferences.xul
===================================================================
--- torbutton/trunk/src/chrome/content/preferences.xul 2008-06-23 21:40:36 UTC (rev 15440)
+++ torbutton/trunk/src/chrome/content/preferences.xul 2008-06-24 06:11:08 UTC (rev 15441)
@@ -8,7 +8,7 @@
xmlns:html="http://www.w3.org/1999/xhtml"
title="&torbutton.prefs.title;"
buttons="accept,cancel,extra1"
- buttonlabelextra1="Restore Defaults"
+ buttonlabelextra1="&torbutton.prefs.restore_defaults;"
ondialogextra1="torbutton_prefs_reset_defaults();"
persist="screenX screenY"
onload="torbutton_prefs_init(document)"
@@ -102,6 +102,13 @@
<checkbox id="torbutton_lockedMode"
label="&torbutton.prefs.locked_mode;"
oncommand="torbutton_prefs_set_field_attributes(document)"/>
+
+ <hbox>
+ <spacer flex="1"/>
+ <button id="torbutton_testSettings"
+ label="&torbutton.prefs.test_settings;"
+ oncommand="torbutton_prefs_test_settings()"/>
+ </hbox>
</vbox>
<!--
<label value="&torbutton.prefs.non_socks;" control="nonsocks_proxy"/>
Modified: torbutton/trunk/src/chrome/content/torbutton.js
===================================================================
--- torbutton/trunk/src/chrome/content/torbutton.js 2008-06-23 21:40:36 UTC (rev 15440)
+++ torbutton/trunk/src/chrome/content/torbutton.js 2008-06-24 06:11:08 UTC (rev 15441)
@@ -244,7 +244,7 @@
torbutton_disable_tor();
} else {
torbutton_close_on_toggle(true);
- torbutton_enable_tor();
+ torbutton_enable_tor(false);
}
}
@@ -282,30 +282,11 @@
m_tb_prefs.setBoolPref("extensions.torbutton.tor_enabled", true);
m_tb_prefs.setBoolPref("extensions.torbutton.proxies_applied", true);
m_tb_prefs.setBoolPref("extensions.torbutton.settings_applied", true);
- torbutton_enable_tor();
+ torbutton_enable_tor(true);
}
}
}
-// load localization strings
-function torbutton_get_stringbundle()
-{
- var o_stringbundle = false;
-
- try {
- var oBundle = Components.classes["@mozilla.org/intl/stringbundle;1"]
- .getService(Components.interfaces.nsIStringBundleService);
- o_stringbundle = oBundle.createBundle("chrome://torbutton/locale/torbutton.properties");
- } catch(err) {
- o_stringbundle = false;
- }
- if (!o_stringbundle) {
- torbutton_log(5, 'ERROR (init): failed to find torbutton-bundle');
- }
-
- return o_stringbundle;
-}
-
function torbutton_init_toolbutton(event)
{
if (event.originalTarget && event.originalTarget.getAttribute('id') == 'torbutton-button')
@@ -538,16 +519,95 @@
torbutton_log(2, 'settings restored');
}
+function torbutton_test_settings() {
+ var wasEnabled = true;
+ var ret = 0;
+ if(!torbutton_check_status()) {
+ wasEnabled = false;
+ torbutton_enable_tor(true);
+ }
+
+ torbutton_log(3, "Testing Tor settings");
+
+ m_tb_prefs.setBoolPref("extensions.torbutton.test_failed", true);
+ try {
+ var req = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"]
+ .createInstance(Components.interfaces.nsIXMLHttpRequest);
+ //var req = new XMLHttpRequest(); Blocked by content policy
+ var url = m_tb_prefs.getCharPref("extensions.torbutton.test_url");
+ req.open('GET', url, false);
+ req.overrideMimeType("text/xml");
+ req.send(null);
+ } catch(e) {
+ // XXX: This happens if this function is called from a browser
+ // window with tor disabled because the content policy will block us.
+ // Right now the check works because we get called from the
+ // preference window. Sort of makes automatic testing a bit trickier..
+ if(!wasEnabled) torbutton_disable_tor();
+ torbutton_log(5, "Test failed! Tor internal error: "+e);
+ return 0;
+ }
+ if(req.status == 200) {
+ if(!req.responseXML) {
+ if(!wasEnabled) torbutton_disable_tor();
+ torbutton_log(5, "Test failed! Not text/xml!");
+ return 1;
+ }
+
+ var result = req.responseXML.getElementById('TorCheckResult');
+
+ if(result===null) {
+ torbutton_log(5, "Test failed! No TorCheckResult element");
+ ret = 2;
+ } else if(typeof(result.target) == 'undefined'
+ || result.target === null) {
+ torbutton_log(5, "Test failed! No target");
+ ret = 3;
+ } else if(result.target === "success") {
+ torbutton_log(3, "Test Successful");
+ m_tb_prefs.setBoolPref("extensions.torbutton.test_failed", false);
+ ret = 4;
+ } else if(result.target === "failure") {
+ torbutton_log(5, "Tor test failed!");
+ ret = 5;
+ } else if(result.target === "unknown") {
+ torbutton_log(5, "Tor test failed. TorDNSEL Failure?");
+ ret = 6;
+ } else {
+ // XXX: Probably wise to remove this log message if it doesn't
+ // happen..
+ torbutton_log(5, "Tor test failed. Strange target: "+result.target);
+ ret = 7;
+ }
+ } else {
+ torbutton_log(5, "Tor test failed. HTTP Error: "+req.status);
+ ret = -req.status;
+ }
+
+ torbutton_log(3, "Done testing Tor settings. Result: "+ret);
+
+ if(!wasEnabled) torbutton_disable_tor();
+ return ret;
+}
+
function torbutton_disable_tor()
{
torbutton_log(3, 'called disable_tor()');
torbutton_restore_nontor_settings();
}
-function torbutton_enable_tor()
+function torbutton_enable_tor(force)
{
torbutton_log(3, 'called enable_tor()');
+ if(!force && m_tb_prefs.getBoolPref("extensions.torbutton.test_failed")) {
+ var strings = torbutton_get_stringbundle();
+ var warning = strings.GetStringFromName("torbutton.popup.test.confirm_toggle");
+ if(!window.confirm(warning)) {
+ return;
+ }
+ }
+
torbutton_save_nontor_settings();
torbutton_activate_tor_settings();
}
@@ -1722,7 +1782,7 @@
torbutton_log(4, "Restoring tor state");
if (torbutton_check_status() == state) return;
- if(state) torbutton_enable_tor();
+ if(state) torbutton_enable_tor(true);
else torbutton_disable_tor();
}
@@ -1822,7 +1882,7 @@
// Reset all browser prefs that torbutton touches just in case
// they get horked. Better everything gets set back to default
- // than some arcane pref gets wedged with no clear way to do it.
+ // than some arcane pref gets wedged with no clear way to fix it.
// Technical users who tuned these by themselves will be able to fix it.
// It's the non-technical ones we should make it easy for
torbutton_reset_browser_prefs();
Modified: torbutton/trunk/src/chrome/content/torbutton_util.js
===================================================================
--- torbutton/trunk/src/chrome/content/torbutton_util.js 2008-06-23 21:40:36 UTC (rev 15440)
+++ torbutton/trunk/src/chrome/content/torbutton_util.js 2008-06-24 06:11:08 UTC (rev 15441)
@@ -167,3 +167,22 @@
torbutton_log(2, 'Done activating tor settings');
}
+// load localization strings
+function torbutton_get_stringbundle()
+{
+ var o_stringbundle = false;
+
+ try {
+ var oBundle = Components.classes["@mozilla.org/intl/stringbundle;1"]
+ .getService(Components.interfaces.nsIStringBundleService);
+ o_stringbundle = oBundle.createBundle("chrome://torbutton/locale/torbutton.properties");
+ } catch(err) {
+ o_stringbundle = false;
+ }
+ if (!o_stringbundle) {
+ torbutton_log(5, 'ERROR (init): failed to find torbutton-bundle');
+ }
+
+ return o_stringbundle;
+}
+
Modified: torbutton/trunk/src/chrome/locale/en-US/torbutton.dtd
===================================================================
--- torbutton/trunk/src/chrome/locale/en-US/torbutton.dtd 2008-06-23 21:40:36 UTC (rev 15440)
+++ torbutton/trunk/src/chrome/locale/en-US/torbutton.dtd 2008-06-24 06:11:08 UTC (rev 15441)
@@ -81,4 +81,7 @@
<!ENTITY torbutton.prefs.nonontor_sessionstore "Prevent session store from saving Non-Tor loaded tabs">
<!ENTITY torbutton.prefs.block_tor_file_net "Block Tor access to network from file:// urls (recommended)">
<!ENTITY torbutton.prefs.block_nontor_file_net "Block Non-Tor access to network from file:// urls">
-
+<!ENTITY torbutton.prefs.restore_defaults "Restore Defaults">
+<!ENTITY torbutton.prefs.test_settings "Test Settings">
+<!ENTITY torbutton.prefs.test_auto "Test my Tor settings after the first time I toggle on every Firefox start">
+<!ENTITY torbutton.prefs.disable_livemarks "Disable livemarks updates during Tor usage">
Modified: torbutton/trunk/src/chrome/locale/en-US/torbutton.properties
===================================================================
--- torbutton/trunk/src/chrome/locale/en-US/torbutton.properties 2008-06-23 21:40:36 UTC (rev 15440)
+++ torbutton/trunk/src/chrome/locale/en-US/torbutton.properties 2008-06-24 06:11:08 UTC (rev 15441)
@@ -11,4 +11,13 @@
torbutton.popup.plugin.warning = Torbutton blocked direct Tor load of plugin content.\n\nUse Save-As instead.\n\n
torbutton.popup.confirm_ca_certs = Torbutton Note: It appears you have no custom Certificate Authorities. Examining the Certificate Authority list is a slow operation and slows down Tor toggle. Would you like to disable the isolation of Certificate Authority certificates? (If you don't understand this, it is safe to click OK)
torbutton.popup.ff3.warning = Warning!\n\nTorbutton on Firefox 3 is known to leak your timezone and livemark feeds during Tor usage. In addition, it has not been as extensively tested for Tor security and usability as Firefox 2.\n\nDo you wish to continue anyway?
-torbutton.popup.toggle.warning = You need to toggle Tor for your settings to take effect.
+torbutton.popup.toggle.warning = You need to toggle Tor or restart for your settings to take effect.
+torbutton.popup.test.success = Tor proxy test successful!
+torbutton.popup.test.failure = Tor proxy test FAILED! Check your proxy and Privoxy settings.
+torbutton.popup.test.confirm_toggle = The most recent Tor proxy test failed to use Tor.\n\nAre you sure you want to enable anyway?
+torbutton.popup.test.ff3_notice = Click OK to test Tor proxy settings. This test will happen in the background. Please be patient.
+torbutton.panel.label.verified = Tor Verified
+torbutton.popup.test.auto_failed = The automatic Tor proxy test failed to use Tor.\n\nAre you sure you want to enable anyway?
+torbutton.prefs.recommended = (recommended)
+torbutton.prefs.optional = (optional)
+torbutton.prefs.crucial = (crucial)
Modified: torbutton/trunk/src/components/torbutton-logger.js
===================================================================
--- torbutton/trunk/src/components/torbutton-logger.js 2008-06-23 21:40:36 UTC (rev 15440)
+++ torbutton/trunk/src/components/torbutton-logger.js 2008-06-24 06:11:08 UTC (rev 15441)
@@ -92,7 +92,7 @@
formatLog: function(str, level) {
var d = new Date();
var now = padInt(d.getUTCMonth()+1)+"-"+padInt(d.getUTCDate())+" "+padInt(d.getUTCHours())+":"+padInt(d.getUTCMinutes())+":"+padInt(d.getUTCSeconds());
- return "["+now+"] Torbutton("+logString[level]+"): "+str;
+ return "["+now+"] Torbutton "+logString[level]+": "+str;
},
// error console log
Modified: torbutton/trunk/src/defaults/preferences/preferences.js
===================================================================
--- torbutton/trunk/src/defaults/preferences/preferences.js 2008-06-23 21:40:36 UTC (rev 15440)
+++ torbutton/trunk/src/defaults/preferences/preferences.js 2008-06-24 06:11:08 UTC (rev 15441)
@@ -22,6 +22,8 @@
pref("extensions.torbutton.socks_host","");
pref("extensions.torbutton.socks_port",0);
pref("extensions.torbutton.locked_mode",false);
+pref("extensions.torbutton.test_url","https://check.torproject.org/?TorButton=true");
+pref("extensions.torbutton.test_failed",false);
// XXX: wtf prefs? These seem not actually connected, but govern
// if user wants own tor proxy settings
@@ -49,6 +51,7 @@
pref("extensions.torbutton.saved.socks_host","");
pref("extensions.torbutton.saved.socks_version",0);
pref("extensions.torbutton.saved.socks_port",0);
+pref("extensions.torbutton.saved.socks_remote_dns",false);
pref("extensions.torbutton.saved.cookieLifetime",0);
pref("extensions.torbutton.saved.full_page_plugins","");
@@ -60,7 +63,7 @@
pref("extensions.torbutton.saved.download_retention", 2);
pref("extensions.torbutton.saved.formfill", true);
pref("extensions.torbutton.saved.remember_signons", true);
-pref("extensions.torbutton.saved.livemark_refresh", true);
+pref("extensions.torbutton.saved.livemark_refresh", 0);
pref("extensions.torbutton.saved.sendSecureXSiteReferrer", true);
pref("extensions.torbutton.saved.sendRefererHeader", 2);
pref("extensions.torbutton.saved.dom_storage", true);