From 67810a8a0b08fc8697ee8fc8843af3757c12a421 Mon Sep 17 00:00:00 2001 From: jmccrohan Date: Wed, 6 Apr 2011 15:29:05 +0100 Subject: Initial Commit --- multiproxy_switch_1.33.xpi | Bin 0 -> 76967 bytes src/chrome.manifest | 20 + src/chrome/content/about.js | 97 +++ src/chrome/content/contents.rdf | 50 ++ src/chrome/content/datasource.js | 386 +++++++++++ src/chrome/content/dialogs/about.xul | 38 + src/chrome/content/dialogs/editcommon.js | 18 + src/chrome/content/dialogs/editproxy.js | 311 +++++++++ src/chrome/content/dialogs/editproxy.xul | 119 ++++ src/chrome/content/dialogs/manager.xul | 36 + src/chrome/content/globals.js | 152 ++++ src/chrome/content/icons/Thumbs.db | Bin 0 -> 9216 bytes src/chrome/content/icons/arrow-dn.gif | Bin 0 -> 56 bytes src/chrome/content/icons/check.png | Bin 0 -> 751 bytes src/chrome/content/icons/cross.png | Bin 0 -> 951 bytes src/chrome/content/icons/isp.png | Bin 0 -> 1150 bytes src/chrome/content/icons/new.png | Bin 0 -> 544 bytes src/chrome/content/icons/options.png | Bin 0 -> 1150 bytes src/chrome/content/icons/pencil.png | Bin 0 -> 810 bytes src/chrome/content/options/options.js | 80 +++ src/chrome/content/options/options.xul | 32 + src/chrome/content/proxy.js | 1080 +++++++++++++++++++++++++++++ src/chrome/content/proxy.xul | 125 ++++ src/chrome/content/proxy_moz.xul | 118 ++++ src/chrome/content/proxy_thunder.xul | 60 ++ src/chrome/content/tabmanager.js | 146 ++++ src/chrome/locale/README.txt | 12 + src/chrome/locale/cs-CZ/contents.rdf | 19 + src/chrome/locale/cs-CZ/locale.dtd | 118 ++++ src/chrome/locale/cs-CZ/locale.properties | 56 ++ src/chrome/locale/de-DE/contents.rdf | 19 + src/chrome/locale/de-DE/locale.dtd | 117 ++++ src/chrome/locale/de-DE/locale.properties | 56 ++ src/chrome/locale/en-US/contents.rdf | 19 + src/chrome/locale/en-US/locale.dtd | 117 ++++ src/chrome/locale/en-US/locale.properties | 56 ++ src/chrome/locale/es-ES/contents.rdf | 19 + src/chrome/locale/es-ES/locale.dtd | 117 ++++ src/chrome/locale/es-ES/locale.properties | 56 ++ src/chrome/locale/fa-IR/contents.rdf | 19 + src/chrome/locale/fa-IR/locale.dtd | 118 ++++ src/chrome/locale/fa-IR/locale.properties | 47 ++ src/chrome/locale/fr-FR/contents.rdf | 19 + src/chrome/locale/fr-FR/locale.dtd | 118 ++++ src/chrome/locale/fr-FR/locale.properties | 55 ++ src/chrome/locale/hu-HU/contents.rdf | 19 + src/chrome/locale/hu-HU/locale.dtd | 117 ++++ src/chrome/locale/hu-HU/locale.properties | 55 ++ src/chrome/locale/is-IS/contents.rdf | 21 + src/chrome/locale/is-IS/locale.dtd | 117 ++++ src/chrome/locale/is-IS/locale.properties | 56 ++ src/chrome/locale/it-IT/contents.rdf | 19 + src/chrome/locale/it-IT/locale.dtd | 118 ++++ src/chrome/locale/it-IT/locale.properties | 56 ++ src/chrome/locale/ja-JP/contents.rdf | 19 + src/chrome/locale/ja-JP/locale.dtd | 117 ++++ src/chrome/locale/ja-JP/locale.properties | 56 ++ src/chrome/locale/zh-CN/contents.rdf | 19 + src/chrome/locale/zh-CN/locale.dtd | 117 ++++ src/chrome/locale/zh-CN/locale.properties | 57 ++ src/chrome/locale/zh-TW/contents.rdf | 19 + src/chrome/locale/zh-TW/locale.dtd | 118 ++++ src/chrome/locale/zh-TW/locale.properties | 57 ++ src/install.rdf | 83 +++ 64 files changed, 5265 insertions(+) create mode 100644 multiproxy_switch_1.33.xpi create mode 100644 src/chrome.manifest create mode 100644 src/chrome/content/about.js create mode 100644 src/chrome/content/contents.rdf create mode 100644 src/chrome/content/datasource.js create mode 100644 src/chrome/content/dialogs/about.xul create mode 100644 src/chrome/content/dialogs/editcommon.js create mode 100644 src/chrome/content/dialogs/editproxy.js create mode 100644 src/chrome/content/dialogs/editproxy.xul create mode 100644 src/chrome/content/dialogs/manager.xul create mode 100644 src/chrome/content/globals.js create mode 100644 src/chrome/content/icons/Thumbs.db create mode 100644 src/chrome/content/icons/arrow-dn.gif create mode 100644 src/chrome/content/icons/check.png create mode 100644 src/chrome/content/icons/cross.png create mode 100644 src/chrome/content/icons/isp.png create mode 100644 src/chrome/content/icons/new.png create mode 100644 src/chrome/content/icons/options.png create mode 100644 src/chrome/content/icons/pencil.png create mode 100644 src/chrome/content/options/options.js create mode 100644 src/chrome/content/options/options.xul create mode 100644 src/chrome/content/proxy.js create mode 100644 src/chrome/content/proxy.xul create mode 100644 src/chrome/content/proxy_moz.xul create mode 100644 src/chrome/content/proxy_thunder.xul create mode 100644 src/chrome/content/tabmanager.js create mode 100644 src/chrome/locale/README.txt create mode 100644 src/chrome/locale/cs-CZ/contents.rdf create mode 100644 src/chrome/locale/cs-CZ/locale.dtd create mode 100644 src/chrome/locale/cs-CZ/locale.properties create mode 100644 src/chrome/locale/de-DE/contents.rdf create mode 100644 src/chrome/locale/de-DE/locale.dtd create mode 100644 src/chrome/locale/de-DE/locale.properties create mode 100644 src/chrome/locale/en-US/contents.rdf create mode 100644 src/chrome/locale/en-US/locale.dtd create mode 100644 src/chrome/locale/en-US/locale.properties create mode 100644 src/chrome/locale/es-ES/contents.rdf create mode 100644 src/chrome/locale/es-ES/locale.dtd create mode 100644 src/chrome/locale/es-ES/locale.properties create mode 100644 src/chrome/locale/fa-IR/contents.rdf create mode 100644 src/chrome/locale/fa-IR/locale.dtd create mode 100644 src/chrome/locale/fa-IR/locale.properties create mode 100644 src/chrome/locale/fr-FR/contents.rdf create mode 100644 src/chrome/locale/fr-FR/locale.dtd create mode 100644 src/chrome/locale/fr-FR/locale.properties create mode 100644 src/chrome/locale/hu-HU/contents.rdf create mode 100644 src/chrome/locale/hu-HU/locale.dtd create mode 100644 src/chrome/locale/hu-HU/locale.properties create mode 100644 src/chrome/locale/is-IS/contents.rdf create mode 100644 src/chrome/locale/is-IS/locale.dtd create mode 100644 src/chrome/locale/is-IS/locale.properties create mode 100644 src/chrome/locale/it-IT/contents.rdf create mode 100644 src/chrome/locale/it-IT/locale.dtd create mode 100644 src/chrome/locale/it-IT/locale.properties create mode 100644 src/chrome/locale/ja-JP/contents.rdf create mode 100644 src/chrome/locale/ja-JP/locale.dtd create mode 100644 src/chrome/locale/ja-JP/locale.properties create mode 100644 src/chrome/locale/zh-CN/contents.rdf create mode 100644 src/chrome/locale/zh-CN/locale.dtd create mode 100644 src/chrome/locale/zh-CN/locale.properties create mode 100644 src/chrome/locale/zh-TW/contents.rdf create mode 100644 src/chrome/locale/zh-TW/locale.dtd create mode 100644 src/chrome/locale/zh-TW/locale.properties create mode 100644 src/install.rdf diff --git a/multiproxy_switch_1.33.xpi b/multiproxy_switch_1.33.xpi new file mode 100644 index 0000000..3dc7567 Binary files /dev/null and b/multiproxy_switch_1.33.xpi differ diff --git a/src/chrome.manifest b/src/chrome.manifest new file mode 100644 index 0000000..48998ce --- /dev/null +++ b/src/chrome.manifest @@ -0,0 +1,20 @@ +content mproxy chrome/content/ + + +overlay chrome://browser/content/browser.xul chrome://mproxy/content/proxy.xul +overlay chrome://navigator/content/navigator.xul chrome://mproxy/content/proxy_moz.xul +overlay chrome://messenger/content/mailWindowOverlay.xul chrome://mproxy/content/proxy_thunder.xul +overlay chrome://messenger/content/messengercompose/messengercompose.xul chrome://mproxy/content/proxy_thunder.xul + +locale mproxy en-US chrome/locale/en-US/ +locale mproxy cs-CZ chrome/locale/cs-CZ/ +locale mproxy de-DE chrome/locale/de-DE/ +locale mproxy es-ES chrome/locale/es-ES/ +locale mproxy fa-IR chrome/locale/fa-IR/ +locale mproxy fr-FR chrome/locale/fr-FR/ +locale mproxy hu-HU chrome/locale/hu-HU/ +locale mproxy is-IS chrome/locale/is-IS/ +locale mproxy it-IT chrome/locale/it-IT/ +locale mproxy ja-JP chrome/locale/ja-JP/ +locale mproxy zh-CN chrome/locale/zh-CN/ +locale mproxy zh-TW chrome/locale/zh-TW/ \ No newline at end of file diff --git a/src/chrome/content/about.js b/src/chrome/content/about.js new file mode 100644 index 0000000..f8370b4 --- /dev/null +++ b/src/chrome/content/about.js @@ -0,0 +1,97 @@ + +function open_tab(UrlToGoTo) { + if( MPS_isThunderBird() ) { + var messenger = Components.classes["@mozilla.org/messenger;1"].createInstance() + .QueryInterface(Components.interfaces.nsIMessenger); + + messenger.launchExternalURL(UrlToGoTo); + } else { + var navWindow; + + // Try to get the most recently used browser window + try { + var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] + .getService(Components.interfaces.nsIWindowMediator); + navWindow = wm.getMostRecentWindow("navigator:browser"); + } catch(ex) {} + + if (navWindow) { // Open the URL in most recently used browser window + if ("delayedOpenTab" in navWindow) { + navWindow.delayedOpenTab(UrlToGoTo); + } else if ("loadURI" in navWindow) { + navWindow.loadURI(UrlToGoTo); + } else { + navWindow._content.location.href = UrlToGoTo; + } + } else { // If there is no recently used browser window open new browser window with the URL + var ass = Components.classes["@mozilla.org/appshell/appShellService;1"] + .getService(Components.interfaces.nsIAppShellService); + var win = ass.hiddenDOMWindow; + + win.openDialog("chrome://navigator/content/navigator.xul", "", + "chrome,all, dialog=no", UrlToGoTo ); + } + } + /* + var uri = Components.classes["@mozilla.org/network/standard-url;1"].createInstance(Components.interfaces.nsIURI); + uri.spec = aURL; + var protocolSvc = Components.classes["@mozilla.org/uriloader/external-protocol-service;1"].getService(Components.interfaces.nsIExternalProtocolService); + protocolSvc.loadUrl(uri); + */ +} + + +const SEAMONKEY_ID = "{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}"; +const THUNDERBIRD_ID = "{3550f703-e582-4d05-9a08-453d09bdfdc6}"; +function MPS_isThunderBird() { + var id; + if("@mozilla.org/xre/app-info;1" in Components.classes) { + // running under Mozilla 1.8 or later + id = Components.classes["@mozilla.org/xre/app-info;1"] + .getService(Components.interfaces.nsIXULAppInfo).ID; + } else { + try { + id = Components.classes["@mozilla.org/preferences-service;1"] + .getService(Components.interfaces.nsIPrefBranch) + .getCharPref("app.id"); + } catch(e) { + } + } + if ( id != null && id == THUNDERBIRD_ID ) { + return true; + } + else { + return false; + } +} + +function MPS_isSunbirdOrLightning() { + var id; + if("@mozilla.org/xre/app-info;1" in Components.classes) { + // running under Mozilla 1.8 or later + id = Components.classes["@mozilla.org/xre/app-info;1"] + .getService(Components.interfaces.nsIXULAppInfo).ID; + } else { + try { + id = Components.classes["@mozilla.org/preferences-service;1"] + .getService(Components.interfaces.nsIPrefBranch) + .getCharPref("app.id"); + } catch(e) { + } + } + + // check if this is Sunbird + if ( id != null && id == "{718e30fb-e89b-41dd-9da7-e25a45638b28}" ) { + return true; + } + else if ( id != null && id == THUNDERBIRD_ID ) { + var em = Components.classes["@mozilla.org/extensions/manager;1"] + .getService(Components.interfaces.nsIExtensionManager); + var addon = em.getItemForID("{e2fda1a4-762b-4020-b5ad-a41df1933103}"); + // check to see if the version attribute exists (if not, then the addon doesn't exist) + if ( addon != null && (addon.version != null && addon.version != "" )) { + return true; + } + } + return false; +} diff --git a/src/chrome/content/contents.rdf b/src/chrome/content/contents.rdf new file mode 100644 index 0000000..90450c4 --- /dev/null +++ b/src/chrome/content/contents.rdf @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + chrome://mproxy/content/proxy.xul + + + + + chrome://mproxy/content/proxy_moz.xul + + + + + chrome://mproxy/content/proxy_thunder.xul + + + chrome://mproxy/content/proxy_thunder.xul + + diff --git a/src/chrome/content/datasource.js b/src/chrome/content/datasource.js new file mode 100644 index 0000000..e31a1ec --- /dev/null +++ b/src/chrome/content/datasource.js @@ -0,0 +1,386 @@ +//DataSource +var gSProxyDs = null; +var gSProxyRdf = null; +var gSProxyRdfC = null; +var gSProxyRDFUtil = null + +//Initializes the RDF Datasource components +function mproxy_ds_initDataSource(){ + try{ + + // Datasource URI + if(gSProxyRdfDataSouce == "rdf:local-store"){ + var file = Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties); + var io = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService); + file = file.get("PrefD", Components.interfaces.nsILocalFile); + file.appendRelativePath("multiproxy.rdf"); + + io = io.newFileURI(file); + gSProxyRdfDataSouce = io.spec; + } + + if(gSProxyRdf == null) + gSProxyRdf = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService); + if(gSProxyDs == null) + gSProxyDs = gSProxyRdf.GetDataSourceBlocking(gSProxyRdfDataSouce); + if(gSProxyRDFUtil == null) + gSProxyRDFUtil = Components.classes["@mozilla.org/rdf/container-utils;1"].getService(Components.interfaces.nsIRDFContainerUtils); + if(gSProxyRdfC == null){ + gSProxyRdfC = Components.classes["@mozilla.org/rdf/container;1"].createInstance(Components.interfaces.nsIRDFContainer); + + //Get or Add Sequence + try{ + gSProxyRdfC.Init(gSProxyDs, gSProxyRdf.GetResource(gSProxyRdfRoot)); //Get + }catch(err){ + gSProxyRdfC = gSProxyRDFUtil.MakeSeq(gSProxyDs, gSProxyRdf.GetResource(gSProxyRdfRoot)); //Create + } + } + + }catch(err){ throw "(mproxy_ds_initDataSource)\n" + err; } +} + +//Add RDF Observer +function mproxy_ds_addObserver(oObserver){ + mproxy_ds_initDataSource(); + + try{ + gSProxyDs.AddObserver(oObserver); + }catch(err){throw "(mproxy_ds_addObserver)\n" + err} +} + +//Returns resource for the given uri +function mproxy_ds_getElement(sUri){ + mproxy_ds_initDataSource(); + + try{ + return gSProxyRdf.GetResource(sUri); + }catch(err){ throw "(mproxy_ds_getElement)\n" + err; } +} + +//Duplicate of mproxy_ds_getElement +function mproxy_ds_getResource(sAbout){ + return mproxy_ds_getElement(sAbout) +} + +//Returns array of all mproxy Element URIs +// array[index] = uri +function mproxy_ds_getAllElements(){ + mproxy_ds_initDataSource(); + + var aOut = new Array(); + var aElements = gSProxyRdfC.GetElements(); + while(aElements.hasMoreElements()){ + var oRes = aElements.getNext(); + oRes = oRes.QueryInterface(Components.interfaces.nsIRDFResource); + + aOut[aOut.length] = oRes.Value; + } + + return aOut; +} + +//Returns an associative array of properties (attributes) contained in sUri element +// array[propName] = oRes +function mproxy_ds_getPropertiesFor(sUri){ + mproxy_ds_initDataSource(); + + var aOut = new Array(); + + //Get an array of elements for sAbout + try{ + var oRes = mproxy_ds_getElement(sUri); + var oTrgts = gSProxyDs.ArcLabelsOut(oRes); + while(oTrgts.hasMoreElements()){ + var oTrgt = oTrgts.getNext(); + + if (oTrgt instanceof Components.interfaces.nsIRDFResource){ + var sTrgName = oTrgt.Value.substring(gSProxyRdfNodeUriRoot.length + 1); //return node name without URI + aOut[sTrgName] = oTrgt; + } + } + }catch(err){throw "(mproxy_ds_getPropertiesFor)\n" + err} + + return aOut; +} + +//Similar to 'mproxy_ds_getPropertiesFor' however returns uri=>literal_object_value +// array[uri] = oLiteral +function mproxy_ds_getPropertyValuesFor(sUri){ + mproxy_ds_initDataSource(); + + var aOut = new Array(); + + //Get an array of elements for sAbout + try{ + var oRes = mproxy_ds_getElement(sUri); + var oTrgts = gSProxyDs.ArcLabelsOut(oRes, true); + while(oTrgts.hasMoreElements()){ + var oTrgt = oTrgts.getNext(); + + if (oTrgt instanceof Components.interfaces.nsIRDFResource){ + aOut[oTrgt.Value] = mproxy_ds_getValueFor(oRes, oTrgt); + } + } + }catch(err){throw "(mproxy_ds_getPropertyValuesFor)\n" + err} + + return aOut; +} + +//Returns element that has this property/value +function mproxy_ds_getElementForValue(sPropertyUri, sValue){ + mproxy_ds_initDataSource(); + + try{ + var oValue = gSProxyRdf.GetLiteral(sValue); + var oProp = gSProxyRdf.GetResource(sPropertyUri); + var oSubject = gSProxyDs.GetSource(oProp, oValue, true); + + return oSubject; + + }catch(err){throw "(mproxy_ds_getElementForValue)\n" + err} + + return null; +} + +// Returns all elements that has this property/value +function mproxy_ds_getElementsForValue(sPropertyUri, sValue){ + mproxy_ds_initDataSource(); + + var aOut = new Array(); + + try{ + var oValue = gSProxyRdf.GetLiteral(sValue); + var oProp = gSProxyRdf.GetResource(sPropertyUri); + var aSubject = gSProxyDs.GetSources(oProp, oValue, true); + var oSubject = null + + while(aSubject.hasMoreElements()){ + oSubject = aSubject.getNext().QueryInterface(Components.interfaces.nsIRDFResource); + aOut[aOut.length] = oSubject; + } + + }catch(err){throw "(mproxy_ds_getElementsForValue)\n" + err} + + return aOut; +} + +//Change element's URI +function mproxy_ds_changeElementUri(oRes, sNewUri){ + mproxy_ds_initDataSource(); + + try{ + + //Get All Properties for element + var aProps = mproxy_ds_getPropertyValuesFor(oRes.Value); + + //Remove Element + mproxy_ds_removeElement(oRes.Value); + + //Create element again with new URI + var newElem = gSProxyRdf.GetResource(sNewUri); + gSProxyRdfC.AppendElement(newElem); + for(sProp in aProps){ + gSProxyDs.Assert(newElem, gSProxyRdf.GetResource(sProp), gSProxyRdf.GetLiteral(aProps[sProp]), true); + } + + }catch(err){throw "(mproxy_ds_changeElementUri)\n" + err} +} + +//Add element with given sUri, returns added resource +function mproxy_ds_addElement(sUri){ + mproxy_ds_initDataSource(); + + try{ + + return oRes = gSProxyRdfC.AppendElement(gSProxyRdf.GetResource(sUri)); + + }catch(err){throw "(mproxy_ds_addElement)\n" + err} +} + +//Remove Element for sUri +function mproxy_ds_removeElement(sUri){ + mproxy_ds_initDataSource(); + + try{ + var oRes = gSProxyRdf.GetResource(sUri); + + //Remove All Archs + // Loop for duplicates + var aArchs = null; + var hasArchs = true; + while(hasArchs){ + aArchs = gSProxyDs.ArcLabelsOut(oRes); + hasArchs = aArchs.hasMoreElements(); + while(aArchs.hasMoreElements()){ + oArch = aArchs.getNext().QueryInterface(Components.interfaces.nsIRDFResource); + + //Remove + gSProxyDs.Unassert(oRes, oArch, gSProxyDs.GetTarget(oRes, oArch, true)); + } + } + + //Remove Element + gSProxyRdfC.RemoveElement(oRes, true); + }catch(err){throw "(mproxy_ds_removeElement)\n" + err} +} + +//Remove property (sUri) from oRes +function mproxy_ds_removeProperty(sUri, oRes, sValue){ + mproxy_ds_initDataSource(); + + try{ + var oPred = gSProxyRdf.GetResource(sUri); + var aValues = mproxy_ds_getValuesFor(oRes, oPred); + + if(typeof(sValue) == 'undefined'){ + // Make sure to delete all properites of this sUri + for(var i = 0; i < aValues.length; i++){ + gSProxyDs.Unassert(oRes, oPred, gSProxyRdf.GetLiteral(aValues[i]) ); + } + } + else{ + // Only delete the property with this value + sValue = gSProxyRdf.GetLiteral(sValue); + if(gSProxyDs.HasAssertion(oRes, oPred, sValue, true)){ + gSProxyDs.Unassert(oRes, oPred, sValue); + } + } + + }catch(err){throw "(mproxy_ds_removeProperty)\n" + err} +} + +//Does URI Exist +function mproxy_ds_doesProxyElementExist(sProxyUri){ + mproxy_ds_initDataSource(); + + try{ + var aElems = mproxy_ds_getAllElements(); + for(var e = 0; e < aElems.length; e++){ + if(aElems[e] == sProxyUri) + return true; + } + }catch(err){throw "(mproxy_ds_doesElementExist)\n" + err} +} + +//Get Index of URI +function mproxy_ds_indexOf(sProxyUri){ + mproxy_ds_initDataSource(); + + try{ + return gSProxyRdfC.IndexOf(mproxy_ds_getResource(sProxyUri)); + }catch(err){throw "(mproxy_ds_indexOf)\n" + err} +} + +//Rename oProp's URI to sNewUri +function mproxy_ds_renamePropertyUri(oRes, oProp, sNewUri){ + mproxy_ds_initDataSource(); + + try{ + var sValue = gSProxyDs.GetTarget(oRes, oProp, true).QueryInterface(Components.interfaces.nsIRDFLiteral); + + gSProxyDs.Unassert(oRes, oProp, gSProxyDs.GetTarget(oRes, oProp, true)); + gSProxyDs.Assert(oRes, gSProxyRdf.GetResource(sNewUri), sValue, true); + + }catch(err){throw "(mproxy_ds_renamePropertyUri)\n" + err} +} + +//Add Property oProp to oRes +function mproxy_ds_addProperty(oRes, oProp, sValue, overwriteExisting){ + mproxy_ds_initDataSource(); + + try{ + //Don't overwrite it this property exists + if(!overwriteExisting && gSProxyDs.hasArcOut(oRes, oProp)) + return; + + //Add + gSProxyDs.Assert(oRes, oProp, gSProxyRdf.GetLiteral(sValue), true); + }catch(err){throw "(mproxy_ds_addProperty)\n" + err} +} + +//Change Property value for sPropUri in oRes +function mproxy_ds_changePropertyValue(oRes, sPropUri, sValue){ + mproxy_ds_initDataSource(); + + try{ + var oProp = gSProxyRdf.GetResource(sPropUri); + + //Get old value + var sOld = mproxy_ds_getValueFor(oRes, oProp); + + //Change + gSProxyDs.Change(oRes, oProp, gSProxyRdf.GetLiteral(sOld), gSProxyRdf.GetLiteral(sValue)); + + }catch(err){throw "(mproxy_ds_changePropertyValue)\n" + err} +} + +//Get Property Value for Property oProp +function mproxy_ds_getValueFor(oRes, oProp){ + mproxy_ds_initDataSource(); + + try{ + oTrgt = gSProxyDs.GetTarget(oRes, oProp, true); + + if(oTrgt instanceof Components.interfaces.nsIRDFLiteral){ + return oTrgt.Value; + } + + }catch(err){throw "(mproxy_ds_getValueFor)\n" + err} + + return null; +} + +//Get All Property Values for Property oProp +// This is similiar to mproxy_ds_getValueFor +// except it returns ALL values for oProp in an array +// array[index] = sValue +function mproxy_ds_getValuesFor(oRes, oProp){ + mproxy_ds_initDataSource(); + + var aOut = new Array(); + + try{ + var aTrgts = gSProxyDs.GetTargets(oRes, oProp, true) + var oTrgt = null; + + while(aTrgts.hasMoreElements()){ + oTrgt = aTrgts.getNext() + + if(oTrgt instanceof Components.interfaces.nsIRDFLiteral){ + aOut[aOut.length] = oTrgt.Value; + } + } + }catch(err){throw "(mproxy_ds_getValueFor)\n" + err} + + return aOut; +} + +//Does Property/Value exist in oRes +function mproxy_ds_doesPropValueExist(oRes, sPropUri, sValue){ + mproxy_ds_initDataSource(); + + try{ + var oProp = gSProxyRdf.GetResource(sPropUri); + var aValues = mproxy_ds_getValuesFor(oRes, oProp); + + //Find in array + for(var i = 0; i < aValues.length; i++){ + if(aValues[i] == sValue) + return true; + } + + }catch(err){throw "(mproxy_ds_doesPropValueExist)\n" + err} + + return false; +} + +/* +* GET PROPERTIES +*/ + + //Get RDF Container + function mproxy_ds_getRDFContainer(){ + mproxy_ds_initDataSource(); + return gSProxyRdf; + } + diff --git a/src/chrome/content/dialogs/about.xul b/src/chrome/content/dialogs/about.xul new file mode 100644 index 0000000..3363c81 --- /dev/null +++ b/src/chrome/content/dialogs/about.xul @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/chrome/content/dialogs/editcommon.js b/src/chrome/content/dialogs/editcommon.js new file mode 100644 index 0000000..c24b619 --- /dev/null +++ b/src/chrome/content/dialogs/editcommon.js @@ -0,0 +1,18 @@ +//Has Special Chars +// + returns true if it only +// + contains allowed chars +function mproxy_allowedChars(str){ + //var regex = new RegExp("[\\s\\.a-zA-Z0-9_]", "g"); //This does not allow utf-8 text! + var regex = new RegExp("[(){}\\\[\\\]<>,;:/~`'\"*?^$#&\\t\\n\\r\\\\]", "g"); + return !regex.test(str); +} + +// Used to test strings +// + converts space to underscore +// + and converts to lowercase +function mproxy_simplify(str){ + str = str.replace(new RegExp("\\s{2,}", "g"), " "); + str = str.replace(new RegExp("\\s", "g"), "_"); + str = str.toLowerCase(); + return str; +} \ No newline at end of file diff --git a/src/chrome/content/dialogs/editproxy.js b/src/chrome/content/dialogs/editproxy.js new file mode 100644 index 0000000..3e01c58 --- /dev/null +++ b/src/chrome/content/dialogs/editproxy.js @@ -0,0 +1,311 @@ + +var gIsEdit = false; +var gList; +var mproxyURI; +var mproxy; +var mproxyConfig; +var mproxyNameField; +var gFromProxyManager; + +function mproxy_initVals(){ + + + //Set Globals + mproxyNameField = document.getElementById("proxy-name"); + + //Edit + if(window.arguments.length > 1 && window.arguments[0] == "edit" && !mproxy_isEmpty(window.arguments[1])){ + + //Proxy URI + mproxyURI = window.arguments[1]; + + gIsEdit = true; + try{ + mproxy = mproxy_ds_getResource(mproxyURI); + + //Load Fields + var mproxyConfig = mproxy_ds_getPropertyValuesFor(mproxyURI); + for(key in gmproxy_options){ + var oField = document.getElementById(key); + var sValue = mproxyConfig[gSProxyRdfNodeUriRoot + "#" + key]; + + oField.value = sValue; + } + + //Label + mproxyNameField.value = mproxyConfig[gSProxyRdfNodeName]; + + //Set Socks Radio + oSocks = document.getElementById("networkProxySOCKSVersion"); + if(oSocks.value == "4") + oSocks.selectedItem = document.getElementById("networkProxySOCKSVersion4"); + else + oSocks.selectedItem = document.getElementById("networkProxySOCKSVersion5"); + + //Share one proxy + oShare = document.getElementById("networkProxyHTTPShare"); + if (oShare.value == "true") + //oShare.checked = true; + document.getElementById("networkProxyHTTPShare").checked = oShare.value; + + else + oShare.checked = false; + + //Sharing box + //if (document.getElementById("networkProxyHTTPShare").value == "true"); + + + + }catch(err){ alert(mproxy_getString("error.unknown")); self.close(); } + } + + //Enable Fields + + mproxy_enableShareSettingOnStart(); + mproxy_enableOptions(); + + // Thunderbird + if(navigator.userAgent.search(/Thunderbird/gi) > -1){ + document.getElementById("ftp_row").style.display = "none"; + document.getElementById("gopher_row").style.display = "none"; + document.getElementById("none_row").style.display = "none"; + document.getElementById("none_example_row").style.display = "none"; + } +} + +function mproxy_saveProxy(){ + + try{ + + /* + * Validation + */ + //Empty + if(mproxyNameField.value == ""){ + alert(mproxy_getString("error.add.empty")); + + mproxyNameField.focus(); + mproxyNameField.setSelectionRange(0, mproxyNameField.textLength); + + return false; + } + //Special Chars + else if(!mproxy_allowedChars(mproxyNameField.value)){ + alert(mproxy_getString("error.add.invalid")); + return false; + } + //Can't be named 'None' or 'tor' + else if(mproxy_simplify(mproxyNameField.value) == mproxy_simplify(mproxy_getString("common.proxy.none"))){ + alert(mproxy_getString("error.add.duplicate")); + return false; + } + //else if((!gIsEdit) && (mproxy_simplify(mproxyNameField.value) == mproxy_simplify("tor"))){ + // alert(mproxy_getString("error.add.duplicate")); + // return false; + // } + // else if((!gIsEdit) && (mproxy_simplify(mproxyNameField.value) == mproxy_simplify(mproxy_getString("common.proxy.tor")))){ + // alert(mproxy_getString("error.add.duplicate")); + // return false; + // } + + //Is This a Duplicate Label? + var oTestProxy = mproxy_ds_getElementForValue(gSProxyRdfNodeName, mproxyNameField.value); + if(oTestProxy != null && (!gIsEdit || oTestProxy.Value != mproxy.Value)){ + alert(mproxy_getString("error.add.duplicate")); + return false; + } + + //save share setting + document.getElementById("networkProxyHTTPShare").value = document.getElementById("networkProxyHTTPShare").checked; + + /* + * Edit + */ + if(gIsEdit){ + //Update RDF Properties + for(key in gmproxy_options){ + mproxy_ds_changePropertyValue(mproxy, (gSProxyRdfNodeUriRoot + "#" + key), document.getElementById(key).value); + } + + //Update Name + mproxy_ds_changePropertyValue(mproxy, gSProxyRdfNodeName, mproxyNameField.value); + } + /* + * Add + */ + else{ + var sProxyUri = opener.mproxy_getUniqueProxyUri(); + var oProxy = mproxy_ds_getResource(sProxyUri); + + //Add Element + mproxy_ds_addElement(sProxyUri); + + //Add Properties + for(key in gmproxy_options){ + var oProp = mproxy_ds_getResource(gSProxyRdfNodeUriRoot + "#" + key); + mproxy_ds_addProperty(oProxy, oProp, document.getElementById(key).value, true); + } + + //Add Name + mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeName), mproxyNameField.value, true); + } + /* + * Finish + */ + opener.mproxy_populateList(); + + if(gIsEdit){ + + //Is this proxy is in use, refresh proxy + var oPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch); + if(oPrefs.prefHasUserValue("mproxy.proxy.current") + && oPrefs.getCharPref("mproxy.proxy.current") == mproxy.Value){ + + opener.mproxy_doCommand("mproxy_setProxy()"); + } + //If not in use, select proxy + else{ + opener.mproxy_doCommand("mproxy_selectItem('"+ mproxyNameField.value +"')"); + } + + //alert("Proxy Info Changed"); + } + else{ + opener.mproxy_doCommand("mproxy_selectItem('"+ mproxyNameField.value +"')"); + //alert("Proxy Added"); + } + + + }catch(e){ + alert(mproxy_getString("error.unknown") +"\n("+ e +")"); + return; + } + + mproxy_openerFocus() + return true; +} + + +//Enable or disable Manual +// + config options +function mproxy_enableOptions(){ + + var disable = !(document.getElementById("networkProxyType").value == "1"); //if 1 then manual is selected + + //Set Radios + oType = document.getElementById("networkProxyType"); + if(!disable){ + oType.selectedItem = document.getElementById("type-manual-radio"); + + } + else{ + oType.selectedItem = document.getElementById("type-auto-radio"); + } + if (document.getElementById("networkProxyType").value == "2"){ + + //Manual Options + document.getElementById("networkProxyHTTP").disabled = true; + document.getElementById("networkProxyHTTP_Port").disabled = true; + document.getElementById("networkProxyHTTPShare").disabled = true; + document.getElementById("networkProxySSL").disabled = true; + document.getElementById("networkProxySSL_Port").disabled = true; + document.getElementById("networkProxyFTP").disabled = true; + document.getElementById("networkProxyFTP_Port").disabled = true; + document.getElementById("networkProxyGopher").disabled = true; + document.getElementById("networkProxyGopher_Port").disabled = true; + document.getElementById("networkProxySOCKS").disabled = true; + document.getElementById("networkProxySOCKS_Port").disabled = true; + document.getElementById("networkProxySOCKSVersion4").disabled = true; + document.getElementById("networkProxySOCKSVersion5").disabled = true; + document.getElementById("networkProxyNone").disabled = true; + + //Auto + document.getElementById("networkProxyAutoconfigURL").disabled = false; + +} +else{ +//When manual setting is checked + mproxy_enableShareSetting(); + document.getElementById("networkProxyHTTP").disabled = false; + document.getElementById("networkProxyHTTP_Port").disabled = false; + document.getElementById("networkProxyHTTPShare").disabled = false; + document.getElementById("networkProxyNone").disabled = false; + document.getElementById("networkProxyAutoconfigURL").disabled = true; +} +} +//Set setting on start-up +function mproxy_enableShareSettingOnStart(){ +var disabletextbox = (document.getElementById("networkProxyHTTPShare").value == "true"); + + document.getElementById("networkProxySSL").disabled = disabletextbox; + document.getElementById("networkProxySSL_Port").disabled = disabletextbox; + document.getElementById("networkProxyFTP").disabled = disabletextbox; + document.getElementById("networkProxyFTP_Port").disabled = disabletextbox; + document.getElementById("networkProxyGopher").disabled = disabletextbox; + document.getElementById("networkProxyGopher_Port").disabled = disabletextbox; + document.getElementById("networkProxySOCKS").disabled = disabletextbox; + document.getElementById("networkProxySOCKS_Port").disabled = disabletextbox; + document.getElementById("networkProxySOCKSVersion4").disabled = disabletextbox; + document.getElementById("networkProxySOCKSVersion5").disabled = disabletextbox; + +} +//Disable below when check sharing setting +function mproxy_enableShareSetting(){ +var disabletextbox = (document.getElementById("networkProxyHTTPShare").checked == true); + + document.getElementById("networkProxySSL").disabled = disabletextbox; + document.getElementById("networkProxySSL_Port").disabled = disabletextbox; + document.getElementById("networkProxyFTP").disabled = disabletextbox; + document.getElementById("networkProxyFTP_Port").disabled = disabletextbox; + document.getElementById("networkProxyGopher").disabled = disabletextbox; + document.getElementById("networkProxyGopher_Port").disabled = disabletextbox; + document.getElementById("networkProxySOCKS").disabled = disabletextbox; + document.getElementById("networkProxySOCKS_Port").disabled = disabletextbox; + document.getElementById("networkProxySOCKSVersion4").disabled = disabletextbox; + document.getElementById("networkProxySOCKSVersion5").disabled = disabletextbox; + + //if (document.getElementById("networkProxyHTTPShare").value == "true"){ + //mproxy_copySetting(); +//} +} +function mproxy_enableShareSettingSelect(){ +var disabletextbox = (document.getElementById("networkProxyHTTPShare").checked == true); + + document.getElementById("networkProxySSL").disabled = disabletextbox; + document.getElementById("networkProxySSL_Port").disabled = disabletextbox; + document.getElementById("networkProxyFTP").disabled = disabletextbox; + document.getElementById("networkProxyFTP_Port").disabled = disabletextbox; + document.getElementById("networkProxyGopher").disabled = disabletextbox; + document.getElementById("networkProxyGopher_Port").disabled = disabletextbox; + document.getElementById("networkProxySOCKS").disabled = disabletextbox; + document.getElementById("networkProxySOCKS_Port").disabled = disabletextbox; + document.getElementById("networkProxySOCKSVersion4").disabled = disabletextbox; + document.getElementById("networkProxySOCKSVersion5").disabled = disabletextbox; + + //if (document.getElementById("networkProxyHTTPShare").value == "true"){ + mproxy_copySetting(); +//} +} +//Copy http proxy +function mproxy_copySetting(){ +if (document.getElementById("networkProxyHTTPShare").checked == true){ + document.getElementById("networkProxySSL").value = document.getElementById("networkProxyHTTP").value; + document.getElementById("networkProxySSL_Port").value = document.getElementById("networkProxyHTTP_Port").value; + document.getElementById("networkProxyFTP").value = document.getElementById("networkProxyHTTP").value; + document.getElementById("networkProxyFTP_Port").value = document.getElementById("networkProxyHTTP_Port").value; + document.getElementById("networkProxyGopher").value = document.getElementById("networkProxyHTTP").value; + document.getElementById("networkProxyGopher_Port").value = document.getElementById("networkProxyHTTP_Port").value; + document.getElementById("networkProxySOCKS").value = document.getElementById("networkProxyHTTP").value; + document.getElementById("networkProxySOCKS_Port").value = document.getElementById("networkProxyHTTP_Port").value; +} +else{ + document.getElementById("networkProxySSL").value = ""; + document.getElementById("networkProxySSL_Port").value = ""; + document.getElementById("networkProxyFTP").value = ""; + document.getElementById("networkProxyFTP_Port").value = ""; + document.getElementById("networkProxyGopher").value = ""; + document.getElementById("networkProxyGopher_Port").value = ""; + document.getElementById("networkProxySOCKS").value = ""; + document.getElementById("networkProxySOCKS_Port").value = ""; +} +} diff --git a/src/chrome/content/dialogs/editproxy.xul b/src/chrome/content/dialogs/editproxy.xul new file mode 100644 index 0000000..1a1cb01 --- /dev/null +++ b/src/chrome/content/dialogs/editproxy.xul @@ -0,0 +1,119 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/chrome/content/dialogs/manager.xul b/src/chrome/content/dialogs/manager.xul new file mode 100644 index 0000000..3cd0cdd --- /dev/null +++ b/src/chrome/content/dialogs/manager.xul @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/chrome/content/globals.js b/src/chrome/content/globals.js new file mode 100644 index 0000000..ba46c76 --- /dev/null +++ b/src/chrome/content/globals.js @@ -0,0 +1,152 @@ + +var gSProxyRdfDataSouce = "rdf:local-store"; +const gSProxyRdfRoot = "http://mozilla.org/package/mproxy/rdf/all"; +const gSProxyRdfNodeUriRoot = "http://mozilla.org/package/mproxy/rdf" +const gSProxyRdfNodeId = gSProxyRdfNodeUriRoot+ "#id"; +const gSProxyRdfNodeName = gSProxyRdfNodeUriRoot+ "#name"; +const gSProxyRdfNodeProxy = gSProxyRdfNodeUriRoot+ "#proxy"; + +const gmproxy_Version = "1.33"; +const gmproxy_DownloadSite = "http://switchproxy.googlepages.com"; + +var gSProxyStrBundle = null; + +var gmproxy_options = new Array(); + gmproxy_options['networkProxyType'] = "network.proxy.type"; + gmproxy_options['networkProxyHTTP'] = "network.proxy.http"; + gmproxy_options['networkProxyHTTP_Port'] = "network.proxy.http_port"; + gmproxy_options['networkProxyHTTPShare'] = "network.proxy.share_proxy_settings"; + gmproxy_options['networkProxySSL'] = "network.proxy.ssl"; + gmproxy_options['networkProxySSL_Port'] = "network.proxy.ssl_port"; + gmproxy_options['networkProxyFTP'] = "network.proxy.ftp"; + gmproxy_options['networkProxyFTP_Port'] = "network.proxy.ftp_port"; + gmproxy_options['networkProxyGopher'] = "network.proxy.gopher"; + gmproxy_options['networkProxyGopher_Port'] = "network.proxy.gopher_port"; + gmproxy_options['networkProxySOCKS'] = "network.proxy.socks"; + gmproxy_options['networkProxySOCKS_Port'] = "network.proxy.socks_port"; + gmproxy_options['networkProxySOCKSVersion'] = "network.proxy.socks_version"; + gmproxy_options['networkProxyNone'] = "network.proxy.no_proxies_on"; + gmproxy_options['networkProxyAutoconfigURL'] = "network.proxy.autoconfig_url"; + +var gmproxy_options_defaults = new Array(); + gmproxy_options_defaults['networkProxyType'] = 1; + gmproxy_options_defaults['networkProxyHTTP'] = ""; + gmproxy_options_defaults['networkProxyHTTP_Port'] = 0; + gmproxy_options_defaults['networkProxyHTTPShare'] = false; + gmproxy_options_defaults['networkProxySSL'] = ""; + gmproxy_options_defaults['networkProxySSL_Port'] = 0; + gmproxy_options_defaults['networkProxyFTP'] = ""; + gmproxy_options_defaults['networkProxyFTP_Port'] = 0; + gmproxy_options_defaults['networkProxyGopher'] = ""; + gmproxy_options_defaults['networkProxyGopher_Port'] = 0; + gmproxy_options_defaults['networkProxySOCKS'] = "127.0.0.1"; + gmproxy_options_defaults['networkProxySOCKS_Port'] = 9050; + gmproxy_options_defaults['networkProxySOCKSVersion'] = 5; + gmproxy_options_defaults['networkProxyNone'] = "localhost, 127.0.0.1"; + gmproxy_options_defaults['networkProxyAutoconfigURL'] = ""; + +/* +* Global Functions +*/ + //Get String Bundle + function mproxy_getString(sKey){ + try{ + + if(gSProxyStrBundle == null){ + var oBundle = Components.classes['@mozilla.org/intl/stringbundle;1'].getService(Components.interfaces.nsIStringBundleService); + gSProxyStrBundle = oBundle.createBundle('chrome://mproxy/locale/locale.properties'); + } + + return gSProxyStrBundle.GetStringFromName(sKey); + + }catch(err){} + + return ""; + } + + // Focus Opener + function mproxy_openerFocus(){ + try{ + if(opener != null && opener.focus != null){ + opener.focus(); + } + } catch(err) { } + } + + //Is string empty + function mproxy_isEmpty(str){ + var oRegExp = new RegExp("([^\\s])", "g"); + + if(str == "") + return true; + + return !oRegExp.test(str); + } + + // Does this sValue exist in oList + function mproxy_existsInList(oList, sValue){ + + for(var i = 0; i < oList.getRowCount(); i++){ + if(oList.getItemAtIndex(i).value == sValue){ + return true; + } + } + + return false; + } + + // Trims space from both sides of str + function mproxy_trim(str){ + str = str.replace(new RegExp("^[\\s\\n\\r]*", "g"), ""); + str = str.replace(new RegExp("[\\s\\n\\r]*$", "g"), ""); + + return str; + } + + // Splits a domain or IP from it's port number + // returns array[1] + // array[0] = (String) Domain or IP + // array[1] = (String) Port Number + function mproxy_splitDomain(sDomain){ + var aOut = new Array(); + var iPort = -1; + + if( (iPort = sDomain.indexOf(":")) > -1){ + aOut[0] = sDomain.substring(0, iPort); + aOut[1] = sDomain.substring(iPort + 1); + } + else{ + aOut[0] = sDomain; + aOut[1] = "80"; + } + + return aOut; + } + + // Returns if str is valid domain or IP address + function mproxy_isValidDomain(str){ + + var oValidDomain = new RegExp("^[a-zA-Z0-9][a-zA-Z0-9-\\.:]{0,63}[a-zA-Z0-9]?$", "i"); + + return oValidDomain.test(str); + } + +/* +* Debug Functions +*/ + //Get Properties for an object + function mproxy_debug_getProps(obj){ + var props = ""; + var i = -1; + for(prop in obj){ + i++; + props += prop + " | "; + + if(i > 3){ + i = -1; + props += "\n"; + } + } + alert(props); + } + diff --git a/src/chrome/content/icons/Thumbs.db b/src/chrome/content/icons/Thumbs.db new file mode 100644 index 0000000..20e4541 Binary files /dev/null and b/src/chrome/content/icons/Thumbs.db differ diff --git a/src/chrome/content/icons/arrow-dn.gif b/src/chrome/content/icons/arrow-dn.gif new file mode 100644 index 0000000..62edbfd Binary files /dev/null and b/src/chrome/content/icons/arrow-dn.gif differ diff --git a/src/chrome/content/icons/check.png b/src/chrome/content/icons/check.png new file mode 100644 index 0000000..59b12c3 Binary files /dev/null and b/src/chrome/content/icons/check.png differ diff --git a/src/chrome/content/icons/cross.png b/src/chrome/content/icons/cross.png new file mode 100644 index 0000000..ed39e19 Binary files /dev/null and b/src/chrome/content/icons/cross.png differ diff --git a/src/chrome/content/icons/isp.png b/src/chrome/content/icons/isp.png new file mode 100644 index 0000000..2ede6f5 Binary files /dev/null and b/src/chrome/content/icons/isp.png differ diff --git a/src/chrome/content/icons/new.png b/src/chrome/content/icons/new.png new file mode 100644 index 0000000..acaf5f4 Binary files /dev/null and b/src/chrome/content/icons/new.png differ diff --git a/src/chrome/content/icons/options.png b/src/chrome/content/icons/options.png new file mode 100644 index 0000000..9469f4e Binary files /dev/null and b/src/chrome/content/icons/options.png differ diff --git a/src/chrome/content/icons/pencil.png b/src/chrome/content/icons/pencil.png new file mode 100644 index 0000000..7422be2 Binary files /dev/null and b/src/chrome/content/icons/pencil.png differ diff --git a/src/chrome/content/options/options.js b/src/chrome/content/options/options.js new file mode 100644 index 0000000..ecd4ea9 --- /dev/null +++ b/src/chrome/content/options/options.js @@ -0,0 +1,80 @@ + +var oMain = null; +var inMozOptions = false; + +function initOptions(){ + try{ + + //Prefs + var oPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch(""); + + //Get Opener + if(opener.mproxy_menuShowing){ + oMain = opener; + } + else if(opener.parent.opener && opener.parent.opener.mproxy_menuShowing){ + oMain = opener.parent.opener + inMozOptions = true; + } + + //Prefill + if(oPrefs.prefHasUserValue("mproxy.clear.cookies")) + document.getElementById("mproxy.clear.cookies").checked = oPrefs.getBoolPref("mproxy.clear.cookies"); + if(oPrefs.prefHasUserValue("mproxy.reload.tab")) + document.getElementById("mproxy.reload.tab").checked = oPrefs.getBoolPref("mproxy.reload.tab"); + if(oPrefs.prefHasUserValue("mproxy.display.context")) + document.getElementById("mproxy.display.context").checked = oPrefs.getBoolPref("mproxy.display.context"); + if(oPrefs.prefHasUserValue("mproxy.display.statusbar")) + document.getElementById("mproxy.display.statusbar").checked = oPrefs.getBoolPref("mproxy.display.statusbar"); + + /*if(oPrefs.prefHasUserValue("mproxy.tabs.manager")) + document.getElementById("mproxy.tabs.manager").checked = oPrefs.getBoolPref("mproxy.tabs.manager");*/ + + //Set menushowing options + if(oMain != null){ + document.getElementById("mproxy.display.toolbar").checked = oMain.mproxy_menuShowing("toolbar"); + } + else{ + document.getElementById("mproxy.display.toolbar").style.display = "none"; + } + + // Thunderbird + if(navigator.userAgent.search(/Thunderbird/gi) > -1){ + document.getElementById("mproxy.display.context").style.display = "none"; + document.getElementById("mproxy.display.toolbar").style.display = "none"; + } + + }catch(err){ alert(mproxy_getString("error.unknown") +"\n"+ err); } +} + +function saveOptions(){ + + try{ + + //Save + var oPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch(""); + + oPrefs.setBoolPref("mproxy.clear.cookies", document.getElementById("mproxy.clear.cookies").checked); + oPrefs.setBoolPref("mproxy.reload.tab", document.getElementById("mproxy.reload.tab").checked); + oPrefs.setBoolPref("mproxy.display.statusbar", document.getElementById("mproxy.display.statusbar").checked); + + // Not Thunderbird + if(navigator.userAgent.search(/Thunderbird/gi) < 0){ + oPrefs.setBoolPref("mproxy.display.context", document.getElementById("mproxy.display.context").checked); + + if(oMain != null){ + oPrefs.setBoolPref("mproxy.display.toolbar", document.getElementById("mproxy.display.toolbar").checked); + } + } + + + if(oMain != null) + oMain.mproxy_showMenus(); + + }catch(err){ alert(mproxy_getString("error.unknown") +"\n"+err); } + + if(oMain != null && !inMozOptions) + oMain.focus(); + + return true; +} diff --git a/src/chrome/content/options/options.xul b/src/chrome/content/options/options.xul new file mode 100644 index 0000000..f555dd5 --- /dev/null +++ b/src/chrome/content/options/options.xul @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/chrome/content/proxy.js b/src/chrome/content/proxy.js new file mode 100644 index 0000000..8c94d0f --- /dev/null +++ b/src/chrome/content/proxy.js @@ -0,0 +1,1080 @@ +/* +* 2008 +* Copyright Steve McFred and Jeremy Gillick (author of SwitchProxy) +*/ + +/* +* +* ERROR CODES +* 100 - 149: mproxy_setProxy() +* 150 - 199: mproxy_removeProxy() +* 200 - 249: mproxy_clearCookies() +* 250 - 299: mproxy_editProxyDialog() +* 300 - 349: mproxy_manualUpgradCheck() +* +*/ + +var gSwitchP_List; +var gSwitchP_ListPopup; +var gSwitchP_ContextList; +var gSwitchP_StatusBar; +var gSwitchP_MenuList; +var gSwitchP_ManageList; +var gSwitchP_ElementList; +var gSwitchP_ElementButton; +var gSwitchP_LastItem; +var gSwitchP_ProxyCount = 0; +var gSwitchP_InManager = false; +var gSwitchP_Loaded = false; +var gSwitchP_Cycle = null; +var gSwitchP_CommandEnd = true; +var gSwitchP_Prefs = null; +var gSwitchP_NoneLabel = "None"; + +var gSwitchPTabMgr = null; + +function mproxy_initProxy(event){ + + window.removeEventListener("load", mproxy_initProxy, true); + + if(!gSwitchP_Loaded){ + + gSwitchP_List = document.getElementById('proxy-list') + gSwitchP_ListPopup = document.getElementById('proxy-list-popup'); + gSwitchP_ManageList = document.getElementById('manage-proxy-list'); + gSwitchP_ContextList = document.getElementById('context-proxy-list'); + gSwitchP_StatusBar = document.getElementById('mproxy-status'); + gSwitchP_MenuList = document.getElementById('mproxy-menu-list'); + gSwitchP_ElementList = document.getElementById('mproxy-element-list'); + gSwitchP_ElementButton = document.getElementById('mproxy-element-button'); + gSwitchP_Prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch); + + gSwitchP_NoneLabel = mproxy_getString("common.proxy.none"); + + //Is in Proxy Manager + if(gSwitchP_ManageList != null){ + gSwitchP_InManager = true; + gSwitchP_List = gSwitchP_ManageList; + } + + mproxy_showMenus(true); + + //Cleanup RDF File + mproxy_cleanupRdf(); + + //Populate Proxy List + mproxy_populateList(); + + //Set Last Proxy Selected + if(gSwitchP_List != null) + gSwitchP_LastItem = gSwitchP_List.selectedItem; + + //Add Preferences Listener + var oProxyObserver = { + observe : function(subject, topic, data){ mproxy_populateList(); } + }; + var oMenuObserver = { + observe : function(subject, topic, data){ mproxy_showMenus(false); } + }; + //var oPrefBranch = Components.classes["@mozilla.org/preferences-service;1"].createInstance(Components.interfaces.nsIPrefBranchInternal); + ////oPrefBranch.addObserver("network.proxy", oPrefObserver, false); + //oPrefBranch.addObserver("mproxy.proxy.rdf.lastupdate", oProxyObserver, false); + //oPrefBranch.addObserver("mproxy.display", oMenuObserver, false); + + //if(navigator.userAgent.search(/Thunderbird/gi) > -1){ + // oPrefBranch = Components.classes["@mozilla.org/preferences-service;1"].createInstance(Components.interfaces.nsIPrefBranchInternal); + //} + //Else{ +oPrefBranch = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService); +//} +oPrefBranch.addObserver("mproxy.proxy.rdf.lastupdate", oProxyObserver, false); +//oPrefBranch.addObserver("mproxy.display", oMenuObserver, false); +//oPrefBranch.addObserver("network.proxy", oPrefObserver, false); + + //Auto-Update Anonymous Proxy Lists (after 10 minutes) + //gAnonUpdateTimout = setTimeout("mproxy_anon_autoUpdateLists()", 600000); + + // Start Anon Rotation + //setTimeout("mproxy_anon_nextProxy()", 1000); + + gSwitchP_Loaded = true; + } +} + +// Return Tab Manager +function mproxy_getTabManager(){ + return gSwitchPTabMgr; +} + +//Used for debugging removed + + +//Displays the context menu based on what +// the user selects in the options +function mproxy_showMenus(onStartup){ + try{ + //Show/Hide menus + var oPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch(""); + + // Status Bar + var isHidden = (oPrefs.prefHasUserValue("mproxy.display.statusbar") && !oPrefs.getBoolPref("mproxy.display.statusbar")) + document.getElementById("mproxy-status").setAttribute("collapsed", isHidden); + + // If not thunderbird + if(navigator.userAgent.search(/Thunderbird/gi) < 0){ + + //Context + var isHidden = (oPrefs.prefHasUserValue("mproxy.display.context") && !oPrefs.getBoolPref("mproxy.display.context")) + document.getElementById("mproxy-context-menu").setAttribute("collapsed", isHidden); + document.getElementById("mproxy-context-separator").setAttribute("hidden", isHidden); + + //Toolbar + if(onStartup){ + oPrefs.setBoolPref("mproxy.display.toolbar", (!document.getElementById("proxy-toolbar").getAttribute("collapsed"))); + } + else{ + var isHidden = (oPrefs.prefHasUserValue("mproxy.display.toolbar") && !oPrefs.getBoolPref("mproxy.display.toolbar")) + document.getElementById("proxy-toolbar").setAttribute("collapsed", isHidden); + } + } + + }catch(err){} +} + +// Show Element List +function mproxy_showElementList(event){ + + var oContext = document.getElementById('context-proxy-list'); + if(oContext == null){ + return; + } + +} + +//Returns is the entered menu is currently showing +// values are 'context' or 'toolbar' +function mproxy_menuShowing(sMenu){ + var oObj = null; + + if(sMenu == "context"){ + oObj = document.getElementById("mproxy-context-menu"); + } + else if(sMenu == "toolbar"){ + oObj = document.getElementById("proxy-toolbar"); + } + + if(oObj == null) + return false; + + return !eval(oObj.getAttribute("collapsed")); +} + + +//Clears current Proxy List +function mproxy_clearList(){ + + gSwitchP_ProxyCount = 0; + + //Toolbar List + if(!gSwitchP_InManager && gSwitchP_List != null && gSwitchP_List.removeAllItems && !gSwitchP_List.open){ + gSwitchP_List.removeAllItems(); + } + //Manage Proxy Box + if(gSwitchP_InManager && gSwitchP_List != null){ + aNodes = gSwitchP_List.childNodes; + for(var i = aNodes.length-1; i >= 0; i--){ + gSwitchP_List.removeChild(aNodes[i]); + } + } + //Context List + if(gSwitchP_ContextList != null){ + aNodes = gSwitchP_ContextList.childNodes; + for(var i = aNodes.length-1; i >= 0; i--){ + gSwitchP_ContextList.removeChild(aNodes[i]); + } + } + //Toolbar Element List + if(gSwitchP_ElementList != null){ + aNodes = gSwitchP_ElementList.childNodes; + for(var i = aNodes.length-1; i >= 0; i--){ + if(aNodes[i].getAttribute("class") == "proxy-menu-item") + gSwitchP_ElementList.removeChild(aNodes[i]); + } + } + // Tools Menu List + if(gSwitchP_MenuList != null){ + aNodes = gSwitchP_MenuList.childNodes; + for(var i = aNodes.length-1; i >= 0; i--){ + if(aNodes[i].getAttribute("class") == "proxy-menu-item") + gSwitchP_MenuList.removeChild(aNodes[i]); + } + } +} + +//Add Item to lists +function mproxy_appendToList(sLabel, sValue, isSelected, iType){ + var oItem = null; + + gSwitchP_ProxyCount++; + + try{ + + //Toolbar List + if(!gSwitchP_InManager && gSwitchP_List != null && !gSwitchP_List.open){ + oItem = gSwitchP_List.appendItem(sLabel, sValue); + oItem.setAttribute("oncommand", "mproxy_selectProxy();"); //mproxy_anon_stopRotation(); + oItem.setAttribute("proxyType", iType); + } + + //Manage Proxy Box + if(gSwitchP_InManager && gSwitchP_List != null && sLabel != gSwitchP_NoneLabel){ + oItem = gSwitchP_List.appendItem(sLabel, sValue); + oItem.setAttribute("proxyType", iType); + } + + //Context List + if(gSwitchP_ContextList != null){ + oItem = document.createElement("menuitem"); + oItem.setAttribute("label", sLabel); + oItem.setAttribute("value", sValue); + oItem.setAttribute("type", "checkbox"); + oItem.setAttribute("autocheck", "false"); + oItem.setAttribute("proxyType", iType); + oItem.setAttribute("oncommand", "mproxy_queueSetProxy(this);"); + gSwitchP_ContextList.appendChild(oItem); + } + + //Toolbar Element List + if(gSwitchP_ElementList != null){ + //Get separator, which is after proxy list + var oSeparator = document.getElementById("mproxy-element-list-separator"); + oItem = document.createElement("menuitem"); + oItem.setAttribute("id", sValue); + oItem.setAttribute("label", sLabel); + oItem.setAttribute("value", sValue); + oItem.setAttribute("type", "checkbox"); + oItem.setAttribute("autocheck", "false"); + oItem.setAttribute("proxyType", iType); + oItem.setAttribute("class", "proxy-menu-item"); + oItem.setAttribute("oncommand", "mproxy_queueSetProxy(this);"); + gSwitchP_ElementList.insertBefore(oItem, oSeparator); + } + + // Tools Menu List + if(gSwitchP_MenuList != null){ + //Get separator, which is after proxy list + var oSeparator = document.getElementById("mproxy-menu-list-separator"); + oItem = document.createElement("menuitem"); + oItem.setAttribute("id", sValue); + oItem.setAttribute("label", sLabel); + oItem.setAttribute("value", sValue); + oItem.setAttribute("type", "checkbox"); + oItem.setAttribute("autocheck", "false"); + oItem.setAttribute("proxyType", iType); + oItem.setAttribute("class", "proxy-menu-item"); + oItem.setAttribute("oncommand", "mproxy_queueSetProxy(this);"); + gSwitchP_MenuList.insertBefore(oItem, oSeparator); + } + + //Select + if(isSelected) + mproxy_selectItem(sLabel); + + }catch(err){} +} + +//Sets List item with labe sLabel, to be selected/checked +function mproxy_selectItem(sLabel){ + + try{ + + //Toolbar List + if(!gSwitchP_InManager && gSwitchP_List != null){ + oItem = gSwitchP_List.getElementsByAttribute("label", sLabel); + if(oItem != null){ + oItem = oItem[0]; + gSwitchP_List.selectedItem = oItem; + oItem.setAttribute("selected", true); + } + } + + //Context + if(gSwitchP_ContextList != null){ + oItem = gSwitchP_ContextList.getElementsByAttribute("label", sLabel); + if(oItem != null){ + //Uncheck Other + var aChecked = gSwitchP_ContextList.getElementsByAttribute("checked", "true"); + for(var c = 0; c < aChecked.length; c++){ + aChecked[c].setAttribute("checked", false); + } + + //Select + oItem = oItem[0]; + gSwitchP_ContextList.selectedItem = oItem; + oItem.setAttribute("checked", true); + } + } + + //Toolbar Element List + if(gSwitchP_ElementList != null){ + oItem = gSwitchP_ElementList.getElementsByAttribute("label", sLabel); + if(oItem != null && oItem.length > 0){ + + //Uncheck Other + var aChecked = gSwitchP_ElementList.getElementsByAttribute("checked", "true"); + for(var c = 0; c < aChecked.length; c++){ + aChecked[c].setAttribute("checked", false); + } + + //Check Selected + oItem = oItem[0]; + gSwitchP_ElementList.selectedItem = oItem; + oItem.setAttribute("selected", true); + oItem.setAttribute("checked", true); + + //Change Button Label + gSwitchP_ElementButton = document.getElementById('mproxy-element-button'); + if(gSwitchP_ElementButton != null){ + gSwitchP_ElementButton.setAttribute("label", sLabel); + } + } + } + + // Tools Menu List + if(gSwitchP_MenuList != null){ + oItem = gSwitchP_MenuList.getElementsByAttribute("label", sLabel); + if(oItem != null && oItem.length > 0){ + + //Uncheck Other + var aChecked = gSwitchP_MenuList.getElementsByAttribute("checked", "true"); + for(var c = 0; c < aChecked.length; c++){ + aChecked[c].setAttribute("checked", false); + } + + //Check Selected + oItem = oItem[0]; + gSwitchP_MenuList.selectedItem = oItem; + oItem.setAttribute("selected", true); + oItem.setAttribute("checked", true); + } + } + + // Status Bar + if(gSwitchP_StatusBar != null){ + gSwitchP_StatusBar.setAttribute("label", mproxy_getString("common.label.proxy")+" "+sLabel); + } + mproxy_clearTimeout(gSwitchP_Cycle); + + }catch(err){ + mproxy_debug(err); + } +} + +//Return menuitem for the given sUri +function mproxy_getMenuItem(sUri){ + var oItem = null; + + //Toolbar + oItem = (gSwitchP_List != null) ? gSwitchP_List.getElementsByAttribute("value", sUri) : null; + if(oItem != null && oItem[0] != null) + return oItem[0]; + + //Context + oItem = (gSwitchP_List != null) ? gSwitchP_ContextList.getElementsByAttribute("value", sUri) : null; + if(oItem != null && oItem[0] != null) + return oItem[0]; + + //Toolbar Element + oItem = (gSwitchP_List != null) ? gSwitchP_ElementList.getElementsByAttribute("value", sUri) : null; + if(oItem != null && oItem[0] != null) + return oItem[0]; + + + //Default + return null; +} + +function mproxy_cycle(sAction){ + if(gSwitchP_Cycle != null){ + + mproxy_clearTimeout(gSwitchP_Cycle); + gSwitchP_CommandEnd = true; + + if(sAction == 'change' && gSwitchP_LastItem != null && gSwitchP_List != null && gSwitchP_List.selectedItem.label != gSwitchP_LastItem.label && gSwitchP_List.selectedIndex > 0){ + gSwitchP_List.label = gSwitchP_LastItem.label; + gSwitchP_List.selectedItem = gSwitchP_LastItem; + gSwitchP_List.selectedItem.value = gSwitchP_LastItem.value; + + mproxy_setProxy(); + } + else if(sAction == 'select' && gSwitchP_List != null && gSwitchP_List.selectedIndex > -1){ + mproxy_setStatus(mproxy_getString("toolbar.notApplied"), "#F00"); + setTimeout("mproxy_setStatus(mproxy_getString('toolbar.loading'))", 3000); + setTimeout("mproxy_populateList('"+ gSwitchP_LastItem.label +"');", 4000); + setTimeout("mproxy_setProxy();", 4500); + } + + } +} + +//When user selects a Proxy from the menu list +function mproxy_selectProxy(){ + + mproxy_clearTimeout(gSwitchP_Cycle); + if(gSwitchP_List == null || gSwitchP_List.selectedItem == null || gSwitchP_InManager) + return; + + //if(gSwitchP_List.selectedItem.label != gSwitchP_NoneLabel){ + //document.getElementById('edit-button').disabled = false; + //document.getElementById('remove-button').disabled = false; + //document.getElementById('edit-button').image = "chrome://mproxy/content/icons/pencil.png"; + //document.getElementById('remove-button').image = "chrome://mproxy/content/icons/cross.png"; + + //} + //else{ + //document.getElementById('edit-button').disabled = true; + //document.getElementById('remove-button').disabled = true; + //document.getElementById('edit-button').image = "chrome://mproxy/content/icons/pencil_disabled.png"; + //document.getElementById('remove-button').image = "chrome://mproxy/content/icons/cross_disabled.png"; + //} + + if(typeof(gSwitchP_List.selectedItem.value) != 'undefined'){ + //If this item is not being used by the browser, + // show a helpful message and cycle + var oPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch(""); + if((!oPrefs.prefHasUserValue("mproxy.proxy.current") || oPrefs.getCharPref("mproxy.proxy.current") != gSwitchP_List.selectedItem.value) && gSwitchP_LastItem != null && gSwitchP_LastItem != gSwitchP_List.selectedItem){ + mproxy_setStatus(mproxy_getString("toolbar.clickApply"), "#060"); + + //Cycle if user doesn't click 'Apply' + //if(gSwitchP_Cycle == null) + // gSwitchP_Cycle = setTimeout("mproxy_cycle('select')", 10000); + } + //If it is being used by the browser + else if(oPrefs.prefHasUserValue("mproxy.proxy.current") && oPrefs.getCharPref("mproxy.proxy.current") == gSwitchP_List.selectedItem.value){ + mproxy_clearTimeout(gSwitchP_Cycle); + + //Anonomous + if(gSwitchP_List.selectedItem.getAttribute("proxyType") == "3"){ + // if(mproxy_anon_getCurrent() == "unknown") + // mproxy_setProxy(false); + // + // mproxy_setStatus(mproxy_getString("toolbar.using") +" "+ gSwitchP_List.selectedItem.label +" ["+ mproxy_anon_getCurrent() +"] ("+ mproxy_anon_getCurrentCount() +")"); + } + //Standard + else{ + mproxy_setStatus(mproxy_getString("toolbar.using") +" "+ gSwitchP_List.selectedItem.label); + } + } + else{ + mproxy_clearTimeout(gSwitchP_Cycle); + mproxy_setStatus(mproxy_getString("toolbar.using.none")); + } + } + + return true; +} + +//Queue Set Proxy +function mproxy_queueSetProxy(oMenuItem){ + mproxy_clearTimeout(gSwitchP_Cycle); + setTimeout("mproxy_setProxy(true, true, null, '"+ oMenuItem.label +"', '"+ oMenuItem.getAttribute("value") +"', '"+ oMenuItem.getAttribute("proxyType") +"')", 10); +} + +//Set Proxy +function mproxy_setProxy(bClean, fromContextMenu, oMenuItem, sLabel, sUri, sType){ + + //Start Command + gSwitchP_CommandEnd = false; + mproxy_clearTimeout(gSwitchP_Cycle); + //mproxy_anon_stopRotation(); + + //If in Proxy Manager, do nothing + if(gSwitchP_InManager){ + gSwitchP_CommandEnd = true; + return; + } + + var hasError = false; + + //Set fromContextMenu + if(fromContextMenu == null) + fromContextMenu = false; + + //Get Proxy URI & Label + var sProxyUri = ""; + var sProxyLabel = ""; + var sProxyType = 0; + if(sUri != null && sLabel != null){ + sProxyUri = sUri; + sProxyLabel = sLabel; + + if(sType) sProxyType = sType; + } + else if(oMenuItem != null){ + sProxyUri = oMenuItem.getAttribute("value"); + sProxyLabel = oMenuItem.getAttribute("label"); + sProxyType = oMenuItem.getAttribute("proxyType"); + } + else{ + if(fromContextMenu == true){ + sProxyUri = gSwitchP_ContextList.selectedItem.value; + sProxyLabel = gSwitchP_ContextList.selectedItem.label; + sProxyType = gSwitchP_ContextList.selectedItem.getAttribute("proxyType"); + } + else if(gSwitchP_List != null){ + sProxyUri = gSwitchP_List.selectedItem.value; + sProxyLabel = gSwitchP_List.selectedItem.label; + sProxyType = gSwitchP_List.selectedItem.getAttribute("proxyType"); + } + } + + //Branch if Anonomous + if(sProxyType == "3"){ + //mproxy_setStatus(mproxy_getString("toolbar.loading")); + //mproxy_anon_loadProxy(sProxyUri, true); + } + else if(sProxyUri != ""){ + mproxy_setStatus(mproxy_getString("toolbar.loading")); + try{ + //Always clear proxy settings first - this may mess up with selection... + //gSwitchP_Prefs.setIntPref("network.proxy.type", 0); + + //Change Browser Preferences + var aProps = mproxy_ds_getPropertyValuesFor(sProxyUri); + + for(key in gmproxy_options){ + + //Get pref type and update preference + var sPrefVal = ""; + if(typeof(gmproxy_options_defaults[key]) == "number"){ + gSwitchP_Prefs.setIntPref(gmproxy_options[key], parseInt(aProps[gSProxyRdfNodeUriRoot +"#"+ key])); + } + else if(typeof(gmproxy_options_defaults[key]) == "boolean"){ + gSwitchP_Prefs.setBoolPref(gmproxy_options[key], eval(aProps[gSProxyRdfNodeUriRoot +"#"+ key])); + } + else{ //String + gSwitchP_Prefs.setCharPref(gmproxy_options[key], aProps[gSProxyRdfNodeUriRoot +"#"+ key]); + } + } + + //Get Proxy Label + sProxyLabel = aProps[gSProxyRdfNodeName]; + + //Update Status + mproxy_setStatus(mproxy_getString("toolbar.using") +" "+ sProxyLabel); + + //Update Preference + gSwitchP_Prefs.setCharPref("mproxy.proxy.current", sProxyUri); + } + catch(err){ + alert("100: "+ mproxy_getString("error.unknown")+ "\n("+ err +")"); + hasError = true; + + //Cycle back to 'None' + //if(gSwitchP_Cycle == null && !fromContextMenu) + // gSwitchP_Cycle = setTimeout("mproxy_cycle('change')", 500); + } + } + else{ + //Turn off proxy pref + try{ + gSwitchP_Prefs.setIntPref("network.proxy.type", 0); + + //Update Status + mproxy_setStatus(mproxy_getString("toolbar.using.none")); + + + //Update Preference + gSwitchP_Prefs.setCharPref("mproxy.proxy.current", ""); + + }catch(e){ + alert("101: "+ mproxy_getString("error.unknown")); + hasError = true; + } + } + + // Finalize + if(hasError){ + //Update Status + mproxy_setStatus(mproxy_getString("error.proxy.load") +" " + sProxyLabel, "#F00"); + } + else{ + + //mproxy_tab_notify(sProxyUri); + + //Select this proxy in all lists + mproxy_selectItem(sProxyLabel); + + //Set Last Proxy + gSwitchP_LastItem = mproxy_getMenuItem(sProxyUri); + + //Options + try{ + if(bClean){ + // Clear Cookies + if(typeof(gBrowser) != 'undefined' && gSwitchP_Prefs.prefHasUserValue("mproxy.clear.cookies") && gSwitchP_Prefs.getBoolPref("mproxy.clear.cookies")){ + mproxy_clearCookies(); + } + + // Reload Page + if((typeof(gBrowser) != 'undefined' && (!gSwitchP_Prefs.prefHasUserValue("mproxy.reload.tab") || gSwitchP_Prefs.getBoolPref("mproxy.reload.tab")))){ + try{ + var oTab = gBrowser.mCurrentBrowser; + oTab.webNavigation.reload(nsIWebNavigation.LOAD_FLAGS_BYPASS_PROXY | nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE); + } catch(err) { } + } + + // Set Update Pref + gSwitchP_Prefs.setIntPref("mproxy.proxy.rdf.lastupdate", (new Date()).getTime()); + } + + }catch(err){alert("102: "+ mproxy_getString("error.unknown") + "\n("+err+")");} + } + + //End Command + gSwitchP_CommandEnd = true; + +} + +//Test if the RDF Element, oRef, is the current proxy being used +function mproxy_isSelected(oRef){ + + try{ + var oPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch); + var aProps = mproxy_ds_getPropertyValuesFor(oRef.Value); + var sCurrUri = ""; + var iType = parseInt(aProps[gSProxyRdfNodeUriRoot + "#networkProxyType"]); + + if(oPrefs.prefHasUserValue("mproxy.proxy.current") && (sCurrUri = oPrefs.getCharPref("mproxy.proxy.current")) == oRef.Value){ + + //Verify this is really what's being used in the browser + if(iType == oPrefs.getIntPref("network.proxy.type")){ + if(iType == 1){ + for(key in gmproxy_options){ + + //Skip These Keys + if(key == "networkProxyType" || key == "networkProxyAutoconfigURL" || key == "networkProxyHTTPShare" ) + continue; + + //Skip if RDF has Default Values + if( (key == "networkProxySOCKSVersion" && (aProps[gSProxyRdfNodeUriRoot +"#"+ key] == "5" || aProps[gSProxyRdfNodeUriRoot +"#"+ key] == "")) + || (key == "networkProxyNone" && aProps[gSProxyRdfNodeUriRoot +"#"+ key] == "localhost, 127.0.0.1")){ + continue; + } + + //If Pref and RDF doesn't have a value for this + if(!oPrefs.prefHasUserValue(gmproxy_options[key]) + && (aProps[gSProxyRdfNodeUriRoot +"#"+ key] == "" || aProps[gSProxyRdfNodeUriRoot +"#"+ key] == "0")){ + continue; + } + + // If pref doesn't have this and the RDF record does + // return false + if(!oPrefs.prefHasUserValue(gmproxy_options[key]) + && (aProps[gSProxyRdfNodeUriRoot +"#"+ key] != "" && aProps[gSProxyRdfNodeUriRoot +"#"+ key] != "0")){ + return false; + } + + + //Get pref and convert to string + var sPrefVal = ""; + if(oPrefs.getPrefType(gmproxy_options[key]) == Components.interfaces.nsIPrefBranch.PREF_INT) + sPrefVal = oPrefs.getIntPref(gmproxy_options[key]) + ""; + if(oPrefs.getPrefType(gmproxy_options[key]) == Components.interfaces.nsIPrefBranch.PREF_BOOL) + sPrefVal = oPrefs.getBoolPref(gmproxy_options[key]) + ""; + if(oPrefs.getPrefType(gmproxy_options[key]) == Components.interfaces.nsIPrefBranch.PREF_STRING) + sPrefVal = oPrefs.getCharPref(gmproxy_options[key]); + + //Return false if isn't equal + if(sPrefVal != aProps[gSProxyRdfNodeUriRoot +"#"+ key]){ + return false; + } + } + return true; + } + //If type is 2 and the PAC url is the same + else if(iType == 2 && oPrefs.prefHasUserValue("mproxy.proxy.current") + && oPrefs.getCharPref("network.proxy.autoconfig_url") == aProps[gSProxyRdfNodeUriRoot + "#networkProxyAutoconfigURL"]){ + return true; + } + } + //Anonomous + else if(iType == 3 && oPrefs.prefHasUserValue("network.proxy.http") && oPrefs.prefHasUserValue("network.proxy.http_port")){ + //var sProxy = oPrefs.getCharPref("network.proxy.http") +":"+ oPrefs.getIntPref("network.proxy.http_port"); + + //is sProxy in proxy list + //oTestRes = mproxy_ds_getElementForValue(gSProxyRdfNodeUriRoot +"#proxy", sProxy); + + //if(oTestRes instanceof Components.interfaces.nsIRDFResource && oTestRes.Value == oRes.Value){ + //mproxy_anon_loadProxy(oRef.Value, true); + //return true; + //} + + return false; + } + } + + }catch(err){} + + + return false; +} + +function mproxy_removeProxy(){ + mproxy_clearTimeout(gSwitchP_Cycle); + var oItem = gSwitchP_List.selectedItem; + + //Can't delete 'None' + if((gSwitchP_List.selectedItem != null) && + (gSwitchP_List.selectedItem.label == gSwitchP_NoneLabel) ){ + alert("150: "+ mproxy_getString("error.remove.forbidden")); + return; + } + + if(!confirm(mproxy_getString("confirm.remove"))) + return; + + try{ + //RDF + //Remove + mproxy_ds_removeElement(oItem.value); + + //Cleanup + mproxy_cleanupRdf(); + + //Update List + mproxy_populateList(); + setTimeout("mproxy_setProxy();", 300); + } + catch(err){ + alert("151: "+ mproxy_getString("error.remove") + "\n("+ err +")"); + } +} + +function mproxy_clearCookies(){ + try{ + var oCookies = Components.classes["@mozilla.org/cookiemanager;1"].createInstance(Components.interfaces.nsICookieManager); + oCookies.removeAll(); + }catch(err){ + alert("200: "+ mproxy_getString("error.cookie")); + } + return true; +} + +function mproxy_add_proxy(sName, sPort, issocks, toset){ + try{ + + var oTestProxy = mproxy_ds_getElementForValue(gSProxyRdfNodeName, sName); + if(oTestProxy != null){ + return false; + } + + var sProxyUri = mproxy_getUniqueProxyUri(); + var oProxy = mproxy_ds_getResource(sProxyUri); + mproxy_ds_addElement(sProxyUri); + + if (issocks) { //socks + mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxyType"), "1", true); + mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxyHTTP"), "", true); + mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxyHTTP_Port"), "", true); + mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxyHTTPShare"), false, true); + mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxySSL"), "", true); + mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxySSL_Port"), "", true); + mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxyFTP"), "", true); + mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxyFTP_Port"), "", true); + mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxyGopher"), "", true); + mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxyGopher_Port"), "", true); + mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxySOCKS"), "127.0.0.1", true); + mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxySOCKS_Port"), sPort, true); + mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxySOCKSVersion"), "5", true); + mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxyNone"), "localhost, 127.0.0.1", true); + mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxyAutoconfigURL"), "", true); + mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#name"), sName, true); + } + else { //regular http for all + mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxyType"), "1", true); + mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxyHTTP"), "127.0.0.1", true); + mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxyHTTP_Port"), sPort, true); + mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxyHTTPShare"), true, true); + mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxySSL"), "127.0.0.1", true); + mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxySSL_Port"), sPort, true); + mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxyFTP"), "127.0.0.1", true); + mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxyFTP_Port"), sPort, true); + mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxyGopher"), "127.0.0.1", true); + mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxyGopher_Port"), sPort, true); + mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxySOCKS"), "", true); + mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxySOCKS_Port"), "", true); + mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxySOCKSVersion"), "5", true); + mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxyNone"), "localhost, 127.0.0.1", true); + mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#networkProxyAutoconfigURL"), "", true); + mproxy_ds_addProperty(oProxy, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+"#name"), sName, true); + } + if (toset) { + mproxy_setProxy(true, null, null, sName, sProxyUri, 1); + mproxy_selectItem(sName); + } + return true; + }catch(e){ + alert(mproxy_getString("error.unknown") +"\n("+ e +")"); + return false; + } +} + +function mproxy_populateList(sSelectedLabel){ + mproxy_clearTimeout(gSwitchP_Cycle); + + var sProxyUri = ""; + var iSelected = (gSwitchP_List != null) ? gSwitchP_List.selectedIndex : -1; + var aProxies = new Array(); + + //Don't populate if a local command has not finished or if list is open + if(!gSwitchP_CommandEnd){ + gSwitchP_CommandEnd = true; //reset + return; + } + else{ //Start Command + gSwitchP_CommandEnd = false; + } + + //Load Elements + try{ + + //Remove List Items & Add 'None' + mproxy_clearList(); + mproxy_appendToList(gSwitchP_NoneLabel, "", true, 0); + mproxy_selectItem(gSwitchP_NoneLabel); + + //Add Tor as default proxy, and set proxy to it + //mproxy_add_proxy(mproxy_getString("common.proxy.tor"), "9050", true, true); + + //Get and Sort Elements + var aProxies = mproxy_ds_getAllElements(); + aProxies.sort(mproxy_sortProxies); + + //Add to list + for(i = 0; i < aProxies.length; i++){ + + if(typeof(aProxies[i]) == 'undefined') + continue; + + try{ + + oRes = mproxy_ds_getResource(aProxies[i]); + sProxyName = mproxy_ds_getValueFor(oRes, mproxy_ds_getResource(gSProxyRdfNodeName)); + sProxyType = mproxy_ds_getValueFor(oRes, mproxy_ds_getResource(gSProxyRdfNodeUriRoot+ "#networkProxyType")); + + if(sProxyName != null){ + oItem = mproxy_appendToList(sProxyName, aProxies[i], false, sProxyType); + + //Select Item + if((sSelectedLabel != null && sSelectedLabel == sProxyName) || (sSelectedLabel == null && mproxy_isSelected(oRes))){ + mproxy_selectItem(sProxyName); + } + } + + } catch(err) {} + } + + //Finish + gSwitchP_CommandEnd = true; + setTimeout("mproxy_selectProxy();", 300); + + }catch(err){} +} + +/* +* Sort Proxy List +* + oResA and oResB are RDF URIs +*/ +function mproxy_sortProxies(oResA, oResB){ + try{ + //Get Proxy Names + sValA = mproxy_ds_getValueFor(mproxy_ds_getResource(oResA), mproxy_ds_getResource(gSProxyRdfNodeName)); + sValB = mproxy_ds_getValueFor(mproxy_ds_getResource(oResB), mproxy_ds_getResource(gSProxyRdfNodeName)); + + + if (sValA < sValB) + return -1; + if (sValA == sValB) + return 0; + if (sValA > sValB) + return 1; + } + catch(e){ return 0; } +} + +/* Cleanup unused mproxy data in RDF +* + Remove resources that have not been applied or used +*/ +function mproxy_cleanupRdf(){ + + try{ + + var aElements = mproxy_ds_getAllElements(); + for(var e = 0; e < aElements.length; e++){ + oRes = mproxy_ds_getResource(aElements[e]); + aProps = mproxy_ds_getPropertyValuesFor(aElements[e]); + + //If does not have a name property, + // then it is not listed -- so it's junk + if(aProps[gSProxyRdfNodeName] == null){ + mproxy_ds_removeElement(aElements[e]); + } + } + }catch(err){} +} + +// Automatic Upgrade +/* +* From Version 0.4 +* + Add preference 'mproxy.version' +* + Add preference 'mproxy.proxy.current' +* + Change proxy's URI to random number +* + Convert #proxy to networkProxyAutoconfigURL +* + Add elements for full manual proxy configuration +* + view the globals.js gmproxy_options array for full list +*/ + + +//Generates random number for proxy URI +function mproxy_getUniqueProxyUri(){ + var sUri = gSProxyRdfRoot + "/mproxy_" + Math.round((Math.random() * 200000)); + + if(mproxy_ds_doesProxyElementExist(sUri)) + return mproxy_getUniqueProxyUri(); + + return sUri; +} + +function mproxy_setStatus(sMsg, sColor){ + if(!sColor) + sColor = "#000"; + + oStatus = document.getElementById('status-text'); + + if(oStatus != null){ + document.getElementById('status-text').style.color = sColor; + document.getElementById('status-text').value = sMsg; + } +} + +//Clear Timeout +function mproxy_clearTimeout(){ + clearTimeout(gSwitchP_Cycle); + gSwitchP_Cycle = null; +} + +//Execute a command when system is ready +// iCurrCount is for internal use, do not +// pass this argument +function mproxy_doCommand(sCommand, iLimitCount){ + + if(iLimitCount == null) + iLimitCount = 0; + + //Wait for current command to end + if(!gSwitchP_CommandEnd && iLimitCount < 10){ + iLimitCount++ + setTimeout("mproxy_doCommand('"+ sCommand +"', "+ iCurrCount +")", 100); + } + else{ + gSwitchP_CommandEnd = true; + setTimeout(sCommand, 100); + } +} + +/* +* Launch Dialogs +*/ + + //Edit Proxy Dialog + function mproxy_editProxyDialog(isNew){ + mproxy_clearTimeout(gSwitchP_Cycle); + + var sAction = null; + + //Nothing Selected + var oEditItem = null + if(!isNew && (oEditItem = gSwitchP_List.selectedItem) == null){ + alert("250: "+ mproxy_getString("error.edit.select")); + return; + } + + //Can't edit 'None' + if(!gSwitchP_InManager && !isNew && gSwitchP_List != null && gSwitchP_List.selectedItem != null && gSwitchP_List.selectedItem.label == gSwitchP_NoneLabel){ + alert("251: "+ mproxy_getString("error.edit.forbidden")); + return; + } + + //Edit + if(!isNew){ + + //Anon + //if(oEditItem.getAttribute("proxyType") == "3"){ + // window.openDialog("chrome://mproxy/content/dialogs/editanon.xul","editproxy","centerscreen, chrome", "edit", oEditItem.value); + //} + //Standard + //else{ + window.openDialog("chrome://mproxy/content/dialogs/editproxy.xul","editproxy","centerscreen, chrome", "edit", oEditItem.value); + //} + } + //Add + else{ + //window.openDialog("chrome://mproxy/content/dialogs/addproxytype.xul","editproxy","centerscreen, chrome", "add"); + window.openDialog("chrome://mproxy/content/dialogs/editproxy.xul","addproxy","centerscreen, chrome", "add", gSwitchP_InManager); + } + } + + //Manage Proxy Dialog + function mproxy_openProxyManager(){ + window.openDialog("chrome://mproxy/content/dialogs/manager.xul","manageproxies","centerscreen, chrome, resizable"); + } + +/* +* Options +*/ + function mproxy_openmproxyPrefs(){ + window.openDialog("chrome://mproxy/content/options/options.xul","mproxyPrefs","centerscreen, chrome"); + } + + function mproxy_goTomproxySite(fromDialog){ + + // If Thunderbird + if(navigator.userAgent.search(/Thunderbird/gi) > -1){ + var messenger = Components.classes["@mozilla.org/messenger;1"].createInstance(); + messenger = messenger.QueryInterface(Components.interfaces.nsIMessenger); + messenger.launchExternalURL(gmproxy_DownloadSite +"?r=mproxy"); + } + else{ + opener.gBrowser.selectedTab = opener.getBrowser().addTab(gmproxy_DownloadSite +"?r=mproxy"); + } + self.close(); + } + + function mproxy_goTomproxyAbout(){ + window.openDialog("chrome://mproxy/content/dialogs/about.xul","mproxyAbout","centerscreen, chrome, modal"); + } + +/* +* Automatic Updator +*/ + + //If there is a new version, returns the XPI url, else returns false + + //The user selects to check for updates + +/* +* UNINSTALL +*/ + function mproxy_uninstall(oLogger){ + try{ + var oPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch); + oPrefs.deleteBranch("mproxy"); + + oLogger.addLog(new window.ExtuninstallLogItem(oLogger.REMOVE_ACTION, oLogger.SUCCESS_STATUS, "Preferences Branch 'mproxy'", null, null)); + }catch(err){ + oLogger.addLog(new window.ExtuninstallLogItem(oLogger.REMOVE_ACTION, oLogger.WARN_STATUS, "Preferences Branch 'mproxy'", 1001, err)); + throw 1001; + } + } + diff --git a/src/chrome/content/proxy.xul b/src/chrome/content/proxy.xul new file mode 100644 index 0000000..b0cb91a --- /dev/null +++ b/src/chrome/content/proxy.xul @@ -0,0 +1,125 @@ + + + + + + + + + + + + + + + + + + + + + + + + + +