diff --git a/Makefile b/Makefile index f0bf90c..e50569b 100644 --- a/Makefile +++ b/Makefile @@ -43,7 +43,9 @@ zip: version profile-install: cp ./i2psetproxy.js@eyedeekay.github.io.xpi $(HOME)/.mozilla/firefox/firefox.profile.i2p/firefox.profile.i2p/extensions cp ./i2psetproxy.js@eyedeekay.github.io.xpi $(HOME)/.mozilla/firefox/.firefox.profile.i2p.default/extensions - sudo cp ./i2psetproxy.js@eyedeekay.github.io.xpi /usr/local/lib/firefox.profile.i2p/firefox.profile.i2p/extensions/ + +to-profile: + cp ./i2psetproxy.js@eyedeekay.github.io.xpi /usr/local/lib/firefox.profile.i2p/firefox.profile.i2p/extensions/ pi: profile-install diff --git a/android-ext.pac b/android-ext.pac deleted file mode 100644 index 53fd271..0000000 --- a/android-ext.pac +++ /dev/null @@ -1,180 +0,0 @@ -/******************************************************* -** Proxy Auto Configure Script with I2P Host Detection. -** -** Author: Cervantes -** License: Public Domain -** Date: 11 May 2004 -** -** Revised: 07 Sep 2004 -** Changes: -** Proxy recursion disabled by default (strict) -** Password Authentication for session commands -** Support for http://path?i2paddresshelper=BASE64 -** Support for http://i2p/BASE64/path syntax -** Revised: 17 May 2004 -** Changes: -** Ability for the user to control the proxy -** status on a per browser-session basis. -********************************************************/ - - -/* C O N F I G U R A T I O N -*/ - -/* Replace normal with "PROXY yourproxy:port" if you run -** behind a Proxy Server by default. -*/ -var normal = "DIRECT"; - -/* Specify the I2P proxy connection details here. -*/ - -var i2pProxy = "PROXY 127.0.0.1:7950"; - -/* Set the default status of proxy detection here: -** -** -** [1] "auto" => Proxy will be used automatically if -** '-> an ".i2p" url is detected. -** '-> You will only be anonymous for ".i2p" domains. -** -** [2] "on" => Proxy is enabled all the time. (safest) -** '-> NB. Normal web available only via -** '-> i2p outproxies. -** '-> You can be fairly confident of anonymity. -** -** [3] "off" => Completely Bypass the proxy and therefore i2p. -** '-> no i2p sites will be accessible... -** '-> ...your browsing habits can potentially -** '-> be traced back to you! -** -*/ - -var proxyStatus = "on"; - -/* By setting statusKeyword to "all" you can set these options at runtime -** for the duration of the browser session by entering special commands -** into your browser address bar. -** -** Due to limitations in the way proxy scripting works, a malicious site -** could change your status mode by linking to command keywords... -** eg. All proxy status urls are available. -** '-> i2p.on, i2p.off, i2p.auto (respective to proxyStatus settings) -** '-> WARNING: Setting "all" is a big risk to your anonymity! -** '-> In this mode it is highly recommended you set an AuthPassword too! -** -** [2] "limited" => Only i2p.on is available.. -** '-> This setting lasts for the duration of the browser setting. -** '-> You have to close your browser in order to revert to -** '-> your default proxyStatus configuration. -** -** [3] "off" => No command urls available. -** '-> The status mode can only be altered by editing the above -** '-> proxyStatus setting. (safest) -** -*/ - -var statusKeyword = "on"; - -/* -** By default if proxyStatus is set to "auto" the config script -** will fall back to your normal connection settings if the -** i2p proxy is offline. This is handy for browsing your locally -** hosted eepsites when your router is not running (for instance). -** However this can mean that requests to external eepsites could -** be forwarded to the outweb and potentially compromise some of -** your rights to anonymity. -** Setting "true" here enables strict mode where all requests to ".i2p" -** sites will be rejected if the i2p proxy is offline. (safest) -*/ - -var strict = true; - -/* -** By setting an authentication password, all activated session keywords -** will require the addition of a password to prevent malicious sites from -** hijacking your proxy settings. ie. if the i2p router is offline. -*/ - -if (strict == false) { - i2pProxy = i2pProxy + "; " + normal; -} - -/*Check for User Authentication Password. -*/ -if (keywordAuthPassword != "") { - keywordAuthPassword = "." + keywordAuthPassword; -} - -/* This function gets called every time a url is submitted -*/ - -function FindProxyForURL(url, host) { - /* checks for a special command url that - ** '-> changes the status of the proxy script. - */ - - if (statusKeyword != "off") { - if (host == "i2p.off" + keywordAuthPassword && statusKeyword == "all") { - /*Proxy is bypassed - outweb available only - */ - proxyStatus = "off"; - } else if (host == "i2p.auto" + keywordAuthPassword && statusKeyword == "all") { - /* Proxy is used only for .i2p hosts otherwise - ** '-> browse as normal. - */ - proxyStatus = "auto"; - } else if (host == "i2p.on" + keywordAuthPassword && (statusKeyword == "limited" || - statusKeyword == "all" )) { - /* Only I2P traffic is accepted. - */ - proxyStatus = "on"; - } - } - - if (proxyStatus == "off") { - /* Proxy is completely bypassed. - */ - return normal; - } else if (proxyStatus == "on") { - /* All requests are forward to the proxy. - */ - return i2pProxy; - } - - host = host.toLowerCase(); - /* check tld for "i2p" or oOo's new "i2paddresshelper" syntax - if found then redirect - ** '-> request to the i2p proxy - */ - - if (url.match(/^http:\/\/i2p\/[a-zA-Z0-9\-\~]{516}|i2paddresshelper=/i) || - shExpMatch(host, "*.i2p")) { // seems more reliable than: - return i2pProxy; // dnsDomainIs(host, ".i2p") || - } else { // i2pRegex.test(host) - return normal; - } -} diff --git a/android.pac b/android.pac deleted file mode 100644 index 4016e54..0000000 --- a/android.pac +++ /dev/null @@ -1,180 +0,0 @@ -/******************************************************* -** Proxy Auto Configure Script with I2P Host Detection. -** -** Author: Cervantes -** License: Public Domain -** Date: 11 May 2004 -** -** Revised: 07 Sep 2004 -** Changes: -** Proxy recursion disabled by default (strict) -** Password Authentication for session commands -** Support for http://path?i2paddresshelper=BASE64 -** Support for http://i2p/BASE64/path syntax -** Revised: 17 May 2004 -** Changes: -** Ability for the user to control the proxy -** status on a per browser-session basis. -********************************************************/ - - -/* C O N F I G U R A T I O N -*/ - -/* Replace normal with "PROXY yourproxy:port" if you run -** behind a Proxy Server by default. -*/ -var normal = "DIRECT"; - -/* Specify the I2P proxy connection details here. -*/ - -var i2pProxy = "PROXY 127.0.0.1:4444"; - -/* Set the default status of proxy detection here: -** -** -** [1] "auto" => Proxy will be used automatically if -** '-> an ".i2p" url is detected. -** '-> You will only be anonymous for ".i2p" domains. -** -** [2] "on" => Proxy is enabled all the time. (safest) -** '-> NB. Normal web available only via -** '-> i2p outproxies. -** '-> You can be fairly confident of anonymity. -** -** [3] "off" => Completely Bypass the proxy and therefore i2p. -** '-> no i2p sites will be accessible... -** '-> ...your browsing habits can potentially -** '-> be traced back to you! -** -*/ - -var proxyStatus = "on"; - -/* By setting statusKeyword to "all" you can set these options at runtime -** for the duration of the browser session by entering special commands -** into your browser address bar. -** -** Due to limitations in the way proxy scripting works, a malicious site -** could change your status mode by linking to command keywords... -** eg. All proxy status urls are available. -** '-> i2p.on, i2p.off, i2p.auto (respective to proxyStatus settings) -** '-> WARNING: Setting "all" is a big risk to your anonymity! -** '-> In this mode it is highly recommended you set an AuthPassword too! -** -** [2] "limited" => Only i2p.on is available.. -** '-> This setting lasts for the duration of the browser setting. -** '-> You have to close your browser in order to revert to -** '-> your default proxyStatus configuration. -** -** [3] "off" => No command urls available. -** '-> The status mode can only be altered by editing the above -** '-> proxyStatus setting. (safest) -** -*/ - -var statusKeyword = "off"; - -/* -** By default if proxyStatus is set to "auto" the config script -** will fall back to your normal connection settings if the -** i2p proxy is offline. This is handy for browsing your locally -** hosted eepsites when your router is not running (for instance). -** However this can mean that requests to external eepsites could -** be forwarded to the outweb and potentially compromise some of -** your rights to anonymity. -** Setting "true" here enables strict mode where all requests to ".i2p" -** sites will be rejected if the i2p proxy is offline. (safest) -*/ - -var strict = true; - -/* -** By setting an authentication password, all activated session keywords -** will require the addition of a password to prevent malicious sites from -** hijacking your proxy settings. ie. if the i2p router is offline. -*/ - -if (strict == false) { - i2pProxy = i2pProxy + "; " + normal; -} - -/*Check for User Authentication Password. -*/ -if (keywordAuthPassword != "") { - keywordAuthPassword = "." + keywordAuthPassword; -} - -/* This function gets called every time a url is submitted -*/ - -function FindProxyForURL(url, host) { - /* checks for a special command url that - ** '-> changes the status of the proxy script. - */ - - if (statusKeyword != "off") { - if (host == "i2p.off" + keywordAuthPassword && statusKeyword == "all") { - /*Proxy is bypassed - outweb available only - */ - proxyStatus = "off"; - } else if (host == "i2p.auto" + keywordAuthPassword && statusKeyword == "all") { - /* Proxy is used only for .i2p hosts otherwise - ** '-> browse as normal. - */ - proxyStatus = "auto"; - } else if (host == "i2p.on" + keywordAuthPassword && (statusKeyword == "limited" || - statusKeyword == "all" )) { - /* Only I2P traffic is accepted. - */ - proxyStatus = "on"; - } - } - - if (proxyStatus == "off") { - /* Proxy is completely bypassed. - */ - return normal; - } else if (proxyStatus == "on") { - /* All requests are forward to the proxy. - */ - return i2pProxy; - } - - host = host.toLowerCase(); - /* check tld for "i2p" or oOo's new "i2paddresshelper" syntax - if found then redirect - ** '-> request to the i2p proxy - */ - - if (url.match(/^http:\/\/i2p\/[a-zA-Z0-9\-\~]{516}|i2paddresshelper=/i) || - shExpMatch(host, "*.i2p")) { // seems more reliable than: - return i2pProxy; // dnsDomainIs(host, ".i2p") || - } else { // i2pRegex.test(host) - return normal; - } -} diff --git a/background.js b/background.js index f5a0504..c69d75d 100644 --- a/background.js +++ b/background.js @@ -1,4 +1,20 @@ -chrome.windows.onCreated.addListener(themeWindow); + +function isDroid() { + var gettingInfo = browser.runtime.getPlatformInfo(); + gettingInfo.then((got) => { + if (got.os == "android") { + console.log("android detected") + return true + }else{ + console.log("desktop detected") + return false + } + }); +} + +if (!isDroid()) { + chrome.windows.onCreated.addListener(themeWindow); +} var titlepref = chrome.i18n.getMessage("titlePreface"); var titleprefpriv = chrome.i18n.getMessage("titlePrefacePrivate"); @@ -8,8 +24,8 @@ function themeWindow(window) { if (window.incognito) { chrome.theme.update(window.id, { colors: { - frame: "#A0A0DE", - toolbar: "#A0A0DE", + frame: "#2D4470", + toolbar: "#2D4470", } }); chrome.windows.update(window.id, { @@ -19,8 +35,8 @@ function themeWindow(window) { else { chrome.theme.update(window.id, { colors: { - frame: "#BFA0DE", - toolbar: "#BFA0DE", + frame: "#9DABD5", + toolbar: "#9DABD5", } }); chrome.windows.update(window.id, { diff --git a/icons/toopie.png b/icons/toopie.png index 9c4711d..d369ec5 100644 Binary files a/icons/toopie.png and b/icons/toopie.png differ diff --git a/manifest.json b/manifest.json index bbad3f1..c71c9c2 100644 --- a/manifest.json +++ b/manifest.json @@ -5,7 +5,17 @@ "strict_min_version": "60.0" } }, - "permissions": ["theme", "browsingData", "notifications", "proxy", "privacy", "storage"], + "permissions": [ + "theme", + "browsingData", + "notifications", + "proxy", + "privacy", + "storage", + "webRequest", + "contextualIdentities", + "" + ], "manifest_version": 2, "name": "__MSG_extensionName__", "version": "1.26", diff --git a/options/options.css b/options/options.css index f744774..c0bff1c 100644 --- a/options/options.css +++ b/options/options.css @@ -33,3 +33,30 @@ label:hover { font-size: 1.2em; margin-bottom: 0.5em; } + +html, body { + width: 350px; +} + +a { + margin: 10px; + display: inline-block; +} + +.panel { + margin: 5px; +} + +span.identity { + width: 100px; + display: inline-block; + margin-left: 1em; +} + +.control-options { + display: none; +} + +.identity-options { + display: none; +} diff --git a/options/options.html b/options/options.html index 137f922..c7b2721 100644 --- a/options/options.html +++ b/options/options.html @@ -25,7 +25,12 @@ - + diff --git a/options/options.js b/options/options.js index 21c2f3c..bffbc82 100644 --- a/options/options.js +++ b/options/options.js @@ -4,6 +4,8 @@ function isDroid() { gettingInfo.then((got) => { if (got.os == "android") { return true + }else{ + return false } }); } @@ -23,6 +25,22 @@ function SetControlHostText(){ controlhostid.textContent = chrome.i18n.getMessage("controlHostText"); } +function setupProxy() { + var controlHost = getControlHost() + var controlPort = getControlPort(); + var Host = getHost() + var Port = getPort() + var Scheme = getScheme() + function handleProxyRequest(requestInfo) { + console.log("proxying request via listener") + console.log(" ", Scheme, Host, ":", Port,) + return {type: Scheme, host: Host, port: Port, proxyDns: true} + } + console.log("Setting up Firefox WebExtension proxy") + browser.proxy.onRequest.addListener(handleProxyRequest, {urls: [""]}); + console.log("i2p settings created for WebExtension Proxy") +} + function SetControlPortText(){ var controlportid = document.getElementById('controlPortText'); controlportid.textContent = chrome.i18n.getMessage("controlPortText"); @@ -36,13 +54,19 @@ function SetControlHelpText(){ function getScheme() { const proxy_scheme = document.querySelector("#proxy_scheme"); console.log("Got i2p proxy scheme:", proxy_scheme.value); + if (proxy_scheme == "HTTP") { + return "http" + } + if (proxy_scheme == "SOCKS") { + return "socks" + } return proxy_scheme.value; } function getHost() { proxy_host = document.getElementById("host").value console.log("Got i2p proxy host:", proxy_host); - if (proxy_host == undefined){ + if (proxy_host == undefined) { return "127.0.0.1" } return proxy_host; @@ -51,8 +75,8 @@ function getHost() { function getPort() { proxy_port = document.getElementById("port").value console.log("Got i2p proxy port:", proxy_port); - if (proxy_port == undefined){ - return 4444 + if (proxy_port == undefined) { + return "4444" } return proxy_port; } @@ -60,7 +84,7 @@ function getPort() { function getControlHost() { control_host = document.getElementById("controlhost").value console.log("Got i2p control host:", control_host); - if (control_host == undefined){ + if (control_host == undefined) { return "127.0.0.1" } return control_host; @@ -69,24 +93,12 @@ function getControlHost() { function getControlPort() { control_port = document.getElementById("controlport").value console.log("Got i2p control port:", control_port); - if (control_port == undefined){ - return 4444 + if (control_port == undefined) { + return "4444" } return control_port; } -function isFirefox() { - testPlain = navigator.userAgent.indexOf('Firefox') !== -1; - if (testPlain) { - return testPlain - } - testTorBrowser = navigator.userAgent.indexOf('Tor') !== -1; - if (testTorBrowser) { - return testTorBrowser - } - return false -} - function checkStoredSettings(storedSettings) { let defaultSettings = {}; if (!storedSettings.proxy_scheme){ @@ -111,38 +123,6 @@ function onError(e) { console.error(e); } -//var controlHost = "127.0.0.1" //getControlHost() -//var controlPort = "7951" //getControlPort(); - -function setupProxy() { - //var controlHost = getControlHost() - //var controlPort = getControlPort() - var Host = getHost() - var Port = getPort() - if (isDroid()) { - console.log("Setting up Firefox Android proxy") - function handleProxyRequest(requestInfo) { - if (shouldProxyRequest(requestInfo)) { - console.log(`Proxying: ${requestInfo.url}`); - return {type: "http", host: Host, port: Port}; - } - return {type: "http", host: Host, port: Port}; - } - browser.proxy.onRequest.addListener(handleProxyRequest, {urls: [""]}); - console.log("i2p settings created for Firefox Android") - }else{ - console.log("Setting up Firefox Desktop proxy") - var proxySettings = { - proxyType: "manual", - http: Host+":"+Port, - passthrough: "", - httpProxyAll: true - }; - browser.proxy.settings.set({value:proxySettings}); - console.log("i2p settings created for Firefox Desktop") - } -} - function storeSettings() { let proxy_scheme = getScheme() let proxy_host = getHost() @@ -178,18 +158,19 @@ function updateUI(restoredSettings) { portitem.value = restoredSettings.proxy_port console.log("showing proxy port:", portitem.value) - /*const controlhostitem = document.getElementById("controlhost") + const controlhostitem = document.getElementById("controlhost") controlhostitem.value = restoredSettings.control_host console.log("showing control host:", controlhostitem.value) const controlportitem = document.getElementById("controlport") controlportitem.value = restoredSettings.control_port - console.log("showing control port:", controlportitem.value)*/ + console.log("showing control port:", controlportitem.value) + SetHostText() SetPortText() - /*SetControlHostText() + SetControlHostText() SetControlPortText() - SetControlHelpText()*/ + SetControlHelpText() setupProxy() } @@ -203,3 +184,6 @@ chrome.storage.local.get(function(got){ const saveButton = document.querySelector("#save-button"); saveButton.addEventListener("click", storeSettings); + +//EXPERIMENTAL: Open in I2P Tab + diff --git a/proxy.js b/proxy.js index 838a8b9..9965a10 100644 --- a/proxy.js +++ b/proxy.js @@ -1,67 +1,144 @@ -function isFirefox() { - testPlain = navigator.userAgent.indexOf('Firefox') !== -1; - if (testPlain) { - console.log("firefox") - return testPlain - } - return false -} function isDroid() { var gettingInfo = browser.runtime.getPlatformInfo(); gettingInfo.then((got) => { if (got.os == "android") { return true + }else{ + return false } }); } -if (isFirefox()) { - browser.privacy.network.peerConnectionEnabled.set({value: false}); -} +browser.privacy.network.peerConnectionEnabled.set({value: false}); + chrome.privacy.network.networkPredictionEnabled.set({value: false}); chrome.privacy.network.webRTCIPHandlingPolicy.set({value: "disable_non_proxied_udp"}); console.log("Preliminarily disabled WebRTC.") function shouldProxyRequest(requestInfo) { - return true; //requestInfo.parentFrameId != -1; + return requestInfo.parentFrameId != -1; +} + +function handleProxyRequest(requestInfo) { + console.log(`Proxying: ${requestInfo.url}`); + console.log(" ", getScheme(), getHost(), ":", getPort(),) + return {type: getScheme(), host: getHost(), port: getPort()}; +} + +var proxy_scheme = "HTTP" + +function getScheme() { + if (proxy_scheme == undefined) { + proxy_scheme = "http" + } + if (proxy_scheme == "HTTP") { + proxy_scheme = "http" + } + if (proxy_scheme == "SOCKS") { + proxy_scheme = "socks" + } + console.log("Got i2p proxy scheme:", proxy_scheme); + return proxy_scheme; +} + +var proxy_host = "127.0.0.1" + +function getHost() { + if (proxy_host == undefined){ + proxy_host = "127.0.0.1" + } + console.log("Got i2p proxy host:", proxy_host); + return proxy_host; +} + +var proxy_port = "4444" + +function getPort() { + if (proxy_port == undefined){ + proxy_port = "4444" + } + console.log("Got i2p proxy port:", proxy_port); + return proxy_port; +} + +var control_host = "127.0.0.1" + +function getControlHost() { + if (control_host == undefined){ + return "127.0.0.1" + } + console.log("Got i2p control host:", control_host); + return control_host; +} + +var control_port = "4444" + +function getControlPort() { + if (control_port == undefined){ + return "4444" + } + console.log("Got i2p control port:", control_port); + return control_port; } function setupProxy() { - var controlHost = "127.0.0.1" //getControlHost() - var controlPort = "7951" //getControlPort(); - var Host = "127.0.0.1" //getHost() - var Port = "4444" //getPort() - if (isDroid()) { - console.log("Setting up Firefox Android proxy") - function handleProxyRequest(requestInfo) { - if (shouldProxyRequest(requestInfo)) { - console.log(`Proxying: ${requestInfo.url}`); - return {type: "http", host: Host, port: Port}; - } - return {type: "http", host: Host, port: Port}; - } - browser.proxy.onRequest.addListener(handleProxyRequest, {urls: [""]}); - console.log("i2p settings created for Firefox Android") - }else{ - console.log("Setting up Firefox Desktop proxy") - var proxySettings = { - proxyType: "manual", - http: Host+":"+Port, - passthrough: "", - httpProxyAll: true - }; - browser.proxy.settings.set({value:proxySettings}); - console.log("i2p settings created for Firefox Desktop") + var controlHost = getControlHost() + var controlPort = getControlPort(); + var Host = getHost() + var Port = getPort() + var Scheme = getScheme() + function handleProxyRequest(requestInfo) { + console.log("proxying request via listener") + console.log(" ", Scheme, Host, ":", Port,) + return {type: Scheme, host: Host, port: Port, proxyDns: true} } + console.log("Setting up Firefox WebExtension proxy") + browser.proxy.onRequest.addListener(handleProxyRequest, {urls: [""]}); + console.log("i2p settings created for WebExtension Proxy") } -if (isFirefox()){ - // Theme all currently open windows +function checkStoredSettings(storedSettings) { + let defaultSettings = {}; + if (!storedSettings.proxy_scheme){ + defaultSettings["proxy_scheme"] = "http" + } + if (!storedSettings.proxy_host) { + defaultSettings["proxy_host"] = "127.0.0.1" + } + if (!storedSettings.proxy_port) { + defaultSettings["proxy_port"] = 4444 + } + if (!storedSettings.control_host) { + defaultSettings["control_host"] = "127.0.0.1" + } + if (!storedSettings.control_port) { + defaultSettings["control_port"] = 4444 + } + chrome.storage.local.set(defaultSettings); +} + +function update(restoredSettings) { + proxy_scheme = restoredSettings.proxy_scheme + console.log("restoring proxy scheme:", proxy_scheme) + proxy_host = restoredSettings.proxy_host + console.log("restoring proxy host:", proxy_host) + proxy_port = restoredSettings.proxy_port + console.log("restoring proxy port:", proxy_port) + control_host = restoredSettings.control_host + console.log("restoring control host:", control_host) + control_port = restoredSettings.control_port + console.log("restoring control port:", control_port) +} + +chrome.storage.local.get(function(got){ + checkStoredSettings(got) + update(got) + setupProxy() +}); + +// Theme all currently open windows +if (!isDroid()) { browser.windows.getAll().then(wins => wins.forEach(themeWindow)); } - -if (isFirefox()) { - setupProxy() -}