2019-11-24 18:13:34 -05:00
|
|
|
var titlepref = chrome.i18n.getMessage("titlePreface");
|
2019-11-25 20:19:44 -05:00
|
|
|
var titleprefpriv = chrome.i18n.getMessage("titlePrefacePrivate");
|
2019-11-11 23:31:37 -05:00
|
|
|
var webpref = chrome.i18n.getMessage("webPreface");
|
|
|
|
var webprefpriv = chrome.i18n.getMessage("webPrefacePrivate");
|
|
|
|
var routerpref = chrome.i18n.getMessage("routerPreface");
|
|
|
|
var routerprefpriv = chrome.i18n.getMessage("routerPrefacePrivate");
|
|
|
|
var mailpref = chrome.i18n.getMessage("mailPreface");
|
|
|
|
var mailprefpriv = chrome.i18n.getMessage("mailPrefacePrivate");
|
|
|
|
var torrentpref = chrome.i18n.getMessage("torrentPreface");
|
|
|
|
var torrentprefpriv = chrome.i18n.getMessage("torrentPrefacePrivate");
|
|
|
|
var tunnelpref = chrome.i18n.getMessage("i2ptunnelPreface");
|
|
|
|
var tunnelprefpriv = chrome.i18n.getMessage("i2ptunnelPrefacePrivate");
|
|
|
|
|
2019-10-28 01:11:16 -04:00
|
|
|
browser.privacy.network.peerConnectionEnabled.set({
|
|
|
|
value: false
|
|
|
|
});
|
|
|
|
console.log("Preliminarily disabled WebRTC.");
|
2019-06-17 19:17:11 -04:00
|
|
|
|
2019-06-27 15:40:43 -04:00
|
|
|
chrome.privacy.network.networkPredictionEnabled.set({
|
2019-10-06 15:14:53 -04:00
|
|
|
value: false
|
2019-06-27 15:40:43 -04:00
|
|
|
});
|
|
|
|
chrome.privacy.network.webRTCIPHandlingPolicy.set({
|
2019-10-06 15:14:53 -04:00
|
|
|
value: "disable_non_proxied_udp"
|
2019-06-27 15:40:43 -04:00
|
|
|
});
|
2019-02-05 17:38:38 -05:00
|
|
|
|
2019-05-03 18:40:46 -04:00
|
|
|
function shouldProxyRequest(requestInfo) {
|
2019-10-06 15:14:53 -04:00
|
|
|
return requestInfo.parentFrameId != -1;
|
2019-10-06 13:38:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
var handleContextProxyRequest = async function(requestDetails) {
|
2019-10-06 15:14:53 -04:00
|
|
|
console.log("(proxy)Searching for proxy by context");
|
|
|
|
try {
|
|
|
|
var handleProxyRequest = function(context) {
|
|
|
|
proxy = {
|
|
|
|
failoverTimeout: 0,
|
|
|
|
proxyDns: false
|
2019-10-06 15:18:10 -04:00
|
|
|
};
|
2019-11-27 00:31:10 -05:00
|
|
|
if (context == "firefox-default" || context == "firefox-private") {
|
|
|
|
proxy = null;
|
|
|
|
return proxy;
|
|
|
|
}
|
2019-11-10 20:28:31 -05:00
|
|
|
if (context != undefined) {
|
2019-11-11 23:31:37 -05:00
|
|
|
if (context.name == titlepref) {
|
2019-11-10 20:28:31 -05:00
|
|
|
proxy = {
|
|
|
|
type: getScheme(),
|
|
|
|
host: getHost(),
|
|
|
|
port: getPort()
|
|
|
|
};
|
2019-12-25 00:42:16 -05:00
|
|
|
console.log("(proxy)", context.name);
|
|
|
|
console.log("Using", proxy.type);
|
|
|
|
console.log("proxy ", proxy.host + ":" + proxy.port);
|
2019-11-10 20:28:31 -05:00
|
|
|
return proxy;
|
2019-11-11 23:31:37 -05:00
|
|
|
} else if (context.name == routerpref) {
|
2019-11-10 22:24:10 -05:00
|
|
|
if (routerHost(requestDetails.url)) {
|
|
|
|
return proxy;
|
2019-11-10 20:28:31 -05:00
|
|
|
} else if (!routerHost(requestDetails.url)) {
|
|
|
|
proxy = {
|
|
|
|
type: "http",
|
|
|
|
host: "localhost",
|
2019-11-10 22:24:10 -05:00
|
|
|
port: "65535"
|
2019-11-10 20:28:31 -05:00
|
|
|
};
|
|
|
|
}
|
2019-11-10 22:24:10 -05:00
|
|
|
proxy = {
|
|
|
|
type: getScheme(),
|
|
|
|
host: getHost(),
|
|
|
|
port: getPort()
|
|
|
|
};
|
2019-12-25 00:42:16 -05:00
|
|
|
console.log("(proxy)", context.name);
|
|
|
|
console.log("Using", proxy.type);
|
|
|
|
console.log("proxy ", proxy.host + ":" + proxy.port);
|
2019-11-10 22:24:10 -05:00
|
|
|
return proxy;
|
2019-11-11 23:31:37 -05:00
|
|
|
} else if (context.name == webpref) {
|
2019-11-10 22:24:10 -05:00
|
|
|
if (localHost(requestDetails.url)) {
|
|
|
|
if (!routerHost(requestDetails.url)) {
|
|
|
|
proxy = {
|
|
|
|
type: "http",
|
|
|
|
host: "localhost",
|
|
|
|
port: "65535"
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2019-12-25 00:42:16 -05:00
|
|
|
console.log("(proxy)", context.name);
|
|
|
|
console.log("Using", proxy.type);
|
|
|
|
console.log("proxy ", proxy.host + ":" + proxy.port);
|
2019-11-10 20:28:31 -05:00
|
|
|
return proxy;
|
|
|
|
}
|
|
|
|
}
|
2019-11-10 22:24:10 -05:00
|
|
|
if (!routerHost(requestDetails.url)) {
|
2019-11-11 02:38:11 -05:00
|
|
|
if (localHost(requestDetails.url)) {
|
2019-11-11 16:34:41 -05:00
|
|
|
console.log(
|
2019-12-24 18:31:44 -05:00
|
|
|
"(proxy) non-routerconsole localhost url, will not interfere",
|
2019-11-11 16:34:41 -05:00
|
|
|
requestDetails.url
|
|
|
|
);
|
2019-12-24 18:31:44 -05:00
|
|
|
/*proxy = {
|
2019-11-11 02:38:11 -05:00
|
|
|
type: "http",
|
|
|
|
host: "localhost",
|
|
|
|
port: "65535"
|
2019-12-24 18:31:44 -05:00
|
|
|
};*/
|
2019-11-11 02:38:11 -05:00
|
|
|
}
|
2019-11-10 22:24:10 -05:00
|
|
|
} else if (i2pHost(requestDetails.url)) {
|
2019-10-06 15:14:53 -04:00
|
|
|
proxy = {
|
|
|
|
type: getScheme(),
|
|
|
|
host: getHost(),
|
2019-10-06 15:18:10 -04:00
|
|
|
port: getPort()
|
|
|
|
};
|
2019-10-06 15:14:53 -04:00
|
|
|
}
|
2019-10-06 15:18:10 -04:00
|
|
|
return proxy;
|
|
|
|
};
|
2019-10-06 15:14:53 -04:00
|
|
|
var contextGet = async function(tabInfo) {
|
|
|
|
try {
|
2019-10-06 15:18:10 -04:00
|
|
|
console.log("(proxy)Tab info from Function", tabInfo);
|
|
|
|
context = await browser.contextualIdentities.get(tabInfo.cookieStoreId);
|
|
|
|
return context;
|
|
|
|
} catch (error) {
|
2019-12-25 00:42:16 -05:00
|
|
|
return; //"firefox-default";
|
2019-10-07 18:45:52 -04:00
|
|
|
}
|
|
|
|
};
|
2019-10-06 15:14:53 -04:00
|
|
|
var tabGet = async function(tabId) {
|
|
|
|
try {
|
2019-10-06 15:18:10 -04:00
|
|
|
console.log("(proxy)Tab ID from Request", tabId);
|
|
|
|
let tabInfo = await browser.tabs.get(tabId);
|
|
|
|
return tabInfo;
|
|
|
|
} catch (error) {
|
|
|
|
console.log("(proxy)Tab error", error);
|
2019-10-06 15:14:53 -04:00
|
|
|
}
|
2019-10-06 15:18:10 -04:00
|
|
|
};
|
2019-10-07 18:45:52 -04:00
|
|
|
|
2019-10-06 15:14:53 -04:00
|
|
|
if (requestDetails.tabId > 0) {
|
2019-11-11 21:39:35 -05:00
|
|
|
console.log("manifest", requestDetails);
|
2019-11-11 21:38:38 -05:00
|
|
|
if (proxyHost(requestDetails.url)) {
|
|
|
|
proxy = {
|
|
|
|
type: getScheme(),
|
|
|
|
host: getHost(),
|
|
|
|
port: getPort()
|
|
|
|
};
|
2019-11-11 21:39:35 -05:00
|
|
|
return proxy;
|
|
|
|
} else if (i2pHost(requestDetails.url)) {
|
2019-10-07 18:45:52 -04:00
|
|
|
console.log("(Proxy)I2P URL detected, ");
|
|
|
|
var tab = tabGet(requestDetails.tabId);
|
2019-11-24 23:29:06 -05:00
|
|
|
requestDetails.tabId = tab;
|
|
|
|
var context = tab.then(contextGet);
|
2019-10-07 18:45:52 -04:00
|
|
|
var proxy = await context.then(handleProxyRequest);
|
|
|
|
console.log("(proxy)Returning I2P Proxy", proxy);
|
|
|
|
return proxy;
|
|
|
|
} else {
|
|
|
|
var tab = tabGet(requestDetails.tabId);
|
|
|
|
var context = tab.then(contextGet);
|
|
|
|
var proxy = await context.then(handleProxyRequest);
|
|
|
|
console.log("(proxy)Returning I2P Proxy", proxy);
|
|
|
|
return proxy;
|
|
|
|
}
|
2019-11-11 02:38:11 -05:00
|
|
|
proxy = {};
|
|
|
|
console.log("(proxy)Returning unset Proxy", proxy);
|
2019-11-10 22:24:10 -05:00
|
|
|
return proxy;
|
2019-10-06 15:14:53 -04:00
|
|
|
}
|
2019-10-06 15:18:10 -04:00
|
|
|
} catch (error) {
|
2019-10-06 15:14:53 -04:00
|
|
|
console.log("(proxy)Not using I2P Proxy.", error);
|
|
|
|
}
|
2019-10-06 15:18:10 -04:00
|
|
|
};
|
2019-06-17 19:17:11 -04:00
|
|
|
|
2019-10-06 15:18:10 -04:00
|
|
|
var proxy_scheme = "HTTP";
|
2019-11-24 20:43:17 -05:00
|
|
|
var proxy_host = "127.0.0.1";
|
|
|
|
var proxy_port = "4444";
|
|
|
|
var control_host = "127.0.0.1";
|
|
|
|
var control_port = "4444";
|
2019-11-25 20:19:44 -05:00
|
|
|
var disable_history = false;
|
2019-11-24 20:43:17 -05:00
|
|
|
|
|
|
|
function SetupSettings() {
|
|
|
|
console.log("Initialising Settings");
|
|
|
|
//
|
|
|
|
function checkSchemeStoredSettings(storedSettings) {
|
2019-11-25 20:19:44 -05:00
|
|
|
if (storedSettings.proxy_scheme != undefined) {
|
|
|
|
proxy_scheme = storedSettings.proxy_scheme;
|
|
|
|
} else {
|
|
|
|
proxy_scheme = "http";
|
|
|
|
storedSettings.proxy_scheme = proxy_scheme;
|
|
|
|
}
|
2019-11-24 20:43:17 -05:00
|
|
|
console.log("Initialising Proxy Scheme", storedSettings.proxy_scheme);
|
2019-11-27 00:03:44 -05:00
|
|
|
setupProxy();
|
2019-11-24 20:43:17 -05:00
|
|
|
}
|
|
|
|
var gettingSchemeStoredSettings = browser.storage.local.get("proxy_scheme");
|
|
|
|
gettingSchemeStoredSettings.then(checkSchemeStoredSettings, onError);
|
|
|
|
|
|
|
|
//
|
|
|
|
function checkHostStoredSettings(storedSettings) {
|
2019-11-25 20:19:44 -05:00
|
|
|
if (storedSettings.proxy_host != undefined) {
|
|
|
|
proxy_host = storedSettings.proxy_host;
|
|
|
|
} else {
|
|
|
|
proxy_host = "127.0.0.1";
|
|
|
|
storedSettings.proxy_host = proxy_host;
|
|
|
|
}
|
2019-11-24 20:43:17 -05:00
|
|
|
console.log("Initialising Host", storedSettings.proxy_host);
|
2019-11-27 00:03:44 -05:00
|
|
|
setupProxy();
|
2019-11-24 20:43:17 -05:00
|
|
|
}
|
|
|
|
var gettingHostStoredSettings = browser.storage.local.get("proxy_host");
|
|
|
|
gettingHostStoredSettings.then(checkHostStoredSettings, onError);
|
|
|
|
|
|
|
|
//
|
|
|
|
function checkPortStoredSettings(storedSettings) {
|
2019-11-25 20:19:44 -05:00
|
|
|
if (storedSettings.proxy_port != undefined) {
|
|
|
|
proxy_port = storedSettings.proxy_port;
|
|
|
|
} else {
|
|
|
|
proxy_port = "4444";
|
|
|
|
storedSettings.proxy_port = proxy_port;
|
|
|
|
}
|
2019-11-24 20:43:17 -05:00
|
|
|
console.log("Initialising Port", storedSettings.proxy_port);
|
2019-11-27 00:03:44 -05:00
|
|
|
setupProxy();
|
2019-11-24 20:43:17 -05:00
|
|
|
}
|
|
|
|
var gettingPortStoredSettings = browser.storage.local.get("proxy_port");
|
|
|
|
gettingPortStoredSettings.then(checkPortStoredSettings, onError);
|
|
|
|
|
|
|
|
//
|
|
|
|
function checkControlHostStoredSettings(storedSettings) {
|
2019-11-25 20:19:44 -05:00
|
|
|
if (storedSettings.control_host != undefined) {
|
|
|
|
control_host = storedSettings.control_host;
|
|
|
|
} else {
|
|
|
|
control_host = "127.0.0.1";
|
|
|
|
storedSettings.control_host = control_host;
|
|
|
|
}
|
2019-11-24 20:43:17 -05:00
|
|
|
console.log("Initialising Control Host", storedSettings.control_host);
|
2019-11-27 00:03:44 -05:00
|
|
|
setupProxy();
|
2019-11-24 20:43:17 -05:00
|
|
|
}
|
2019-12-24 16:51:38 -05:00
|
|
|
var gettingControlHostStoredSettings = browser.storage.local.get(
|
|
|
|
"control_host"
|
|
|
|
);
|
2019-11-24 20:43:17 -05:00
|
|
|
gettingControlHostStoredSettings.then(
|
|
|
|
checkControlHostStoredSettings,
|
|
|
|
onError
|
|
|
|
);
|
|
|
|
|
|
|
|
//
|
|
|
|
function checkControlPortStoredSettings(storedSettings) {
|
2019-11-25 20:19:44 -05:00
|
|
|
if (storedSettings.control_port != undefined) {
|
|
|
|
contro_port = storedSettings.control_port;
|
|
|
|
} else {
|
2019-11-26 23:06:24 -05:00
|
|
|
control_port = "7657";
|
2019-11-25 20:19:44 -05:00
|
|
|
storedSettings.control_port = control_port;
|
|
|
|
}
|
2019-11-24 20:43:17 -05:00
|
|
|
console.log("Initialising Control Port", storedSettings.control_port);
|
2019-11-27 00:03:44 -05:00
|
|
|
setupProxy();
|
2019-11-24 20:43:17 -05:00
|
|
|
}
|
2019-12-24 16:51:38 -05:00
|
|
|
var gettingControlPortStoredSettings = browser.storage.local.get(
|
|
|
|
"control_port"
|
|
|
|
);
|
2019-11-24 20:43:17 -05:00
|
|
|
gettingControlPortStoredSettings.then(
|
|
|
|
checkControlPortStoredSettings,
|
|
|
|
onError
|
|
|
|
);
|
2019-11-25 20:19:44 -05:00
|
|
|
|
|
|
|
//
|
|
|
|
function checkHistoryStoredSettings(storedSettings) {
|
|
|
|
if (storedSettings.disable_history != undefined) {
|
|
|
|
disable_history = storedSettings.disable_history;
|
|
|
|
} else {
|
|
|
|
disable_history = false;
|
|
|
|
storedSettings.disable_history = disable_history;
|
|
|
|
}
|
|
|
|
console.log(
|
|
|
|
"Initialising Disabled History",
|
|
|
|
storedSettings.disable_history
|
|
|
|
);
|
2019-11-27 00:03:44 -05:00
|
|
|
setupProxy();
|
2019-11-25 20:19:44 -05:00
|
|
|
}
|
2019-12-24 16:51:38 -05:00
|
|
|
var gettingHistoryStoredSettings = browser.storage.local.get(
|
|
|
|
"disable_history"
|
|
|
|
);
|
2019-11-25 20:19:44 -05:00
|
|
|
gettingHistoryStoredSettings.then(checkHistoryStoredSettings, onError);
|
2019-11-24 20:43:17 -05:00
|
|
|
}
|
2019-06-17 19:17:11 -04:00
|
|
|
|
|
|
|
function getScheme() {
|
2019-10-06 15:14:53 -04:00
|
|
|
if (proxy_scheme == undefined) {
|
2019-10-06 15:18:10 -04:00
|
|
|
proxy_scheme = "http";
|
2019-10-06 15:14:53 -04:00
|
|
|
}
|
|
|
|
if (proxy_scheme == "HTTP") {
|
2019-10-06 15:18:10 -04:00
|
|
|
proxy_scheme = "http";
|
2019-10-06 15:14:53 -04:00
|
|
|
}
|
|
|
|
if (proxy_scheme == "SOCKS") {
|
2019-10-06 15:18:10 -04:00
|
|
|
proxy_scheme = "socks";
|
2019-10-06 15:14:53 -04:00
|
|
|
}
|
|
|
|
if (proxy_scheme != "http" && proxy_scheme != "socks") {
|
2019-10-06 15:18:10 -04:00
|
|
|
proxy_scheme = "http";
|
2019-10-06 15:14:53 -04:00
|
|
|
}
|
|
|
|
//console.log("Got i2p proxy scheme:", proxy_scheme);
|
|
|
|
return proxy_scheme;
|
2019-06-17 19:17:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function getHost() {
|
2019-10-06 15:14:53 -04:00
|
|
|
if (proxy_host == undefined) {
|
2019-10-06 15:18:10 -04:00
|
|
|
proxy_host = "127.0.0.1";
|
2019-10-06 15:14:53 -04:00
|
|
|
}
|
|
|
|
return proxy_host;
|
2019-06-17 19:17:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function getPort() {
|
2019-10-06 15:14:53 -04:00
|
|
|
if (proxy_port == undefined) {
|
2019-10-06 15:18:10 -04:00
|
|
|
var scheme = getScheme();
|
2019-10-06 15:14:53 -04:00
|
|
|
if (scheme == "socks") {
|
2019-10-06 15:18:10 -04:00
|
|
|
proxy_port = "4446";
|
2019-10-06 15:14:53 -04:00
|
|
|
} else {
|
2019-10-06 15:18:10 -04:00
|
|
|
proxy_port = "4444";
|
2019-06-17 19:17:11 -04:00
|
|
|
}
|
2019-10-06 15:14:53 -04:00
|
|
|
}
|
|
|
|
return proxy_port;
|
2019-06-17 19:17:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function getControlHost() {
|
2019-10-06 15:14:53 -04:00
|
|
|
if (control_host == undefined) {
|
2019-10-06 15:18:10 -04:00
|
|
|
return "127.0.0.1";
|
2019-10-06 15:14:53 -04:00
|
|
|
}
|
|
|
|
return control_host;
|
2019-06-17 19:17:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function getControlPort() {
|
2019-10-06 15:14:53 -04:00
|
|
|
if (control_port == undefined) {
|
2019-11-26 23:06:24 -05:00
|
|
|
return "7657";
|
2019-10-06 15:14:53 -04:00
|
|
|
}
|
|
|
|
return control_port;
|
2019-05-03 18:40:46 -04:00
|
|
|
}
|
|
|
|
|
2019-02-07 17:25:06 -05:00
|
|
|
function setupProxy() {
|
2019-10-28 01:11:16 -04:00
|
|
|
/**/
|
|
|
|
console.log("Setting up Firefox WebExtension proxy");
|
|
|
|
browser.proxy.onRequest.addListener(handleContextProxyRequest, {
|
|
|
|
urls: ["<all_urls>"]
|
|
|
|
});
|
|
|
|
console.log("i2p settings created for WebExtension Proxy");
|
|
|
|
/**/
|
2019-07-13 22:07:24 -04:00
|
|
|
}
|
|
|
|
|
2019-11-24 20:43:17 -05:00
|
|
|
function update() {
|
2019-10-06 15:18:10 -04:00
|
|
|
console.log("restoring proxy scheme:", proxy_scheme);
|
|
|
|
console.log("restoring proxy host:", proxy_host);
|
|
|
|
console.log("restoring proxy port:", proxy_port);
|
|
|
|
console.log("restoring control host:", control_host);
|
|
|
|
console.log("restoring control port:", control_port);
|
2019-06-17 19:17:11 -04:00
|
|
|
}
|
|
|
|
|
2019-11-24 20:43:17 -05:00
|
|
|
function updateFromStorage() {
|
|
|
|
console.log("updating settings from storage");
|
|
|
|
var gettingInfo = browser.runtime.getPlatformInfo();
|
|
|
|
gettingInfo.then(got => {
|
|
|
|
if (got.os != "android") {
|
|
|
|
browser.windows.getAll().then(wins => wins.forEach(themeWindow));
|
|
|
|
chrome.storage.local.get(function(got) {
|
|
|
|
SetupSettings();
|
|
|
|
update();
|
|
|
|
setupProxy();
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
chrome.storage.local.get(function(got) {
|
|
|
|
SetupSettings();
|
|
|
|
update();
|
|
|
|
setupProxy();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2019-05-02 17:31:04 -04:00
|
|
|
}
|
2019-11-24 04:28:14 -05:00
|
|
|
|
2019-11-24 20:43:17 -05:00
|
|
|
browser.storage.onChanged.addListener(updateFromStorage);
|
2019-11-25 20:19:44 -05:00
|
|
|
SetupSettings();
|
2019-11-27 00:31:10 -05:00
|
|
|
setupProxy();
|