Skip to content

Commit

Permalink
moving to GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-portmen committed Apr 10, 2017
0 parents commit f754849
Show file tree
Hide file tree
Showing 29 changed files with 715 additions and 0 deletions.
17 changes: 17 additions & 0 deletions EventEmitter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

var EventEmitter = function () {
this.ecb = {};
};
EventEmitter.prototype.emit = function (id, data) {
(this.ecb[id] || []).forEach(c => c(data));
chrome.runtime.sendMessage({
cmd: 'event',
id,
data
});
};
EventEmitter.prototype.on = function (id, callback) {
this.ecb[id] = this.ecb[id] || [];
this.ecb[id].push(callback);
};
95 changes: 95 additions & 0 deletions common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/* globals Tor, proxy, privacy, ui */
'use strict';

var prefs = {
webrtc: 2,
policy: {
'proxy': 0, // 0: turn on when tor is active and turn off when tor is disabled; 1: turn on when browser starts and do not turn off when tor is disabled
'webrtc': 0, // 0: turn on when tor is active and turn off when tor is disabled; 1: turn on when browser starts and do not turn off when tor is disabled
},
'auto-run': false,
'directory': null
};
chrome.storage.onChanged.addListener(ps => {
Object.keys(ps).forEach(p => prefs[p] = ps[p].newValue);
});

var tor = new Tor({
directory: ''
});

// get external IP address
tor.on('status', status => {
ui.emit('title', {status});
if (status === 'connected') {
tor.getIP();
}
});

// Set proxy
tor.on('status', s => {
if (s === 'connected') {
proxy.set(tor.info);
privacy.set(prefs.webrtc);
}
else if (s === 'disconnected') {
if (prefs.policy.proxy === 0) {
proxy.reset();
}
if (prefs.policy.webrtc === 0) {
privacy.reset();
}
}
});
// ip changes
tor.on('ip', ip => ui.emit('title', {ip}));
//
proxy.addListener('change', bol => ui.emit('title', {
proxy: bol ? 'SOCKS' : 'default'
}));
chrome.storage.local.get(prefs, p => {
prefs = p;
// directory
tor.directory = p.directory;
// auto run?
if (prefs['auto-run']) {
tor.refresh();
}
if (prefs.policy.proxy === 1) {
privacy.set(prefs.proxy);
}
if (prefs.policy.webrtc === 1) {
privacy.set(prefs.webrtc);
}
});
// logs
proxy.addListener('change', s => {
tor.emit('stdout', `Proxy status is "${s}"`);
});
privacy.addListener('change', (type, state) => {
tor.emit('stdout', `Protection: module -> ${type}, status -> ${state}`);
});

chrome.runtime.onMessage.addListener(request => {
if (request.method === 'popup-command') {
if (request.cmd) {
tor.command(request.cmd);
}
}
else if (request.method === 'popup-action') {
if (request.cmd === 'connection') {
if (request.action === 'disconnect') {
tor.disconnect();
}
else {
if (prefs.directory) {
tor.refresh();
}
else {
ui.notification('Tor Bundle path is not set in the options page');
chrome.runtime.openOptionsPage();
}
}
}
}
});
1 change: 1 addition & 0 deletions data/helper
Binary file added data/icons/128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/icons/16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/icons/256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/icons/32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/icons/48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/icons/512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/icons/64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/icons/enabled/128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/icons/enabled/16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/icons/enabled/256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/icons/enabled/32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/icons/enabled/48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/icons/enabled/512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/icons/enabled/64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions data/options/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html>
<head>
<title>My Test Extension Options</title>
<style>
body {
padding: 10px;
}
input[type=text] {
width: 100%;
}
</style>
</head>

<body>
<p>
Tor bundle path:
<input type="text" id="directory" placeholder="e.g.: C:\Users\username\Desktop\tor">
<div>First download the latest "Tor Bundle" pack from <a href="">github.com</a>, and extract it in a local directory. Then place the root's absolute path here.</div>
</p>

<div>
<button id="save">Save</button>
<span id="status"></span>
</div>

<script src="index.js"></script>
</body>
</html>
22 changes: 22 additions & 0 deletions data/options/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

function save () {
let directory = document.getElementById('directory').value;
chrome.storage.local.set({
directory
}, () => {
let status = document.getElementById('status');
status.textContent = 'Options saved.';
setTimeout(() => status.textContent = '', 750);
});
}

function restore () {
chrome.storage.local.get({
directory: '',
}, (prefs) => {
document.getElementById('directory').value = prefs.directory;
});
}
document.addEventListener('DOMContentLoaded', restore);
document.getElementById('save').addEventListener('click', save);
74 changes: 74 additions & 0 deletions data/popup/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
body {
width: 500px;
height: 300px;
}
img {
cursor: pointer;
}
input[type=button] {
border: solid 1px #eee;
background-color: #fff;
width: 120px;
margin: 2px 0;
outline: none;
cursor: pointer;
}
input {
outline: none;
}
input[type=button]:active {
border-color: #00a;
}

[hbox] {
display: flex;
flex-direction: row;
}
[vbox] {
display: flex;
flex-direction: column;
}
[flex="1"] {
flex: 1;
}
[flex="2"] {
flex: 2;
}
[pack=center] {
justify-content: center;
}
[align=center] {
align-items: center;
}
body[data-status=connecting] img[data-cmd=connection] {
opacity: 0.3;
}

#log {
padding: 10px;
overflow-x: hidden;
overflow-y: auto;
width: calc(47vw - 20px);
background-color: rgba(0, 0, 0, 0.01);
border: dashed 1px rgba(0, 0, 0, 0.05);
}
#log>* {
margin-bottom: 10px;
}
#toolbar {
margin-top: 8px;
}

.msg span:nth-child(1) {
font-size: 80%;
}
.msg span:nth-child(2) {
padding: 0 5px;
background-color: rgba(0, 0, 0, 0.05);
}

.log {
background-color: rgba(0, 0, 0, 0.05);
border: dotted 1px rgba(0, 0, 0, 0.05);
padding: 0 5px;
}
32 changes: 32 additions & 0 deletions data/popup/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link rel="stylesheet" href="index.css">
</head>
<body vbox>
<div hbox flex=1>
<div flex=1 hbox id="toggle" pack="center" align="center">
<img width="120" height="120" src="off.png" data-cmd="connection">
</div>

<div flex=2 vbox id="log">
<template>
<div class="msg">
<span></span>
<span></span>
<span></span>
</div>
</template>
</div>
</div>
<div id="toolbar">
<input type="button" value="New Identity" data-rcmd="SIGNAL NEWNYM">
<input type="button" value="Get IP" data-rcmd="GETINFO address">
<input type="button" value="Status" data-rcmd="GETINFO circuit-status">
<input type="button" value="Verify" data-cmd="verify">
</div>

<script src="index.js"></script>
</body>
</html>
73 changes: 73 additions & 0 deletions data/popup/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
'use strict';

var elements = {
log: document.getElementById('log'),
template: document.querySelector('#log template'),
webrtc: document.getElementById('prefs.webrtc')
};

function log (msg) {
function single (msg) {
let node = document.importNode(elements.template.content, true);
let parts = /(.*)\[(err|warn|notice)\] (.*)/.exec(msg);
if (parts) {
node.querySelector('span:nth-child(1)').textContent = parts[1];
node.querySelector('span:nth-child(2)').textContent = parts[2];
node.querySelector('span:nth-child(3)').textContent = parts[3];
}
else {
node = document.createElement('span');
node.classList.add('log');
node.textContent = msg;
}

elements.log.appendChild(node);
elements.log.scrollTop = elements.log.scrollHeight;
}
msg.split('\n').filter(m => m.trim()).forEach(single);
}

function status (s) {
document.body.dataset.status = s;
document.querySelector('[data-cmd="connection"]').src =
s === 'disconnected' ? 'off.png' : 'on.png';
}

window.addEventListener('load', () => {
chrome.runtime.getBackgroundPage(b => {
log(b.tor.info.stdout);
status(b.tor.info.status);
});
});

chrome.runtime.onMessage.addListener(request => {
if (request.cmd === 'event' && request.id === 'stdout') {
log(request.data);
}
else if (request.cmd === 'event' && request.id === 'status') {
status(request.data);
}
});

document.addEventListener('click', e => {
let cmd = e.target.dataset.rcmd;
if (cmd) {
chrome.runtime.sendMessage({
method: 'popup-command',
cmd
});
}
cmd = e.target.dataset.cmd;
if (cmd === 'verify') {
chrome.tabs.create({
url: 'https://check.torproject.org/'
});
}
else if (cmd === 'connection') {
chrome.runtime.sendMessage({
method: 'popup-action',
cmd,
action: document.body.dataset.status === 'disconnected' ? 'connect' : 'disconnect'
});
}
});
Binary file added data/popup/off.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/popup/on.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 47 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "Tor Browser",
"short_name": "itbrowser",
"description": "Enables Tor network and modify few settings to protect user privacy",
"author": "Jeremy Schomery",
"version": "0.1.0",
"manifest_version": 2,
"permissions": [
"storage",
"tabs",
"proxy",
"privacy",
"webRequest",
"downloads",
"management",
"notifications",
"nativeMessaging",
"https://api.github.com/repos/andy-portmen/native-client/releases/latest"
],
"background": {
"scripts": [
"EventEmitter.js",
"tor.js",
"proxy.js",
"privacy.js",
"ui.js",
"common.js"
]
},
"browser_action": {
"default_icon": {
"16": "data/icons/16.png",
"32": "data/icons/32.png"
},
"default_popup": "data/popup/index.html"
},
"homepage_url": "http://add0n.com/media-tools.html",
"icons": {
"16": "data/icons/16.png",
"48": "data/icons/48.png",
"128": "data/icons/128.png"
},
"options_ui": {
"page": "data/options/index.html",
"chrome_style": true
}
}
Loading

0 comments on commit f754849

Please sign in to comment.