From 1de16215be43ccce13c0e6394940708660ee859d Mon Sep 17 00:00:00 2001 From: idk Date: Thu, 21 Feb 2019 22:51:59 -0500 Subject: [PATCH] add reset functionality --- Makefile | 3 ++- README.md | 1 + _locales/en/messages.json | 8 ++++++ options/options.html | 11 ++++++++ options/options.js | 55 +++++++++++++++++++++++++++++++++++++-- proxy.js | 13 +++++++++ 6 files changed, 88 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index edfb88f..d055ebb 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ install: uninstall /usr/share/mozilla/extensions/{ec8030f7-c20a-464f-9b0e-13a3a9e97384}/ cp -rv options /usr/share/webext/i2psetproxy.js@eyedeekay.github.io/options cp -rv icons /usr/share/webext/i2psetproxy.js@eyedeekay.github.io/icons + cp -rv _locales /usr/share/webext/i2psetproxy.js@eyedeekay.github.io/_locales cp background.js /usr/share/webext/i2psetproxy.js@eyedeekay.github.io cp proxy.js /usr/share/webext/i2psetproxy.js@eyedeekay.github.io cp manifest.json /usr/share/webext/i2psetproxy.js@eyedeekay.github.io/ @@ -13,7 +14,7 @@ install: uninstall /usr/share/mozilla/extensions/{ec8030f7-c20a-464f-9b0e-13a3a9e97384}/i2psetproxy.js@eyedeekay.github.io uninstall: - rm -rf /usr/share/webext/i2psetproxy.js/i2psetproxy.js@eyedeekay.github.io \ + rm -rf /usr/share/webext/i2psetproxy.js@eyedeekay.github.io \ /usr/share/mozilla/extensions/{ec8030f7-c20a-464f-9b0e-13a3a9e97384}/i2psetproxy.js@eyedeekay.github.io zip: diff --git a/README.md b/README.md index 2a3e2b1..251fd3f 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ Features * [done] **Set** the http proxy to use the local i2p proxy * [done] **Disable** risky webRTC features * [done] **Change** the color of the browser window to indicate that i2p is in use + * [done] **Reset** the HTTP Proxy tunnel to generate a new destination on-demand * [started] **Provide** help in a variety of languages. Screenshot diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 6d55363..ce1ebf1 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -27,5 +27,13 @@ "portText": { "message": "Port: ", "description": "Message for the Reset Tunnel button" + }, + "controlHostText": { + "message": "Host: ", + "description": "Message for the Reset Tunnel button" + }, + "controlPortText": { + "message": "Port: ", + "description": "Message for the Reset Tunnel button" } } diff --git a/options/options.html b/options/options.html index 37d643b..8c6dca6 100644 --- a/options/options.html +++ b/options/options.html @@ -26,6 +26,17 @@ +
+
Controller Options
+ + + +
+ + + +
+ diff --git a/options/options.js b/options/options.js index 31f068b..c5f6138 100644 --- a/options/options.js +++ b/options/options.js @@ -1,6 +1,8 @@ var hosttext = browser.i18n.getMessage("hostText"); var porttext = browser.i18n.getMessage("portText"); +var controlhosttext = browser.i18n.getMessage("hostText"); +var controlporttext = browser.i18n.getMessage("portText"); function getScheme() { const proxy_scheme = document.querySelector("#proxy_scheme"); @@ -26,6 +28,24 @@ function getPort() { return proxy_port; } +function getControlHost() { + control_host = document.getElementById("controlhost").value + console.log("Got i2p control host:", control_host); + if (control_host == undefined){ + return "127.0.0.1" + } + return control_host; +} + +function getControlPort() { + control_port = document.getElementById("controlport").value + console.log("Got i2p control port:", control_port); + if (control_port == undefined){ + return 4444 + } + return control_port; +} + function isFirefox() { testPlain = navigator.userAgent.indexOf('Firefox') !== -1; if (testPlain) { @@ -49,6 +69,12 @@ function checkStoredSettings(storedSettings) { 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 + } browser.storage.local.set(defaultSettings); } @@ -105,14 +131,20 @@ function storeSettings() { let proxy_scheme = getScheme() let proxy_host = getHost() let proxy_port = getPort() + let control_host = getControlHost() + let control_port = getControlPort() browser.storage.local.set({ proxy_scheme, proxy_host, proxy_port, + control_host, + control_port, }); - console.log("storing proxy host:", proxy_scheme) + console.log("storing proxy scheme:", proxy_scheme) console.log("storing proxy host:", proxy_host) console.log("storing proxy port:", proxy_port) + console.log("storing control host:", control_host) + console.log("storing control port:", control_port) setupProxy() } @@ -126,11 +158,18 @@ function updateUI(restoredSettings) { hostitem.value = restoredSettings.proxy_host console.log("showing proxy host:", hostitem.value) - const portitem = document.getElementById("port") portitem.value = restoredSettings.proxy_port console.log("showing proxy port:", portitem.value) + 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) + } function SetHostText(){ @@ -143,6 +182,16 @@ function SetPortText(){ portid.textContent = porttext; } +function SetControlHostText(){ + var hostid = document.getElementById('controlHostText'); + hostid.textContent = hosttext; +} + +function SetControlPortText(){ + var portid = document.getElementById('controlPortText'); + portid.textContent = porttext; +} + function onError(e) { console.error(e); } @@ -158,3 +207,5 @@ saveButton.addEventListener("click", storeSettings); SetHostText() SetPortText() +SetControlHostText() +SetControlPortText() diff --git a/proxy.js b/proxy.js index 55a32b8..1c86f73 100644 --- a/proxy.js +++ b/proxy.js @@ -60,3 +60,16 @@ function setupProxy() { console.log("i2p settings created for Chromium") } } + +function RefreshIdentity(){ + console.log("Generating new identity") + const Http = new XMLHttpRequest(); + const url='http://' + getControlHost() + ":" + getControlPort(); + Http.open("GET", url); + Http.send(); + Http.onreadystatechange=(e)=>{ + console.log(Http.responseText) + } +} + +browser.browserAction.onClicked.addListener(RefreshIdentity);