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

Fixed bug in same duplicate IP test

This commit is contained in:
Andrew Van Tassel 2016-09-01 21:36:55 -06:00
parent 73a50b765d
commit 2ba08ecd9f
3 changed files with 31 additions and 35 deletions

View File

@ -171,7 +171,6 @@ mailHops.getRoute = function(){
//lists box //lists box
var headListUnsubscribe = mailHops.options.show_lists ? mailHops.headers.extractHeader ( "List-Unsubscribe" , false ) : null; var headListUnsubscribe = mailHops.options.show_lists ? mailHops.headers.extractHeader ( "List-Unsubscribe" , false ) : null;
var received_ips;
var all_ips = new Array(); var all_ips = new Array();
var rline = ''; var rline = '';
//empty secure //empty secure
@ -186,34 +185,31 @@ mailHops.getRoute = function(){
} }
//loop through the received headers and parse for IP addresses //loop through the received headers and parse for IP addresses
if ( headReceived ){ if (!!headReceived){
var headReceivedArr = headReceived.split('\n'); var received_ips = new Array();
if(headReceivedArr.length != 0){ var headReceivedArr = headReceived.split('\n');
for ( var h=0; h<headReceivedArr.length; h++ ) { for( var h=0; h < headReceivedArr.length; h++ ) {
//build the received line by concat until semi-colon ; date/time //build the received line by concat until semi-colon ; date/time
rline += headReceivedArr[h]; rline += headReceivedArr[h];
if(headReceivedArr[h].indexOf(';')==-1) if(headReceivedArr[h].indexOf(';')==-1)
continue; continue;
received_ips = rline.match(regexAllIp); received_ips = rline.match(regexAllIp);
//get unique IPs for each Received header
//maybe multiple IPs in one Received: line received_ips = received_ips.filter(function(item, pos) {
if(received_ips != null && received_ips.length !=0){ return received_ips.indexOf(item) == pos;
for( var r=0; r<received_ips.length; r++ ){ });
if(regexIp.test(received_ips[r]) && mailHops.testIP(received_ips[r],rline)){ for( var r=0; r < received_ips.length; r++ ){
all_ips.unshift( received_ips[r] ); if(regexIp.test(received_ips[r]) && mailHops.testIP(received_ips[r],rline)){
//don't want duplicate IPs from the same Received header all_ips.unshift( received_ips[r] );
if(r < received_ips.length && received_ips[r] == received_ips[r+1]) }
break; }
} //reset the line
} rline='';
}
//reset the line
rline='';
}
} }
} }
//get the originating IP address //get the originating IP address
if(headXOrigIP){ if(!!headXOrigIP){
//remove brackets //remove brackets
headXOrigIP = headXOrigIP.replace('[','').replace(']',''); headXOrigIP = headXOrigIP.replace('[','').replace(']','');
//IPV6 check //IPV6 check
@ -221,12 +217,12 @@ mailHops.getRoute = function(){
all_ips.unshift( headXOrigIP ); all_ips.unshift( headXOrigIP );
} else { } else {
var ip = headXOrigIP.match(regexAllIp); var ip = headXOrigIP.match(regexAllIp);
if(ip != null && ip.length != 0 && all_ips.indexOf(ip[0])==-1) if(!!ip && ip.length && all_ips.indexOf(ip[0])==-1)
all_ips.unshift( ip[0] ); all_ips.unshift( ip[0] );
} }
} }
if ( all_ips.length != 0 ){ if ( all_ips.length ){
mailHops.lookupRoute ( all_ips ) ; mailHops.lookupRoute ( all_ips ) ;
} else { } else {
mailHopsDisplay.clear( true ); mailHopsDisplay.clear( true );
} }
@ -247,7 +243,9 @@ mailHops.testIP = function(ip,header){
|| lastchar == ';' || lastchar == ';'
|| parseInt(ip.substring(0,ip.indexOf('.'))) >= 240 //IANA-RESERVED || parseInt(ip.substring(0,ip.indexOf('.'))) >= 240 //IANA-RESERVED
){ ){
validIP = false; //only if there is one instance of this IP
if(header.indexOf(ip) == header.lastIndexOf(ip))
validIP = false;
} else { } else {
//check if this IP was part of a secure transmission //check if this IP was part of a secure transmission
if(header.indexOf('using SSL') != -1){ if(header.indexOf('using SSL') != -1){

View File

@ -78,7 +78,7 @@ var mailHopsDisplay =
if(header_unsubscribe){ if(header_unsubscribe){
var listArr=header_unsubscribe.split(','); var listArr=header_unsubscribe.split(',');
var href=''; var href='';
if(listArr.length!=0){ if(listArr.length){
for(var h=0;h<listArr.length;h++){ for(var h=0;h<listArr.length;h++){
href = listArr[h].replace('<','').replace('>',''); href = listArr[h].replace('<','').replace('>','');
var label = document.createElement('label'); var label = document.createElement('label');
@ -338,7 +338,7 @@ var mailHopsDisplay =
mailHopsUtils.launchWhoIs(this.getAttribute('data-ip')); mailHopsUtils.launchWhoIs(this.getAttribute('data-ip'));
}, false); }, false);
} else { } else {
label.setAttribute('value','Hop #'+(i+1)+' Private'); label.setAttribute('value','Hop #'+(i+1)+' Private');
} }
//build tooltip //build tooltip

View File

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