From 9fe427ff45778f53214ce110bf94fe43459491d1 Mon Sep 17 00:00:00 2001 From: Ruben Rodriguez Date: Wed, 7 Nov 2018 23:45:25 -0500 Subject: Updated extensions through running updated data/update-extensions.sh --- .../lib/chrome/background.html | 9 ++ .../lib/chrome/chrome.js | 49 +++++++++++ .../lib/common.js | 96 ++++++++++++++++++++++ .../lib/config.js | 45 ++++++++++ .../lib/proxy.js | 56 +++++++++++++ 5 files changed, 255 insertions(+) create mode 100644 data/extensions/tortm-browser-button@jeremybenthum/lib/chrome/background.html create mode 100644 data/extensions/tortm-browser-button@jeremybenthum/lib/chrome/chrome.js create mode 100644 data/extensions/tortm-browser-button@jeremybenthum/lib/common.js create mode 100644 data/extensions/tortm-browser-button@jeremybenthum/lib/config.js create mode 100644 data/extensions/tortm-browser-button@jeremybenthum/lib/proxy.js (limited to 'data/extensions/tortm-browser-button@jeremybenthum/lib') diff --git a/data/extensions/tortm-browser-button@jeremybenthum/lib/chrome/background.html b/data/extensions/tortm-browser-button@jeremybenthum/lib/chrome/background.html new file mode 100644 index 0000000..12a37a9 --- /dev/null +++ b/data/extensions/tortm-browser-button@jeremybenthum/lib/chrome/background.html @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/data/extensions/tortm-browser-button@jeremybenthum/lib/chrome/chrome.js b/data/extensions/tortm-browser-button@jeremybenthum/lib/chrome/chrome.js new file mode 100644 index 0000000..14491f7 --- /dev/null +++ b/data/extensions/tortm-browser-button@jeremybenthum/lib/chrome/chrome.js @@ -0,0 +1,49 @@ +var app = {}; + +app.button = {set icon (o) {chrome.browserAction.setIcon(o)}}; +app.version = function () {return chrome.runtime.getManifest().version}; +app.homepage = function () {return chrome.runtime.getManifest().homepage_url}; +app.tab = {"open": function (url) {chrome.tabs.create({"url": url, "active": true})}}; +if (chrome.runtime.setUninstallURL) chrome.runtime.setUninstallURL(app.homepage() + "?v=" + app.version() + "&type=uninstall", function () {}); + +app.storage = (function () { + var objs = {}; + window.setTimeout(function () { + chrome.storage.local.get(null, function (o) { + objs = o; + var script = document.createElement("script"); + script.src = "../common.js"; + document.body.appendChild(script); + }); + }, 300); + /* */ + return { + "read": function (id) {return objs[id]}, + "write": function (id, data) { + var tmp = {}; + objs[id] = data; + tmp[id] = data; + chrome.storage.local.set(tmp, function () {}); + } + } +})(); + +app.popup = (function () { + var _tmp = {}; + chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) { + for (var id in _tmp) { + if (_tmp[id] && (typeof _tmp[id] === "function")) { + if (request.path === 'popup-to-background') { + if (request.method === id) _tmp[id](request.data); + } + } + } + }); + /* */ + return { + "receive": function (id, callback) {_tmp[id] = callback}, + "send": function (id, data, tabId) { + chrome.runtime.sendMessage({"path": 'background-to-popup', "method": id, "data": data}); + } + } +})(); diff --git a/data/extensions/tortm-browser-button@jeremybenthum/lib/common.js b/data/extensions/tortm-browser-button@jeremybenthum/lib/common.js new file mode 100644 index 0000000..d631376 --- /dev/null +++ b/data/extensions/tortm-browser-button@jeremybenthum/lib/common.js @@ -0,0 +1,96 @@ +window.setTimeout(function () { + var version = config.welcome.version; + if (!version) { + app.tab.open(app.homepage() + "?v=" + app.version() + "&type=install"); + config.welcome.version = app.version(); + } +}, 3000); + +var popupsend = function () { + tor.icon(tor.id); + app.popup.send("tor-data", { + "id": tor.id, + "log": tor.log, + "whitelist": config.addon.whitelist + }); +}; + +var setproxy = function (callback) { + if (tor.id === "OFF") chrome.proxy.settings.set({"scope": "regular", "value": {"mode": "system"}}, callback); + else chrome.proxy.settings.set({ + "scope": "regular", + "value": { + "mode": "fixed_servers", + "rules": { + "bypassList": tor.bypassList, + "singleProxy": {"scheme": "socks5", "host": "127.0.0.1", "port": 9050} + } + } + }, callback); +}; + +var tor = { + "id": "OFF", + "bypassList": [], + "log": "Tor Browser Button", + "update": function () { + if (config.addon.state === "ON") { + tor.once(function () { + var url = config.addon.check + "?t=" + new Date().getTime() + "&r=" + Math.round(Math.random() * 10000); + config.request(url, function (e) { + if (e === "ok") config.addon.state === "ON" ? tor.start() : tor.stop(); + else { + tor.stop(); + config.notifications.create("TOR is NOT running. Please connect your computer to TOR network and try again."); + } + }); + }); + } else tor.stop(); + }, + "stop": function () { + tor.id = "OFF"; + tor.log = "TOR proxy is disabled"; + setproxy(popupsend); + }, + "start": function () { + tor.id = "ON"; + tor.log = "Connected to 127.0.0.1:9050"; + config.notifications.create("TOR is running. Connected to 127.0.0.1:9050"); + tor.bypassList = config.addon.whitelist ? config.addon.whitelist.split(',') : []; + setproxy(popupsend); + }, + "once": function (callback) { + tor.id = "CHECK"; + tor.log = "Checking tor proxy connection..."; + tor.bypassList = config.addon.whitelist ? config.addon.whitelist.split(',') : []; + setproxy(function () {window.setTimeout(function () {callback(true)}, 300)}); + popupsend(); + }, + "icon": function (state) { + app.button.icon = { + "path": { + "16": '../../data/icons/' + state + '/16.png', + "32": '../../data/icons/' + state + '/32.png', + "48": '../../data/icons/' + state + '/48.png', + "64": '../../data/icons/' + state + '/64.png' + } + }; + } +}; + +app.popup.receive("popup-data", function (e) { + if (e.name === "support") app.tab.open(app.homepage()); + if (e.name === "check") app.tab.open(config.addon.check); + if (e.name === "install") app.tab.open(config.addon.github); + if (e.name === "bypassList") { + config.addon.whitelist = e.whitelist; + tor.update(); + } + if (e.name === "ON" || e.name === "OFF") { + config.addon.state = e.name; + tor.update(); + } +}); + +window.setTimeout(tor.update, 0); +app.popup.receive("load", popupsend); diff --git a/data/extensions/tortm-browser-button@jeremybenthum/lib/config.js b/data/extensions/tortm-browser-button@jeremybenthum/lib/config.js new file mode 100644 index 0000000..37aeaf5 --- /dev/null +++ b/data/extensions/tortm-browser-button@jeremybenthum/lib/config.js @@ -0,0 +1,45 @@ +var config = {}; + +config.welcome = { + get version () {return app.storage.read("version")}, + set version (val) {app.storage.write("version", val)} +}; + +config.addon = { + "check": "https://check.torproject.org/", + set state (val) {app.storage.write("state", val)}, + set whitelist (val) {app.storage.write("whitelist", val)}, + get whitelist () {return app.storage.read("whitelist") || ''}, + "github": "https://github.com/jeremy-jr-benthum/tor-button/releases", + get state () {return app.storage.read("state") !== undefined ? app.storage.read("state") : "OFF"} +}; + +config.request = function (url, callback) { + var xhr = new XMLHttpRequest(); + try { + xhr.onload = function () {xhr.status >= 200 && xhr.status < 304 ? callback("ok") : callback("error")}; + xhr.open("HEAD", url, true); + xhr.onerror = function () {callback("error")}; + xhr.ontimeout = function () {callback("error")}; + xhr.send(''); + } catch (e) {callback("error")} +}; + +config.notifications = (function () { + chrome.notifications.onClosed.addListener(function () {config.notifications.id = ''}); + chrome.notifications.onClicked.addListener(function (id) {if (id === config.notifications.id) app.tab.open(app.homepage() + "#faq")}); + /* */ + return { + "id": '', + "create": function (message) { + var iconUrl = /Firefox/.test(navigator.userAgent) ? "data/icons/ON/64.png" : chrome.runtime.getURL("data/icons/ON/64.png"); + var o = {"message": message, "type": "basic", "title": "Tor Browser Button", "iconUrl": iconUrl}; + if (config.notifications.id) { + if (chrome.notifications.update) { + return chrome.notifications.update(config.notifications.id, o, function () {}); + } + } + return chrome.notifications.create(o, function (id) {config.notifications.id = id}); + } + } +})(); diff --git a/data/extensions/tortm-browser-button@jeremybenthum/lib/proxy.js b/data/extensions/tortm-browser-button@jeremybenthum/lib/proxy.js new file mode 100644 index 0000000..a8e3748 --- /dev/null +++ b/data/extensions/tortm-browser-button@jeremybenthum/lib/proxy.js @@ -0,0 +1,56 @@ +if (/Firefox/.test(navigator.userAgent)) { + chrome.proxy = {"settings": {}}; + chrome.proxy.convert = { + "to": ({value}) => { + const mode = value.mode; + const settings = { + "autoLogin": value.noPrompt, + "proxyDNS": value.remoteDNS, + "autoConfigUrl": mode === 'pac_script' ? value.pacScript.url : '', + "socksVersion": mode === 'fixed_servers' && value.rules.singleProxy.scheme === 'socks5' ? 5 : 4, + "passthrough": mode === 'fixed_servers' && value.rules.bypassList && value.rules.bypassList.length ? value.rules.bypassList.join(', ') : '', + "proxyType": {'direct': 'none', 'system': 'system', 'auto_detect': 'autoDetect', 'fixed_servers': 'manual', 'pac_script': 'autoConfig'}[mode] + }; + /* */ + if (mode === 'fixed_servers') { + const rules = value.rules; + const url = ({host, port, scheme}) => {return host && port ? (scheme === "https" ? "https://" : '') + (host.trim().replace(/.*:\/\//, '') + ':' + port) : ''}; + if (rules.singleProxy.scheme.startsWith('socks')) { + settings.http = settings.ssl = settings.ftp = ''; + settings.socks = url(rules.singleProxy); + } else settings.ssl = settings.ftp = settings.http = url(rules.singleProxy); + } + /* */ + return {"value": settings}; + }, + "from": ({value}) => { + const config = {"value": {"remoteDNS": value.proxyDNS, "noPrompt": value.autoLogin}}; + config.value.mode = {'none': 'direct', 'system': 'system', 'autoDetect': 'auto_detect', 'manual': 'fixed_servers', 'autoConfig': 'pac_script'}[value.proxyType]; + if (value.proxyType === 'autoConfig' || value.proxyType === 'manual') config.value.rules = {}; + /* */ + if (value.proxyType === 'autoConfig') config.value.pacScript = {"url": value.autoConfigUrl}; + else if (value.proxyType === 'manual') { + config.value.rules.bypassList = value.passthrough ? value.passthrough.split(', ') : []; + const type = url => {return value.socks ? 'socks' + value.socksVersion : (url.startsWith('https://') ? 'https' : 'http')}; + const parse = url => { + const scheme = type(url); + const [host, port] = url.split('://')[0].split(':'); + return {scheme, host, "port": Number(port)}; + }; + /* */ + config.value.rules.singleProxy = parse(value.http || value.socks); + } + /* */ + return config; + } + }; + /* */ + chrome.proxy.settings.clear = (o, callback) => browser.proxy.settings.clear(o).then(callback); + chrome.proxy.settings.get = (o, callback) => browser.proxy.settings.get(o).then(e => callback(chrome.proxy.convert.from(e))); + chrome.proxy.settings.set = async(o, callback = function () {}) => { + const settings = chrome.proxy.convert.to(o); + await browser.proxy.settings.clear({}); + browser.proxy.settings.set(settings); + callback(); + }; +} -- cgit v1.2.3