Skip to content

Commit

Permalink
Merge pull request #36 from darkowlzz/proxying
Browse files Browse the repository at this point in the history
Implemented proxying.
  • Loading branch information
nb333 committed Dec 30, 2013
2 parents f38af82 + 42865a2 commit d56ecc1
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 36 deletions.
121 changes: 86 additions & 35 deletions jetpack/lib/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const widgets = require('sdk/widget');
const data = require('sdk/self').data;
const ss = require('sdk/simple-storage');
const _ = require('sdk/l10n').get;
const config = require('sdk/preferences/service');
const sp = require('sdk/simple-prefs');

// Magical strings.
const ICON_ON = 'icon-on.png';
Expand All @@ -11,65 +13,114 @@ const TOOLTIP_OFF = _('enable_openfaux');

const DEBUG = true;

// Proxy address and port number.
let HTTP_ADDRESS = '';
let HTTP_PORT = 0;

// Set the button status.
if (typeof ss.storage.button_is_on === 'undefined') {
// set default status
ss.storage.button_is_on = true;
}

/*
* Init openfaux status.
* Set the icon and tooltip contents.
*/
let init_openfaux = function () {
if (ss.storage.button_is_on) {
openfaux_button.contentURL = data.url(ICON_ON);
openfaux_button.tooltip = TOOLTIP_ON;
}
else {
openfaux_button.contentURL = data.url(ICON_OFF);
openfaux_button.tooltip = TOOLTIP_OFF;
}
// set default status to deactivated.
ss.storage.button_is_on = false;
};

/*
/**
* Toggle openfaux status, icon and tooltip.
*
* 'network.proxy.type' is a browser preference value which
* is used to decide whether to use a proxy or not.
* 0 : Direct connection, no proxy.
* 1 : Manual proxy configuration.
*
* 'network.proxy.http' is another browser preference value.
* It stores the manual http proxy address.
*
* 'network.proxy.http_port' stores the manual http proxy port
* number.
*/
let toggle_openfaux = function () {
if (ss.storage.button_is_on) {
openfaux_button.contentURL = data.url(ICON_OFF);
openfaux_button.tooltip = TOOLTIP_OFF;
ss.storage.button_is_on = false;
}
else {
config.set('network.proxy.type', 0);

if (DEBUG) {
console.log('TURNING OFF');
console.log('http address set ' + config.get('network.proxy.http'));
console.log('port set ' + config.get('network.proxy.http_port'));
console.log('proxy type set to ' + config.get('network.proxy.type'));
}
} else {
openfaux_button.contentURL = data.url(ICON_ON);
openfaux_button.tooltip = TOOLTIP_ON;
ss.storage.button_is_on = true;
}
config.set('network.proxy.type', 1);

if (DEBUG) {
console.log('TURNING ON');
console.log('http address set ' + config.get('network.proxy.http'));
console.log('port set ' + config.get('network.proxy.http_port'));
console.log('proxy type set to ' + config.get('network.proxy.type'));
}
}
};

/*
/**
* Create and return button.
*/
let createButton = function () {
config.set('network.proxy.http', HTTP_ADDRESS);
config.set('network.proxy.http_port', HTTP_PORT);
config.set('network.proxy.type', 0);

if (DEBUG) {
console.log('INITIALIZED...');
console.log('http address set ' + config.get('network.proxy.http'));
console.log('port set ' + config.get('network.proxy.http_port'));
console.log('proxy type set to ' + config.get('network.proxy.type'));
}

// Register the pref listeners.
prefListen();

openfaux_button = widgets.Widget({
id: 'openfaux-addon-bar-button',
label: 'Openfaux',
tooltip: TOOLTIP_ON,
contentURL: data.url(ICON_ON),
onClick: function () {
toggle_openfaux();
id: 'openfaux-addon-bar-button',
label: 'Openfaux',
tooltip: TOOLTIP_OFF,
contentURL: data.url(ICON_OFF),
onClick: function () {
toggle_openfaux();
if (DEBUG) {
console.log('button clicked, now openfaux is ' +
(ss.storage.button_is_on ? 'on': 'off'));
console.log('button clicked, now openfaux is ' +
(ss.storage.button_is_on ? 'on': 'off'));
}
},
onAttach: function () {
init_openfaux();
}
}
});

return openfaux_button;
};

exports.createButton = createButton;

// Set new proxy address.
function addressChange() {
HTTP_ADDRESS = sp.prefs['openfaux-proxy-address'];
config.set('network.proxy.http', HTTP_ADDRESS);
if (DEBUG) {
console.log('http proxy address: ' + config.get('network.proxy.http'));
}
}

// Set new proxy port address.
function portChange() {
HTTP_PORT = sp.prefs['openfaux-proxy-port'];
config.set('network.proxy.http_port', HTTP_PORT);
if (DEBUG) {
console.log('http proxy port: ' + config.get('network.proxy.http_port'));
}
}

// Register pref change listeners.
function prefListen() {
sp.on('openfaux-proxy-address', addressChange);
sp.on('openfaux-proxy-port', portChange);
}
17 changes: 16 additions & 1 deletion jetpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,20 @@
"description": "Browser add-on for encrypting and masking internet traffic",
"author": "OpenFaux team",
"license": "AGPL 3",
"version": "0.1.0"
"version": "0.1.0",

"preferences": [{
"name": "openfaux-proxy-address",
"description": "Set a proxy ip address",
"type": "string",
"title": "Proxy Address",
"value": ""
},
{
"name": "openfaux-proxy-port",
"description": "Set a port number for the proxy",
"type": "integer",
"title": "Proxy Port Number",
"value": 0
}]
}

0 comments on commit d56ecc1

Please sign in to comment.