Files
I2P_in_Private_Browsing_Mod…/handler.js

126 lines
4.4 KiB
JavaScript
Raw Normal View History

function routerHost(url) {
// console.log("(urlcheck) HANDLER URL CHECK");
let hostname = '';
let path = '';
function pathcheck(str) {
// console.log("(urlcheck) HANDLER PATH CHECK", str);
if (str != undefined) {
let final = str.split('/')[0];
if (final === 'i2ptunnelmgr' || final === 'i2ptunnel') {
console.log('(urlcheck) Tunnel application path', final);
return 'i2ptunnelmgr';
} else if (
final === 'i2psnark' ||
final === 'torrents' ||
final.startsWith('transmission') ||
final.startsWith('tracker') ||
url.includes(':7662')
) {
console.log('(urlcheck) Torrent application path', final);
return 'i2psnark';
} else if (final === 'webmail' || final === 'susimail') {
if (!url.includes('.css')) {
console.log('(urlcheck) Mail application path', final);
return 'webmail';
}
} else if (final.startsWith('MuWire')) {
if (!url.includes('.png')) {
console.log('(urlcheck) MuWire application path', final);
return 'muwire';
}
} else if (final.startsWith('i2pbote')) {
if (!url.includes('.png')) {
console.log('(urlcheck) I2PBote application path', final);
return 'i2pbote';
}
} else if (
final === 'home' ||
final === 'console' ||
final === 'dns' ||
final === 'susidns' ||
final.startsWith('susidns') ||
final === 'sitemap' ||
final.startsWith('config')
) {
console.log('(urlcheck) Console application path', final);
return 'routerconsole';
}
2020-03-24 19:46:37 -04:00
}
return true;
}
if (url.indexOf('://') > -1) {
hostname = url.split('/')[2];
let prefix = url.substr(0, url.indexOf('://') + 3);
path = url.replace(prefix + hostname + '/', '');
} else if (identifyProtocolHandler(url)) {
let newurl = identifyProtocolHandler(url);
return routerHost(newurl);
} else {
hostname = url.split('/')[0];
path = url.replace(hostname + '/', '');
}
if (hostname === control_host + ':' + control_port) {
//console.log("(hostcheck) router console found on configured ports");
return pathcheck(path);
}
if (hostname === 'localhost' + ':' + control_port) {
//console.log("(hostcheck) router console found on configured ports");
return pathcheck(path);
}
if (hostname === '127.0.0.1' + ':' + control_port) {
return pathcheck(path);
}
if (hostname === 'localhost' + ':' + 7667) {
return pathcheck(path);
}
if (hostname === '127.0.0.1' + ':' + 7667) {
return pathcheck(path);
}
return false;
}
2019-11-23 18:41:18 -05:00
function identifyProtocolHandler(url) {
//console.log("looking for handler-able requests")
if (routerHost(url)) {
if (url.includes(encodeURIComponent('ext+rc:'))) {
return url.replace(encodeURIComponent('ext+rc:'), '');
} else if (url.includes('ext+rc:')) {
return url.replace('ext+rc:', '');
}
2021-12-28 20:36:17 -05:00
} else if (url.includes('ext+rc:')) {
return url;
2019-11-23 18:41:18 -05:00
}
return false;
2019-11-23 18:41:18 -05:00
}
2019-11-23 22:17:20 -05:00
function trimHost(url) {
let hostname = '';
let prefix = '';
if (url.indexOf('://') > -1) {
prefix = url.substr(0, url.indexOf('://') + 3);
hostname = url.split('/')[2];
} else {
hostname = url.split('/')[0];
}
let path = url.replace(prefix + hostname, '');
console.log('(handler) path', prefix + hostname, path);
return path;
2019-11-23 22:17:20 -05:00
}
2021-12-28 20:36:17 -05:00
var handlerSetup = function(requestDetails) {
//console.log("checking protocol handler listener")
let rwurl = identifyProtocolHandler(requestDetails.url);
if (rwurl != false) {
console.log('(handler) rewrite URL requested', rwurl);
requestDetails.redirectUrl = rwurl;
requestDetails.url = trimHost(rwurl);
requestDetails.originUrl = trimHost(rwurl);
}
return requestDetails;
2019-11-23 18:41:18 -05:00
};
2020-12-09 17:49:36 -05:00
/*
browser.webRequest.onBeforeRequest.addListener(handlerSetup, {
urls: ['<all_urls>'],
});
*/