2022-10-07 13:26:09 -04:00
|
|
|
function proxyHost(requestDetails) {
|
2023-05-25 03:49:17 +00:00
|
|
|
const originUrl = requestDetails.originUrl;
|
|
|
|
const isWindowOrHomeUrl =
|
|
|
|
originUrl !== browser.runtime.getURL("window.html") &&
|
|
|
|
originUrl !== browser.runtime.getURL("home.html");
|
|
|
|
|
|
|
|
if (isWindowOrHomeUrl) {
|
2022-10-16 16:50:28 -04:00
|
|
|
return false;
|
|
|
|
}
|
2022-10-16 15:00:54 -04:00
|
|
|
|
2023-05-25 03:49:17 +00:00
|
|
|
const urlParts = requestDetails.url.split("/");
|
|
|
|
const hostname = urlParts[2].indexOf("://") > -1 ? urlParts[2] : urlParts[0];
|
2022-10-16 16:08:01 -04:00
|
|
|
|
2022-10-16 16:50:28 -04:00
|
|
|
if (
|
2023-05-25 03:49:17 +00:00
|
|
|
hostname === "proxy.i2p" ||
|
|
|
|
hostname === "c6lilt4cr5x7jifxridpkesf2zgfwqfchtp6laihr4pdqomq25iq.b32.i2p"
|
2022-10-16 16:50:28 -04:00
|
|
|
) {
|
|
|
|
return true;
|
|
|
|
}
|
2023-05-25 03:49:17 +00:00
|
|
|
|
2022-10-16 16:50:28 -04:00
|
|
|
return false;
|
2019-11-23 18:41:18 -05:00
|
|
|
}
|
|
|
|
|
2023-05-25 03:49:17 +00:00
|
|
|
function isLocalHost(url) {
|
|
|
|
// function getLocalhostUrlType(url) {
|
|
|
|
const urlPath = url.split("/")[2].split(":")[0];
|
|
|
|
if (urlPath === "127.0.0.1" || urlPath === "localhost") {
|
|
|
|
if (url.includes(":8084")) {
|
2023-05-24 23:24:28 +00:00
|
|
|
return "blog";
|
|
|
|
}
|
2023-05-25 03:49:17 +00:00
|
|
|
if (url.includes(":7669")) {
|
2023-05-24 23:24:28 +00:00
|
|
|
return "irc";
|
|
|
|
}
|
2023-05-25 03:49:17 +00:00
|
|
|
if (url.includes(":7695")) {
|
2023-05-24 23:24:28 +00:00
|
|
|
return "tor";
|
|
|
|
}
|
2022-10-16 16:50:28 -04:00
|
|
|
}
|
|
|
|
return false;
|
2019-11-23 18:41:18 -05:00
|
|
|
}
|
|
|
|
|
2019-11-26 01:07:48 -05:00
|
|
|
function extensionHost(url) {
|
2022-10-16 16:50:28 -04:00
|
|
|
var prefix = browser.runtime
|
2022-10-24 19:57:51 -04:00
|
|
|
.getURL("")
|
|
|
|
.replace("moz-extension://", "")
|
|
|
|
.replace("/", "");
|
2022-10-16 16:50:28 -04:00
|
|
|
if (url.originUrl !== undefined) {
|
|
|
|
var originUrl = url.originUrl
|
2022-10-24 19:57:51 -04:00
|
|
|
.replace("moz-extension://", "")
|
|
|
|
.replace("/", "");
|
2023-05-24 23:24:28 +00:00
|
|
|
/* console.log("(urlcheck) Extension application path", originUrl);
|
|
|
|
console.log("(urlcheck) Extension application path", prefix); */
|
2022-10-16 16:50:28 -04:00
|
|
|
var res = originUrl.startsWith(prefix);
|
|
|
|
// console.log("(urlcheck) Extension application path", res);
|
2023-05-24 23:24:28 +00:00
|
|
|
if (res) {
|
|
|
|
return res;
|
|
|
|
}
|
2022-10-16 16:50:28 -04:00
|
|
|
}
|
|
|
|
if (url.documentUrl !== undefined) {
|
2023-05-24 23:24:28 +00:00
|
|
|
/* console.log("(urlcheck) Extension application path", originUrl);
|
|
|
|
console.log("(urlcheck) Extension application path", prefix); */
|
2022-10-16 16:50:28 -04:00
|
|
|
var res = originUrl.startsWith(prefix);
|
|
|
|
// console.log("(urlcheck) Extension application path", res);
|
2023-05-24 23:24:28 +00:00
|
|
|
if (res) {
|
|
|
|
return res;
|
|
|
|
}
|
2022-10-16 16:50:28 -04:00
|
|
|
}
|
2022-10-24 19:57:51 -04:00
|
|
|
console.log("(urlcheck) Extension application path", url);
|
2019-11-26 01:07:48 -05:00
|
|
|
}
|
|
|
|
|
2019-11-23 18:41:18 -05:00
|
|
|
function i2pHostName(url) {
|
2022-10-24 19:57:51 -04:00
|
|
|
let hostname = "";
|
2023-05-24 23:24:28 +00:00
|
|
|
const u = new URL(url);
|
2022-10-24 19:57:51 -04:00
|
|
|
if (u.host.endsWith(".i2p")) {
|
2022-10-16 16:50:28 -04:00
|
|
|
hostname = u.host;
|
2023-05-24 23:24:28 +00:00
|
|
|
} else if (url.includes("=") && url.includes(".i2p")) {
|
|
|
|
const lsit = url.split("=");
|
|
|
|
for (const item of lsit) {
|
|
|
|
const items = item.split(" % "); //"\%")
|
|
|
|
for (const p of items) {
|
|
|
|
if (p.includes(".i2p")) {
|
|
|
|
hostname = p.replace("3D", 1);
|
2022-10-16 16:50:28 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2023-05-24 23:24:28 +00:00
|
|
|
if (hostname !== "") {
|
|
|
|
break;
|
|
|
|
}
|
2022-10-16 16:50:28 -04:00
|
|
|
}
|
2022-10-24 19:57:51 -04:00
|
|
|
} else if (url.indexOf("://") > -1) {
|
|
|
|
hostname = url.split("/")[2];
|
2022-10-16 16:50:28 -04:00
|
|
|
} else {
|
2022-10-24 19:57:51 -04:00
|
|
|
hostname = url.split("/")[0];
|
2022-10-16 16:50:28 -04:00
|
|
|
}
|
|
|
|
return hostname;
|
2019-11-23 18:41:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function i2pHost(url) {
|
2022-10-16 16:50:28 -04:00
|
|
|
if (proxyHost(url)) {
|
2022-10-24 19:57:51 -04:00
|
|
|
console.warn("(host) proxy.i2p", url.url);
|
2022-10-16 16:50:28 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
let hostname = i2pHostName(url.url);
|
2022-10-24 19:57:51 -04:00
|
|
|
let postname = hostname.split(":")[0];
|
|
|
|
if (postname.endsWith("proxy.i2p")) {
|
2022-10-16 16:50:28 -04:00
|
|
|
return false;
|
|
|
|
}
|
2022-10-24 19:57:51 -04:00
|
|
|
return postname.endsWith(".i2p");
|
2019-11-23 18:41:18 -05:00
|
|
|
}
|
|
|
|
|
2023-05-24 23:24:28 +00:00
|
|
|
function notAnImage(url, path) {
|
|
|
|
if (!url.includes(".png")) {
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPathApplication(str, url) {
|
|
|
|
if (!str) return true;
|
|
|
|
|
|
|
|
const path = str.split("/")[0];
|
|
|
|
|
|
|
|
if (path === "i2ptunnelmgr" || path === "i2ptunnel") {
|
|
|
|
return "i2ptunnelmgr";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
path === "i2psnark" ||
|
|
|
|
path === "torrents" ||
|
|
|
|
path.startsWith("transmission") ||
|
|
|
|
path.startsWith("tracker") ||
|
|
|
|
url.includes(":7662")
|
|
|
|
) {
|
|
|
|
return "i2psnark";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (path === "webmail" || path === "susimail") {
|
|
|
|
return "webmail";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (path.startsWith("MuWire")) {
|
|
|
|
return notAnImage("muwire");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (path.startsWith("i2pbote")) {
|
|
|
|
return notAnImage("i2pbote");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
path === "home" ||
|
|
|
|
path === "console" ||
|
|
|
|
path === "dns" ||
|
|
|
|
path === "susidns" ||
|
|
|
|
path.startsWith("susidns") ||
|
|
|
|
path === "sitemap" ||
|
|
|
|
path.startsWith("config")
|
|
|
|
) {
|
|
|
|
return "routerconsole";
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-05-25 03:49:17 +00:00
|
|
|
function isRouterHost(url) {
|
2022-10-24 19:57:51 -04:00
|
|
|
let hostname = "";
|
|
|
|
let path = "";
|
2022-02-15 21:15:47 -05:00
|
|
|
|
2022-10-24 19:57:51 -04:00
|
|
|
if (url.indexOf("://") > -1) {
|
|
|
|
hostname = url.split("/")[2];
|
2023-05-25 03:49:17 +00:00
|
|
|
const protocol = url.substr(0, url.indexOf("://") + 3);
|
|
|
|
path = url.replace(protocol + hostname + "/", "");
|
2022-10-16 16:50:28 -04:00
|
|
|
} else if (identifyProtocolHandler(url)) {
|
2023-05-25 03:49:17 +00:00
|
|
|
const newUrl = identifyProtocolHandler(url);
|
|
|
|
return isRouterHost(newUrl);
|
2022-10-16 16:50:28 -04:00
|
|
|
} else {
|
2022-10-24 19:57:51 -04:00
|
|
|
hostname = url.split("/")[0];
|
|
|
|
path = url.replace(hostname + "/", "");
|
2022-10-16 16:50:28 -04:00
|
|
|
}
|
2023-05-25 03:49:17 +00:00
|
|
|
|
|
|
|
const localHosts = ["localhost", "127.0.0.1"];
|
|
|
|
const controlHost = control_host();
|
|
|
|
const controlPort = control_port();
|
|
|
|
const isLocalHost = localHosts.includes(hostname.split(":")[0]);
|
|
|
|
|
|
|
|
if (hostname === `${controlHost}:${controlPort}` || isLocalHost) {
|
2023-05-24 23:24:28 +00:00
|
|
|
return getPathApplication(path, url);
|
2022-10-16 16:50:28 -04:00
|
|
|
}
|
2023-05-25 03:49:17 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function identifyProtocolHandler(url) {
|
|
|
|
//console.log("looking for handler-able requests")
|
|
|
|
if (isRouterHost(url)) {
|
|
|
|
if (url.includes(encodeURIComponent("ext+rc:"))) {
|
|
|
|
return url.replace(encodeURIComponent("ext+rc:"), "");
|
|
|
|
} else if (url.includes("ext+rc:")) {
|
|
|
|
return url.replace("ext+rc:", "");
|
|
|
|
}
|
|
|
|
} else if (url.includes("ext+rc:")) {
|
|
|
|
return url;
|
2022-10-16 16:50:28 -04:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|