introduce a proxy health check
This commit is contained in:
@@ -77,6 +77,10 @@ submission to AMO.
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
Super Extra Important Background Info:
|
||||
|
||||
4
info.css
4
info.css
@@ -16,3 +16,7 @@ span.identity {
|
||||
display: inline-block;
|
||||
margin-left: 1em;
|
||||
}
|
||||
|
||||
figcaption {
|
||||
display: inline;
|
||||
}
|
||||
29
info.js
29
info.js
@@ -55,3 +55,32 @@ document.addEventListener("click", e => {
|
||||
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
function proxyReadiness() {
|
||||
console.log(this.responseText);
|
||||
}
|
||||
|
||||
//document.addEventListener("onpageshow", e => {
|
||||
console.log("(Check) Checking Proxy Readiness");
|
||||
const Http = new XMLHttpRequest();
|
||||
Http.addEventListener("load", proxyReadiness);
|
||||
const url = "http://proxy.i2p"; ///themes/console/images/favicon.ico";
|
||||
Http.open("GET", url);
|
||||
Http.send();
|
||||
//});
|
||||
|
||||
function transferComplete(evt) {
|
||||
console.log("The transfer is complete.", this.status, this.statusText, this.responseText);
|
||||
}
|
||||
|
||||
function transferFailed(evt) {
|
||||
console.log("An error occurred while transferring the file.", this.status, this.statusText, this.responseText);
|
||||
}
|
||||
|
||||
function transferCanceled(evt) {
|
||||
console.log("The transfer has been canceled by the user.", this.status, this.statusText, this.responseText);
|
||||
}
|
||||
|
||||
Http.addEventListener("load", transferComplete);
|
||||
Http.addEventListener("error", transferFailed);
|
||||
Http.addEventListener("abort", transferCanceled);
|
||||
|
||||
56
proxy.js
56
proxy.js
@@ -39,19 +39,39 @@ var handleContextProxyRequest = async function(requestDetails) {
|
||||
);
|
||||
return proxy;
|
||||
} else if (context.name == "routerconsole") {
|
||||
if (i2pHost(requestDetails.url)) {
|
||||
proxy = {
|
||||
type: getScheme(),
|
||||
host: getHost(),
|
||||
port: getPort()
|
||||
};
|
||||
if (routerHost(requestDetails.url)) {
|
||||
return proxy;
|
||||
} else if (!routerHost(requestDetails.url)) {
|
||||
proxy = {
|
||||
type: "http",
|
||||
host: "localhost",
|
||||
port: "1"
|
||||
port: "65535"
|
||||
};
|
||||
}
|
||||
proxy = {
|
||||
type: getScheme(),
|
||||
host: getHost(),
|
||||
port: getPort()
|
||||
};
|
||||
console.log(
|
||||
"(proxy)",
|
||||
context.name,
|
||||
"Using",
|
||||
proxy.type,
|
||||
"proxy ",
|
||||
proxy.host + ":" + proxy.port
|
||||
);
|
||||
return proxy;
|
||||
} else if (context.name == "Personal") {
|
||||
if (localHost(requestDetails.url)) {
|
||||
if (!routerHost(requestDetails.url)) {
|
||||
proxy = {
|
||||
type: "http",
|
||||
host: "localhost",
|
||||
port: "65535"
|
||||
};
|
||||
}
|
||||
}
|
||||
console.log(
|
||||
"(proxy)",
|
||||
context.name,
|
||||
@@ -63,18 +83,18 @@ var handleContextProxyRequest = async function(requestDetails) {
|
||||
return proxy;
|
||||
}
|
||||
}
|
||||
if (i2pHost(requestDetails.url)) {
|
||||
if (!routerHost(requestDetails.url)) {
|
||||
proxy = {
|
||||
type: "http",
|
||||
host: "localhost",
|
||||
port: "65535"
|
||||
};
|
||||
} else if (i2pHost(requestDetails.url)) {
|
||||
proxy = {
|
||||
type: getScheme(),
|
||||
host: getHost(),
|
||||
port: getPort()
|
||||
};
|
||||
} else if (!routerHost(requestDetails.url)) {
|
||||
proxy = {
|
||||
type: "http",
|
||||
host: "localhost",
|
||||
port: "1"
|
||||
};
|
||||
}
|
||||
return proxy;
|
||||
};
|
||||
@@ -111,6 +131,7 @@ var handleContextProxyRequest = async function(requestDetails) {
|
||||
|
||||
if (requestDetails.tabId > 0) {
|
||||
if (proxyHost(requestDetails.url)) {
|
||||
console.log("(Proxy)I2P Proxy test URL detected, ", requestDetails.url);
|
||||
return {
|
||||
type: getScheme(),
|
||||
host: getHost(),
|
||||
@@ -132,6 +153,13 @@ var handleContextProxyRequest = async function(requestDetails) {
|
||||
console.log("(proxy)Returning I2P Proxy", proxy);
|
||||
return proxy;
|
||||
}
|
||||
proxy = {
|
||||
type: getScheme(),
|
||||
host: getHost(),
|
||||
port: getPort()
|
||||
};
|
||||
console.log("(proxy)Returning I2P Proxy", proxy);
|
||||
return proxy;
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("(proxy)Not using I2P Proxy.", error);
|
||||
|
||||
66
scrub.js
66
scrub.js
@@ -80,7 +80,7 @@ var contextScrub = async function(requestDetails) {
|
||||
tab = tabGet(requestDetails.tabId);
|
||||
context = tab.then(contextGet);
|
||||
req = await context.then(headerScrub);
|
||||
console.log("(scrub)Scrubbing I2P Request", req);
|
||||
console.log("(scrub)Scrubbing non-I2P Request", req);
|
||||
return req;
|
||||
}
|
||||
}
|
||||
@@ -168,6 +168,44 @@ var contextSetup = async function(requestDetails) {
|
||||
console.log("(isolate)Context Error", error);
|
||||
}
|
||||
};
|
||||
var anyTabFind = async function(tabId) {
|
||||
try {
|
||||
var context = await browser.contextualIdentities.query({
|
||||
name: "Personal"
|
||||
});
|
||||
if (tabId.cookieStoreId != context[0].cookieStoreId) {
|
||||
console.log(
|
||||
"(isolate) forcing",
|
||||
requestDetails.url,
|
||||
" context",
|
||||
tabId.cookieStoreId,
|
||||
context[0].cookieStoreId
|
||||
);
|
||||
function Create(window) {
|
||||
function onCreated(tab) {
|
||||
console.log("(isolate) Closing old, un-isolated tab");
|
||||
browser.tabs.remove(tabId.id);
|
||||
browser.tabs.remove(window.tabs[0].id);
|
||||
}
|
||||
function onError(error) {
|
||||
console.log(`Error: ${error}`);
|
||||
}
|
||||
var created = browser.tabs.create({
|
||||
active: true,
|
||||
cookieStoreId: context[0].cookieStoreId,
|
||||
url: requestDetails.url,
|
||||
windowId: window.id
|
||||
});
|
||||
created.then(onCreated, onError);
|
||||
}
|
||||
var getting = browser.windows.getCurrent();
|
||||
getting.then(Create);
|
||||
return tabId;
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("(isolate)Context Error", error);
|
||||
}
|
||||
};
|
||||
var tabGet = async function(tabId) {
|
||||
try {
|
||||
console.log("(isolate)Tab ID from Request", tabId);
|
||||
@@ -178,6 +216,9 @@ var contextSetup = async function(requestDetails) {
|
||||
}
|
||||
};
|
||||
if (requestDetails.tabId > 0) {
|
||||
if (proxyHost(requestDetails.url)){
|
||||
return requestDetails;
|
||||
}
|
||||
if (i2pHost(requestDetails.url)) {
|
||||
var tab = tabGet(requestDetails.tabId);
|
||||
var mtab = tab.then(tabFind);
|
||||
@@ -188,7 +229,13 @@ var contextSetup = async function(requestDetails) {
|
||||
var mtab = tab.then(routerTabFind);
|
||||
return requestDetails;
|
||||
}
|
||||
var tab = tabGet(requestDetails.tabId);
|
||||
var mtab = tab.then(anyTabFind);
|
||||
return requestDetails;
|
||||
}
|
||||
//var tab = tabGet(requestDetails.tabId);
|
||||
//var mtab = tab.then(anyTabFind);
|
||||
return requestDetails;
|
||||
} catch (error) {
|
||||
console.log("(isolate)Not an I2P request, blackholing", error);
|
||||
}
|
||||
@@ -222,6 +269,23 @@ function proxyHost(url) {
|
||||
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 routerHost(url) {
|
||||
let hostname = "";
|
||||
if (url.indexOf("://") > -1) {
|
||||
|
||||
@@ -35,7 +35,11 @@
|
||||
<input type="checkbox" id="enable-web-rtc" name="enablewebrtc" value="webrtc">
|
||||
<label for="enable-web-rtc">Enable WebRTC <strong>with Proxy?</strong></label>
|
||||
<div class="panel-section-separator"></div>
|
||||
<a href="#" id="check-i2p-control">Check I2P Router Health</a><div id="panel-section-i2pcontrol-check"></div>
|
||||
<!--<a href="#" id="check-i2p-control">Check I2P Router Health</a><div id="panel-section-i2pcontrol-check"></div>-->
|
||||
<figure>
|
||||
<img src="http://proxy.i2p/themes/console/images/favicon.ico" id="panel-proxy-check" alt="Proxy is not ready yet"/>
|
||||
<figcaption>I2P Proxy is Ready</figcaption>
|
||||
</figure>
|
||||
<div class="panel-section-separator"></div>
|
||||
<div class="panel-section-identity">
|
||||
<div id="identity-list"></div>
|
||||
@@ -47,7 +51,7 @@
|
||||
<script src="privacy.js"></script>
|
||||
<script src="info.js"></script>
|
||||
<script src="content.js" crossorigin="anonymous"></script>
|
||||
<script src="i2pcontrol.js"></script>
|
||||
<script src="i2pcontrol/i2pcontrol.js"></script>
|
||||
|
||||
</body>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user