From c6b50d04f6c8af3099c47ed203cef3f492ec773c Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Wed, 22 Oct 2014 18:17:40 +0200 Subject: [PATCH 1/2] Use manifest config for webmail --- .jshintrc | 1 + src/js/app-config.js | 60 ++++++++++++++++++++++++-------------------- 2 files changed, 34 insertions(+), 27 deletions(-) diff --git a/.jshintrc b/.jshintrc index 6c4c255..9e10c16 100644 --- a/.jshintrc +++ b/.jshintrc @@ -18,6 +18,7 @@ "unused": true, "predef": [ + "$", "self", "importScripts", "console", diff --git a/src/js/app-config.js b/src/js/app-config.js index 1fa6650..41271ad 100644 --- a/src/js/app-config.js +++ b/src/js/app-config.js @@ -1,34 +1,11 @@ 'use strict'; -var appVersion, cloudUrl, keychainUrl, clientId; - -// parse manifest to get configurations for current runtime -try { - var manifest = chrome.runtime.getManifest(); - // get key server base url - cloudUrl = _.find(manifest.permissions, function(permission) { - return typeof permission === 'string' && permission.indexOf('https://keys') === 0; - }); - // remove last '/' from url due to required syntax in manifest - cloudUrl = cloudUrl.substring(0, cloudUrl.length - 1); - // get keychain server base url - keychainUrl = _.find(manifest.permissions, function(permission) { - return typeof permission === 'string' && permission.indexOf('https://keychain') === 0; - }); - // remove last '/' from url due to required syntax in manifest - keychainUrl = keychainUrl.substring(0, keychainUrl.length - 1); - // get client ID for OAuth requests - clientId = manifest.oauth2.client_id; - // get the app version - appVersion = manifest.version; -} catch (e) {} - /** * Global app configurations */ exports.config = { - cloudUrl: cloudUrl || 'https://keys.whiteout.io', - privkeyServerUrl: keychainUrl || 'https://keychain.whiteout.io', + cloudUrl: 'https://keys.whiteout.io', + privkeyServerUrl: 'https://keychain.whiteout.io', adminUrl: 'https://admin-node.whiteout.io', wmailDomain: 'wmail.io', serverPrivateKeyId: 'EE342F0DDBB0F3BE', @@ -57,7 +34,7 @@ exports.config = { } }, gmail: { - clientId: clientId || '440907777130.apps.googleusercontent.com', + clientId: '440907777130.apps.googleusercontent.com', imap: { host: 'imap.gmail.com', port: 993, @@ -171,7 +148,7 @@ exports.config = { verificationUrl: '/verify/', verificationUuidLength: 36, dbVersion: 5, - appVersion: appVersion, + appVersion: undefined, outboxMailboxPath: 'OUTBOX', outboxMailboxName: 'Outbox', outboxMailboxType: 'Outbox', @@ -179,6 +156,35 @@ exports.config = { imapUpdateBatchSize: 25 }; +// parse manifest to get configurations for current runtime +if (typeof chrome !== 'undefined' && chrome.runtime && chrome.runtime.getManifest) { + setConfigParams(chrome.runtime.getManifest()); +} else if (typeof $ !== 'undefined' && $.get) { + $.get('/manifest.json', setConfigParams, 'json'); +} + +function setConfigParams(manifest) { + var cfg = exports.config, + cloudUrl, keychainUrl; + + // get key server base url + cloudUrl = _.find(manifest.permissions, function(permission) { + return typeof permission === 'string' && permission.indexOf('https://keys') === 0; + }); + // remove last '/' from url due to required syntax in manifest + cfg.cloudUrl = cloudUrl.substring(0, cloudUrl.length - 1); + // get keychain server base url + keychainUrl = _.find(manifest.permissions, function(permission) { + return typeof permission === 'string' && permission.indexOf('https://keychain') === 0; + }); + // remove last '/' from url due to required syntax in manifest + cfg.privkeyServerUrl = keychainUrl.substring(0, keychainUrl.length - 1); + // get client ID for OAuth requests + cfg.gmail.clientId = manifest.oauth2.client_id; + // get the app version + cfg.appVersion = manifest.version; +} + /** * Strings are maintained here */ From eb81028123c1598f6fbdf7b72a5d5dea5b8f7048 Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Wed, 22 Oct 2014 19:42:56 +0200 Subject: [PATCH 2/2] Use regex to parse key server urls from manifest --- package.json | 1 - src/js/app-config.js | 21 +++++++++------------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 19cb5d1..05d520c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,5 @@ { "name": "whiteout-mail", - "version": "0.0.1", "description": "Mail App with integrated OpenPGP encryption.", "author": "Whiteout Networks", "homepage": "https://whiteout.io", diff --git a/src/js/app-config.js b/src/js/app-config.js index 41271ad..d10da0a 100644 --- a/src/js/app-config.js +++ b/src/js/app-config.js @@ -164,21 +164,18 @@ if (typeof chrome !== 'undefined' && chrome.runtime && chrome.runtime.getManifes } function setConfigParams(manifest) { - var cfg = exports.config, - cloudUrl, keychainUrl; + var cfg = exports.config; + + function getUrl(beginsWith) { + return _.find(manifest.permissions, function(permission) { + return typeof permission === 'string' && permission.indexOf(beginsWith) === 0; + }).replace(/\/$/, ''); // remove last '/' from url due to required syntax in manifest + } // get key server base url - cloudUrl = _.find(manifest.permissions, function(permission) { - return typeof permission === 'string' && permission.indexOf('https://keys') === 0; - }); - // remove last '/' from url due to required syntax in manifest - cfg.cloudUrl = cloudUrl.substring(0, cloudUrl.length - 1); + cfg.cloudUrl = getUrl('https://keys'); // get keychain server base url - keychainUrl = _.find(manifest.permissions, function(permission) { - return typeof permission === 'string' && permission.indexOf('https://keychain') === 0; - }); - // remove last '/' from url due to required syntax in manifest - cfg.privkeyServerUrl = keychainUrl.substring(0, keychainUrl.length - 1); + cfg.privkeyServerUrl = getUrl('https://keychain'); // get client ID for OAuth requests cfg.gmail.clientId = manifest.oauth2.client_id; // get the app version