diff --git a/handler.js b/handler.js new file mode 100644 index 0000000..7ea7943 --- /dev/null +++ b/handler.js @@ -0,0 +1,30 @@ +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:", ""); + } + } else if (url.includes("ext+rc:")) { + return url; + } + return false; +} + +var handlerSetup = async function(requestDetails) { + //console.log("checking protocol handler listener") + var rwurl = identifyProtocolHandler(requestDetails.url); + if (rwurl != false) { + console.log("handler rewrite URL requested", rwurl); + requestDetails.redirectUrl = rwurl; + requestDetails.url = rwurl; + } + return requestDetails; +}; + +browser.webRequest.onBeforeRequest.addListener( + handlerSetup, + { urls: [""] }, + ["blocking"] +); diff --git a/host.js b/host.js new file mode 100644 index 0000000..b2f7318 --- /dev/null +++ b/host.js @@ -0,0 +1,102 @@ +function proxyHost(url) { + let hostname = ""; + if (url.indexOf("://") > -1) { + hostname = url.split("/")[2]; + } else { + hostname = url.split("/")[0]; + } + if (hostname == "proxy.i2p") { + return true; + } + return false; +} + +function localHost(url) { + let hostname = ""; + if (url.indexOf("://") > -1) { + hostname = url.split("/")[2]; + } else { + hostname = url.split("/")[0]; + } + hostname = hostname.split(":")[0]; + if (hostname === "127.0.0.1") { + return true; + } else if (hostname === "localhost") { + return true; + } + + return false; +} + +function i2pHostName(url) { + let hostname = ""; + if (url.indexOf("://") > -1) { + hostname = url.split("/")[2]; + } else { + hostname = url.split("/")[0]; + } + return hostname; +} + +function i2pHost(url) { + let hostname = i2pHostName(url); + return hostname.endsWith(".i2p"); +} + +function routerHost(url) { + let hostname = ""; + let path = ""; + function pathcheck(str) { + if (str != undefined) { + let final = str.split("/")[0]; + if (final === "i2ptunnelmgr" || final === "i2ptunnel") { + console.log("(urlcheck) application path", final); + return "i2ptunnelmgr"; + } else if (final === "i2psnark" || final === "torrents") { + console.log("(urlcheck) application path", final); + return "i2psnark"; + } else if (final === "webmail" || final === "susimail") { + console.log("(urlcheck) application path", final); + return "webmail"; + } else if ( + final === "home" || + final === "console" || + final.startsWith("config") + ) { + console.log("(urlcheck) application path", final); + return "routerconsole"; + } + } + return true; + } + if (url.indexOf("://") > -1) { + hostname = url.split("/")[2]; + prefix = url.substr(0, url.indexOf("://") + 3); + path = url.replace(prefix + hostname + "/", ""); + } else if (identifyProtocolHandler(url)) { + url = identifyProtocolHandler(url); + return routerHost(url); + } else { + hostname = url.split("/")[0]; + path = url.replace(hostname + "/", ""); + } + if (hostname === "127.0.0.1:7657") { + return pathcheck(path); + } else if (hostname === "localhost:7657") { + return pathcheck(path); + } + + if (hostname === "127.0.0.1:7647") { + return pathcheck(path); + } else if (hostname === "localhost:7647") { + return pathcheck(path); + } + + if (hostname === "127.0.0.1:7070") { + return pathcheck(path); + } else if (hostname === "localhost:7070") { + return pathcheck(path); + } + + return false; +} diff --git a/manifest.json b/manifest.json index 70b63c5..1ab370d 100644 --- a/manifest.json +++ b/manifest.json @@ -44,6 +44,7 @@ "privacy.js", "platform.js", "background.js", + "host.js", "handler.js", "proxy.js", "info.js", diff --git a/proxy.js b/proxy.js index 15d3ded..392c005 100644 --- a/proxy.js +++ b/proxy.js @@ -332,109 +332,6 @@ function checkStoredSettings(storedSettings) { //var gettingInfo = browser.proxy.settings.get({}); //gettingInfo.then(gotProxyInfo); -function proxyHost(url) { - let hostname = ""; - if (url.indexOf("://") > -1) { - hostname = url.split("/")[2]; - } else { - hostname = url.split("/")[0]; - } - if (hostname == "proxy.i2p") { - return true; - } - return false; -} - -function localHost(url) { - let hostname = ""; - if (url.indexOf("://") > -1) { - hostname = url.split("/")[2]; - } else { - hostname = url.split("/")[0]; - } - hostname = hostname.split(":")[0]; - if (hostname === "127.0.0.1") { - return true; - } else if (hostname === "localhost") { - return true; - } - - return false; -} - -function i2pHostName(url) { - let hostname = ""; - if (url.indexOf("://") > -1) { - hostname = url.split("/")[2]; - } else { - hostname = url.split("/")[0]; - } - return hostname; -} - -function i2pHost(url) { - let hostname = i2pHostName(url); - return hostname.endsWith(".i2p"); -} - -function routerHost(url) { - let hostname = ""; - let path = ""; - function pathcheck(str) { - if (str != undefined) { - let final = str.split("/")[0]; - if (final === "i2ptunnelmgr" || final === "i2ptunnel") { - console.log("(urlcheck) application path", final); - return "i2ptunnelmgr"; - } else if (final === "i2psnark" || final === "torrents") { - console.log("(urlcheck) application path", final); - return "i2psnark"; - } else if (final === "webmail" || final === "susimail") { - console.log("(urlcheck) application path", final); - return "webmail"; - } else if ( - final === "home" || - final === "console" || - final.startsWith("config") - ) { - console.log("(urlcheck) application path", final); - return "routerconsole"; - } - } - return true; - } - if (url.indexOf("://") > -1) { - hostname = url.split("/")[2]; - prefix = url.substr(0, url.indexOf("://") + 3); - path = url.replace(prefix + hostname + "/", ""); - } else if (identifyProtocolHandler(url)) { - url = identifyProtocolHandler(url); - return routerHost(url); - } else { - hostname = url.split("/")[0]; - path = url.replace(hostname + "/", ""); - } - if (hostname === "127.0.0.1:7657") { - return pathcheck(path); - } else if (hostname === "localhost:7657") { - return pathcheck(path); - } - - if (hostname === "127.0.0.1:7647") { - return pathcheck(path); - } else if (hostname === "localhost:7647") { - return pathcheck(path); - } - - if (hostname === "127.0.0.1:7070") { - return pathcheck(path); - } else if (hostname === "localhost:7070") { - return pathcheck(path); - } - - return false; -} - function update(restoredSettings) { proxy_scheme = restoredSettings.proxy_scheme; console.log("restoring proxy scheme:", proxy_scheme);