1
0
mirror of https://github.com/MailHops/mailhops-plugin.git synced 2025-05-19 07:40:08 -07:00

Fixed prefs not loading

Removed client_location
Cleaned up prefs ssl default option
This commit is contained in:
Andrew Van Tassel 2016-08-25 21:31:26 -06:00
parent 82beb032f4
commit e06c19d5b9
4 changed files with 56 additions and 184 deletions

View File

@ -12,15 +12,15 @@ var mailHops =
'version':'MailHops Plugin 2.0.0', 'version':'MailHops Plugin 2.0.0',
'lan':'en', 'lan':'en',
'unit':'mi', 'unit':'mi',
'api_url':'https://api.mailhops.com', 'api_http':'https://',
'api_host':'api.mailhops.com',
'debug':false, 'debug':false,
'country_tag':false, 'country_tag':false,
'country_filter':[] 'country_filter':[]
}, },
message: { message: {
secure:[] secure:[]
}, }
client_location: null
}; };
mailHops.LOG = function(msg) { mailHops.LOG = function(msg) {
@ -51,6 +51,7 @@ mailHops.init = function() {
mailHops.loadPref = function() mailHops.loadPref = function()
{ {
mailHops.LOG('load MailHops prefs');
//get preferences //get preferences
mailHops.options.lan = mailHops.getCharPref('mail.mailHops.lang','en'); mailHops.options.lan = mailHops.getCharPref('mail.mailHops.lang','en');
mailHops.options.unit = mailHops.getCharPref('mail.mailHops.unit','mi'); mailHops.options.unit = mailHops.getCharPref('mail.mailHops.unit','mi');
@ -74,9 +75,9 @@ mailHops.loadPref = function()
mailHops.options.debug = mailHops.getCharPref('mail.mailHops.debug','false')=='true'?true:false; mailHops.options.debug = mailHops.getCharPref('mail.mailHops.debug','false')=='true'?true:false;
mailHops.options.client_location = mailHops.getCharPref('mail.mailHops.client_location',''); mailHops.options.api_host = mailHops.getCharPref('mail.mailHops.api_host','api.mailhops.com');
mailHops.options.api_url = mailHops.getCharPref('mail.mailHops.api_url','https://api.mailhops.com'); mailHops.options.api_http = mailHops.getCharPref('mail.mailHops.api_http','https://');
mailHops.options.api_key = mailHops.getCharPref('mail.mailHops.api_key',''); mailHops.options.api_key = mailHops.getCharPref('mail.mailHops.api_key','');
@ -86,12 +87,6 @@ mailHops.loadPref = function()
mailHops.options.country_filter = mailHops.getCharPref('mail.mailHops.country_filter',[]); mailHops.options.country_filter = mailHops.getCharPref('mail.mailHops.country_filter',[]);
if(mailHops.options.client_location == ''){
mailHops.setClientLocation(function(response){
mailHops.options.client_location=response;
});
}
//init display //init display
mailHopsDisplay.init( mailHops.options ); mailHopsDisplay.init( mailHops.options );
}; };
@ -326,39 +321,6 @@ mailHops.getCharPref = function ( strName , strDefault ){
return ( value ) ; return ( value ) ;
}; };
mailHops.setClientLocation = function(cb){
var xmlhttp = new XMLHttpRequest();
if (!pref){
var pref = Components.classes["@mozilla.org/preferences-service;1"].getService( Components.interfaces.nsIPrefBranch ) ;
}
xmlhttp.open("GET", mailHopsUtils.getAPIUrl(mailHops.options)+'/lookup/?'+mailHopsUtils.getAPIUrlParams(mailHops.options)+'&r=&c=1',true);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && !!xmlhttp.responseText) {
try {
var data = JSON.parse(xmlhttp.responseText);
if(data && data.meta.code==200){
//display the result
pref.setCharPref("mail.mailHops.client_location", JSON.stringify(data.response)) ;
cb(data.response);
} else {
pref.setCharPref("mail.mailHops.client_location", '') ;
cb('');
}
} catch(e){
pref.setCharPref("mail.mailHops.client_location", '') ;
cb('');
}
} else {
pref.setCharPref("mail.mailHops.client_location", '') ;
cb('');
}
};
xmlhttp.send(null);
};
//mailhops lookup //mailhops lookup
mailHops.lookupRoute = function(header_route){ mailHops.lookupRoute = function(header_route){
@ -370,11 +332,6 @@ mailHops.lookupRoute = function(header_route){
if(mailHops.options.fkey != '') if(mailHops.options.fkey != '')
lookupURL += '&fkey='+mailHops.options.fkey; lookupURL += '&fkey='+mailHops.options.fkey;
if(mailHops.options.client_location != '')
lookupURL+='&c=0';
mailHops.LOG(lookupURL);
//check for cache //check for cache
var cached_results = mailHops.getResults(); var cached_results = mailHops.getResults();
@ -389,6 +346,8 @@ mailHops.lookupRoute = function(header_route){
} }
} }
mailHops.LOG("Calling MailHops API: "+lookupURL);
//call mailhops api for lookup //call mailhops api for lookup
var xmlhttp = new XMLHttpRequest(); var xmlhttp = new XMLHttpRequest();
@ -407,12 +366,12 @@ mailHops.lookupRoute = function(header_route){
//display the result //display the result
mailHopsDisplay.route(header_route, mailHops.message, data.response, data.meta, lookupURL); mailHopsDisplay.route(header_route, mailHops.message, data.response, data.meta, lookupURL);
} else { } else {
mailHops.LOG(JSON.stringify(data)); mailHops.LOG("lookupRoute: "+JSON.stringify(data));
//display the error //display the error
mailHopsDisplay.error(data); mailHopsDisplay.error(data);
} }
} catch(e){ } catch(e){
mailHops.LOG(JSON.stringify(e)); mailHops.LOG("lookupRoute: Error "+JSON.stringify(e));
mailHopsDisplay.error(); mailHopsDisplay.error();
} }
} }

View File

@ -3,24 +3,22 @@ if (!pref) {
} }
var mailHopPreferences = { var mailHopPreferences = {
api_url: '', //mailhops api url api_host: 'api.mailhops.com', //mailhops api url
api_ssl: '', //ssl? api_http: 'https://', //ssl?
api_key: '', //api key api_key: '', //api key
fkey: '', //forecast.io api key fkey: '', //forecast.io api key
country_filter: [], country_filter: [],
loadPreferences: function(){ loadPreferences: function(){
this.api_url = document.getElementById("mailhop.api_url").value; this.api_host = document.getElementById("mailhop.api_host").value;
this.api_ssl = document.getElementById("mailhop.api_ssl").value; this.api_http = document.getElementById("mailhop.api_http");
this.api_key = document.getElementById("mailhop.api_key").value; this.api_key = document.getElementById("mailhop.api_key").value;
this.fkey = document.getElementById("mailhop.fkey").value; this.fkey = document.getElementById("mailhop.fkey").value;
document.getElementById("mailhop.api_ssl").value = "true";
document.getElementById("mailhop.lang").value = pref.getCharPref("mail.mailHops.lang",'en'); document.getElementById("mailhop.lang").value = pref.getCharPref("mail.mailHops.lang",'en');
document.getElementById("mailhop.map_provider").value = pref.getCharPref("mail.mailHops.map_provider",'OpenStreetMap.Mapnik'); document.getElementById("mailhop.map_provider").value = pref.getCharPref("mail.mailHops.map_provider",'OpenStreetMap.Mapnik');
@ -86,14 +84,13 @@ var mailHopPreferences = {
// API info // API info
this.api_key = pref.getCharPref("mail.mailHops.api_key",''); this.api_key = pref.getCharPref("mail.mailHops.api_key",'');
this.api_url = pref.getCharPref("mail.mailHops.api_url",'https://api.mailhops.com'); this.api_http.value = pref.getCharPref("mail.mailHops.api_http",'https://');
if(this.api_http.value=='https://')
if(this.api_url.indexOf('https')===0) this.api_http.selectedIndex = 0;
this.api_ssl = "true";
else else
this.api_ssl = "false"; this.api_http.selectedIndex = 1;
this.api_url = this.api_url.replace('http://','').replace('https://',''); this.api_host = pref.getCharPref("mail.mailHops.api_host",'api.mailhops.com');
this.fkey = pref.getCharPref("mail.mailHops.fkey",''); this.fkey = pref.getCharPref("mail.mailHops.fkey",'');
@ -111,8 +108,6 @@ var mailHopPreferences = {
document.getElementById("mailhop.country_tag").checked = true; document.getElementById("mailhop.country_tag").checked = true;
saveAPIKey(); saveAPIKey();
ResetLocation(document.getElementById("mailhop.refresh_location"));
}, },
savePreferences: function() { savePreferences: function() {
pref.setCharPref("mail.mailHops.lang", document.getElementById("mailhop.lang").selectedItem.value); pref.setCharPref("mail.mailHops.lang", document.getElementById("mailhop.lang").selectedItem.value);
@ -131,12 +126,8 @@ var mailHopPreferences = {
//API vars //API vars
pref.setCharPref("mail.mailHops.api_key", this.api_key); pref.setCharPref("mail.mailHops.api_key", this.api_key);
pref.setCharPref("mail.mailHops.api_http", this.api_http.value);
this.api_url = this.api_url.replace('http://','').replace('https://',''); pref.setCharPref("mail.mailHops.api_host", this.api_host);
if(this.api_ssl=="true")
pref.setCharPref("mail.mailHops.api_url", 'https://'+this.api_url);
else
pref.setCharPref("mail.mailHops.api_url", 'http://'+this.api_url);
pref.setCharPref("mail.mailHops.fkey", String(this.fkey)); pref.setCharPref("mail.mailHops.fkey", String(this.fkey));
@ -164,17 +155,12 @@ function saveAPIKey() {
if(!!mailHopPreferences.api_key && mailHopPreferences.api_key != ''){ if(!!mailHopPreferences.api_key && mailHopPreferences.api_key != ''){
var xmlhttp = new XMLHttpRequest(); var xmlhttp = new XMLHttpRequest();
var nativeJSON = Components.classes["@mozilla.org/dom/json;1"].createInstance(Components.interfaces.nsIJSON); var nativeJSON = Components.classes["@mozilla.org/dom/json;1"].createInstance(Components.interfaces.nsIJSON);
var apiBase = mailHopPreferences.api_url, var apiBase = mailHopPreferences.api_http.value+mailHopPreferences.api_host,
accountURL = '/v2/accounts/?app='+mailHops.options.version+'&api_key='+mailHopPreferences.api_key; accountURL = '/v2/accounts/?api_key='+mailHopPreferences.api_key;
if(mailHopPreferences.api_ssl=="true")
apiBase='https://'+apiBase;
else
apiBase='http://'+apiBase;
xmlhttp.open("GET", apiBase+accountURL,true); xmlhttp.open("GET", apiBase+accountURL,true);
xmlhttp.onreadystatechange=function() { xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && !!xmlhttp.responseText) { if (xmlhttp.readyState==4) {
try{ try{
var data = JSON.parse(xmlhttp.responseText); var data = JSON.parse(xmlhttp.responseText);
if(!!data && data.meta.code==200){ if(!!data && data.meta.code==200){
@ -188,8 +174,6 @@ function saveAPIKey() {
catch (ex){ catch (ex){
document.getElementById("key_details").innerHTML = 'Connection Failed to\n '+apiBase+'!'; document.getElementById("key_details").innerHTML = 'Connection Failed to\n '+apiBase+'!';
} }
} else {
document.getElementById("key_details").innerHTML = 'Connection Failed to\n '+apiBase+'!';
} }
}; };
xmlhttp.send(null); xmlhttp.send(null);
@ -198,19 +182,14 @@ function saveAPIKey() {
} }
} }
function TestConnection(e){ function TestConnection(){
var xmlhttp = new XMLHttpRequest(); var xmlhttp = new XMLHttpRequest();
var nativeJSON = Components.classes["@mozilla.org/dom/json;1"].createInstance(Components.interfaces.nsIJSON); var nativeJSON = Components.classes["@mozilla.org/dom/json;1"].createInstance(Components.interfaces.nsIJSON);
var apiBase = mailHopPreferences.api_url || 'https://api.mailhops.com', var apiBase = mailHopPreferences.api_http.value+mailHopPreferences.api_host,
lookupURL = '/v1/lookup/?app='+mailHops.options.version+'&healthcheck'; lookupURL = '/v1/lookup/?healthcheck';
if(mailHopPreferences.api_ssl=="true")
apiBase='https://'+apiBase;
else
apiBase='http://'+apiBase;
if(mailHopPreferences.api_key != '') if(mailHopPreferences.api_key != '')
lookupURL = '/v2/lookup/?app='+mailHops.options.version+'&healthcheck&api_key='+mailHopPreferences.api_key; lookupURL = '/v2/lookup/?healthcheck&api_key='+mailHopPreferences.api_key;
xmlhttp.open("GET", apiBase+lookupURL,true); xmlhttp.open("GET", apiBase+lookupURL,true);
xmlhttp.onreadystatechange=function() { xmlhttp.onreadystatechange=function() {
@ -218,71 +197,22 @@ function TestConnection(e){
try{ try{
var data = JSON.parse(xmlhttp.responseText); var data = JSON.parse(xmlhttp.responseText);
if(!!data && data.meta.code==200){ if(!!data && data.meta.code==200){
e.style.backgroundImage='';
alert('Connection Succeeded to\n '+apiBase+'!'); alert('Connection Succeeded to\n '+apiBase+'!');
} else { } else {
//display the error //display the error
e.style.backgroundImage='';
alert('Connection Failed to\n '+apiBase+'!'); alert('Connection Failed to\n '+apiBase+'!');
} }
} }
catch (ex){ catch (ex){
e.style.backgroundImage=''; alert('Connection Failed to\n '+apiBase+'! '+JSON.stringify(ex));
alert('Connection Failed to\n '+apiBase+'!');
} }
} }
}; };
xmlhttp.send(null); xmlhttp.send(null);
} }
function ResetLocation(e){
//clear the location
document.getElementById("mailhop.client_location").value='Getting your location...';
document.getElementById("mailhop.client_location_ip").value = '';
document.getElementById("mailhop.client_location_host").value = '';
document.getElementById("mailhop.client_location_whois").value = '';
var MH_APIURL = mailHopPreferences.api_ssl=="true"?'https://'+mailHopPreferences.api_url:'http://'+mailHopPreferences.api_url;
mailHops.setClientLocation(function(response){
if(response){
var location = '';
if(response.route[0].city)
location+=response.route[0].city;
if(response.route[0].state)
location+=', '+response.route[0].state;
if(response.route[0].countryName)
location+=' ( '+response.route[0].countryName+' )';
else if(response.route[0].countryCode)
location+=' ( '+response.route[0].countryCode+' )';
//set location
document.getElementById("mailhop.client_location").value=location;
//set ip
document.getElementById("mailhop.client_location_ip").value='IP: '+response.route[0].ip;
//set host
if(response.route[0].host)
document.getElementById("mailhop.client_location_host").value='Host: '+response.route[0].host;
document.getElementById("mailhop.client_location_whois").value = 'whois';
document.getElementById("mailhop.client_location_whois").setAttribute('href', 'https://www.mailhops.com/whois/'+response.route[0].ip);
//set country flag
if(response.route[0].countryCode)
document.getElementById("mailhop.client_location").style.backgroundImage='url(chrome://mailhops/content/images/flags/'+response.route[0].countryCode.toLowerCase()+'.png)';
} else {
document.getElementById("mailhop.client_location").value='Failed connecting...';
}
},MH_APIURL);
}
function ResetConnection(){ function ResetConnection(){
mailHopPreferences.api_ssl=="true"; mailHopPreferences.api_http.value=="https://";
mailHopPreferences.api_ssl.selectedIndex = 0; mailHopPreferences.api_http.selectedIndex = 0;
mailHopPreferences.api_url='api.mailhops.com'; mailHopPreferences.api_host='api.mailhops.com';
} }

View File

@ -11,7 +11,6 @@
title="MailHops Preferences"> title="MailHops Preferences">
<script type="application/x-javascript" src="chrome://mailhops/content/utils.js"/> <script type="application/x-javascript" src="chrome://mailhops/content/utils.js"/>
<script type="application/x-javascript" src="chrome://mailhops/content/mailhops.js"/>
<script type="application/x-javascript" src="chrome://mailhops/content/preferences.js"/> <script type="application/x-javascript" src="chrome://mailhops/content/preferences.js"/>
<!-- <image src="chrome://mailhops/content/images/mailhops-logo.png" width="200"/> --> <!-- <image src="chrome://mailhops/content/images/mailhops-logo.png" width="200"/> -->
@ -21,11 +20,10 @@
<tabbox id="mhTabs" selectedIndex="0"> <tabbox id="mhTabs" selectedIndex="0">
<tabs> <tabs>
<tab label="Pro"/> <tab label="Pro"/>
<tab label="Filter"/> <tab label="Security"/>
<tab label="Defaults"/> <tab label="Defaults"/>
<tab label="Display"/> <tab label="Display"/>
<tab label="API &amp; Hosting"/> <tab label="API &amp; Hosting"/>
<tab label="Current Location"/>
</tabs> </tabs>
<tabpanels> <tabpanels>
<tabpanel> <tabpanel>
@ -56,7 +54,7 @@
<tabpanel> <tabpanel>
<groupbox flex="1" style="height:400px;overflow: scroll;"> <groupbox flex="1" style="height:400px;overflow: scroll;">
<caption label="Filter"/> <caption label="Security"/>
<checkbox id="mailhop.country_tag" label="Tag messages with country origin" checked="false"/> <checkbox id="mailhop.country_tag" label="Tag messages with country origin" checked="false"/>
<description>Mark messages as Junk from Countries checked below. <description>Mark messages as Junk from Countries checked below.
<label class="text-link plain" value="All " onclick="mailHopPreferences.countryListSelectAll(true);"/> <label class="text-link plain" value="All " onclick="mailHopPreferences.countryListSelectAll(true);"/>
@ -497,18 +495,18 @@
</columns> </columns>
<rows> <rows>
<row> <row>
<menulist id="mailhop.api_ssl"> <menulist id="mailhop.api_http">
<menupopup> <menupopup>
<menuitem value="true" label="https://" /> <menuitem value="https://" label="https://" />
<menuitem value="false" label="http://" /> <menuitem value="http://" label="http://" />
</menupopup> </menupopup>
</menulist> </menulist>
<textbox id="mailhop.api_url" value="api.mailhops.com" flex="1"/> <textbox id="mailhop.api_host" value="api.mailhops.com" flex="1"/>
</row> </row>
<row> <row>
<hbox/> <hbox/>
<hbox flex="1"> <hbox flex="1">
<button onclick="TestConnection(this);">Test Connection</button> <button onclick="TestConnection();">Test Connection</button>
<button onclick="ResetConnection();">Reset Connection</button> <button onclick="ResetConnection();">Reset Connection</button>
</hbox> </hbox>
</row> </row>
@ -525,21 +523,6 @@
</groupbox> </groupbox>
</tabpanel> </tabpanel>
<tabpanel>
<groupbox flex="1">
<description>
Your Location is cached on startup and clicking refresh below to reduce the number of lookups by one.
</description>
<description>
<button id="mailhop.refresh_location" onclick="ResetLocation(this);">Refresh your location</button>
</description>
<label id="mailhop.client_location" class="act" value="Not Set" />
<label id="mailhop.client_location_ip" class="plain act" value="" />
<label id="mailhop.client_location_host" class="plain act" value="" />
<label id="mailhop.client_location_whois" class="text-link plain act" value="whois" tooltiptext="Click for whois" />
</groupbox>
</tabpanel>
</tabpanels> </tabpanels>
</tabbox> </tabbox>
</vbox> </vbox>

View File

@ -154,8 +154,8 @@ launchMap: function(route,options){
getAPIUrl: function(options){ getAPIUrl: function(options){
if(!!options.api_key && options.api_key != '') if(!!options.api_key && options.api_key != '')
return options.api_url+'/v2'; return options.api_http+options.api_host+'/v2';
return options.api_url+'/v1'; return options.api_http+options.api_host+'/v1';
}, },
getAPIUrlParams: function(options){ getAPIUrlParams: function(options){