2023-06-03 19:43:41 +00:00
|
|
|
function isProxyHost(requestDetails) {
|
2024-04-15 20:42:40 -04:00
|
|
|
let requestUrl = new URL(requestDetails.url);
|
|
|
|
let hostname = requestUrl.hostname;
|
2024-07-28 22:47:17 -04:00
|
|
|
console.debug("(proxy) proxyinfo proxy.i2p check", hostname);
|
2022-10-16 16:50:28 -04:00
|
|
|
if (
|
2024-07-28 22:47:17 -04:00
|
|
|
hostname === "proxy.i2p"
|
2022-10-16 16:50:28 -04:00
|
|
|
) {
|
2023-06-20 13:19:49 -04:00
|
|
|
console.log("(proxy) proxyinfo proxy.i2p positive", hostname);
|
2022-10-16 16:50:28 -04:00
|
|
|
return true;
|
|
|
|
}
|
2024-04-15 20:42:40 -04:00
|
|
|
console.log("(proxy) proxyinfo proxy.i2p check negative", hostname);
|
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) {
|
2024-07-28 22:47:17 -04:00
|
|
|
console.debug("(host) checking local host", url);
|
|
|
|
if (!url.startsWith("http")){
|
|
|
|
url = "http://" + url
|
|
|
|
}
|
2024-04-15 20:42:40 -04:00
|
|
|
let requestUrl = new URL(url);
|
|
|
|
let hostname = requestUrl.hostname;
|
|
|
|
if (hostname === "localhost" || hostname === "127.0.0.1") {
|
2024-07-28 22:47:17 -04:00
|
|
|
return hostname+":"+requestUrl.port;
|
2022-10-16 16:50:28 -04:00
|
|
|
}
|
|
|
|
return false;
|
2019-11-23 18:41:18 -05:00
|
|
|
}
|
|
|
|
|
2024-07-28 22:47:17 -04:00
|
|
|
function tidyLocalHost(url) {
|
|
|
|
let hostPort = isLocalHost(url)
|
|
|
|
if (hostPort) {
|
|
|
|
return hostPort.replace("127.0.0.1", "localhost")
|
|
|
|
}
|
|
|
|
return url.hostname+":"+url.port
|
|
|
|
}
|
|
|
|
|
|
|
|
function isTorHost(url) {
|
|
|
|
let host = isLocalHost(url)
|
|
|
|
if (host.includes(":7695")) {
|
|
|
|
return "tor";
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
function isBlogHost(url) {
|
|
|
|
let host = isLocalHost(url)
|
|
|
|
if (host.includes(":8084")) {
|
|
|
|
return "blog";
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
function isIRCHost(url) {
|
|
|
|
let host = isLocalHost(url)
|
|
|
|
if (host.includes(":7669")) {
|
|
|
|
return "irc";
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2023-06-03 19:43:41 +00:00
|
|
|
function isExtensionHost(url) {
|
|
|
|
const extensionPrefix = browser.runtime
|
2022-10-24 19:57:51 -04:00
|
|
|
.getURL("")
|
|
|
|
.replace("moz-extension://", "")
|
|
|
|
.replace("/", "");
|
2023-06-03 19:43:41 +00:00
|
|
|
let isHost = false;
|
|
|
|
|
2022-10-16 16:50:28 -04:00
|
|
|
if (url.originUrl !== undefined) {
|
2023-06-03 19:43:41 +00:00
|
|
|
const originUrl = url.originUrl
|
2022-10-24 19:57:51 -04:00
|
|
|
.replace("moz-extension://", "")
|
|
|
|
.replace("/", "");
|
2023-06-03 19:43:41 +00:00
|
|
|
isHost = originUrl.startsWith(extensionPrefix);
|
|
|
|
} else if (url.documentUrl !== undefined) {
|
|
|
|
const documentUrl = url.documentUrl
|
|
|
|
.replace("moz-extension://", "")
|
|
|
|
.replace("/", "");
|
|
|
|
isHost = documentUrl.startsWith(extensionPrefix);
|
2022-10-16 16:50:28 -04:00
|
|
|
}
|
2024-07-28 22:47:17 -04:00
|
|
|
console.debug(`(urlcheck) Is URL from extension host? ${isHost}`);
|
2023-06-03 19:43:41 +00:00
|
|
|
return isHost;
|
2019-11-26 01:07:48 -05:00
|
|
|
}
|
|
|
|
|
2019-11-23 18:41:18 -05:00
|
|
|
function i2pHostName(url) {
|
2024-07-28 22:47:17 -04:00
|
|
|
let hostname = false;
|
|
|
|
const requestUrl = new URL(url);
|
2022-10-24 19:57:51 -04:00
|
|
|
if (u.host.endsWith(".i2p")) {
|
2024-07-28 22:47:17 -04:00
|
|
|
hostname = requestUrl.host;
|
2022-10-16 16:50:28 -04:00
|
|
|
}
|
|
|
|
return hostname;
|
2019-11-23 18:41:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function i2pHost(url) {
|
2023-06-03 19:43:41 +00:00
|
|
|
if (isProxyHost(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;
|
|
|
|
}
|
2024-04-15 20:42:40 -04:00
|
|
|
console.log("(host) i2p", url.url);
|
|
|
|
let requestUrl = new URL(url.url);
|
|
|
|
return requestUrl.hostname.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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-28 22:47:17 -04:00
|
|
|
function getFirstPathElement(url) {
|
2024-04-15 20:42:40 -04:00
|
|
|
let requestUrl = new URL(url);
|
2024-07-28 22:47:17 -04:00
|
|
|
let path = requestUrl.pathname
|
|
|
|
while (path.startsWith("/")) {
|
|
|
|
path = path.substring(1)
|
|
|
|
}
|
|
|
|
return path.split("/")[0]
|
|
|
|
}
|
2023-05-24 23:24:28 +00:00
|
|
|
|
2024-07-28 22:47:17 -04:00
|
|
|
function getPathApplication(url) {
|
|
|
|
const path = getFirstPathElement(url)
|
2023-05-24 23:24:28 +00:00
|
|
|
if (path === "i2ptunnelmgr" || path === "i2ptunnel") {
|
|
|
|
return "i2ptunnelmgr";
|
|
|
|
}
|
2024-07-28 22:47:17 -04:00
|
|
|
console.debug("(host) router path name",path)
|
2023-05-24 23:24:28 +00:00
|
|
|
|
|
|
|
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" ||
|
2024-04-15 20:42:40 -04:00
|
|
|
path.startsWith("config") ||
|
|
|
|
path === ""
|
2023-05-24 23:24:28 +00:00
|
|
|
) {
|
|
|
|
return "routerconsole";
|
|
|
|
}
|
2024-04-15 20:42:40 -04:00
|
|
|
console.warn("(host) unknown path", path);
|
2023-05-24 23:24:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-05-25 03:49:17 +00:00
|
|
|
function isRouterHost(url) {
|
2024-04-15 20:42:40 -04:00
|
|
|
let requestUrl = new URL(url);
|
|
|
|
let hostname = requestUrl.hostname;
|
2024-07-28 22:47:17 -04:00
|
|
|
let port = requestUrl.port;
|
2024-04-15 20:42:40 -04:00
|
|
|
if (identifyProtocolHandler(url)) {
|
2023-05-25 03:49:17 +00:00
|
|
|
const newUrl = identifyProtocolHandler(url);
|
2023-06-20 15:38:33 -04:00
|
|
|
console.log("(host) testing router host protocol handler identified");
|
2023-05-25 03:49:17 +00:00
|
|
|
return isRouterHost(newUrl);
|
2022-10-16 16:50:28 -04:00
|
|
|
}
|
2024-07-28 22:47:17 -04:00
|
|
|
const controlHost = control_host();
|
2023-05-25 03:49:17 +00:00
|
|
|
const controlPort = control_port();
|
2024-07-28 22:47:17 -04:00
|
|
|
console.log("(host) testing router hostname", tidyLocalHost(`${hostname}:${port}`) ,"against", tidyLocalHost(`${controlHost}:${controlPort}`));
|
|
|
|
if (tidyLocalHost(`${hostname}:${port}`) === tidyLocalHost(`${controlHost}:${controlPort}`)) {
|
|
|
|
return getPathApplication(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 (url.includes(encodeURIComponent("ext+rc:"))) {
|
|
|
|
return url.replace(encodeURIComponent("ext+rc:"), "");
|
|
|
|
} else if (url.includes("ext+rc:")) {
|
|
|
|
return url.replace("ext+rc:", "");
|
|
|
|
}
|
2022-10-16 16:50:28 -04:00
|
|
|
return false;
|
|
|
|
}
|