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