summaryrefslogtreecommitdiff
path: root/ui/app
diff options
context:
space:
mode:
authorSukhbir Singh <sukhbir@torproject.org>2017-12-12 02:59:34 -0500
committerRuben Pollan <meskio@sindominio.net>2017-12-17 18:21:06 +0200
commit8c50952bb542a09ebe591d9dba3b4d89d4837b54 (patch)
tree902a832f999c1198da3e3094a3d9bbcb6c1e8804 /ui/app
parent2acf226ac3503f349422ae29fee4145f459e66db (diff)
[feat] Add support for calling bitmask.js from Firefox/Thunderbird
- To be able to call bitmask.js from Thunderbird (for the Bitmask Thunderbird extension), we need to set `api_url' and also read the `authtoken' file from disk. This commit adds support for that and restricts the changes by using window.location.protocol. - Add function for fetching bitmaskd status. Signed-off-by: Ruben Pollan <meskio@sindominio.net>
Diffstat (limited to 'ui/app')
-rw-r--r--ui/app/lib/bitmask.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/ui/app/lib/bitmask.js b/ui/app/lib/bitmask.js
index 31a1e938..6ab87ff3 100644
--- a/ui/app/lib/bitmask.js
+++ b/ui/app/lib/bitmask.js
@@ -48,6 +48,29 @@ var bitmask = function(){
api_token = window.location.hash.replace('#', '')
}
+ // If the script is running from a Firefox (or Thunderbird) extension, get
+ // the api_token from ~/.config/leap/authtoken, and also set the api_url.
+ if (window.location.protocol === "chrome:") {
+ // Use the correct URL for the API.
+ api_url = 'http://localhost:7070/API/';
+
+ // Now fetch the token file and set api_token.
+ Components.utils.import("resource://gre/modules/osfile.jsm")
+
+ let tokenPath = OS.Path.join(OS.Constants.Path.homeDir, ".config", "leap", "authtoken")
+ let decoder = new TextDecoder();
+
+ setInterval(function get_token_file() {
+ let promise = OS.File.read(tokenPath);
+ promise = promise.then(array => {
+ api_token = decoder.decode(array);
+ }, ex => {
+ api_token = null;
+ });
+ return get_token_file;
+ }(), 3000);
+ }
+
function call(command) {
var url = api_url + command.slice(0, 3).join('/');
var data = JSON.stringify(command.slice(3));
@@ -131,6 +154,13 @@ var bitmask = function(){
*/
stop: function() {
return call(['core', 'stop']);
+ },
+
+ /**
+ * Get bitmaskd status
+ */
+ status: function() {
+ return call(['core', 'status']);
}
},