home *** CD-ROM | disk | FTP | other *** search
- var gAnonRotate = false;
- var gAnonTimout = null;
- var gAnonUri = null;
- var gAnonLabel = "unknown";
- var gAnonCurrent = "unknown";
- var gCurrentCount = 0;
- var gAnonUpdateTimout = null;
- var gAnonLastUrl = "";
-
- /*
- * Load an anonomous proxy from sUri.
- * cleanLoad is set to true when this is called
- * for the first time for sUri
- */
- function switchproxy_anon_loadProxy(sUri, cleanLoad){
-
- clearTimeout(gAnonTimout);
- gAnonTimout = null;
-
- if(cleanLoad){
- gAnonRotate = true;
- }
- else if(!gAnonRotate){
- return;
- }
-
- if(sUri == null && gAnonUri != null){
- sUri = gAnonUri;
- }
-
- try{
- var iPause = (60) * 1000;
- var oProxy = switchProxy_ds_getResource(sUri);
- var oProxyConfig = switchProxy_ds_getPropertyValuesFor(sUri);
- var sProxyLabel = oProxyConfig[gSProxyRdfNodeName];
- var oPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
-
- //Set Interval
- if(oProxyConfig[gSProxyRdfNodeUriRoot + "#interval"] && !isNaN(oProxyConfig[gSProxyRdfNodeUriRoot + "#interval"]) && parseInt(oProxyConfig[gSProxyRdfNodeUriRoot + "#interval"]) > 0)
- iPause = parseInt(oProxyConfig[gSProxyRdfNodeUriRoot + "#interval"]) * 1000;
-
- //Get Proxy List
- var aProxyList = switchProxy_ds_getValuesFor(oProxy, switchProxy_ds_getResource(gSProxyRdfNodeUriRoot + "#proxy"));
- if(aProxyList.length == 0){
- alert("SwitchProxy\n"+ switchproxy_getString("anon.config.empty"));
- return;
- }
-
- // Pick a Random proxy
- var iPick = Math.round(Math.random() * (aProxyList.length - 1));
-
- if(gAnonLastUrl == aProxyList[iPick])
- iPick = Math.round(Math.random() * (aProxyList.length - 1));
-
- var gAnonLastUrl = aProxyList[iPick];
- var aProxy = switchproxy_splitDomain(aProxyList[iPick]);
- gAnonLabel = sProxyLabel;
- gAnonCurrent = aProxyList[iPick];
- gCurrentCount = ( iPause / 1000 );
- gAnonUri = sUri;
-
- //Exit if couldn't split domain
- if(aProxy.length == 0){
- alert("SwitchProxy\n"+ switchproxy_getString("error.unknown"));
- return;
- }
-
- //Reset all proxy prefs
- for(key in gSwichProxy_options){
-
- if(key != "networkProxyAutoconfigURL" && oPrefs.prefHasUserValue(gSwichProxy_options[key]))
- oPrefs.clearUserPref(gSwichProxy_options[key]);
- }
-
- //Set Proxy
- oPrefs.setIntPref("network.proxy.type", 1);
- oPrefs.setCharPref("switchproxy.proxy.current", sUri);
-
- // Set Types
- if(!oProxyConfig[gSProxyRdfNodeUriRoot + "#http"] || oProxyConfig[gSProxyRdfNodeUriRoot + "#http"] == "true"){
- oPrefs.setCharPref("network.proxy.http", aProxy[0]);
- oPrefs.setIntPref("network.proxy.http_port", parseInt(aProxy[1]));
- }
- if(!oProxyConfig[gSProxyRdfNodeUriRoot + "#ssl"] || oProxyConfig[gSProxyRdfNodeUriRoot + "#ssl"] == "true"){
- oPrefs.setCharPref("network.proxy.ssl", aProxy[0]);
- oPrefs.setIntPref("network.proxy.ssl_port", parseInt(aProxy[1]));
- }
- if(!oProxyConfig[gSProxyRdfNodeUriRoot + "#ftp"] || oProxyConfig[gSProxyRdfNodeUriRoot + "#ftp"] == "true"){
- oPrefs.setCharPref("network.proxy.ftp", aProxy[0]);
- oPrefs.setIntPref("network.proxy.ftp_port", parseInt(aProxy[1]));
- }
- if(!oProxyConfig[gSProxyRdfNodeUriRoot + "#gopher"] || oProxyConfig[gSProxyRdfNodeUriRoot + "#gopher"] == "true"){
- oPrefs.setCharPref("network.proxy.gopher", aProxy[0]);
- oPrefs.setIntPref("network.proxy.gopher_port", parseInt(aProxy[1]));
- }
- if(!oProxyConfig[gSProxyRdfNodeUriRoot + "#socks"] || oProxyConfig[gSProxyRdfNodeUriRoot + "#socks"] == "true"){
- oPrefs.setCharPref("network.proxy.socks", aProxy[0]);
- oPrefs.setIntPref("network.proxy.socks_port", parseInt(aProxy[1]));
- }
- if(oProxyConfig[gSProxyRdfNodeUriRoot + "#socks_type"] && !isNaN(oProxyConfig[gSProxyRdfNodeUriRoot + "#socks_type"])){
- oPrefs.setIntPref("network.proxy.socks_version", parseInt(oProxyConfig[gSProxyRdfNodeUriRoot + "#socks_type"]));
- }
-
- //Start loop
- gAnonTimout = setTimeout("switchproxy_anon_countdown('"+ sUri +"');", 1000);
-
- //Update Status
- try{
- switchproxy_setStatus(switchproxy_getString("toolbar.using") +" "+ sProxyLabel +" ["+ aProxyList[iPick] +"] ("+ gCurrentCount +")");
- gSwitchP_StatusBar.setAttribute("label", "Proxy: "+ sProxyLabel +" ["+ aProxyList[iPick] +"] ("+ gCurrentCount +")");
- }catch(e){ }
-
-
- }catch(err){alert("SwitchProxy\n"+ switchproxy_getString("error.unknown") + "\n"+ err);}
- }
-
- // Goto next anon proxy in list
- function switchproxy_anon_nextProxy(){
- try{
- var oContext = document.getElementById('context-proxy-list');
- var sUri = oContext.selectedItem.value;
- var sType = oContext.selectedItem.getAttribute("proxyType");
-
- if(sType == "3")
- switchproxy_anon_loadProxy(sUri);
-
- } catch(e){ }
- }
-
- //Stop Anonomous Proxy Rotation
- function switchproxy_anon_stopRotation(){
- gAnonRotate = false;
- gAnonUri = null;
- gAnonLabel = "unknown";
- gAnonCurrent = "unknown";
- gCurrentCount = 0;
-
- if(gAnonTimout != null)
- clearTimeout(gAnonTimout);
-
- gAnonTimout = null;
- }
-
- //Get the current proxy
- function switchproxy_anon_getCurrent(){
- return gAnonCurrent;
- }
-
- //Get the current countdown
- function switchproxy_anon_getCurrentCount(){
- return gCurrentCount;
- }
-
- //Pause Rotation by sTime in milliseconds
- function switchproxy_anon_pauseRotation(sTime){
- if(gAnonTimout != null){
- clearTimeout(gAnonTimout);
- gAnonTimout = setTimeout("switchproxy_anon_countdown('"+ gAnonUri +"');", sTime);
- }
- }
-
- //Countdown Rotation
- function switchproxy_anon_countdown(sUri){
-
- if(!gAnonRotate)
- return;
-
- gCurrentCount--;
-
- //End
- if(gCurrentCount < 0){
- switchproxy_anon_loadProxy(sUri);
- return;
- }
-
- //Continue
- gAnonTimout = setTimeout("switchproxy_anon_countdown('"+ sUri +"');", 1000);
- try{
- switchproxy_setStatus(switchproxy_getString("toolbar.using") +" "+ gAnonLabel +" ["+ gAnonCurrent +"] ("+ gCurrentCount +")");
- gSwitchP_StatusBar.setAttribute("label", "Proxy: "+ gAnonLabel +" ["+ gAnonCurrent +"] ("+ gCurrentCount +")");
- } catch(e){ }
- }
-
- //Auto-Update Proxy Lists with URL
- function switchproxy_anon_autoUpdateLists(){
-
- var iNow = (new Date()).getTime();
- var iTime = iNow - (90000 * 1000); //25 hours ago
-
- //Get all anon configurations
- var aAnon = switchProxy_ds_getElementsForValue(gSProxyRdfNodeUriRoot + "#networkProxyType", "3");
-
- //Find one that needs updating
- var sValue = "";
- var sUrl = "";
- var sAuto = "";
- var iLast = 0;
-
- for(var i = 0; i < aAnon.length; i++){
- try{
- sAuto = switchProxy_ds_getValueFor(aAnon[i], switchProxy_ds_getResource(gSProxyRdfNodeUriRoot + "#autoUpdate"));
- sUrl = switchProxy_ds_getValueFor(aAnon[i], switchProxy_ds_getResource(gSProxyRdfNodeUriRoot + "#autoUpdateUrl"));
- sValue = switchProxy_ds_getValueFor(aAnon[i], switchProxy_ds_getResource(gSProxyRdfNodeUriRoot + "#autoUpdateTime"));
- if(sAuto == "true" && !switchproxy_isEmpty(sUrl) && sValue != null && !isNaN(sValue)){
- iValue = parseInt(sValue);
-
- //Needs to be updated
- if(iValue <= iTime){
-
- //Import
- switchproxy_anon_import("url", sUrl, null, aAnon[i].Value);
-
- //Update Timestamp
- switchProxy_ds_removeProperty(gSProxyRdfNodeUriRoot + "#autoUpdateTime", aAnon[i]);
- switchProxy_ds_addProperty(aAnon[i], switchProxy_ds_getResource(gSProxyRdfNodeUriRoot + "#autoUpdateTime"), iNow, true);
-
- break;
- }
- }
- }catch(err){ }
- }
-
- //Check Again
- if(aAnon.length > 0){
- var iRecheck = ((43200 * 1000) / aAnon.length) //Break up checks throughout the day
- gAnonUpdateTimout = setTimeout("switchproxy_anon_autoUpdateLists()", iRecheck);
- }
- }
-
- //Get Auto Update Timout Object
- function switchproxy_anon_getAutoUpdateTimout(){
- return gAnonUpdateTimout;
- }