home *** CD-ROM | disk | FTP | other *** search
-
- var gProxy = null;
- var gProxyList = null;
- var gProxyLabel = "";
- var gAutoUrl = false;
- var gIsEdit = false;
- var gAutoTime = 0;
-
- // Prepopulate fields
- function switchproxy_anon_initDialog(){
-
- gProxyList = document.getElementById('proxy-list');
- gProxyLabel = document.getElementById('proxy-label-field');
-
- if(window.arguments.length > 1 && window.arguments[0] == "edit" && !switchproxy_isEmpty(window.arguments[1])){
-
- gIsEdit = true;
- gProxyURI = window.arguments[1];
-
- try{
- gProxy = switchProxy_ds_getResource(gProxyURI);
-
- //Load Fields
- var oProxyConfig = switchProxy_ds_getPropertyValuesFor(gProxyURI);
-
- // Label
- gProxyLabel.value = oProxyConfig[gSProxyRdfNodeName];
-
- // Auto URL & Checkbox
- if(typeof(oProxyConfig[gSProxyRdfNodeUriRoot + "#autoUpdate"]) != 'undefined' && oProxyConfig[gSProxyRdfNodeUriRoot + "#autoUpdate"] == "true"){
- document.getElementById('auto-import-check').checked = true;
- switchproxy_anon_enableAutoUrl(document.getElementById('auto-import-check'))
-
- // URL
- if(typeof(oProxyConfig[gSProxyRdfNodeUriRoot + "#autoUpdateUrl"]) != 'undefined');
- document.getElementById('import-url-field').value = oProxyConfig[gSProxyRdfNodeUriRoot + "#autoUpdateUrl"];
- }
-
- // Last Auto Update
- if(typeof(oProxyConfig[gSProxyRdfNodeUriRoot + "#autoUpdateTime"]) != 'undefined' && !isNaN(oProxyConfig[gSProxyRdfNodeUriRoot + "#autoUpdateTime"]))
- gAutoTime = parseInt(oProxyConfig[gSProxyRdfNodeUriRoot + "#autoUpdateTime"]);
-
- // Interval
- if(oProxyConfig[gSProxyRdfNodeUriRoot + "#interval"])
- document.getElementById('increment-field').value = oProxyConfig[gSProxyRdfNodeUriRoot + "#interval"];
- else
- document.getElementById('increment-field').value = "60";
-
- // Proxy List
- var aProxyList = switchProxy_ds_getValuesFor(gProxy, switchProxy_ds_getResource(gSProxyRdfNodeUriRoot + "#proxy"));
- for(var i = 0; i < aProxyList.length; i++){
- switchproxy_anon_addProxyToList(aProxyList[i]);
- }
-
- // Proxy Types
- if(oProxyConfig[gSProxyRdfNodeUriRoot + "#http"])
- document.getElementById("type_http").setAttribute("checked", oProxyConfig[gSProxyRdfNodeUriRoot + "#http"]);
- if(oProxyConfig[gSProxyRdfNodeUriRoot + "#ssl"])
- document.getElementById("type_ssl").setAttribute("checked", oProxyConfig[gSProxyRdfNodeUriRoot + "#ssl"]);
- if(oProxyConfig[gSProxyRdfNodeUriRoot + "#ftp"])
- document.getElementById("type_ftp").setAttribute("checked", oProxyConfig[gSProxyRdfNodeUriRoot + "#ftp"]);
- if(oProxyConfig[gSProxyRdfNodeUriRoot + "#gopher"])
- document.getElementById("type_gopher").setAttribute("checked", oProxyConfig[gSProxyRdfNodeUriRoot + "#gopher"]);
- if(oProxyConfig[gSProxyRdfNodeUriRoot + "#socks"])
- document.getElementById("type_socks").setAttribute("checked", oProxyConfig[gSProxyRdfNodeUriRoot + "#socks"]);
-
- if(oProxyConfig[gSProxyRdfNodeUriRoot + "#socks_type"] && oProxyConfig[gSProxyRdfNodeUriRoot + "#socks_type"] == "4"){
- document.getElementById("socks_v4").setAttribute("selected", "true");
- document.getElementById("socks_v5").setAttribute("selected", "false");
- }
- else if(oProxyConfig[gSProxyRdfNodeUriRoot + "#socks_type"] && oProxyConfig[gSProxyRdfNodeUriRoot + "#socks_type"] == "5"){
- document.getElementById("socks_v4").setAttribute("selected", "false");
- document.getElementById("socks_v5").setAttribute("selected", "true");
- }
-
-
- }catch(err){ alert(switchproxy_getString("error.unknown") +"\n"+ err); self.close(); }
- }
-
- // Thunderbird
- if(navigator.userAgent.search(/Thunderbird/gi) > -1){
- document.getElementById("type_ftp").style.display = "none";
- document.getElementById("type_gopher").style.display = "none";
- }
-
- }
-
- // Open file picker
- // set sId value to file path
- // on return OK, enable sEnableId element
- function switchproxy_anon_pickFile(sId, sEnableId){
-
- try{
- //Open Dialog
- var oField = document.getElementById(sId);
- var nsIFilePicker = Components.interfaces.nsIFilePicker;
- var oPicker = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
- oPicker.init(window, "Select a File", nsIFilePicker.modeOpen);
- oPicker.appendFilter("Text Files","*.txt");
- oPicker.appendFilter("Document Files","*.doc");
- oPicker.appendFilter("All Files","*.*");
- var oRes = oPicker.show();
-
- //Get Filepath
- if(oRes == nsIFilePicker.returnOK && oField != null){
- oField.value = oPicker.file.path;
-
- if(sEnableId != null){
- oEnable = document.getElementById(sEnableId);
-
- if(oEnable)
- oEnable.disabled = false;
- }
- }
- }catch(err){ alert(switchproxy_getString("error.unknown") +"\n"+ err); }
- }
-
- // Manuall add proxy
- function switchproxy_anon_addProxy(){
-
- var oAddField = document.getElementById('add-field');
- var oAddButton = document.getElementById('add-button');
- var oProxyList = document.getElementById('proxy-list');
-
- //Validate
- //Empty
- if(switchproxy_isEmpty(oAddField.value)){
- alert(switchproxy_getString("add.anon.validate.empty"));
- return;
- }
- //Does entry exist?
- if(switchproxy_existsInList(oProxyList, oAddField.value)){
- alert(switchproxy_getString("add.anon.validate.duplicate"));
- return;
- }
- //Is valid Domain or IP
- if(!switchproxy_isValidDomain(oAddField.value)){
- alert(switchproxy_getString("add.anon.validate.domain"));
- return;
- }
-
- //Add Item
- switchproxy_anon_addProxyToList(oAddField.value);
-
- //Clear field
- oAddField.value = "";
- }
-
- // Manually remove proxy
- function switchproxy_anon_removeProxy(){
-
- var oProxyList = document.getElementById('proxy-list');
- var aSelected = oProxyList.selectedItems;
- var iSelected = oProxyList.getIndexOfItem(aSelected[0]);
-
- if(oProxyList.selectedItem == null){
- alert(switchproxy_getString("add.anon.validate.remove"));
- return;
- }
-
- //Remove Selected
- for(var i = (oProxyList.selectedCount - 1); i < oProxyList.selectedCount; i--){
- oProxyList.removeItemAt(oProxyList.getIndexOfItem(aSelected[i]));
- }
-
- //Select next item
- if(oProxyList.getRowCount() > 0){
- if(oProxyList.getRowCount() >= (iSelected + 1)){
- oProxyList.selectItem(oProxyList.getItemAtIndex(iSelected));
- }
- else if(oProxyList.getRowCount() > 0){
- oProxyList.selectItem(oProxyList.getItemAtIndex(iSelected - 1));
- }
-
- oProxyList.focus();
- }
- }
-
- /*
- * Save Anon Configuration
- */
- function switchproxy_anon_save(){
-
- var oProxyLabel = document.getElementById("proxy-label-field");
- var oUrlField = document.getElementById("import-url-field");
- var oUrlAutoCheck = document.getElementById("auto-import-check");
- var oIntervalField = document.getElementById("increment-field");
- var oProxyList = document.getElementById("proxy-list");
-
- //Validation
- //Empty Label
- if(switchproxy_isEmpty(oProxyLabel.value)){
- alert(switchproxy_getString("add.anon.validate.label"));
- oProxyLabel.focus();
- return false;
- }
- //Label with special chars
- if(!switchproxy_allowedChars(oProxyLabel.value)){
- alert(switchproxy_getString("error.add.invalid"));
- return false;
- }
- //Label can't be named 'None'
- if(switchproxy_simplify(oProxyLabel.value) == switchproxy_simplify(switchproxy_getString("common.proxy.none"))){
- alert(switchproxy_getString("error.add.duplicate"));
- return false;
- }
- //Is This a Duplicate Label?
- var oTestProxy = switchProxy_ds_getElementForValue(gSProxyRdfNodeName, oProxyLabel.value);
- if(oTestProxy != null && (!gIsEdit || oTestProxy.Value != gProxy.Value)){
- alert(switchproxy_getString("error.add.duplicate"));
- return false;
- }
- //Empty Interval
- if(switchproxy_isEmpty(oIntervalField.value)){
- alert(switchproxy_getString("add.anon.validate.rotation"));
- oIntervalField.focus();
- return false;
- }
- //Interval not a number
- if(isNaN(oIntervalField.value)){
- alert(switchproxy_getString("add.anon.validate.rotation.type"));
- oIntervalField.focus();
- return false;
- }
-
- try{
- var oProxy = null;
- var sProxyUri = opener.switchproxy_getUniqueProxyUri();
-
- /*
- * EDIT
- */
- if(gIsEdit){
- oProxy = gProxy;
-
- //Remove Properties
- //Label
- switchProxy_ds_removeProperty(gSProxyRdfNodeName, oProxy);
- //Interval
- switchProxy_ds_removeProperty(gSProxyRdfNodeUriRoot + "#interval", oProxy);
- //Auto Update
- switchProxy_ds_removeProperty(gSProxyRdfNodeUriRoot + "#autoUpdate", oProxy);
- //Auto Update URL
- switchProxy_ds_removeProperty(gSProxyRdfNodeUriRoot + "#autoUpdateUrl", oProxy);
- //Proxy
- switchProxy_ds_removeProperty(gSProxyRdfNodeUriRoot + "#proxy", oProxy);
-
- // Types
- switchProxy_ds_removeProperty(gSProxyRdfNodeUriRoot + "#http", oProxy);
- switchProxy_ds_removeProperty(gSProxyRdfNodeUriRoot + "#ssl", oProxy);
- switchProxy_ds_removeProperty(gSProxyRdfNodeUriRoot + "#ftp", oProxy);
- switchProxy_ds_removeProperty(gSProxyRdfNodeUriRoot + "#gopher", oProxy);
- switchProxy_ds_removeProperty(gSProxyRdfNodeUriRoot + "#http", oProxy);
- switchProxy_ds_removeProperty(gSProxyRdfNodeUriRoot + "#socks", oProxy);
- switchProxy_ds_removeProperty(gSProxyRdfNodeUriRoot + "#socks_type", oProxy);
- }
-
- /*
- * ADD
- */
- //Create New Element
- if(!gIsEdit)
- var oProxy = switchProxy_ds_getResource(sProxyUri);
-
- //Add Element
- switchProxy_ds_addElement(sProxyUri);
-
- //Add Properties
- // Proxy Label
- switchProxy_ds_addProperty(oProxy,
- switchProxy_ds_getResource(gSProxyRdfNodeName),
- oProxyLabel.value, true);
- // Type = 3 (anon)
- switchProxy_ds_addProperty(oProxy,
- switchProxy_ds_getResource(gSProxyRdfNodeUriRoot + "#networkProxyType"),
- "3", true);
- // Interval
- switchProxy_ds_addProperty(oProxy,
- switchProxy_ds_getResource(gSProxyRdfNodeUriRoot + "#interval"),
- oIntervalField.value, true);
- // Auto Update
- switchProxy_ds_addProperty(oProxy,
- switchProxy_ds_getResource(gSProxyRdfNodeUriRoot + "#autoUpdate"),
- oUrlAutoCheck.checked, true);
- // Auto Update URL
- if(oUrlAutoCheck.checked){
- switchProxy_ds_addProperty(oProxy,
- switchProxy_ds_getResource(gSProxyRdfNodeUriRoot + "#autoUpdateUrl"),
- oUrlField.value, true);
- }
-
- //Last Auto Update
- switchProxy_ds_addProperty(oProxy,
- switchProxy_ds_getResource(gSProxyRdfNodeUriRoot + "#autoUpdateTime"),
- gAutoTime, true);
-
- // Types
- switchProxy_ds_addProperty(oProxy,
- switchProxy_ds_getResource(gSProxyRdfNodeUriRoot + "#http"),
- document.getElementById("type_http").checked, true);
- switchProxy_ds_addProperty(oProxy,
- switchProxy_ds_getResource(gSProxyRdfNodeUriRoot + "#ssl"),
- document.getElementById("type_ssl").checked, true);
- switchProxy_ds_addProperty(oProxy,
- switchProxy_ds_getResource(gSProxyRdfNodeUriRoot + "#ftp"),
- document.getElementById("type_ftp").checked, true);
- switchProxy_ds_addProperty(oProxy,
- switchProxy_ds_getResource(gSProxyRdfNodeUriRoot + "#gopher"),
- document.getElementById("type_gopher").checked, true);
- switchProxy_ds_addProperty(oProxy,
- switchProxy_ds_getResource(gSProxyRdfNodeUriRoot + "#socks"),
- document.getElementById("type_socks").checked, true);
-
- if(document.getElementById("socks_v4").getAttribute("selected") == "true"){
- switchProxy_ds_addProperty(oProxy,
- switchProxy_ds_getResource(gSProxyRdfNodeUriRoot + "#socks_type"),
- "4", true);
- }
- else if(document.getElementById("socks_v5").getAttribute("selected") == "true"){
- switchProxy_ds_addProperty(oProxy,
- switchProxy_ds_getResource(gSProxyRdfNodeUriRoot + "#socks_type"),
- "5", true);
- }
-
- //Proxy List
- var sProxy = "";
- for(var i = 0; i < oProxyList.getRowCount(); i++){
- sProxy = oProxyList.getItemAtIndex(i).getAttribute("value");
- if(sProxy && !switchproxy_isEmpty(sProxy)){
- switchProxy_ds_addProperty(oProxy,
- switchProxy_ds_getResource(gSProxyRdfNodeUriRoot + "#proxy"),
- sProxy, true);
- }
- }
-
- //Refresh Browser List
- var oPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
- oPrefs.setIntPref("switchproxy.proxy.rdf.lastupdate", (new Date()).getTime());
-
- //Set Auto Update
- if(opener.switchproxy_anon_getAutoUpdateTimout() == null)
- gAnonUpdateTimout = setTimeout("switchproxy_anon_autoUpdateLists()", 600000);
-
- switchproxy_openerFocus();
-
- }catch(err){ alert(switchproxy_getString("error.unknown") +"\n("+ err +")"); return false; }
- }
-
- /*
- * IMPORT WRAPPERS
- */
- // File
- function switchproxy_anon_importFile(){
- var oField = document.getElementById("import-file-field");
- var oButton = document.getElementById("import-file-button");
- var oList = document.getElementById("proxy-list");
- var sValue = oField.value;
-
- try{
-
- oButton.blur();
-
- //Cancel
- if(oButton.label == "Cancel"){
- switchproxy_anon_cancelImport();
- oButton.label = switchproxy_getString("common.buttons.load");
- return;
- }
-
- //Load
- if(!switchproxy_isEmpty(sValue)){
- oButton.label = switchproxy_getString("common.buttons.cancel");
- oField.value = switchproxy_getString("toolbar.loading");
- switchproxy_anon_import("file", sValue, oList, null);
- oField.value = sValue;
- oButton.label = switchproxy_getString("common.buttons.load");
-
- if(switchproxy_anon_getNumImported() == 0)
- alert(switchproxy_getString("add.anon.import.file.validate.empty"));
- else if(switchproxy_anon_getNewImported() == 0)
- alert(switchproxy_getString("add.anon.import.validate.old"));
- }
-
-
- }catch(err){ alert(switchproxy_getString("error.unknown") +"\n("+ err +")"); }
- }
-
- // URL
- function switchproxy_anon_importUrl(){
- var oField = document.getElementById("import-url-field");
- var oButton = document.getElementById("import-url-button");
- var oList = document.getElementById("proxy-list");
- var sValue = oField.value;
-
- try{
-
- oButton.blur();
-
- //Cancel
- if(oButton.label == "Cancel"){
- switchproxy_anon_cancelImport();
- oButton.label = switchproxy_getString("common.buttons.load");
- return;
- }
-
- //Load
- if(!switchproxy_isEmpty(sValue)){
- oButton.label = switchproxy_getString("common.buttons.cancel");
- oField.value = switchproxy_getString("toolbar.loading");
-
- switchproxy_anon_import("url", sValue, oList, null);
-
- oField.value = sValue;
- oButton.label = switchproxy_getString("common.buttons.load");
-
- if(switchproxy_anon_getNumImported() == 0)
- alert(switchproxy_getString("add.anon.import.url.validate.empty"));
- else if(switchproxy_anon_getNewImported() == 0)
- alert(switchproxy_getString("add.anon.import.validate.old"));
-
- gAutoTime = (new Date()).getTime()
- }
-
- self.focus();
-
- }catch(err){ alert(switchproxy_getString("error.unknown") +"\n("+ err +")"); }
- }
-
-
- /*
- * ENABLE FORM FIELDS
- */
- // Enable Load button for the URL or File field
- function switchproxy_anon_enableLoadButton(oField){
- var oButton = null;
-
- if(oField.id == "import-url-field")
- oButton = document.getElementById('import-url-button');
- else if(oField.id == "import-file-field")
- oButton = document.getElementById('import-file-button');
-
- if(oField && oButton && oField.value != ""){
- oButton.disabled = false;
- }
- else if(oField && oButton && oField.value == ""){
- oButton.disabled = true;
- }
- }
-
- // Toggles if the list is automatically generated from URL
- // if true, it disables the add button
- function switchproxy_anon_enableAutoUrl(oCheckbox){
-
- var oAddField = document.getElementById('add-field');
- var oAddButton = document.getElementById('add-button');
-
- if(oAddField == null || oAddButton == null)
- return;
-
- if(oCheckbox.checked){
- oAddField.value = "";
- oAddField.setAttribute("disabled", "true");
- oAddButton.setAttribute("disabled", "true");
- }
- else{
- oAddField.setAttribute("disabled", "false");
- oAddButton.setAttribute("disabled", "false");
- }
- }
-
- // Enable Remove Field
- function switchproxy_anon_enableRemove(doEnable){
-
- var oRemoveButton = document.getElementById('remove-button');
- oRemoveButton.setAttribute("disabled", (!doEnable) );
- }
-
- /*
- * UTILS
- */
- function switchproxy_anon_addProxyToList(sProxy){
- if(gProxyList != null){
-
- //Add
- var oItem = gProxyList.appendItem(sProxy, sProxy);
- oItem.setAttribute("onclick", "switchproxy_anon_enableRemove(true)");
- oItem.setAttribute("style", "border-bottom: #CCCCCC 1px solid;");
-
- //Select Item
- gProxyList.scrollToIndex(0);
- if(gProxyList.selectedIndex > 0){
- gProxyList.selectItem(oItem);
- }
- }
- }