diff --git a/extension/background.js b/extension/background.js index c27abfa..12a717d 100644 --- a/extension/background.js +++ b/extension/background.js @@ -187,6 +187,8 @@ webpg.background = { webpg.preferences.decorate_inline.get(), 'mode': webpg.preferences.decorate_inline.mode(), 'render_toolbar': (webpg.preferences.render_toolbar.get() === "true"), + 'filtering_mode': webpg.preferences.site_exceptions.mode(), + 'site_exceptions': webpg.preferences.site_exceptions.get(), }; break; diff --git a/extension/browser_action_menu.html b/extension/browser_action_menu.html index 3a368eb..ed2bd14 100644 --- a/extension/browser_action_menu.html +++ b/extension/browser_action_menu.html @@ -5,9 +5,13 @@ -
+
diff --git a/extension/inline.js b/extension/inline.js index 7994669..5190e7c 100644 --- a/extension/inline.js +++ b/extension/inline.js @@ -248,7 +248,7 @@ webpg.inline = { } return true; }); - + if (!proceed) return false; diff --git a/extension/options.html b/extension/options.html index 5fbfb78..36885cf 100644 --- a/extension/options.html +++ b/extension/options.html @@ -1,265 +1,340 @@ - - -WebPG Options - - - - - - - - - - - - - - - -
-
- - WebPG Options - - - - - - - -
-
-
-    -    -    -    - - - -
-
    -

    -
    - - -
    -
    -
    -
    -
    -
    - - Your system appears to be configured correctly for WebPG -
    - -
    -
    -
    -
    -
    -

    -
    -
    -
    -
    -
    -
    -
    -
    -
    - - + + +WebPG Options + + + + + + + + + + + + + + + + +
    +
    + + WebPG Options + + + + + + + +
    +
    +
    +
    +
    +
    + + Your system appears to be configured correctly for WebPG +
    + +
    +
    +
    +
    + + + +
    +
    +
    + +    + + + + + +    + + + + +    + + + + +    + + + + +
    +
      +

      +
      +
      + +
      +

      +
      +
      +
      +
      +
      +
      + Filtering Mode + + + + + + +
      +
      + Whitelist + + + + +
      +
      + Blacklist + + + + +
      +
      +
      + +
      +
      + +    + + + + + +    + + + + + +    + + + + + +    + + + + +
      +
      +
      +
      +
      +
      +
      +
      +
      + + diff --git a/extension/options.js b/extension/options.js index 3f29192..1ad6160 100644 --- a/extension/options.js +++ b/extension/options.js @@ -1,575 +1,651 @@ -/* The Window object housing firefoxOverlay.xul - or thunderbirdOverlay.xul in Mozilla applications - not passed in Google Chrome - */ - init: function(browserWindow) { - var _ = webpg.utils.i18n.gettext; - document.title = _("WebPG Options"); - document.dir = (webpg.utils.isRTL() ? 'rtl' : 'ltr'); - if (webpg.utils.detectedBrowser.vendor == "mozilla") - webpg.plugin = browserWindow.webpg.plugin; - else if (webpg.utils.detectedBrowser.product == "chrome") - webpg.plugin = chrome.extension.getBackgroundPage().webpg.plugin; - - webpg.jq('#step-1').ready(function() { - doSystemCheck(); - }); - - function doSystemCheck() { - var _ = webpg.utils.i18n.gettext; - if (webpg.utils.detectedBrowser.product == "chrome") - pf = window.clientInformation.platform.substr(0,3); - else - pf = navigator.oscpu.substr(0,3); - platform = ""; - if (pf == "Win") { - platform = "-mswindows"; - } - if (pf == "Mac") { - platform = "-macosx"; - } - if (webpg.plugin && webpg.plugin.valid) { - webpg_status = webpg.plugin.webpg_status; - errors = { - 'NPAPI' : { 'error' : false, 'detail': _("The WebPG NPAPI Plugin is valid") + "; version " + webpg.plugin.version }, - 'openpgp' : { 'error' : false, 'detail' : _("OpenPGP was detected") + "; version " + webpg_status.OpenPGP.version }, - 'gpg_agent' : { 'error' : false, 'detail' : _("It appears you have a key-agent configured") }, - 'gpgconf' : { 'error' : false, 'detail' : _("gpgconf was detected") + "; " + _("you can use the signature methods") } - }; - - if (!webpg_status.openpgp_detected) { - errors.openpgp = { - 'error': true, - 'detail': _("OpenPGP does not appear to be installed"), - 'link' : "https://webpg.org/docs/webpg-userdocs/#!/guide/prerequisites" - }; - } - - if (!webpg_status.gpg_agent_info) { - errors.gpg_agent = { - 'error': true, - 'detail': _("You do not appear to have a key-agent configured") + " " + _("A working key-agent is required"), - 'link' : "https://webpg.org/docs/webpg-userdocs/#!/guide/prerequisites" - }; - } - - if (!webpg_status.gpgconf_detected) { - errors.gpgconf = { - 'error': true, - 'detail': _("gpgconf does not appear to be installed") + "; " + _("You will not be able to create signatures"), - 'link' : "https://webpg.org/docs/webpg-userdocs/#!/guide/prerequisites-section-windows" - }; - } - - } else { - errors = { - "NPAPI" : { - 'error': true, - 'detail': _("There was a problem loading the plugin") + "; " + _("the plugin might be incompatibly compiled for this architechture"), - 'link' : null - } - }; - webpg.jq('#valid-options').hide(); - console.log(errors.NPAPI.detail); - } - errors_found = false; - for (var error in errors) { - if (errors[error].error) { - document.getElementById('system-good').style.display = 'none'; - document.getElementById('system-error').style.display = 'block'; - errors_found = true; - } - extra_class = (errors[error].error && error != 'gpgconf') ? ' error' : ''; - extra_class = (errors[error].error && error == 'gpgconf') ? ' warning' : extra_class; - item_result = webpg.jq("
      ", { - 'class': "trust-level-desc" + extra_class - }).append(webpg.jq("", { - 'class': "system-check", - 'style': "margin-right: 8px" - }).append(webpg.jq("", { - 'src': (errors[error].error) ? - "skin/images/cancel.png" : "skin/images/check.png" - }) - ) - ).append(webpg.jq("", { - 'class': "trust-desc", - 'html': (errors[error].error && errors[error].link) ? - errors[error].detail + " - " + _("click here for help resolving this issue") + "" : errors[error].detail - }) - ); - webpg.jq('#status_result').append(item_result); - } - if (errors_found && error == 'NPAPI') { - // Hide the options for invalid installations - webpg.jq('#valid-options').hide(); - } else { - // Only display the inline check if this is not the app version of webpg-chrome. - // and don't show the "GMAIL integration" option in Thunderbird - if (webpg.utils.detectedBrowser.product == "thunderbird") { - webpg.jq("#enable-gmail-integration").hide(); - webpg.jq("#gmail-action-sign").hide(); - webpg.jq("#gmail-linked-identities").hide(); - } - - if (webpg.preferences.gmail_integration.get() !== 'true') { - webpg.jq("#gmail-action-sign").hide(); - //webpg.jq("#gmail-linked-identities").hide(); - } - - if ((webpg.utils.detectedBrowser.product == "chrome") && - !chrome.app.getDetails().hasOwnProperty("content_scripts")) { - webpg.jq('#enable-decorate-inline').hide(); - } else { - webpg.jq('#enable-decorate-inline-check')[0].checked = - (webpg.preferences.decorate_inline.get() == 'true'); - if (!webpg.jq('#enable-decorate-inline-check')[0].checked || - webpg.utils.detectedBrowser.product == "thunderbird") - webpg.jq("#inline-options-link").hide(); - } - - // If no errors were found in the configuration, only display - // the "good-to-go" status item - if (!errors_found) { - webpg.jq('#status_result').children().hide(); - webpg.jq("#system-good").show(); - } - - webpg.jq(".webpg-options-title").first().text(_("WebPG Options")); - - webpg.jq("#enable-decorate-inline").find(".webpg-options-text"). - text(_("Enable Inline formatting of PGP Messages and Keys")); - - webpg.jq("#inline-options-link").text(_("Inline Options")); - - webpg.jq("#enable-encrypt-to-self").find(".webpg-options-text"). - text(_("Always encrypt to your default key in addition to the recipient")); - - webpg.jq("#enable-gmail-integration").find(".webpg-options-text"). - text(_("Enable WebPG GMAIL integration") + " [" + _("EXPERIMENTAL") + "]"); - - webpg.jq("#gmail-action-sign").find(".webpg-options-text"). - text(_("Automatically Sign outgoing messages in GMAIL")); - - webpg.jq("#gmail-linked-identities").find(".webpg-options-text"). - text(_("Linked GMAIL Identities")); - - webpg.jq("#link-gmail-identity").text(_("Link new GMAIL identity")).click(function() { - webpg.xoauth2.requestCodeCallback = function() { - webpg.xoauth2.requestCodeCallback = undefined; - document.location.reload(); - }; - webpg.xoauth2.requestCode(); - }); - - webpg.jq("#advanced-options-link").text(_("Advanced Options")); - - webpg.jq("#gnupg-path-select").find(".webpg-options-text"). - text(_("GnuPG home directory")); - - webpg.jq("#gnupg-path-select").find("input:button").val(_("Save")); - - webpg.jq("#gnupg-binary-select").find(".webpg-options-text"). - text(_("GnuPG binary") + " (i.e. /usr/bin/gpg)"); - - webpg.jq("#gnupg-binary-select").find("input:button").val(_("Save")); - - webpg.jq("#gpgconf-binary-select").find(".webpg-options-text"). - text(_("GPGCONF binary") + " (i.e. /usr/bin/gpgconf)"); - - webpg.jq("#gpgconf-binary-select").find("input:button").val(_("Save")); - - webpg.jq("#gnupg-keyserver-select").find(".webpg-options-text"). - text(_("Keyserver") + " (i.e. hkp://subkeys.pgp.net)"); - - webpg.jq("#gnupg-keyserver-select").find("input:button").val(_("Save")); - - webpg.jq("#system-good").find(".trust-desc").text(_("Your system appears to be configured correctly for WebPG")); - - webpg.jq("#system-error").find(".trust-desc").text(_("There is a problem with your configuration")); - - webpg.jq('#enable-encrypt-to-self-check')[0].checked = - (webpg.preferences.encrypt_to_self.get()); - - if (webpg.preferences.default_key.get() === "") - webpg.jq('#enable-encrypt-to-self-check')[0].disabled = true; - - webpg.jq('#enable-gmail-integration-check')[0].checked = - (webpg.preferences.gmail_integration.get() == 'true'); - - webpg.jq('#gmail-action-sign-check')[0].checked = - (webpg.preferences.sign_gmail.get() == 'true'); - - webpg.jq('#enable-decorate-inline-check').button({ - 'label': (webpg.preferences.decorate_inline.get() == 'true') ? _('Enabled') : _('Disabled') - }).click(function(e) { - var status; - if (webpg.preferences.decorate_inline.get() == 'true') { - webpg.preferences.decorate_inline.set(false); - status = _("Disabled"); - this.checked = false; - webpg.jq("#inline-options-link").hide(); - } else { - webpg.preferences.decorate_inline.set(true); - status = _("Enabled"); - this.checked = true; - webpg.jq("#inline-options-link").show(); - } - webpg.jq(this).button('option', 'label', status); - webpg.jq(this).button('refresh'); - } - ); - - webpg.jq("#inline-options-link").click(function() { - if (webpg.utils.detectedBrowser.vendor == 'mozilla') { - webpg.jq("#options-dialog-content").html( - "" + _("Inline formatting mode") + "  " + - "
      " + - "" + - "" + - "
      " + - "" + _("Sample") + "" + - "

      " + - "" + _("WebPG Toolbar") + "  " + - "
      " + - "" + - "
      " + - "" + _("Sample") + "

      " + - "
      " - ); - webpg.jq("#inline-sample-link").click(function(e) { - webpg.jq("#inline-sample-image").toggle("slide"); - }); - webpg.jq("#toolbar-sample-link").click(function(e) { - webpg.jq("#toolbar-sample-textarea").toggle("slide"); - }); - if (webpg.preferences.render_toolbar.get() == "false") - webpg.jq("#toolbar-sample-link").hide(); - } else { - webpg.jq("#options-dialog-content").html( - "" + _("Inline formatting mode") + "  " + - "
      " + - "" + - "" + - "
      " + - "" + _("Sample") + "" + - "
      -----BEGIN PGP MESSAGE-----\n" +
      -                            "Version: GnuPG v1.4.11 (GNU/Linux)\n\n"+
      -                            "jA0EAwMCL/ruujWlHoVgyS7nibjGsDtEt9QcaHAmknBXnk9yjrh42ug0SxCD/tEO\n" +
      -                            "ztexzAlHOvxqca3GWTYC\n" +
      -                            "=HMC5\n" +
      -                            "-----END PGP MESSAGE-----


      " + - "" + _("WebPG Toolbar") + "  " + - "
      " + - "" + - "
      " + - "" + _("Sample") + "" + - "
      " - - ); - webpg.jq("#inline-sample-link").click(function(e) { - webpg.jq("#inline-options-pgp-test").toggle("slide"); - }); - webpg.jq("#toolbar-sample-link").click(function(e) { - webpg.jq("#toolbar-sample-textarea").html("").toggle("slide"); - webpg.inline.render_toolbar = (webpg.preferences.render_toolbar.get() === "true"); - webpg.inline.PGPDataSearch(document, false, false); - }); - } - webpg.jq("#inline-format-options").buttonset() - .find("#" + webpg.preferences.decorate_inline.mode()).attr({"checked": "checked"}) - .parent().buttonset("refresh").click(function(e) { - if (e.target.type == "radio") { - webpg.preferences.decorate_inline.mode(e.target.id); - if (webpg.utils.detectedBrowser.vendor == 'mozilla') { - webpg.jq("#inline-sample-image")[0].src = webpg.utils.resourcePath + - "skin/images/examples/inline-formatting-" + - webpg.preferences.decorate_inline.mode() + - ".png"; - } else { - webpg.inline.mode = e.target.id; - webpg.jq("#inline-options-pgp-test")[0].innerHTML = webpg.jq("#inline-options-pgp-test").text(); - } - webpg.inline.PGPDataSearch(document, false, false); - } - }); - webpg.jq("#toolbar-check").button({ - 'label': (webpg.preferences.render_toolbar.get() == "true") ? _("Enabled") : _("Disabled") - }).click(function(e) { - webpg.preferences.render_toolbar.set((this.checked)); - webpg.inline.render_toolbar = (this.checked); - var status = (this.checked) ? _("Enabled") : _("Disabled"); - webpg.jq(this).button('option', 'label', status); - webpg.jq(this).button('refresh'); - if (this.checked) { - if (webpg.utils.detectedBrowser.vendor == 'mozilla') - webpg.jq("#toolbar-sample-link").show(); - else - webpg.inline.PGPDataSearch(document, false, false); - } else { - if (webpg.utils.detectedBrowser.vendor == 'mozilla') - webpg.jq("#toolbar-sample-link").hide(); - webpg.jq("#toolbar-sample-textarea").hide(); - } - }); - - if (webpg.preferences.render_toolbar.get() == "true") - webpg.jq("#toolbar-check").attr({'checked': 'checked'}).button("refresh"); - - webpg.jq("#options-dialog").attr("title", _("Inline Options")); - - webpg.jq("#options-dialog").dialog({ - 'resizable': true, - 'height': 420, - 'width': 630, - 'modal': true, - 'position': "top", - 'buttons': [ - { - 'text': _("Close"), - 'click': function() { - webpg.jq("#options-dialog").dialog("close"); - webpg.jq("#options-dialog").dialog("destroy"); - webpg.jq("#options-dialog").hide(); - } - } - ]}).parent().animate({"top": window.scrollY}, 1, function() { - document.activeElement.blur(); - webpg.jq(this).animate({"top": 20}, 1); - webpg.inline.mode = webpg.preferences.decorate_inline.mode(); - webpg.inline.PGPDataSearch(document, false, false); - }); - }); - - webpg.jq('#enable-encrypt-to-self-check').button({ - 'label': (webpg.preferences.default_key.get() === "") ? - _("No default key set") : - (webpg.preferences.encrypt_to_self.get()) ? - _('Enabled') : _('Disabled') - }).click(function(e) { - var status; - if (webpg.preferences.encrypt_to_self.get()) { - webpg.preferences.encrypt_to_self.set(false); - this.checked = false; - status = _('Disabled'); - } else { - webpg.preferences.encrypt_to_self.set(true); - this.checked = true; - status = _('Enabled'); - } - webpg.jq(this).button('option', 'label', status); - webpg.jq(this).button('refresh'); - } - ); - - webpg.jq('#enable-gmail-integration-check').button({ - 'label': (webpg.preferences.gmail_integration.get() == 'true') ? _('Enabled') : _('Disabled') - }).click(function(e) { - if (webpg.preferences.gmail_integration.get() === null || - webpg.preferences.gmail_integration.get() === 'false') { - alert(_("WebPG GMAIL integration is EXPERIMENTAL") + "; " + _("use at your own risk")); - } - - (webpg.preferences.gmail_integration.get() == 'true') ? - webpg.preferences.gmail_integration.set(false) - : webpg.preferences.gmail_integration.set(true); - status = (webpg.preferences.gmail_integration.get() == 'true') ? _('Enabled') : _('Disabled'); - if (webpg.preferences.gmail_integration.get() == 'true') { - webpg.jq("#gmail-action-sign").show(); - //webpg.jq("#gmail-linked-identities").show() - } else { - webpg.jq("#gmail-action-sign").hide(); - webpg.jq("#gmail-linked-identities").hide(); - } - webpg.jq(this).button('option', 'label', status); - this.checked = (webpg.preferences.gmail_integration.get() == 'true'); - webpg.jq(this).button('refresh'); - } - ); - - webpg.jq('#gmail-action-sign-check').button({ - 'label': (webpg.preferences.sign_gmail.get() == 'true') ? _('Enabled') : _('Disabled') - }).click(function(e) { - (webpg.preferences.sign_gmail.get() == 'true') ? - webpg.preferences.sign_gmail.set(false) - : webpg.preferences.sign_gmail.set(true); - status = (webpg.preferences.sign_gmail.get() == 'true') ? _('Enabled') : _('Disabled'); - webpg.jq(this).button('option', 'label', status); - this.checked = (webpg.preferences.sign_gmail.get() == 'true'); - webpg.jq(this).button('refresh'); - } - ); - - for (var ident in webpg.xoauth2.comp_data) { - var id = webpg.xoauth2.comp_data[ident]; - var identli = "
    • " + ident + "[" + _("delete") + "]
    • "; - webpg.jq("#gmail-linked-identities").find(".ident-list").append(identli); - } - - // Hide the gmail linked identies feature (not yet implemented) - webpg.jq("#gmail-linked-identities").hide(); - - webpg.jq("#gmail-linked-identities").find(".ident-list").find("a").click(function() { - if (webpg.xoauth2.comp_data.hasOwnProperty(this.id)) { - delete webpg.xoauth2.comp_data[this.id]; - webpg.preferences.xoauth2_data.set(webpg.xoauth2.comp_data); - console.log(webpg.xoauth2.comp_data); - this.parentElement.remove(); - } - }); - - - webpg.jq("#gnupg-path-save").button().click(function(e) { - webpg.preferences.gnupghome.set(webpg.jq("#gnupg-path-input")[0].value); - webpg.jq(this).hide(); - }); - - webpg.jq("#gnupg-path-input").each(function() { - // Save current value of element - webpg.jq(this).data('oldVal', webpg.jq(this).val()); - - // Look for changes in the value - webpg.jq(this).bind("change propertychange keyup input paste", function(event) { - // If value has changed... - if (webpg.jq(this).data('oldVal') != webpg.jq(this).val()) { - // Updated stored value - webpg.jq(this).data('oldVal', webpg.jq(this).val()); - - // Show save dialog - if (webpg.jq(this).val() != webpg.preferences.gnupghome.get()) - webpg.jq("#gnupg-path-save").show(); - else - webpg.jq("#gnupg-path-save").hide(); - } - }); - })[0].value = webpg.preferences.gnupghome.get(); - - webpg.jq("#gnupg-path-input")[0].dir = "ltr"; - - webpg.jq("#gnupg-binary-save").button().click(function(e) { - webpg.preferences.gnupgbin.set(webpg.jq("#gnupg-binary-input")[0].value); - window.top.document.location.reload(); - webpg.jq(this).hide(); - }); - - webpg.jq("#gnupg-binary-input").each(function() { - // Save current value of element - webpg.jq(this).data('oldVal', webpg.jq(this).val()); - - // Look for changes in the value - webpg.jq(this).bind("change propertychange keyup input paste", function(event) { - // If value has changed... - if (webpg.jq(this).data('oldVal') != webpg.jq(this).val()) { - // Updated stored value - webpg.jq(this).data('oldVal', webpg.jq(this).val()); - - // Show save dialog - if (webpg.jq(this).val() != webpg.preferences.gnupgbin.get()) - webpg.jq("#gnupg-binary-save").show(); - else - webpg.jq("#gnupg-binary-save").hide(); - } - }); - })[0].value = webpg.preferences.gnupgbin.get(); - - webpg.jq("#gnupg-binary-input")[0].dir = "ltr"; - - webpg.jq("#gpgconf-binary-save").button().click(function(e) { - webpg.preferences.gpgconf.set(webpg.jq("#gpgconf-binary-input")[0].value); - window.top.document.location.reload(); - webpg.jq(this).hide(); - }); - - webpg.jq("#gpgconf-binary-input").each(function() { - // Save current value of element - webpg.jq(this).data('oldVal', webpg.jq(this).val()); - - // Look for changes in the value - webpg.jq(this).bind("change propertychange keyup input paste", function(event) { - // If value has changed... - if (webpg.jq(this).data('oldVal') != webpg.jq(this).val()) { - // Updated stored value - webpg.jq(this).data('oldVal', webpg.jq(this).val()); - - // Show save dialog - if (webpg.jq(this).val() != webpg.preferences.gpgconf.get()) - webpg.jq("#gpgconf-binary-save").show(); - else - webpg.jq("#gpgconf-binary-save").hide(); - } - }); - })[0].value = webpg.preferences.gpgconf.get(); - - webpg.jq("#gpgconf-binary-input")[0].dir = "ltr"; - - webpg.jq("#gnupg-keyserver-save").button().click(function(e) { - if (!webpg.plugin.webpg_status.gpgconf_detected) - return false; - webpg.plugin.gpgSetPreference("keyserver", webpg.jq("#gnupg-keyserver-input")[0].value); - webpg.jq(this).hide(); - }); - - webpg.jq("#gnupg-keyserver-input").each(function() { - // Save current value of element - webpg.jq(this).data('oldVal', webpg.jq(this).val()); - - // Look for changes in the value - webpg.jq(this).bind("change propertychange keyup input paste", function(event) { - // If value has changed... - if (webpg.jq(this).data('oldVal') != webpg.jq(this).val()) { - // Updated stored value - webpg.jq(this).data('oldVal', webpg.jq(this).val()); - - // Show save dialog - if (webpg.jq(this).val() != webpg.plugin.gpgGetPreference("keyserver").value) - webpg.jq("#gnupg-keyserver-save").show(); - else - webpg.jq("#gnupg-keyserver-save").hide(); - } - }); - })[0].value = webpg.plugin.gpgGetPreference("keyserver").value; - - webpg.jq("#gnupg-keyserver-input")[0].dir = "ltr"; - - webpg.jq("#advanced-options-link").click(function(e) { - webpg.jq("#advanced-options").toggle("slide"); - }); - } - } - - if (webpg.utils.detectedBrowser.vendor == "mozilla") - webpg.jq('#window_functions').hide(); - - webpg.jq('#close').button().button("option", "label", _("Finished")) - .click(function(e) { window.top.close(); }); - - webpg.utils.extension.version(function(version) { - webpg.jq("#webpg-info-version-string").text( - _("Version") + ": " + webpg.utils.escape(version) - ); - }); - } -}; -webpg.jq(function() { - var browserWindow = null; - if (webpg.utils.detectedBrowser['vendor'] == 'mozilla') - browserWindow = webpg.utils.mozilla.getChromeWindow(); - webpg.options.init(browserWindow); -}); -/* ]]> */ +/* The Window object housing firefoxOverlay.xul + or thunderbirdOverlay.xul in Mozilla applications - not passed in Google Chrome + */ + init: function(browserWindow) + { + var _ = webpg.utils.i18n.gettext; + document.title = _("WebPG Options"); + document.dir = (webpg.utils.isRTL() ? 'rtl' : 'ltr'); + if (webpg.utils.detectedBrowser.vendor == "mozilla") + { + webpg.plugin = browserWindow.webpg.plugin; + } + else if (webpg.utils.detectedBrowser.product == "chrome") + { + webpg.plugin = chrome.extension.getBackgroundPage().webpg.plugin; + } + + // jQuery UI elements + webpg.jq('#tabs').tabs(); + + webpg.jq('#step-1').ready(function() { + doSystemCheck(); + }); + + function doSystemCheck() { + var _ = webpg.utils.i18n.gettext; + if (webpg.utils.detectedBrowser.product == "chrome") + pf = window.clientInformation.platform.substr(0,3); + else + pf = navigator.oscpu.substr(0,3); + platform = ""; + if (pf == "Win") { + platform = "-mswindows"; + } + else if (pf == "Mac") { + platform = "-macosx"; + } + if (webpg.plugin && webpg.plugin.valid) { + webpg_status = webpg.plugin.webpg_status; + errors = { + 'NPAPI' : { 'error' : false, 'detail': _("The WebPG NPAPI Plugin is valid") + "; version " + webpg.plugin.version }, + 'openpgp' : { 'error' : false, 'detail' : _("OpenPGP was detected") + "; version " + webpg_status.OpenPGP.version }, + 'gpg_agent' : { 'error' : false, 'detail' : _("It appears you have a key-agent configured") }, + 'gpgconf' : { 'error' : false, 'detail' : _("gpgconf was detected") + "; " + _("you can use the signature methods") } + }; + + if (!webpg_status.openpgp_detected) { + errors.openpgp = { + 'error': true, + 'detail': _("OpenPGP does not appear to be installed"), + 'link' : "https://webpg.org/docs/webpg-userdocs/#!/guide/prerequisites" + }; + } + + if (!webpg_status.gpg_agent_info) { + errors.gpg_agent = { + 'error': true, + 'detail': _("You do not appear to have a key-agent configured") + " " + _("A working key-agent is required"), + 'link' : "https://webpg.org/docs/webpg-userdocs/#!/guide/prerequisites" + }; + } + + if (!webpg_status.gpgconf_detected) { + errors.gpgconf = { + 'error': true, + 'detail': _("gpgconf does not appear to be installed") + "; " + _("You will not be able to create signatures"), + 'link' : "https://webpg.org/docs/webpg-userdocs/#!/guide/prerequisites-section-windows" + }; + } + + } else { + errors = { + "NPAPI" : { + 'error': true, + 'detail': _("There was a problem loading the plugin") + "; " + _("the plugin might be incompatibly compiled for this architechture"), + 'link' : null + } + }; + webpg.jq('#valid-options').hide(); + console.log(errors.NPAPI.detail); + } + errors_found = false; + for (var error in errors) { + if (errors[error].error) { + document.getElementById('system-good').style.display = 'none'; + document.getElementById('system-error').style.display = 'block'; + errors_found = true; + } + extra_class = (errors[error].error && error != 'gpgconf') ? ' error' : ''; + extra_class = (errors[error].error && error == 'gpgconf') ? ' warning' : extra_class; + item_result = webpg.jq("
      ", { + 'class': "trust-level-desc" + extra_class + }).append(webpg.jq("", { + 'class': "system-check", + 'style': "margin-right: 8px" + }).append(webpg.jq("", { + 'src': (errors[error].error) ? + "skin/images/cancel.png" : "skin/images/check.png" + }) + ) + ).append(webpg.jq("", { + 'class': "trust-desc", + 'html': (errors[error].error && errors[error].link) ? + errors[error].detail + " - " + _("click here for help resolving this issue") + "" : errors[error].detail + }) + ); + webpg.jq('#status_result').append(item_result); + } + if (errors_found && error == 'NPAPI') { + // Hide the options for invalid installations + webpg.jq('#valid-options').hide(); + } else { + // Only display the inline check if this is not the app version of webpg-chrome. + // and don't show the "GMAIL integration" option in Thunderbird + if (webpg.utils.detectedBrowser.product == "thunderbird") { + webpg.jq("#enable-gmail-integration").hide(); + webpg.jq("#gmail-action-sign").hide(); + webpg.jq("#gmail-linked-identities").hide(); + } + + if (webpg.preferences.gmail_integration.get() !== 'true') { + webpg.jq("#gmail-action-sign").hide(); + //webpg.jq("#gmail-linked-identities").hide(); + } + + if ((webpg.utils.detectedBrowser.product == "chrome") && + !chrome.app.getDetails().hasOwnProperty("content_scripts")) { + webpg.jq('#enable-decorate-inline').hide(); + } else { + webpg.jq('#enable-decorate-inline-check')[0].checked = + (webpg.preferences.decorate_inline.get() == 'true'); + if (!webpg.jq('#enable-decorate-inline-check')[0].checked || + webpg.utils.detectedBrowser.product == "thunderbird") + webpg.jq("#inline-options-link").hide(); + } + + // If no errors were found in the configuration, only display + // the "good-to-go" status item + if (!errors_found) { + webpg.jq('#status_result').children().hide(); + webpg.jq("#system-good").show(); + } + + webpg.jq(".webpg-options-title").first().text(_("WebPG Options")); + + webpg.jq("#enable-decorate-inline").find(".webpg-options-text"). + text(_("Enable Inline formatting of PGP Messages and Keys")); + + webpg.jq("#inline-options-link").text(_("Inline Options")); + + webpg.jq("#enable-encrypt-to-self").find(".webpg-options-text"). + text(_("Always encrypt to your default key in addition to the recipient")); + + webpg.jq("#enable-gmail-integration").find(".webpg-options-text"). + text(_("Enable WebPG GMAIL integration") + " [" + _("EXPERIMENTAL") + "]"); + + webpg.jq("#gmail-action-sign").find(".webpg-options-text"). + text(_("Automatically Sign outgoing messages in GMAIL")); + + webpg.jq("#gmail-linked-identities").find(".webpg-options-text"). + text(_("Linked GMAIL Identities")); + + webpg.jq("#link-gmail-identity").text(_("Link new GMAIL identity")).click(function() { + webpg.xoauth2.requestCodeCallback = function() { + webpg.xoauth2.requestCodeCallback = undefined; + document.location.reload(); + }; + webpg.xoauth2.requestCode(); + }); + + webpg.jq("#gnupg-path-select").find(".webpg-options-text"). + text(_("GnuPG home directory")); + webpg.jq("#gnupg-path-select").find("input:button").val(_("Save")); + webpg.jq("#gnupg-path-input").attr('placeholder', '~/.gnupg'); + + webpg.jq("#gnupg-binary-select").find(".webpg-options-text"). + text(_("GnuPG binary")); + webpg.jq("#gnupg-binary-input").attr('placeholder', '/usr/bin/gpg'); + webpg.jq("#gnupg-binary-select").find("input:button").val(_("Save")); + + webpg.jq("#gpgconf-binary-select").find(".webpg-options-text"). + text(_("GPGCONF binary")); + webpg.jq("#gpgconf-binary-input").attr('placeholder', '/usr/bin/gpgconf'); + webpg.jq("#gpgconf-binary-select").find("input:button").val(_("Save")); + + webpg.jq("#gnupg-keyserver-select").find(".webpg-options-text"). + text(_("Keyserver")); + webpg.jq("#gnupg-keyserver-input").attr('placeholder', 'hkp://subkeys.pgp.net'); + webpg.jq("#gnupg-keyserver-select").find("input:button").val(_("Save")); + + webpg.jq("#system-good").find(".trust-desc").text(_("Your system appears to be configured correctly for WebPG")); + + webpg.jq("#system-error").find(".trust-desc").text(_("There is a problem with your configuration")); + + webpg.jq('#enable-encrypt-to-self-check')[0].checked = + (webpg.preferences.encrypt_to_self.get()); + + if (webpg.preferences.default_key.get() === "") + webpg.jq('#enable-encrypt-to-self-check')[0].disabled = true; + + webpg.jq('#enable-gmail-integration-check')[0].checked = + (webpg.preferences.gmail_integration.get() == 'true'); + + webpg.jq('#gmail-action-sign-check')[0].checked = + (webpg.preferences.sign_gmail.get() == 'true'); + + webpg.jq('#enable-decorate-inline-check').button({ + 'label': (webpg.preferences.decorate_inline.get() == 'true') ? _('Enabled') : _('Disabled') + }).click(function(e) { + var status; + if (webpg.preferences.decorate_inline.get() == 'true') { + webpg.preferences.decorate_inline.set(false); + status = _("Disabled"); + this.checked = false; + webpg.jq("#inline-options-link").hide(); + } else { + webpg.preferences.decorate_inline.set(true); + status = _("Enabled"); + this.checked = true; + webpg.jq("#inline-options-link").show(); + } + webpg.jq(this).button('option', 'label', status); + webpg.jq(this).button('refresh'); + } + ); + + webpg.jq("#inline-options-link").click(function() { + if (webpg.utils.detectedBrowser.vendor == 'mozilla') { + webpg.jq("#options-dialog-content").html( + "" + _("Inline formatting mode") + "  " + + "
      " + + "" + + "" + + "
      " + + "" + _("Sample") + "" + + "

      " + + "" + _("WebPG Toolbar") + "  " + + "
      " + + "" + + "
      " + + "" + _("Sample") + "

      " + + "
      " + ); + webpg.jq("#inline-sample-link").click(function(e) { + webpg.jq("#inline-sample-image").toggle("slide"); + }); + webpg.jq("#toolbar-sample-link").click(function(e) { + webpg.jq("#toolbar-sample-textarea").toggle("slide"); + }); + if (webpg.preferences.render_toolbar.get() == "false") + webpg.jq("#toolbar-sample-link").hide(); + } else { + webpg.jq("#options-dialog-content").html( + "" + _("Inline formatting mode") + "  " + + "
      " + + "" + + "" + + "
      " + + "" + _("Sample") + "" + + "
      -----BEGIN PGP MESSAGE-----\n" +
      +                            "Version: GnuPG v1.4.11 (GNU/Linux)\n\n"+
      +                            "jA0EAwMCL/ruujWlHoVgyS7nibjGsDtEt9QcaHAmknBXnk9yjrh42ug0SxCD/tEO\n" +
      +                            "ztexzAlHOvxqca3GWTYC\n" +
      +                            "=HMC5\n" +
      +                            "-----END PGP MESSAGE-----


      " + + "" + _("WebPG Toolbar") + "  " + + "
      " + + "" + + "
      " + + "" + _("Sample") + "" + + "
      " + + ); + webpg.jq("#inline-sample-link").click(function(e) { + webpg.jq("#inline-options-pgp-test").toggle("slide"); + }); + webpg.jq("#toolbar-sample-link").click(function(e) { + webpg.jq("#toolbar-sample-textarea").html("").toggle("slide"); + webpg.inline.render_toolbar = (webpg.preferences.render_toolbar.get() === "true"); + webpg.inline.PGPDataSearch(document, false, false); + }); + } + webpg.jq("#inline-format-options").buttonset() + .find("#" + webpg.preferences.decorate_inline.mode()).attr({"checked": "checked"}) + .parent().buttonset("refresh").click(function(e) { + if (e.target.type == "radio") { + webpg.preferences.decorate_inline.mode(e.target.id); + if (webpg.utils.detectedBrowser.vendor == 'mozilla') { + webpg.jq("#inline-sample-image")[0].src = webpg.utils.resourcePath + + "skin/images/examples/inline-formatting-" + + webpg.preferences.decorate_inline.mode() + + ".png"; + } else { + webpg.inline.mode = e.target.id; + webpg.jq("#inline-options-pgp-test")[0].innerHTML = webpg.jq("#inline-options-pgp-test").text(); + } + webpg.inline.PGPDataSearch(document, false, false); + } + }); + webpg.jq("#toolbar-check").button({ + 'label': (webpg.preferences.render_toolbar.get() == "true") ? _("Enabled") : _("Disabled") + }).click(function(e) { + webpg.preferences.render_toolbar.set((this.checked)); + webpg.inline.render_toolbar = (this.checked); + var status = (this.checked) ? _("Enabled") : _("Disabled"); + webpg.jq(this).button('option', 'label', status); + webpg.jq(this).button('refresh'); + if (this.checked) { + if (webpg.utils.detectedBrowser.vendor == 'mozilla') + webpg.jq("#toolbar-sample-link").show(); + else + webpg.inline.PGPDataSearch(document, false, false); + } else { + if (webpg.utils.detectedBrowser.vendor == 'mozilla') + webpg.jq("#toolbar-sample-link").hide(); + webpg.jq("#toolbar-sample-textarea").hide(); + } + }); + + if (webpg.preferences.render_toolbar.get() == "true") + webpg.jq("#toolbar-check").attr({'checked': 'checked'}).button("refresh"); + + webpg.jq("#options-dialog").attr("title", _("Inline Options")); + + webpg.jq("#options-dialog").dialog({ + 'resizable': true, + 'height': 420, + 'width': 630, + 'modal': true, + 'position': "top", + 'buttons': [ + { + 'text': _("Close"), + 'click': function() { + webpg.jq("#options-dialog").dialog("close"); + webpg.jq("#options-dialog").dialog("destroy"); + webpg.jq("#options-dialog").hide(); + } + } + ]}).parent().animate({"top": window.scrollY}, 1, function() { + document.activeElement.blur(); + webpg.jq(this).animate({"top": 20}, 1); + webpg.inline.mode = webpg.preferences.decorate_inline.mode(); + webpg.inline.PGPDataSearch(document, false, false); + }); + }); + + webpg.jq('#enable-encrypt-to-self-check').button({ + 'label': (webpg.preferences.default_key.get() === "") ? + _("No default key set") : + (webpg.preferences.encrypt_to_self.get()) ? + _('Enabled') : _('Disabled') + }).click(function(e) { + var status; + if (webpg.preferences.encrypt_to_self.get()) { + webpg.preferences.encrypt_to_self.set(false); + this.checked = false; + status = _('Disabled'); + } else { + webpg.preferences.encrypt_to_self.set(true); + this.checked = true; + status = _('Enabled'); + } + webpg.jq(this).button('option', 'label', status); + webpg.jq(this).button('refresh'); + } + ); + + webpg.jq('#enable-gmail-integration-check').button({ + 'label': (webpg.preferences.gmail_integration.get() == 'true') ? _('Enabled') : _('Disabled') + }).click(function(e) { + if (webpg.preferences.gmail_integration.get() === null || + webpg.preferences.gmail_integration.get() === 'false') { + alert(_("WebPG GMAIL integration is EXPERIMENTAL") + "; " + _("use at your own risk")); + } + + (webpg.preferences.gmail_integration.get() == 'true') ? + webpg.preferences.gmail_integration.set(false) + : webpg.preferences.gmail_integration.set(true); + status = (webpg.preferences.gmail_integration.get() == 'true') ? _('Enabled') : _('Disabled'); + if (webpg.preferences.gmail_integration.get() == 'true') { + webpg.jq("#gmail-action-sign").show(); + //webpg.jq("#gmail-linked-identities").show() + } else { + webpg.jq("#gmail-action-sign").hide(); + webpg.jq("#gmail-linked-identities").hide(); + } + webpg.jq(this).button('option', 'label', status); + this.checked = (webpg.preferences.gmail_integration.get() == 'true'); + webpg.jq(this).button('refresh'); + } + ); + + webpg.jq('#gmail-action-sign-check').button({ + 'label': (webpg.preferences.sign_gmail.get() == 'true') ? _('Enabled') : _('Disabled') + }).click(function(e) { + (webpg.preferences.sign_gmail.get() == 'true') ? + webpg.preferences.sign_gmail.set(false) + : webpg.preferences.sign_gmail.set(true); + status = (webpg.preferences.sign_gmail.get() == 'true') ? _('Enabled') : _('Disabled'); + webpg.jq(this).button('option', 'label', status); + this.checked = (webpg.preferences.sign_gmail.get() == 'true'); + webpg.jq(this).button('refresh'); + } + ); + + for (var ident in webpg.xoauth2.comp_data) { + var id = webpg.xoauth2.comp_data[ident]; + var identli = "
    • " + ident + "[" + _("delete") + "]
    • "; + webpg.jq("#gmail-linked-identities").find(".ident-list").append(identli); + } + + // Hide the gmail linked identies feature (not yet implemented) + webpg.jq("#gmail-linked-identities").hide(); + + webpg.jq("#gmail-linked-identities").find(".ident-list").find("a").click(function() { + if (webpg.xoauth2.comp_data.hasOwnProperty(this.id)) { + delete webpg.xoauth2.comp_data[this.id]; + webpg.preferences.xoauth2_data.set(webpg.xoauth2.comp_data); + console.log(webpg.xoauth2.comp_data); + this.parentElement.remove(); + } + }); + + + webpg.jq("#gnupg-path-save").button().click(function(e) { + webpg.preferences.gnupghome.set(webpg.jq("#gnupg-path-input")[0].value); + webpg.jq(this).hide(); + }); + + webpg.jq("#gnupg-path-input").each(function() { + // Save current value of element + webpg.jq(this).data('oldVal', webpg.jq(this).val()); + + // Look for changes in the value + webpg.jq(this).bind("change propertychange keyup input paste", function(event) { + // If value has changed... + if (webpg.jq(this).data('oldVal') != webpg.jq(this).val()) { + // Updated stored value + webpg.jq(this).data('oldVal', webpg.jq(this).val()); + + // Show save dialog + if (webpg.jq(this).val() != webpg.preferences.gnupghome.get()) + webpg.jq("#gnupg-path-save").show(); + else + webpg.jq("#gnupg-path-save").hide(); + } + }); + })[0].value = webpg.preferences.gnupghome.get(); + + webpg.jq("#gnupg-path-input")[0].dir = "ltr"; + + webpg.jq("#gnupg-binary-save").button().click(function(e) { + webpg.preferences.gnupgbin.set(webpg.jq("#gnupg-binary-input")[0].value); + window.top.document.location.reload(); + webpg.jq(this).hide(); + }); + + webpg.jq("#gnupg-binary-input").each(function() { + // Save current value of element + webpg.jq(this).data('oldVal', webpg.jq(this).val()); + + // Look for changes in the value + webpg.jq(this).bind("change propertychange keyup input paste", function(event) { + // If value has changed... + if (webpg.jq(this).data('oldVal') != webpg.jq(this).val()) { + // Updated stored value + webpg.jq(this).data('oldVal', webpg.jq(this).val()); + + // Show save dialog + if (webpg.jq(this).val() != webpg.preferences.gnupgbin.get()) + webpg.jq("#gnupg-binary-save").show(); + else + webpg.jq("#gnupg-binary-save").hide(); + } + }); + })[0].value = webpg.preferences.gnupgbin.get(); + + webpg.jq("#gnupg-binary-input")[0].dir = "ltr"; + + webpg.jq("#gpgconf-binary-save").button().click(function(e) { + webpg.preferences.gpgconf.set(webpg.jq("#gpgconf-binary-input")[0].value); + window.top.document.location.reload(); + webpg.jq(this).hide(); + }); + + webpg.jq("#gpgconf-binary-input").each(function() { + // Save current value of element + webpg.jq(this).data('oldVal', webpg.jq(this).val()); + + // Look for changes in the value + webpg.jq(this).bind("change propertychange keyup input paste", function(event) { + // If value has changed... + if (webpg.jq(this).data('oldVal') != webpg.jq(this).val()) { + // Updated stored value + webpg.jq(this).data('oldVal', webpg.jq(this).val()); + + // Show save dialog + if (webpg.jq(this).val() != webpg.preferences.gpgconf.get()) + webpg.jq("#gpgconf-binary-save").show(); + else + webpg.jq("#gpgconf-binary-save").hide(); + } + }); + })[0].value = webpg.preferences.gpgconf.get(); + + webpg.jq("#gpgconf-binary-input")[0].dir = "ltr"; + + webpg.jq("#gnupg-keyserver-save").button().click(function(e) { + if (!webpg.plugin.webpg_status.gpgconf_detected) + return false; + webpg.plugin.gpgSetPreference("keyserver", webpg.jq("#gnupg-keyserver-input")[0].value); + webpg.jq(this).hide(); + }); + + webpg.jq("#gnupg-keyserver-input").each(function() { + // Save current value of element + webpg.jq(this).data('oldVal', webpg.jq(this).val()); + + // Look for changes in the value + webpg.jq(this).bind("change propertychange keyup input paste", function(event) { + // If value has changed... + if (webpg.jq(this).data('oldVal') != webpg.jq(this).val()) { + // Updated stored value + webpg.jq(this).data('oldVal', webpg.jq(this).val()); + + // Show save dialog + if (webpg.jq(this).val() != webpg.plugin.gpgGetPreference("keyserver").value) + webpg.jq("#gnupg-keyserver-save").show(); + else + webpg.jq("#gnupg-keyserver-save").hide(); + } + }); + })[0].value = webpg.plugin.gpgGetPreference("keyserver").value; + + webpg.jq("#gnupg-keyserver-input")[0].dir = "ltr"; + + // Site exceptions stuff + + webpg.jq("#site-whitelist-list").html( + '' + ); + webpg.jq("#site-blacklist-list").html( + '' + ); + + webpg.jq("input[name=site-filtering-mode]") + .filter('[value=' + webpg.preferences.site_exceptions.mode() + ']') + .attr('checked', 'checked'); + + webpg.jq("input[name=site-filtering-mode]").change(function() { + var filter_mode = webpg.jq("input[name=site-filtering-mode]:checked").val(); + webpg.preferences.site_exceptions.mode(filter_mode); + }); + + webpg.jq("#site-whitelist-add").click(function() { + var site_input = webpg.jq(this).siblings('input[type=text]'); + if (site_input.val() != "") { + // Validate before adding + var site_URI = new URI(site_input.val()); + if (site_URI.scheme().length == 0) + site_URI.scheme('http'); + + // At least path (eg google.com) and http(s) is expected of the URI + if (site_URI.scheme() != "http" && site_URI.scheme() != "https") + { + alert('Invalid URI scheme'); + return; + } + + if (site_URI.path().length == 0) + { + alert('Invalid URI'); + return; + } + + webpg.preferences.site_exceptions.add('whitelist', site_URI.toString()); + var site_exceptions = webpg.preferences.site_exceptions.get(); + webpg.jq('#site-whitelist-list').html(''); + } + site_input.val(''); + site_input.focus(); + }); + webpg.jq("#site-blacklist-add").click(function() { + var site_input = webpg.jq(this).siblings('input[type=text]'); + if (site_input.val() != "") { + webpg.preferences.site_exceptions.add('blacklist', site_input.val()); + var site_exceptions = webpg.preferences.site_exceptions.get(); + webpg.jq('#site-blacklist-list').html(''); + } + site_input.val(''); + site_input.focus(); + }); + + webpg.jq("#site-whitelist-remove").click(function() { + var sites = webpg.jq('#site-whitelist-list').val(); + webpg.jq.each(sites, function(index, site) { + webpg.preferences.site_exceptions.remove('whitelist', site); + var site_exceptions = webpg.preferences.site_exceptions.get(); + webpg.jq('#site-whitelist-list').html(''); + }); + }); + webpg.jq("#site-blacklist-remove").click(function() { + var sites = webpg.jq('#site-blacklist-list').val(); + webpg.jq.each(sites, function(index, site) { + webpg.preferences.site_exceptions.remove('blacklist', site); + var site_exceptions = webpg.preferences.site_exceptions.get(); + webpg.jq('#site-blacklist-list').html(''); + }); + }); + } + } + + if (webpg.utils.detectedBrowser.vendor == "mozilla") + webpg.jq('#window_functions').hide(); + + webpg.jq('#close').button().button("option", "label", _("Finished")) + .click(function(e) { window.top.close(); }); + + webpg.utils.extension.version(function(version) { + webpg.jq("#webpg-info-version-string").text( + _("Version") + ": " + webpg.utils.escape(version) + ); + }); + } +}; +webpg.jq(function() { + var browserWindow = null; + if (webpg.utils.detectedBrowser['vendor'] == 'mozilla') + browserWindow = webpg.utils.mozilla.getChromeWindow(); + webpg.options.init(browserWindow); +}); +/* ]]> */ diff --git a/extension/preferences.js b/extension/preferences.js index 73d9351..bbea8b9 100644 --- a/extension/preferences.js +++ b/extension/preferences.js @@ -1,743 +1,795 @@ -/* The boolean value to set - */ - set: function(value) { - webpg.localStorage.setItem('enabled', value); - } - }, - - /* - Class: webpg.preferences.decorate_inline - Provides methods to get/set the "decorate_inline" preference - */ - decorate_inline: { - /* - Function: get - Provides methods to get the preference item - */ - get: function() { - var value = webpg.localStorage.getItem('decorate_inline'); - return (value === null) ? "true" : value; - }, - - /* - Function: set - Provides method to set the preference item - - Parameters: - value - The boolean value to set - */ - set: function(value) { - webpg.localStorage.setItem('decorate_inline', value); - }, - - mode: function(value) { - if (typeof(value)!="undefined") { - webpg.localStorage.setItem('decorate_mode', value); - } else { - var mode = webpg.localStorage.getItem('decorate_mode'); - return (mode === null || mode === -1) ? "window" : mode; - } - } - }, - - render_toolbar: { - /* - Function: get - Provides methods to get the preference item - */ - get: function() { - var value = webpg.localStorage.getItem('render_toolbar'); - return (value === null) ? true : value; - }, - - /* - Function: set - Provides method to set the preference item - - Parameters: - value - The boolean value to set - */ - set: function(value) { - webpg.localStorage.setItem('render_toolbar', value); - } - }, - - /* - Class: webpg.preferences.gmail_integration - Provides methods to get/set the "gmail_integration" preference - */ - gmail_integration: { - /* - Function: get - Provides methods to get the preference item - */ - get: function() { - var value = webpg.localStorage.getItem('gmail_integration'); - return (value && value != -1) ? value : 'false'; - }, - - /* - Function: set - Provides method to set the preference item - - Parameters: - value - The boolean value to set - */ - set: function(value) { - webpg.localStorage.setItem('gmail_integration', value); - } - }, - - /* - Class: webpg.preferences.gmail_action - Provides methods to get/set the "gmail_action" preference - - 0: Do not use WebPG by default for gmail messages - 1: Encrypt by default for gmail messages - 2: Sign by default for gmail messages - 3: Sign & Encrypt by default for gmail messages - 4: Symmetric Encryption by default for gmail messages - - */ - sign_gmail: { - /* - Function: get - Provides methods to get the preference item - */ - get: function() { - var value = webpg.localStorage.getItem('sign_gmail'); - return (value && value != -1) ? value : 'false'; - }, - - /* - Function: set - Provides method to set the preference item - - Parameters: - value - The boolean value to set - */ - set: function(value) { - webpg.localStorage.setItem('sign_gmail', value); - } - }, - - /* - Class: webpg.preferences.encrypt_to_self - Provides methods to get/set the "encrypt_to_self" preference - */ - encrypt_to_self: { - /* - Function: get - Provides method to get the preference item - */ - get: function() { - try { - var encrypt_to = webpg.plugin.gpgGetPreference('encrypt-to').value; - var default_key = webpg.plugin.gpgGetPreference('default-key').value; - var encrypt_to_self = (default_key !== "" && encrypt_to === default_key) ? 'true' : 'false'; - webpg.localStorage.setItem('encrypt_to_self', encrypt_to_self); - return encypt_to_self; - } catch (e) { - return webpg.localStorage.getItem('encrypt_to_self'); - } - }, - - /* - Function: set - Provides method to set the preference item - - Parameters: - value - The KeyID to set as the default key - */ - set: function(value) { - // if this setting is disabled, remove the value for 'encrypt-to' - if (!value) { - webpg.plugin.gpgSetPreference('encrypt-to', 'blank'); - } else { - var default_key = webpg.preferences.default_key.get(); - webpg.plugin.gpgSetPreference('encrypt-to', default_key); - } - } - }, - - /* - Class: webpg.preferences.gnupghome - Provides methods to get/set the "gnupghome" preference - */ - gnupghome: { - /* - Function: get - Provides method to get the preference item - */ - get: function() { - var value = webpg.localStorage.getItem('gnupghome'); - return (value && value != -1) ? value : ''; - }, - - /* - Function: set - Provides method to set the preference item - - Parameters: - value - The string value for GNUPGHOME - */ - set: function(value) { - webpg.localStorage.setItem('gnupghome', value); - webpg.plugin.gpgSetHomeDir(value); - (webpg.background.hasOwnProperty("webpg")) ? - webpg.background.webpg.background.init() : - webpg.background.init(); - webpg.plugin = (webpg.plugin.valid) ? webpg.plugin : - webpg.background.webpg.plugin; - }, - - /* - Function: clear - Provides method to clear the preference item (erase/unset) - */ - clear: function(){ - webpg.localStorage.setItem('gnupghome', ''); - webpg.plugin.gpgSetHomeDir(''); - (webpg.background.hasOwnProperty("webpg")) ? - webpg.background.webpg.background.init() : - webpg.background.init(); - webpg.plugin = (webpg.plugin.valid) ? webpg.plugin : - webpg.background.webpg.plugin; - } - }, - - /* - Class: webpg.preferences.gnupgbin - Provides methods to get/set the GnuPG binary execututable - */ - gnupgbin: { - /* - Function: get - Provides method to get the preference item - */ - get: function() { - var value = webpg.localStorage.getItem('gnupgbin'); - return (value && value != -1) ? value : ''; - }, - - /* - Function: set - Provides method to set the preference item - - Parameters: - value - The string value for GNUPGHOME - */ - set: function(value) { - webpg.localStorage.setItem('gnupgbin', value); - webpg.plugin.gpgSetBinary(value); - (webpg.background.hasOwnProperty("webpg")) ? - webpg.background.webpg.background.init() : - webpg.background.init(); - webpg.plugin = (webpg.plugin.valid) ? webpg.plugin : - webpg.background.webpg.plugin; - }, - - /* - Function: clear - Provides method to clear the preference item (erase/unset) - */ - clear: function(){ - webpg.localStorage.setItem('gnupgbin', ''); - webpg.plugin.gpgSetBinary(''); - (webpg.background.hasOwnProperty("webpg")) ? - webpg.background.webpg.background.init() : - webpg.background.init(); - webpg.plugin = (webpg.plugin.valid) ? webpg.plugin : - webpg.background.webpg.plugin; - } - }, - - /* - Class: webpg.preferences.gpgconf - Provides methods to get/set the GPGCONF binary execututable - */ - gpgconf: { - /* - Function: get - Provides method to get the preference item - */ - get: function() { - var value = webpg.localStorage.getItem('gpgconf'); - return (value && value != -1) ? value : ''; - }, - - /* - Function: set - Provides method to set the preference item - - Parameters: - value - The string value for GPGCONF - */ - set: function(value) { - webpg.localStorage.setItem('gpgconf', value); - webpg.plugin.gpgSetGPGConf(value); - (webpg.background.hasOwnProperty("webpg")) ? - webpg.background.webpg.background.init() : - webpg.background.init(); - webpg.plugin = (webpg.plugin.valid) ? webpg.plugin : - webpg.background.webpg.plugin; - }, - - /* - Function: clear - Provides method to clear the preference item (erase/unset) - */ - clear: function(){ - webpg.localStorage.setItem('gpgconf', ''); - webpg.plugin.gpgSetGPGConf(''); - (webpg.background.hasOwnProperty("webpg")) ? - webpg.background.webpg.background.init() : - webpg.background.init(); - webpg.plugin = (webpg.plugin.valid) ? webpg.plugin : - webpg.background.webpg.plugin; - } - }, - - /* - Class: webpg.preferences.enabled_keys - Provides methods to get/set the "enabled_keys" preference - */ - enabled_keys: { - /* - Function: get - Provides method to get the preference item - */ - get: function() { - var value = webpg.localStorage.getItem('enabled_keys'); - return (value && value != -1) ? value.split(",") : []; - }, - - /* - Function: add - Provides method to add the preference item - - Parameters: - keyid - The KeyID to add to the list - */ - add: function(keyid) { - var keys_arr = this.get(); - keys_arr.push(keyid); - webpg.localStorage.setItem('enabled_keys', keys_arr); - }, - - /* - Function: remove - Provides method to remove the key from the preference item - - Parameters: - keyid - The KeyID to remove from the list - */ - remove: function(keyid) { - var keys_tmp = this.get(); - var keys_arr = []; - for (var key in keys_tmp) { - if (keys_tmp[key] != keyid) { - keys_arr.push(keys_tmp[key]); - } - } - webpg.localStorage.setItem('enabled_keys', keys_arr); - }, - - /* - Function: clear - Provides method to clear the preference item (erase/unset) - */ - clear: function(){ - webpg.localStorage.setItem('enabled_keys', ''); - }, - - /* - Function: length - Returns the length of items stored in preference - */ - length: function(){ - return this.get().length; - }, - - /* - Function: has - Determines if keyid is contained in the preference item - - Parameters: - keyid - The KeyID to look for; Returns true/false - */ - has: function(keyid){ - var key_arr = this.get(); - for (var i = 0; i < this.length(); i++) { - if (key_arr[i] == keyid) - return true; - } - return false; - } - }, - - /* - Class: webpg.preferences.default_key - Provides methods to get/set the "default_key" preference - */ - default_key: { - /* - Function: get - Provides method to get the preference item - */ - get: function() { - return webpg.plugin.gpgGetPreference('default-key').value; - }, - - /* - Function: set - Provides method to set the preference item - - Parameters: - keyid - The KeyID to add to the preference item - */ - set: function(keyid) { - if (webpg.preferences.encrypt_to_self.get() == 'true') { - webpg.plugin.gpgSetPreference("encrypt-to", keyid); - } - webpg.plugin.gpgSetPreference("default-key", keyid); - }, - - /* - Function: clear - Provides method to clear the preference item (erase/unset) - */ - clear: function() { - webpg.plugin.gpgSetPreference('default-key', 'blank'); - } - }, - - /* - Class: webpg.preferences.groups - Provides methods to create/manage groups - */ - group: { - /* - Function: get - Provides method to get the preference item - */ - get: function(group) { - var value = JSON.parse(webpg.localStorage.getItem('groups')); - return (value && value.hasOwnProperty(group)) ? value[group] : []; - }, - - /* - Function: get_groups - Provides method to get all defined groups - */ - get_group_names: function() { - var value = JSON.parse(webpg.localStorage.getItem('groups')); - return (value && typeof(value)=='object') ? Object.keys(value) : []; - }, - - /* - Function: get_groups_for_key - Provides method to get all defined groups - */ - get_groups_for_key: function(keyid) { - var groups = JSON.parse(webpg.localStorage.getItem('groups')); - var ingroups = []; - for (var group in groups) { - if (groups[group].indexOf(keyid) != -1) - ingroups.push(group); - } - return ingroups; - }, - - /* - Function: add - Provides method to add a recipient to the named group - - Parameters: - group - The group to add the recipient to - recipient - The recipient to add to the group - */ - add: function(group, recipient) { - if (!group && !recipient) - return "usage: add('group', 'recipient')"; - - // Get the currently defined group object (if any) and convert it - // to an object - var groups = webpg.localStorage.getItem('groups'); - groups = (groups && groups.length > 1) ? JSON.parse(groups) : {}; - - groups = (groups !== null) ? groups : {}; - - // Check if the groups object contains the named group, if not - // create it - if (!groups.hasOwnProperty(group)) - groups[group] = []; - - // Check if the recipient is alredy in the named group, if not - // add it - if (groups[group].indexOf(recipient) == -1) - groups[group].push(recipient); - else - return { 'error': false, 'group': group, 'modified': false}; - - // Convert the groups object back to a string and store it - webpg.localStorage.setItem('groups', JSON.stringify(groups)); - - // Set the group via gpgconf - var groupstr = - this.get(group).toString().replace(RegExp(",", "g"), " "); - - webpg.plugin.gpgSetGroup(group, groupstr); - - return { 'error': false, 'group': group, 'modified': true}; - }, - - /* - Function: remove - Provides method to remove a recipient from the named group - - Parameters: - group - The group to remove the recipient from - recipient - The recipient to remove from the group - */ - remove: function(group, recipient) { - // Get the currently defined group object (if any) and convert it - // to an object - var groups = JSON.parse(webpg.localStorage.getItem('groups')); - - groups = (groups !== null) ? groups : {}; - - // Check if the groups object contains the named group, if not - // create it - if (!groups.hasOwnProperty(group)) - groups[group] = []; - - // Check if the recipient is in the named group, if so - // remove it - var recipIndex = groups[group].indexOf(recipient); - if (recipIndex > -1) - groups[group].splice(recipIndex, 1); - else - return { 'error': false, 'group': group, 'modified': false}; - - // Convert the groups object back to a string and store it - webpg.localStorage.setItem('groups', JSON.stringify(groups)); - - // Set the modified group via gpgconf - var groupstr = - this.get(group).toString().replace(RegExp(",", "g"), " "); - - // Set the group, and retreive the entire gpgconf "group" string - var group_res = webpg.plugin.gpgSetGroup(group, groupstr); - -// // Check if there are any empty groups laying around -// if (group_res.indexOf("= ,") > -1 || group_res.search(new RegExp(/[^=]$/gm)) > -1) { -// group_res = group_res.split(", "); - -// // TODO: -// // FIXME: -// // The following kludge is due to the fact that, when removing the last -// // entry in a group, it leaves "group groupname =" in the gpg.conf file -// // since the npapi library does not (yet) permit removing the value entirely - -// // Clear all the groups -// webpg.plugin.gpgSetPreference("group", ""); -// // Iterate through the array of "group = values" -// for (var rgroup in group_res) { -// // check if this group contains a string like "groupname =" -// if (group_res[rgroup].length != group_res[rgroup].indexOf("=") + 1) { -// // Break out the group name it's values -// group_res[rgroup].replace( -// new RegExp("([^?=&]+)(=([^&]*))?", "g"), -// function($0, $1, $2, $3) { -// // Set the new group value -// webpg.plugin.gpgSetGroup($1.trim(), $3.trim()); -// } -// ); -// } -// } -// } - - return { 'error': false, 'group': group, 'modified': true}; - }, - - delete_group: function(group) { - var gpg_groups = webpg.plugin.gpgGetPreference("group"); - if (gpg_groups.value !== undefined) - groups = gpg_groups.value.split(", "); - else - return false; - - // Clear all the groups, and we will add them back without the group - // specified. - webpg.plugin.gpgSetPreference("group", ""); - - for (var rgroup in groups) { - // Break out the group name it's values - groups[rgroup].replace( - new RegExp("([^?=&]+)(=([^&]*))?", "g"), - function($0, $1, $2, $3) { - // Set the new group value - if ($1.trim() !== group) - webpg.plugin.gpgSetGroup($1.trim(), $3.trim()); - else - console.log("Removed '" + $1.trim() + "' from gpg.conf"); - } - ); - } - groups = JSON.parse(webpg.localStorage.getItem("groups")); - if (groups.hasOwnProperty(group)) { - delete groups[group]; - webpg.localStorage.setItem("groups", JSON.stringify(groups)); - console.log("Removed '" + group + "' from localStorage"); - } - }, - - /* - Function: refresh_from_config - Provides method to retrieve the group item(s) in gpg.conf - */ - refresh_from_config: function() { - if (!webpg.plugin.gpgGetPreference("group").error) { - var groups = webpg.plugin.gpgGetPreference("group").value.split(", "); - var groups_json = {}; - for (var rgroup in groups) { - if (groups[rgroup] === "") - return; - var g_v = groups[rgroup].split(" = "); - if (g_v.length > 1) - groups_json[g_v[0]] = g_v[1].split(" "); - } - webpg.localStorage.setItem('groups', JSON.stringify(groups_json)); - } - }, - - /* - Function: clear - Provides method to clear the preference item (erase/unset) - */ - clear: function() { - webpg.localStorage.setItem('groups', ''); - } - }, - - /* - Class: webpg.preferences.banner_version - Provides methods to get/set the "banner_version" preference - - */ - banner_version: { - /* - Function: get - Provides methods to get the preference item - */ - get: function() { - var value = webpg.localStorage.getItem('banner_version'); - return (value && value != -1) ? value : 0; - }, - - /* - Function: set - Provides method to set the preference item - - Parameters: - value - The boolean value to set - */ - set: function(value) { - webpg.localStorage.setItem('banner_version', value); - } - }, - - xoauth2_data: { - get: function() { - var stored_data = webpg.localStorage.getItem('xoauth2_data'); - return (stored_data && stored_data.length > 1) ? JSON.parse(stored_data) : {}; - }, - - set: function(data) { - webpg.localStorage.setItem('xoauth2_data', JSON.stringify(data)); - } - } -}; - -if (webpg.utils.detectedBrowser.product === "chrome") { - try { - webpg.browserWindow = chrome.extension.getBackgroundPage(); - } catch (err) { - // We must be loading from a non-background source, so the method - // chrome.extension.getBackgroundPage() is expected to fail. - webpg.browserWindow = null; - } - webpg.localStorage = window.localStorage; -} else if (webpg.utils.detectedBrowser.product === "safari") { - webpg.browserWindow = safari.extension.globalPage.contentWindow; - webpg.localStorage = window.localStorage; -// If this is Firefox, set up required objects -} else if (webpg.utils.detectedBrowser.vendor === "mozilla") { - webpg.browserWindow = webpg.utils.mozilla.getChromeWindow(); - // We are running on Mozilla, we need to set our localStorage object to - // use the 'mozilla.org/preference-service' - webpg.localStorage = { - getItem: function(item) { - var prefs = Components.classes["@mozilla.org/preferences-service;1"] - .getService(Components.interfaces.nsIPrefService).getBranch("extensions.webpg."); - var prefType = prefs.getPrefType(item); - return (prefType == 32) ? prefs.getCharPref(item) : - (prefType == 64) ? prefs.getIntPref(item).toString() : - (prefType == 128) ? prefs.getBoolPref(item).toString() : -1; - }, - setItem: function(item, value) { - value = (typeof(value) == "object") ? value.toString() : value; - var prefType = webpg.constants.ff_prefTypes[typeof(value)]; - var prefs = Components.classes["@mozilla.org/preferences-service;1"] - .getService(Components.interfaces.nsIPrefService).getBranch("extensions.webpg."); - return (prefType == 32) ? prefs.setCharPref(item, value) : - (prefType == 64) ? prefs.setIntPref(item, value) : - (prefType == 128) ? prefs.setBoolPref(item, value): -1; - } - }; -} else if (webpg.utils.detectedBrowser.vendor === "opera") { - webpg.browserWindow = opera.extension.bgProcess; - webpg.localStorage = window.localStorage; -} - -webpg.preferences.init(webpg.browserWindow); -/* ]]> */ +/* The boolean value to set + */ + set: function(value) { + webpg.localStorage.setItem('enabled', value); + } + }, + + /* + Class: webpg.preferences.decorate_inline + Provides methods to get/set the "decorate_inline" preference + */ + decorate_inline: { + /* + Function: get + Provides methods to get the preference item + */ + get: function() { + var value = webpg.localStorage.getItem('decorate_inline'); + return (value === null) ? "true" : value; + }, + + /* + Function: set + Provides method to set the preference item + + Parameters: + value - The boolean value to set + */ + set: function(value) { + webpg.localStorage.setItem('decorate_inline', value); + }, + + mode: function(value) { + if (typeof(value)!="undefined") { + webpg.localStorage.setItem('decorate_mode', value); + } else { + var mode = webpg.localStorage.getItem('decorate_mode'); + return (mode === null || mode === -1) ? "window" : mode; + } + } + }, + + render_toolbar: { + /* + Function: get + Provides methods to get the preference item + */ + get: function() { + var value = webpg.localStorage.getItem('render_toolbar'); + return (value === null) ? true : value; + }, + + /* + Function: set + Provides method to set the preference item + + Parameters: + value - The boolean value to set + */ + set: function(value) { + webpg.localStorage.setItem('render_toolbar', value); + } + }, + + /* + Class: webpg.preferences.gmail_integration + Provides methods to get/set the "gmail_integration" preference + */ + gmail_integration: { + /* + Function: get + Provides methods to get the preference item + */ + get: function() { + var value = webpg.localStorage.getItem('gmail_integration'); + return (value && value != -1) ? value : 'false'; + }, + + /* + Function: set + Provides method to set the preference item + + Parameters: + value - The boolean value to set + */ + set: function(value) { + webpg.localStorage.setItem('gmail_integration', value); + } + }, + + /* + Class: webpg.preferences.gmail_action + Provides methods to get/set the "gmail_action" preference + + 0: Do not use WebPG by default for gmail messages + 1: Encrypt by default for gmail messages + 2: Sign by default for gmail messages + 3: Sign & Encrypt by default for gmail messages + 4: Symmetric Encryption by default for gmail messages + + */ + sign_gmail: { + /* + Function: get + Provides methods to get the preference item + */ + get: function() { + var value = webpg.localStorage.getItem('sign_gmail'); + return (value && value != -1) ? value : 'false'; + }, + + /* + Function: set + Provides method to set the preference item + + Parameters: + value - The boolean value to set + */ + set: function(value) { + webpg.localStorage.setItem('sign_gmail', value); + } + }, + + /* + Class: webpg.preferences.encrypt_to_self + Provides methods to get/set the "encrypt_to_self" preference + */ + encrypt_to_self: { + /* + Function: get + Provides method to get the preference item + */ + get: function() { + try { + var encrypt_to = webpg.plugin.gpgGetPreference('encrypt-to').value; + var default_key = webpg.plugin.gpgGetPreference('default-key').value; + var encrypt_to_self = (default_key !== "" && encrypt_to === default_key) ? 'true' : 'false'; + webpg.localStorage.setItem('encrypt_to_self', encrypt_to_self); + return encypt_to_self; + } catch (e) { + return webpg.localStorage.getItem('encrypt_to_self'); + } + }, + + /* + Function: set + Provides method to set the preference item + + Parameters: + value - The KeyID to set as the default key + */ + set: function(value) { + // if this setting is disabled, remove the value for 'encrypt-to' + if (!value) { + webpg.plugin.gpgSetPreference('encrypt-to', 'blank'); + } else { + var default_key = webpg.preferences.default_key.get(); + webpg.plugin.gpgSetPreference('encrypt-to', default_key); + } + } + }, + + /* + Class: webpg.preferences.gnupghome + Provides methods to get/set the "gnupghome" preference + */ + gnupghome: { + /* + Function: get + Provides method to get the preference item + */ + get: function() { + var value = webpg.localStorage.getItem('gnupghome'); + return (value && value != -1) ? value : ''; + }, + + /* + Function: set + Provides method to set the preference item + + Parameters: + value - The string value for GNUPGHOME + */ + set: function(value) { + webpg.localStorage.setItem('gnupghome', value); + webpg.plugin.gpgSetHomeDir(value); + (webpg.background.hasOwnProperty("webpg")) ? + webpg.background.webpg.background.init() : + webpg.background.init(); + webpg.plugin = (webpg.plugin.valid) ? webpg.plugin : + webpg.background.webpg.plugin; + }, + + /* + Function: clear + Provides method to clear the preference item (erase/unset) + */ + clear: function(){ + webpg.localStorage.setItem('gnupghome', ''); + webpg.plugin.gpgSetHomeDir(''); + (webpg.background.hasOwnProperty("webpg")) ? + webpg.background.webpg.background.init() : + webpg.background.init(); + webpg.plugin = (webpg.plugin.valid) ? webpg.plugin : + webpg.background.webpg.plugin; + } + }, + + /* + Class: webpg.preferences.gnupgbin + Provides methods to get/set the GnuPG binary execututable + */ + gnupgbin: { + /* + Function: get + Provides method to get the preference item + */ + get: function() { + var value = webpg.localStorage.getItem('gnupgbin'); + return (value && value != -1) ? value : ''; + }, + + /* + Function: set + Provides method to set the preference item + + Parameters: + value - The string value for GNUPGHOME + */ + set: function(value) { + webpg.localStorage.setItem('gnupgbin', value); + webpg.plugin.gpgSetBinary(value); + (webpg.background.hasOwnProperty("webpg")) ? + webpg.background.webpg.background.init() : + webpg.background.init(); + webpg.plugin = (webpg.plugin.valid) ? webpg.plugin : + webpg.background.webpg.plugin; + }, + + /* + Function: clear + Provides method to clear the preference item (erase/unset) + */ + clear: function(){ + webpg.localStorage.setItem('gnupgbin', ''); + webpg.plugin.gpgSetBinary(''); + (webpg.background.hasOwnProperty("webpg")) ? + webpg.background.webpg.background.init() : + webpg.background.init(); + webpg.plugin = (webpg.plugin.valid) ? webpg.plugin : + webpg.background.webpg.plugin; + } + }, + + /* + Class: webpg.preferences.gpgconf + Provides methods to get/set the GPGCONF binary execututable + */ + gpgconf: { + /* + Function: get + Provides method to get the preference item + */ + get: function() { + var value = webpg.localStorage.getItem('gpgconf'); + return (value && value != -1) ? value : ''; + }, + + /* + Function: set + Provides method to set the preference item + + Parameters: + value - The string value for GPGCONF + */ + set: function(value) { + webpg.localStorage.setItem('gpgconf', value); + webpg.plugin.gpgSetGPGConf(value); + (webpg.background.hasOwnProperty("webpg")) ? + webpg.background.webpg.background.init() : + webpg.background.init(); + webpg.plugin = (webpg.plugin.valid) ? webpg.plugin : + webpg.background.webpg.plugin; + }, + + /* + Function: clear + Provides method to clear the preference item (erase/unset) + */ + clear: function(){ + webpg.localStorage.setItem('gpgconf', ''); + webpg.plugin.gpgSetGPGConf(''); + (webpg.background.hasOwnProperty("webpg")) ? + webpg.background.webpg.background.init() : + webpg.background.init(); + webpg.plugin = (webpg.plugin.valid) ? webpg.plugin : + webpg.background.webpg.plugin; + } + }, + + /* + Class: webpg.preferences.enabled_keys + Provides methods to get/set the "enabled_keys" preference + */ + enabled_keys: { + /* + Function: get + Provides method to get the preference item + */ + get: function() { + var value = webpg.localStorage.getItem('enabled_keys'); + return (value && value != -1) ? value.split(",") : []; + }, + + /* + Function: add + Provides method to add the preference item + + Parameters: + keyid - The KeyID to add to the list + */ + add: function(keyid) { + var keys_arr = this.get(); + keys_arr.push(keyid); + webpg.localStorage.setItem('enabled_keys', keys_arr); + }, + + /* + Function: remove + Provides method to remove the key from the preference item + + Parameters: + keyid - The KeyID to remove from the list + */ + remove: function(keyid) { + var keys_tmp = this.get(); + var keys_arr = []; + for (var key in keys_tmp) { + if (keys_tmp[key] != keyid) { + keys_arr.push(keys_tmp[key]); + } + } + webpg.localStorage.setItem('enabled_keys', keys_arr); + }, + + /* + Function: clear + Provides method to clear the preference item (erase/unset) + */ + clear: function(){ + webpg.localStorage.setItem('enabled_keys', ''); + }, + + /* + Function: length + Returns the length of items stored in preference + */ + length: function(){ + return this.get().length; + }, + + /* + Function: has + Determines if keyid is contained in the preference item + + Parameters: + keyid - The KeyID to look for; Returns true/false + */ + has: function(keyid){ + var key_arr = this.get(); + for (var i = 0; i < this.length(); i++) { + if (key_arr[i] == keyid) + return true; + } + return false; + } + }, + + /* + Class: webpg.preferences.default_key + Provides methods to get/set the "default_key" preference + */ + default_key: { + /* + Function: get + Provides method to get the preference item + */ + get: function() { + return webpg.plugin.gpgGetPreference('default-key').value; + }, + + /* + Function: set + Provides method to set the preference item + + Parameters: + keyid - The KeyID to add to the preference item + */ + set: function(keyid) { + if (webpg.preferences.encrypt_to_self.get() == 'true') { + webpg.plugin.gpgSetPreference("encrypt-to", keyid); + } + webpg.plugin.gpgSetPreference("default-key", keyid); + }, + + /* + Function: clear + Provides method to clear the preference item (erase/unset) + */ + clear: function() { + webpg.plugin.gpgSetPreference('default-key', 'blank'); + } + }, + + /* + Class: webpg.preferences.groups + Provides methods to create/manage groups + */ + group: { + /* + Function: get + Provides method to get the preference item + */ + get: function(group) { + var value = JSON.parse(webpg.localStorage.getItem('groups')); + return (value && value.hasOwnProperty(group)) ? value[group] : []; + }, + + /* + Function: get_groups + Provides method to get all defined groups + */ + get_group_names: function() { + var value = JSON.parse(webpg.localStorage.getItem('groups')); + return (value && typeof(value)=='object') ? Object.keys(value) : []; + }, + + /* + Function: get_groups_for_key + Provides method to get all defined groups + */ + get_groups_for_key: function(keyid) { + var groups = JSON.parse(webpg.localStorage.getItem('groups')); + var ingroups = []; + for (var group in groups) { + if (groups[group].indexOf(keyid) != -1) + ingroups.push(group); + } + return ingroups; + }, + + /* + Function: add + Provides method to add a recipient to the named group + + Parameters: + group - The group to add the recipient to + recipient - The recipient to add to the group + */ + add: function(group, recipient) { + if (!group && !recipient) + return "usage: add('group', 'recipient')"; + + // Get the currently defined group object (if any) and convert it + // to an object + var groups = webpg.localStorage.getItem('groups'); + groups = (groups && groups.length > 1) ? JSON.parse(groups) : {}; + + groups = (groups !== null) ? groups : {}; + + // Check if the groups object contains the named group, if not + // create it + if (!groups.hasOwnProperty(group)) + groups[group] = []; + + // Check if the recipient is alredy in the named group, if not + // add it + if (groups[group].indexOf(recipient) == -1) + groups[group].push(recipient); + else + return { 'error': false, 'group': group, 'modified': false}; + + // Convert the groups object back to a string and store it + webpg.localStorage.setItem('groups', JSON.stringify(groups)); + + // Set the group via gpgconf + var groupstr = + this.get(group).toString().replace(RegExp(",", "g"), " "); + + webpg.plugin.gpgSetGroup(group, groupstr); + + return { 'error': false, 'group': group, 'modified': true}; + }, + + /* + Function: remove + Provides method to remove a recipient from the named group + + Parameters: + group - The group to remove the recipient from + recipient - The recipient to remove from the group + */ + remove: function(group, recipient) { + // Get the currently defined group object (if any) and convert it + // to an object + var groups = JSON.parse(webpg.localStorage.getItem('groups')); + + groups = (groups !== null) ? groups : {}; + + // Check if the groups object contains the named group, if not + // create it + if (!groups.hasOwnProperty(group)) + groups[group] = []; + + // Check if the recipient is in the named group, if so + // remove it + var recipIndex = groups[group].indexOf(recipient); + if (recipIndex > -1) + groups[group].splice(recipIndex, 1); + else + return { 'error': false, 'group': group, 'modified': false}; + + // Convert the groups object back to a string and store it + webpg.localStorage.setItem('groups', JSON.stringify(groups)); + + // Set the modified group via gpgconf + var groupstr = + this.get(group).toString().replace(RegExp(",", "g"), " "); + + // Set the group, and retreive the entire gpgconf "group" string + var group_res = webpg.plugin.gpgSetGroup(group, groupstr); + +// // Check if there are any empty groups laying around +// if (group_res.indexOf("= ,") > -1 || group_res.search(new RegExp(/[^=]$/gm)) > -1) { +// group_res = group_res.split(", "); + +// // TODO: +// // FIXME: +// // The following kludge is due to the fact that, when removing the last +// // entry in a group, it leaves "group groupname =" in the gpg.conf file +// // since the npapi library does not (yet) permit removing the value entirely + +// // Clear all the groups +// webpg.plugin.gpgSetPreference("group", ""); +// // Iterate through the array of "group = values" +// for (var rgroup in group_res) { +// // check if this group contains a string like "groupname =" +// if (group_res[rgroup].length != group_res[rgroup].indexOf("=") + 1) { +// // Break out the group name it's values +// group_res[rgroup].replace( +// new RegExp("([^?=&]+)(=([^&]*))?", "g"), +// function($0, $1, $2, $3) { +// // Set the new group value +// webpg.plugin.gpgSetGroup($1.trim(), $3.trim()); +// } +// ); +// } +// } +// } + + return { 'error': false, 'group': group, 'modified': true}; + }, + + delete_group: function(group) { + var gpg_groups = webpg.plugin.gpgGetPreference("group"); + if (gpg_groups.value !== undefined) + groups = gpg_groups.value.split(", "); + else + return false; + + // Clear all the groups, and we will add them back without the group + // specified. + webpg.plugin.gpgSetPreference("group", ""); + + for (var rgroup in groups) { + // Break out the group name it's values + groups[rgroup].replace( + new RegExp("([^?=&]+)(=([^&]*))?", "g"), + function($0, $1, $2, $3) { + // Set the new group value + if ($1.trim() !== group) + webpg.plugin.gpgSetGroup($1.trim(), $3.trim()); + else + console.log("Removed '" + $1.trim() + "' from gpg.conf"); + } + ); + } + groups = JSON.parse(webpg.localStorage.getItem("groups")); + if (groups.hasOwnProperty(group)) { + delete groups[group]; + webpg.localStorage.setItem("groups", JSON.stringify(groups)); + console.log("Removed '" + group + "' from localStorage"); + } + }, + + /* + Function: refresh_from_config + Provides method to retrieve the group item(s) in gpg.conf + */ + refresh_from_config: function() { + if (!webpg.plugin.gpgGetPreference("group").error) { + var groups = webpg.plugin.gpgGetPreference("group").value.split(", "); + var groups_json = {}; + for (var rgroup in groups) { + if (groups[rgroup] === "") + return; + var g_v = groups[rgroup].split(" = "); + if (g_v.length > 1) + groups_json[g_v[0]] = g_v[1].split(" "); + } + webpg.localStorage.setItem('groups', JSON.stringify(groups_json)); + } + }, + + /* + Function: clear + Provides method to clear the preference item (erase/unset) + */ + clear: function() { + webpg.localStorage.setItem('groups', ''); + } + }, + + /* + Class: webpg.preferences.banner_version + Provides methods to get/set the "banner_version" preference + + */ + banner_version: { + /* + Function: get + Provides methods to get the preference item + */ + get: function() { + var value = webpg.localStorage.getItem('banner_version'); + return (value && value != -1) ? value : 0; + }, + + /* + Function: set + Provides method to set the preference item + + Parameters: + value - The boolean value to set + */ + set: function(value) { + webpg.localStorage.setItem('banner_version', value); + } + }, + + xoauth2_data: { + get: function() { + var stored_data = webpg.localStorage.getItem('xoauth2_data'); + return (stored_data && stored_data.length > 1) ? JSON.parse(stored_data) : {}; + }, + + set: function(data) { + webpg.localStorage.setItem('xoauth2_data', JSON.stringify(data)); + } + }, + + /* + Class: webpg.preferences.site_exceptions + Provides methods to get/set the "site_exceptions" user white & blacklists. + */ + site_exceptions: { + get: function() { + var stored_data = webpg.localStorage.getItem('site_exceptions'); + var site_exceptions = webpg.utils.tryParseJSON(stored_data); + return (site_exceptions) ? site_exceptions : { whitelist: [], blacklist: [] }; + }, + + add: function(type, site) { + var site_exceptions = webpg.preferences.site_exceptions.get(); + if (type == "whitelist") { + site_exceptions.whitelist.push(site); + } + else if (type == "blacklist") { + site_exceptions.blacklist.push(site); + } + else + { + alert("Code error in site_exceptions preference handler."); + } + + return webpg.localStorage.setItem('site_exceptions', JSON.stringify(site_exceptions)); + }, + + remove: function(type, site) { + var site_exceptions = webpg.preferences.site_exceptions.get(); + if (type == "whitelist") { + site_exceptions.whitelist.splice(webpg.jq.inArray(site, site_exceptions), 1); + } + else if (type == "blacklist") { + site_exceptions.blacklist.splice(webpg.jq.inArray(site, site_exceptions), 1); + } + else + { + alert("Code error in site_exceptions preference handler."); + } + + return webpg.localStorage.setItem('site_exceptions', JSON.stringify(site_exceptions)); + }, + + mode: function(value) { + if (!value) + return webpg.localStorage.getItem('site_filtering_mode'); + + return webpg.localStorage.setItem('site_filtering_mode', value); + } + }, + +}; + +if (webpg.utils.detectedBrowser.product === "chrome") { + try { + webpg.browserWindow = chrome.extension.getBackgroundPage(); + } catch (err) { + // We must be loading from a non-background source, so the method + // chrome.extension.getBackgroundPage() is expected to fail. + webpg.browserWindow = null; + } + webpg.localStorage = window.localStorage; +} else if (webpg.utils.detectedBrowser.product === "safari") { + webpg.browserWindow = safari.extension.globalPage.contentWindow; + webpg.localStorage = window.localStorage; +// If this is Firefox, set up required objects +} else if (webpg.utils.detectedBrowser.vendor === "mozilla") { + webpg.browserWindow = webpg.utils.mozilla.getChromeWindow(); + // We are running on Mozilla, we need to set our localStorage object to + // use the 'mozilla.org/preference-service' + webpg.localStorage = { + getItem: function(item) { + var prefs = Components.classes["@mozilla.org/preferences-service;1"] + .getService(Components.interfaces.nsIPrefService).getBranch("extensions.webpg."); + var prefType = prefs.getPrefType(item); + return (prefType == 32) ? prefs.getCharPref(item) : + (prefType == 64) ? prefs.getIntPref(item).toString() : + (prefType == 128) ? prefs.getBoolPref(item).toString() : -1; + }, + setItem: function(item, value) { + value = (typeof(value) == "object") ? value.toString() : value; + var prefType = webpg.constants.ff_prefTypes[typeof(value)]; + var prefs = Components.classes["@mozilla.org/preferences-service;1"] + .getService(Components.interfaces.nsIPrefService).getBranch("extensions.webpg."); + return (prefType == 32) ? prefs.setCharPref(item, value) : + (prefType == 64) ? prefs.setIntPref(item, value) : + (prefType == 128) ? prefs.setBoolPref(item, value): -1; + } + }; +} else if (webpg.utils.detectedBrowser.vendor === "opera") { + webpg.browserWindow = opera.extension.bgProcess; + webpg.localStorage = window.localStorage; +} + +webpg.preferences.init(webpg.browserWindow); +/* ]]> */ diff --git a/extension/resources/jquery/js/URI.js b/extension/resources/jquery/js/URI.js new file mode 100644 index 0000000..2b2c774 --- /dev/null +++ b/extension/resources/jquery/js/URI.js @@ -0,0 +1,58 @@ +/*! URI.js v1.11.2 http://medialize.github.com/URI.js/ */ +/* build contains: IPv6.js, URI.js, jquery.URI.js */ +(function(f,k){"object"===typeof exports?module.exports=k():"function"===typeof define&&define.amd?define(k):f.IPv6=k(f)})(this,function(f){var k=f&&f.IPv6;return{best:function(g){g=g.toLowerCase().split(":");var f=g.length,d=8;""===g[0]&&""===g[1]&&""===g[2]?(g.shift(),g.shift()):""===g[0]&&""===g[1]?g.shift():""===g[f-1]&&""===g[f-2]&&g.pop();f=g.length;-1!==g[f-1].indexOf(".")&&(d=7);var l;for(l=0;lk;k++)if("0"===f[0]&&1k&&(f=r,k=n)):"0"==g[l]&&(s=!0,r=l,n=1);n>k&&(f=r,k=n);1]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?\u00ab\u00bb\u201c\u201d\u2018\u2019]))/ig;d.defaultPorts={http:"80",https:"443",ftp:"21",gopher:"70",ws:"80",wss:"443"};d.invalid_hostname_characters=/[^a-zA-Z0-9\.-]/;d.domAttributes={a:"href",blockquote:"cite",link:"href",base:"href",script:"src",form:"action",img:"src",area:"href", +iframe:"src",embed:"src",source:"src",track:"src",input:"src"};d.getDomAttribute=function(a){if(a&&a.nodeName){var b=a.nodeName.toLowerCase();return"input"===b&&"image"!==a.type?void 0:d.domAttributes[b]}};d.encode=h;d.decode=decodeURIComponent;d.iso8859=function(){d.encode=escape;d.decode=unescape};d.unicode=function(){d.encode=h;d.decode=decodeURIComponent};d.characters={pathname:{encode:{expression:/%(24|26|2B|2C|3B|3D|3A|40)/ig,map:{"%24":"$","%26":"&","%2B":"+","%2C":",","%3B":";","%3D":"=", +"%3A":":","%40":"@"}},decode:{expression:/[\/\?#]/g,map:{"/":"%2F","?":"%3F","#":"%23"}}},reserved:{encode:{expression:/%(21|23|24|26|27|28|29|2A|2B|2C|2F|3A|3B|3D|3F|40|5B|5D)/ig,map:{"%3A":":","%2F":"/","%3F":"?","%23":"#","%5B":"[","%5D":"]","%40":"@","%21":"!","%24":"$","%26":"&","%27":"'","%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%3B":";","%3D":"="}}}};d.encodeQuery=function(a,b){var c=d.encode(a+"");return b?c.replace(/%20/g,"+"):c};d.decodeQuery=function(a,b){a+="";try{return d.decode(b? +a.replace(/\+/g,"%20"):a)}catch(c){return a}};d.recodePath=function(a){a=(a+"").split("/");for(var b=0,c=a.length;bd)return a.charAt(0)===b.charAt(0)&&"/"===a.charAt(0)?"/":"";if("/"!==a.charAt(d)||"/"!==b.charAt(d))d=a.substring(0,d).lastIndexOf("/");return a.substring(0,d+1)};d.withinString=function(a,b){return a.replace(d.find_uri_expression,b)};d.ensureValidHostname=function(a){if(a.match(d.invalid_hostname_characters)){if(!f)throw new TypeError("Hostname '"+a+"' contains characters other than [A-Z0-9.-] and Punycode.js is not available");if(f.toASCII(a).match(d.invalid_hostname_characters))throw new TypeError("Hostname '"+ +a+"' contains characters other than [A-Z0-9.-]");}};d.noConflict=function(a){if(a)return a={URI:this.noConflict()},URITemplate&&"function"==typeof URITemplate.noConflict&&(a.URITemplate=URITemplate.noConflict()),k&&"function"==typeof k.noConflict&&(a.IPv6=k.noConflict()),SecondLevelDomains&&"function"==typeof SecondLevelDomains.noConflict&&(a.SecondLevelDomains=SecondLevelDomains.noConflict()),a;w.URI===this&&(w.URI=t);return this};e.build=function(a){if(!0===a)this._deferred_build=!0;else if(void 0=== +a||this._deferred_build)this._string=d.build(this._parts),this._deferred_build=!1;return this};e.clone=function(){return new d(this)};e.valueOf=e.toString=function(){return this.build(!1)._string};q={protocol:"protocol",username:"username",password:"password",hostname:"hostname",port:"port"};v=function(a){return function(b,c){if(void 0===b)return this._parts[a]||"";this._parts[a]=b||null;this.build(!c);return this}};for(p in q)e[p]=v(q[p]);q={query:"?",fragment:"#"};v=function(a,b){return function(c, +d){if(void 0===c)return this._parts[a]||"";null!==c&&(c+="",c.charAt(0)===b&&(c=c.substring(1)));this._parts[a]=c;this.build(!d);return this}};for(p in q)e[p]=v(p,q[p]);q={search:["?","query"],hash:["#","fragment"]};v=function(a,b){return function(c,d){var e=this[a](c,d);return"string"===typeof e&&e.length?b+e:e}};for(p in q)e[p]=v(q[p][1],q[p][0]);e.pathname=function(a,b){if(void 0===a||!0===a){var c=this._parts.path||(this._parts.hostname?"/":"");return a?d.decodePath(c):c}this._parts.path=a?d.recodePath(a): +"/";this.build(!b);return this};e.path=e.pathname;e.href=function(a,b){var c;if(void 0===a)return this.toString();this._string="";this._parts=d._parts();var m=a instanceof d,e="object"===typeof a&&(a.hostname||a.path||a.pathname);a.nodeName&&(e=d.getDomAttribute(a),a=a[e]||"",e=!1);!m&&e&&void 0!==a.pathname&&(a=a.toString());if("string"===typeof a)this._parts=d.parse(a,this._parts);else if(m||e)for(c in m=m?a._parts:a,m)u.call(this._parts,c)&&(this._parts[c]=m[c]);else throw new TypeError("invalid input"); +this.build(!b);return this};e.is=function(a){var b=!1,c=!1,e=!1,f=!1,h=!1,t=!1,k=!1,l=!this._parts.urn;this._parts.hostname&&(l=!1,c=d.ip4_expression.test(this._parts.hostname),e=d.ip6_expression.test(this._parts.hostname),b=c||e,h=(f=!b)&&g&&g.has(this._parts.hostname),t=f&&d.idn_expression.test(this._parts.hostname),k=f&&d.punycode_expression.test(this._parts.hostname));switch(a.toLowerCase()){case "relative":return l;case "absolute":return!l;case "domain":case "name":return f;case "sld":return h; +case "ip":return b;case "ip4":case "ipv4":case "inet4":return c;case "ip6":case "ipv6":case "inet6":return e;case "idn":return t;case "url":return!this._parts.urn;case "urn":return!!this._parts.urn;case "punycode":return k}return null};var z=e.protocol,A=e.port,B=e.hostname;e.protocol=function(a,b){if(void 0!==a&&a&&(a=a.replace(/:(\/\/)?$/,""),a.match(/[^a-zA-z0-9\.+-]/)))throw new TypeError("Protocol '"+a+"' contains characters other than [A-Z0-9.+-]");return z.call(this,a,b)};e.scheme=e.protocol; +e.port=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0!==a&&(0===a&&(a=null),a&&(a+="",":"===a.charAt(0)&&(a=a.substring(1)),a.match(/[^0-9]/))))throw new TypeError("Port '"+a+"' contains characters other than [0-9]");return A.call(this,a,b)};e.hostname=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0!==a){var c={};d.parseHost(a,c);a=c.hostname}return B.call(this,a,b)};e.host=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a)return this._parts.hostname? +d.buildHost(this._parts):"";d.parseHost(a,this._parts);this.build(!b);return this};e.authority=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a)return this._parts.hostname?d.buildAuthority(this._parts):"";d.parseAuthority(a,this._parts);this.build(!b);return this};e.userinfo=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a){if(!this._parts.username)return"";var c=d.buildUserinfo(this._parts);return c.substring(0,c.length-1)}"@"!==a[a.length-1]&&(a+= +"@");d.parseUserinfo(a,this._parts);this.build(!b);return this};e.resource=function(a,b){var c;if(void 0===a)return this.path()+this.search()+this.hash();c=d.parse(a);this._parts.path=c.path;this._parts.query=c.query;this._parts.fragment=c.fragment;this.build(!b);return this};e.subdomain=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a){if(!this._parts.hostname||this.is("IP"))return"";var c=this._parts.hostname.length-this.domain().length-1;return this._parts.hostname.substring(0, +c)||""}c=this._parts.hostname.length-this.domain().length;c=this._parts.hostname.substring(0,c);c=RegExp("^"+l(c));a&&"."!==a.charAt(a.length-1)&&(a+=".");a&&d.ensureValidHostname(a);this._parts.hostname=this._parts.hostname.replace(c,a);this.build(!b);return this};e.domain=function(a,b){if(this._parts.urn)return void 0===a?"":this;"boolean"===typeof a&&(b=a,a=void 0);if(void 0===a){if(!this._parts.hostname||this.is("IP"))return"";var c=this._parts.hostname.match(/\./g);if(c&&2>c.length)return this._parts.hostname; +c=this._parts.hostname.length-this.tld(b).length-1;c=this._parts.hostname.lastIndexOf(".",c-1)+1;return this._parts.hostname.substring(c)||""}if(!a)throw new TypeError("cannot set domain empty");d.ensureValidHostname(a);!this._parts.hostname||this.is("IP")?this._parts.hostname=a:(c=RegExp(l(this.domain())+"$"),this._parts.hostname=this._parts.hostname.replace(c,a));this.build(!b);return this};e.tld=function(a,b){if(this._parts.urn)return void 0===a?"":this;"boolean"===typeof a&&(b=a,a=void 0);if(void 0=== +a){if(!this._parts.hostname||this.is("IP"))return"";var c=this._parts.hostname.lastIndexOf("."),c=this._parts.hostname.substring(c+1);return!0!==b&&g&&g.list[c.toLowerCase()]?g.get(this._parts.hostname)||c:c}if(a)if(a.match(/[^a-zA-Z0-9-]/))if(g&&g.is(a))c=RegExp(l(this.tld())+"$"),this._parts.hostname=this._parts.hostname.replace(c,a);else throw new TypeError("TLD '"+a+"' contains characters other than [A-Z0-9]");else{if(!this._parts.hostname||this.is("IP"))throw new ReferenceError("cannot set TLD on non-domain host"); +c=RegExp(l(this.tld())+"$");this._parts.hostname=this._parts.hostname.replace(c,a)}else throw new TypeError("cannot set TLD empty");this.build(!b);return this};e.directory=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a||!0===a){if(!this._parts.path&&!this._parts.hostname)return"";if("/"===this._parts.path)return"/";var c=this._parts.path.length-this.filename().length-1,c=this._parts.path.substring(0,c)||(this._parts.hostname?"/":"");return a?d.decodePath(c):c}c=this._parts.path.length- +this.filename().length;c=this._parts.path.substring(0,c);c=RegExp("^"+l(c));this.is("relative")||(a||(a="/"),"/"!==a.charAt(0)&&(a="/"+a));a&&"/"!==a.charAt(a.length-1)&&(a+="/");a=d.recodePath(a);this._parts.path=this._parts.path.replace(c,a);this.build(!b);return this};e.filename=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a||!0===a){if(!this._parts.path||"/"===this._parts.path)return"";var c=this._parts.path.lastIndexOf("/"),c=this._parts.path.substring(c+1);return a? +d.decodePathSegment(c):c}c=!1;"/"===a.charAt(0)&&(a=a.substring(1));a.match(/\.?\//)&&(c=!0);var e=RegExp(l(this.filename())+"$");a=d.recodePath(a);this._parts.path=this._parts.path.replace(e,a);c?this.normalizePath(b):this.build(!b);return this};e.suffix=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a||!0===a){if(!this._parts.path||"/"===this._parts.path)return"";var c=this.filename(),e=c.lastIndexOf(".");if(-1===e)return"";c=c.substring(e+1);c=/^[a-z0-9%]+$/i.test(c)?c: +"";return a?d.decodePathSegment(c):c}"."===a.charAt(0)&&(a=a.substring(1));if(c=this.suffix())e=a?RegExp(l(c)+"$"):RegExp(l("."+c)+"$");else{if(!a)return this;this._parts.path+="."+d.recodePath(a)}e&&(a=d.recodePath(a),this._parts.path=this._parts.path.replace(e,a));this.build(!b);return this};e.segment=function(a,b,c){var d=this._parts.urn?":":"/",e=this.path(),f="/"===e.substring(0,1),e=e.split(d);void 0!==a&&"number"!==typeof a&&(c=b,b=a,a=void 0);if(void 0!==a&&"number"!==typeof a)throw Error("Bad segment '"+ +a+"', must be 0-based integer");f&&e.shift();0>a&&(a=Math.max(e.length+a,0));if(void 0===b)return void 0===a?e:e[a];if(null===a||void 0===e[a])if(n(b)){e=[];a=0;for(var h=b.length;a The JSON to try and parse + + Returns: + - An object of the parsed JSON (false on failure) + */ + tryParseJSON: function(jsonString){ + try { + var o = JSON.parse(jsonString); + + // Handle non-exception-throwing cases: + //JSON.parse(null) returns 'null', and typeof null === "object" + if (o && typeof o === "object" && o !== null) { + return o; + } + } + catch (e) { } + + return false; + }, + + /* + Function: unique + Returns a copy of a string array without any duplicate values + + Parameters: + array - string[] The array to unique + + Returns: + string[] - The copy without duplicates + */ + unique: function(list) { + var result = []; + webpg.jq.each(list, function(i, e) { + if (webpg.jq.inArray(e, result) == -1) result.push(e); + }); + return result; + }, formatSearchParameter: function(item) { var pParam = item.split(":")[0]; diff --git a/extension/webpg_overlay.js b/extension/webpg_overlay.js index 21ba75e..bb4d289 100644 --- a/extension/webpg_overlay.js +++ b/extension/webpg_overlay.js @@ -119,15 +119,36 @@ webpg.overlay = { } }; // Check if inline formatting is enabled and setup - // required parsers + // required parsers webpg.utils.sendRequest({ 'msg': "decorate_inline" }, function(response) { webpg.overlay.decorate_inline = response.result.decorate_inline; - if (webpg.overlay.decorate_inline === 'true') { + if (webpg.overlay.decorate_inline === 'true') + { + var filtering_mode = response.result.filtering_mode; + if (filtering_mode != "off") + { + var site_exceptions = response.result.site_exceptions; + var this_uri = webpg.doc.location.href; + //this_uri.normalize(); + + if (filtering_mode == "deny-allow") { + // Must be in the whitelist to continue + if (!(site_exceptions.whitelist.indexOf(this_uri) > -1)) + return; + } + else if (filtering_mode == "allow-deny") { + // Only stop if in blacklist + if (site_exceptions.blacklist.indexOf(this_uri) > -1) + return; + } + } + webpg.inline.mode = response.result.mode; webpg.inline.render_toolbar = response.result.render_toolbar; - if (webpg.utils.detectedBrowser.vendor === 'mozilla') { + if (webpg.utils.detectedBrowser.vendor === 'mozilla') + { if (typeof(browserWindow)==='undefined') browserWindow = webpg.utils.mozilla.getChromeWindow(); if (!webpg.plugin) @@ -642,10 +663,10 @@ if (webpg.utils.detectedBrowser.vendor === 'mozilla') { } else { webpg.appcontent = document.getElementById("appcontent") || document; webpg.appcontent.addEventListener("DOMContentLoaded", webpg.overlay.init, false); - webpg.appcontent.addEventListener("scroll", webpg.overlay.executeInline, true); + //webpg.appcontent.addEventListener("scroll", webpg.overlay.executeInline, true); } } else { webpg.overlay.init(); - window.addEventListener("scroll", webpg.overlay.executeInline, true); + //window.addEventListener("scroll", webpg.overlay.executeInline, true); } /* ]]> */ diff --git a/extension/webpg_results.js b/extension/webpg_results.js index cf84cef..1216285 100644 --- a/extension/webpg_results.js +++ b/extension/webpg_results.js @@ -1,692 +1,692 @@ -/* 10) - webpg.inline_results.mouseCount = 0; - }); - webpg.jq(window).bind("mouseout", - function(event) { - document.querySelector('.webpg-results-trusted-hover').textContent = ""; - webpg.utils.setStatusBarText(""); - } - ); - }, - - /* - Function: doResize - Resizes the parent iframe by sending a request to the listener of - the webpg.background object - - Parameters: - scrollTop - Indicates if the parent window should scroll to the top of the frame - */ - doResize: function(scrollTop) { - if (webpg.utils.isRTL()) { - webpg.jq(".signed_text_header").addClass("rtl"); - webpg.jq(".results-control").addClass("rtl"); - webpg.jq(".webpg-results-trusted-hover").addClass("rtl"); - webpg.jq(".signed_text").addClass("rtl"); - webpg.jq(".signature-box").addClass("rtl"); - webpg.jq(".footer").addClass("rtl"); - webpg.jq(".footer_icon").addClass("rtl"); - } - var block_height = webpg.jq(".pgp_block_container")[0].scrollHeight; - var body_height = document.body.scrollHeight; - var height = webpg.jq(".pgp_block_container")[0].scrollHeight + webpg.jq("#footer")[0].scrollHeight + 40; - height = (height < body_height) ? height : body_height; - - webpg.utils.sendRequest({ - 'msg': 'sendtoiframe', - 'iframe_id': webpg.inline_results.qs.id, - 'width': null, - 'height': height, - 'scrollTop': scrollTop - }); - }, - - /* - Function: createSignatureBox - Creates an HTML element with information concerning a signature - - Parameters: - sigObj - An object with information about a signature - sigIdx - The index of the signature within the keyring - */ - // TODO: Maybe move this to some place generic so we can use the same - // generator on the key manager - createSignatureBox: function(sigObj, sigIdx) { - sigObj.timestamp = parseInt(sigObj.timestamp, 10); - sigObj.expiration = parseInt(sigObj.expiration, 10); - var _ = webpg.utils.i18n.gettext, - scrub = webpg.utils.escape, - sig_keyid = sigObj.fingerprint.substr(-8), - subkey_index = 0, - key_name = sig_keyid, - sigkey_url = null, - email = null, - key; - - if (sigObj.status != "NO_PUBKEY") { - key = sigObj.public_key; - for (var subkey in key.subkeys) { - if (key.subkeys[subkey].subkey === sigObj.fingerprint) { - subkey_index = subkey; - } - } - email = (key.uids && key.uids[0].email.length > 1) ? "<" + scrub(key.uids[0].email) + - ">" : "(no email address provided)"; - sigkey_url = webpg.utils.resourcePath + "key_manager.html" + - "?auto_init=true&tab=-1&openkey=" + sigObj.public_key.id + "&opensubkey=" + subkey_index; - key_name = key.name; - } - var sig_class = ""; - var sig_image = "stock_signature.png"; - if (sigObj.status === "GOOD") { - sig_image = "stock_signature-ok.png"; - sig_class = "sign-good"; - } - if (sigObj.status === "BAD_SIG") { - sig_image = "stock_signature-bad.png"; - sig_class = "sign-revoked"; - } - var sig_box = "
      " + - "
      " + - key_name + ""; - - if (sigkey_url) - sig_box += "(" + sig_keyid + ")"; - - sig_box += "
      "; - - if (email) - sig_box += "" + email + "
      "; - - var date_created = (sigObj.timestamp === 0) ? - _('Unknown') : new Date(sigObj.timestamp * 1000).toJSON().substring(0, 10); - var date_expires = (sigObj.expiration === 0) ? - _('Never') : new Date(sigObj.expiration * 1000).toJSON().substring(0, 10); - sig_box += "" + _('Created') + ": " + date_created + "
      "; - sig_box += "" + _('Expires') + ": " + date_expires + "
      " + - "" + _('Status') + ": " + sigObj.validity + "
      " + - "" + _('Validity') + ": " + sigObj.status + "
      "; - return sig_box; - }, - - receiveMessage: function(event) { - webpg.inline_results.processRequest(event.data); - }, - - processRequest: function(request, sender, sendResponse) { - var _ = webpg.utils.i18n.gettext, - scrub = webpg.utils.escape, - descText = ""; - if (request.target_id === webpg.inline_results.qs.id) { - var icon = document.createElement("img"); - switch(request.block_type) { - case webpg.constants.PGPBlocks.PGP_ENCRYPTED: - icon.src = "skin/images/badges/48x48/stock_encrypted.png"; - webpg.jq(icon).addClass('footer_icon'); - var gpg_error_code = request.verify_result.gpg_error_code; - webpg.jq('#header .title').html("" + _("PGP ENCRYPTED OR SIGNED MESSAGE") + ""); - webpg.jq('#footer .content, #header .content').html(""); - if (gpg_error_code === 58) { - descText = _("UNABLE TO DECRYPT OR VERIFY THIS MESSAGE"); - webpg.jq('.watermark').text(descText) - webpg.jq('#footer, #header').addClass("signature_bad_sig"); - webpg.jq('#footer .content').html(descText + "
      "); - } - if (request.verify_result.error) { - webpg.jq('#signature_text')[0].textContent = request.verify_result.original_text; - } else { - webpg.jq('#signature_text')[0].textContent = request.verify_result.data; - } - if (request.message_event === "manual" && - request.verify_result.original_text.substr(0,5) === "-----") { - if (request.verify_result.signatures && - request.verify_result.signatures.hasOwnProperty(0)) { - webpg.jq('#header .title').html("" + _("PGP ENCRYPTED AND SIGNED MESSAGE") + ""); - icon.src = "skin/images/badges/48x48/stock_decrypted-signature.png"; - var sig_ok = true; - var sig_boxes = "
      "; - for (var sig in request.verify_result.signatures) { - if (request.verify_result.signatures[sig].status != "GOOD") { - sig_ok = false; - } - sig_boxes += webpg.inline_results. - createSignatureBox(request.verify_result. - signatures[sig], sig); - } - sig_boxes += "
      "; - webpg.jq('#signature_text').append(sig_boxes); - if (sig_ok) { - webpg.jq('#footer, #header').addClass("signature_good"); - icon.src = "skin/images/badges/48x48/stock_decrypted-signature-ok.png"; - } - } else { - icon.src = "skin/images/badges/48x48/stock_decrypted.png"; - } - } - webpg.jq('#footer .icon, #header .icon').html(icon.outerHTML || new XMLSerializer().serializeToString(icon)); - webpg.jq('#original_text')[0].textContent = request.verify_result.original_text; - webpg.jq('#clipboard_input')[0].textContent = request.verify_result.original_text; - webpg.jq('#original_text').hide(); - if (gpg_error_code === 11 || - gpg_error_code === 152) { - webpg.jq('#footer, #header').addClass("signature_no_pubkey"); - if (gpg_error_code === 152) { - webpg.jq('#footer .content').html(_("DECRYPTION FAILED") + "; " + _("NO SECRET KEY") + "
      "); - } - if (gpg_error_code === 11) { - if (request.message_type === "encrypted_message" && - request.message_event === "manual") { - webpg.jq('#footer .content').html(_("DECRYPTION FAILED") + "; " + _("BAD PASSPHRASE") + "
      "); - if (request.noninline) { - webpg.jq('#footer .content, #header .content').append("" + _("DECRYPT THIS MESSAGE") + " |"); - } - } else { - webpg.jq('#footer .content, #header .content').html("" + _("DECRYPT THIS MESSAGE") + " | "); - } - } - } else if (!request.verify_result.error) { - webpg.jq('#footer, #header').addClass("signature_good"); - } - if (!request.verify_result.error && - request.verify_result.original_text.length >0) { - webpg.jq('#footer .content, #header .content').html("" + _("DISPLAY ORIGINAL") + " | "); - } - webpg.jq('#footer .content, #header .content').append("" + _("COPY TO CLIPBOARD") + ""); - webpg.inline_results.doResize(); - break; - - case webpg.constants.PGPBlocks.PGP_SIGNED_MSG: - webpg.inline_results.missingKeys = []; - if (request.verify_result.message_type === "detached_signature") - var title = "" + _("DETACHED PGP SIGNATURE") + ""; - else - var title = "" + _("PGP SIGNED MESSAGE") + ""; - webpg.jq('#header .title').html(title); - webpg.jq('#header .content').html(""); - if (request.verify_result.error) { - webpg.jq('#signature_text')[0].textContent = request.verify_result.original_text; - } else { - var contents = webpg.utils.linkify(webpg.descript((request.verify_result.data || ""))) - .replace(/(<|<\/)(textarea|button|input|iframe|frame)(.*?)(>)/gm, "<$2$3>"); - webpg.jq('#signature_text').html(contents); - } - webpg.jq('#clipboard_input')[0].textContent = request.verify_result.original_text; - - gpg_error_code = request.verify_result.gpg_error_code; - if (gpg_error_code === 58) { - descText = _("THE SIGNATURE ON THIS MESSAGE IS INVALID") + "; " + _("THE SIGNATURE MIGHT BE TAMPERED WITH"); - webpg.jq('.watermark').text(descText) - webpg.jq('#footer, #header').addClass("signature_bad_sig"); - icon.src = "skin/images/badges/48x48/stock_signature-bad.png"; - webpg.jq(icon).addClass('footer_icon'); - webpg.jq('#footer .icon, #header .icon').html(icon.outerHTML || new XMLSerializer().serializeToString(icon)); - webpg.jq('#footer .content').html(descText + "
      "); - webpg.jq('#footer .content, #header .content').append("" + _("COPY TO CLIPBOARD") + ""); - } else { - webpg.jq('#footer, #header').addClass("signature_bad_sig"); - } - webpg.jq('#original_text').text(request.verify_result.original_text); - webpg.jq('#original_text').hide(); - sig_boxes = "
      "; - if (request.verify_result.signatures === null) { - descText = _("THE SIGNATURE ON THIS MESSAGE FAILED") + "; " + _("THE MESSAGE MAY BE TAMPERED WITH"); - webpg.jq('#footer, #header').addClass("signature_bad_sig"); - icon.src = "skin/images/badges/48x48/stock_signature-bad.png"; - webpg.jq(icon).addClass('footer_icon'); - webpg.jq('#footer .icon, #header .icon').html(icon.outerHTML || new XMLSerializer().serializeToString(icon)); - webpg.jq('.watermark').text(descText); - webpg.jq('#footer .content, #header .content').html(descText + "
      "); - webpg.jq('#footer .content').append("" + _("DISPLAY ORIGINAL") + " | "); - webpg.jq('#footer .content').append("" + _("COPY TO CLIPBOARD") + ""); - } - for (var sig in request.verify_result.signatures) { - sig_boxes += webpg.inline_results. - createSignatureBox(request.verify_result. - signatures[sig], sig); - if (request.verify_result.signatures[sig].status === "GOOD") { - icon.src = "skin/images/badges/48x48/stock_signature-ok.png"; - webpg.jq(icon).addClass('footer_icon'); - webpg.jq('#footer, #header').addClass("signature_good"); - webpg.jq('#footer .icon, #header .icon').html(icon.outerHTML || new XMLSerializer().serializeToString(icon)); - var key_id = request.verify_result.signatures[sig].fingerprint.substring(16, -1) - var sig_fp = request.verify_result.signatures[sig].fingerprint; - var public_key = request.verify_result.signatures[sig].public_key; - var sigkey_link = key_id; - if (public_key) { - for (var pubkey_subkey in public_key.subkeys) { - if (sig_fp === public_key.subkeys[pubkey_subkey].subkey) { - var sigkey_url = webpg.utils.resourcePath + "key_manager.html" + - "?auto_init=true&tab=-1&openkey=" + scrub(public_key.id) + "&opensubkey=" + - scrub(pubkey_subkey); - sigkey_link = "" + - public_key.id + ""; - } - } - } - descText = _("THIS MESSAGE WAS SIGNED WITH KEY") + " " + sigkey_link; - webpg.jq('#header .title').append(" | " + descText); - webpg.jq('#footer .content').html(descText + "
      "); - webpg.jq('#footer .content, #header .content').append("" + _("DISPLAY ORIGINAL") + " | " + _("COPY TO CLIPBOARD") + ""); - } - if (request.verify_result.signatures[sig].status === "GOOD_EXPKEY") { - descText = _("THIS MESSAGE WAS SIGNED WITH AN EXPIRED PUBLIC KEY"); - webpg.jq('.watermark').text(descText); - webpg.inline_results.missingKeys.push(request.verify_result.signatures[sig].fingerprint); - webpg.jq('#footer, #header').addClass("signature_no_pubkey"); - icon.src = "skin/images/badges/48x48/stock_signature.png"; - webpg.jq(icon).addClass('footer_icon'); - webpg.jq('#footer .icon, #header .icon').html(icon.outerHTML || new XMLSerializer().serializeToString(icon)); - webpg.jq('#footer .content, #header .content').html(""); - webpg.jq('#header .title').append(" | " + descText); - webpg.jq('#footer .content').append(descText + "
      "); - webpg.jq('#footer .content, #header .content').append("" + _("DISPLAY ORIGINAL") + " | "); - webpg.jq('#footer .content, #header .content').append("" + _("COPY TO CLIPBOARD") + " | "); - webpg.jq('#footer .content, #header .content').append("" + _("Refresh from Keyserver") + ""); - } - if (request.verify_result.signatures[sig].status === "NO_PUBKEY") { - descText = _("THIS MESSAGE WAS SIGNED WITH A PUBLIC KEY NOT IN YOUR KEYRING"); - webpg.jq('#footer, #header').addClass("signature_no_pubkey"); - icon.src = "skin/images/badges/48x48/stock_signature.png"; - webpg.jq(icon).addClass('footer_icon'); - webpg.jq('#footer .icon, #header .icon').html(icon.outerHTML || new XMLSerializer().serializeToString(icon)); - webpg.jq('.watermark').text(descText); - webpg.jq('#header .title').append(" | " + descText); - webpg.jq('#footer .content').html(descText + "
      "); - webpg.jq('#header .content').html(""); - webpg.jq('#footer .content, #header .content').append("" + _("DISPLAY ORIGINAL") + " | "); - webpg.inline_results.missingKeys.push(request.verify_result.signatures[sig].fingerprint); - webpg.jq('#footer .content, #header .content').append("" + _("COPY TO CLIPBOARD") + " | "); - webpg.jq('#footer .content, #header .content').append("" + _("SEARCH FOR KEYS ON KEYSERVER") + ""); - } - if (request.verify_result.signatures[sig].status === "BAD_SIG" || - request.verify_result.signatures[sig].status === "INVALID") { - descText = _("THE SIGNATURE ON THIS MESSAGE FAILED") + "; " + _("THE MESSAGE MAY BE TAMPERED WITH"); - webpg.jq('#footer, #header').addClass("signature_bad_sig"); - icon.src = "skin/images/badges/48x48/stock_signature-bad.png"; - webpg.jq(icon).addClass('footer_icon'); - webpg.jq('#footer .icon, #header .icon').html(icon.outerHTML || new XMLSerializer().serializeToString(icon)); - webpg.jq('.watermark').text(descText); - webpg.jq('#footer .content, #header .content').html(descText + "
      "); - webpg.jq('#footer .content').append("" + _("DISPLAY ORIGINAL") + " | "); - webpg.jq('#footer .content').append("" + _("COPY TO CLIPBOARD") + ""); - } - if (document.location.hash.indexOf("searched") > -1) - webpg.jq(document.createTextNode(" | " + _("Key not found on keyserver"))) - .insertBefore(webpg.jq('#footer .content').children().first()); - } - sig_boxes += "
      "; - webpg.jq('#signature_text').append(sig_boxes); - webpg.jq('.refresh_key_link').click(function(){ - webpg.utils.sendRequest({ - "temp_context": true, - "external": true, - "key_array": webpg.inline_results.missingKeys, - "msg": "doKeyImport" - }, function(response) { - if (response.result.import_status.error) - window.location.href = "#searched"; - window.location.reload(); - } - ); - }); - webpg.inline_results.doResize(); - webpg.jq('.webpg-link').click(function() { - webpg.utils.sendRequest({ - 'msg': "newtab", - 'url': this.id, - } - ); - }); - break; - - case webpg.constants.PGPBlocks.PGP_KEY: - webpg.jq('#header .title').html("" + _("PGP PUBLIC KEY") + ""); - webpg.jq('#original_text').text(request.original_text); - webpg.jq('#clipboard_input')[0].value = request.original_text; - icon.src = "skin/images/badges/48x48/stock_keypair.png"; - webpg.jq(icon).addClass('footer_icon'); - webpg.jq('#footer .icon, #header .icon').html(icon.outerHTML || new XMLSerializer().serializeToString(icon)); - var get_key_response = null; - var import_status = null; - webpg.utils.sendRequest({ - 'msg': 'doKeyImport', - 'data': request.original_text, - 'temp_context': true, - }, - function(response) { - var fpsi = {}; - fpsi.keys_found = []; - fpsi.keys_imported = []; - import_status = response.result.import_status; - for (var imported in import_status.imports) { - if (import_status.imports[imported].fingerprint != "unknown" - && import_status.imports[imported].result === "Success") { - key_id = import_status.imports[imported].fingerprint; - webpg.utils.sendRequest({ - 'msg': "getNamedKey", - 'key_id': key_id, - 'temp_context': true}, - function(get_key_response) { - var key = get_key_response.result; - fpsi.keys_found[fpsi.keys_found.length] = key; - if (import_status.imports[imported].new_key){ - fpsi.keys_imported[fpsi.keys_imported.length] = key; - webpg.utils.sendRequest({ - 'msg': 'deleteKey', - 'key_type': "public_key", - 'key_id': key_id, - 'temp_context': true, } - ); - } - keyobj = fpsi.keys_found[0]; - if (keyobj.in_real_keyring) { - var new_public_key = false; - var keyobj = keyobj.real_keyring_item; - } else { - var new_public_key = true; - } - webpg.jq('#signature_text').html(_("Names/UIDs on Key") + ":"); - if (keyobj.revoked || keyobj.expired) { - descText = (keyobj.revoked) ? _('REVOKED') : - (keyobj.expired) ? _('EXPIRED') : ''; - webpg.jq('#footer, #header').addClass("signature_bad_sig"); - webpg.jq('.watermark').text(descText); - } - webpg.jq('#signature_text').append("
        "); - for (var uid in keyobj.uids) { - uid_email = (keyobj.uids[uid].email.length > 1) ? "" + scrub(keyobj.uids[uid].email) + - "" : ""; - sig_class = "sig_class_normal"; - webpg.jq('#signature_text').append("
      • " + scrub(keyobj.uids[uid].uid) + - " <" + uid_email + ">
      • "); - } - webpg.jq('#signature_text').append("
      "); - webpg.jq('#signature_text').append("
      "); - key_algo = {} - key_algo.abbr = "?" - key_algo.name = keyobj.subkeys[0].algorithm_name; - if (key_algo.name in webpg.constants.algoTypes) { - key_algo.abbr = webpg.constants.algoTypes[key_algo.name]; - } - webpg.jq('#header .title').append(" (" + scrub(keyobj.subkeys[0].size) + scrub(key_algo.abbr) + "/" + keyobj.fingerprint.substr(-8) + ")
      "); - created = new Date(); - created.setTime(keyobj.subkeys[0].created*1000); -// expires = new Date(); -// expires.setTime(keyobj.subkeys[0].expires*1000); - webpg.jq('#signature_text').append(_("Created") + ": " + created.toUTCString() + "
      "); - var expires = (keyobj.subkeys[0].expires === 0) ? 'Never' : new Date(keyobj.subkeys[0].expires * 1000).toUTCString(); - webpg.jq('#signature_text').append(_("Expires") + ": " + expires + "
      "); - webpg.jq('#footer, #header').addClass("public_key"); - if (new_public_key) { - webpg.jq('#footer .content').append(_("THIS KEY IS NOT IN YOUR KEYRING") + "
      "); - } else { - key_url = webpg.utils.resourcePath + "key_manager.html" + - "?auto_init=true&tab=-1&openkey=" + keyobj.fingerprint.substr(-16); - key_link = "(" + keyobj.fingerprint.substr(-8) + ")"; - webpg.jq('#footer .content').append(_("THIS KEY IS IN YOUR KEYRING") + " " + key_link + "
      "); - } - webpg.jq('#footer .content, #header .content').append("" + _("DISPLAY ORIGINAL") + " | "); - if (new_public_key) { - // This is a key we don't already have, make import available - webpg.jq('#footer .content, #header .content').append("" + _("IMPORT THIS KEY") + " | "); - } else { - // This is a key we already have, make delete available - webpg.jq('#footer .content, #header .content').append("" + _("DELETE THIS KEY") + " | "); - } - webpg.jq('#footer .content, #header .content').append("" + _("COPY TO CLIPBOARD") + ""); - - webpg.jq('.delete_key_link').click(function(){ - webpg.utils.sendRequest({ - 'msg': 'deleteKey', - 'key_type': "public_key", - 'key_id': this.id }, - function(response) { - window.location.reload(); - } - ); - }) - webpg.jq('.webpg-link').click(function() { - webpg.utils.sendRequest({ - 'msg': "newtab", - 'url': this.id, - } - ); - }); - webpg.jq('.original_text_link').off('click'); - webpg.jq('.original_text_link').click(function(){ - if (this.textContent === _("DISPLAY ORIGINAL")){ - webpg.jq('#signature_text').hide(); - webpg.jq('#original_text').show(); - webpg.jq('.original_text_link').text(_("HIDE ORIGINAL")); - webpg.inline_results.doResize(); - } else { - webpg.jq('.original_text_link').text(_("DISPLAY ORIGINAL")); - webpg.jq('#signature_text').show(); - webpg.jq('#original_text').hide(); - webpg.inline_results.doResize((this.parentElement.parentElement.id !== 'header')); - } - }); - webpg.jq('.import_key_link').click(function(){ - console.log("import link clicked..."); - webpg.utils.sendRequest({ - 'msg': 'doKeyImport', - 'data': request.original_text }, - function(response) { - //TODO: this fails if the public keyring - // is unwritable (bad path/permissions). - // We should catch such events and act - // accordingly. This is what the return - // object looks like when it fails: - // Object {result: Object} - // result: Object - // import_status: Object - // considered: 0 - // imported: 0 - // imported_rsa: 0 - // imports: Object - // 0: Object - // fingerprint: "unknown" - // new_key: false - // new_revocations: 0 - // new_signatures: 0 - // new_sub_keys: 0 - // new_user_ids: 0 - // no_user_id: 0 - // not_imported: 0 - // secret_imported: 0 - // secret_read: 0 - // secret_unchanged: 0 - window.location.reload(); - } - ); - }) - webpg.jq('.copy_to_clipboard').click(function(){ - webpg.jq('#clipboard_input')[0].select(); - var copyResult = webpg.utils.copyToClipboard(window, document, this); - }) - if (webpg.jq('.original_text_link')[0].textContent === _("DISPLAY ORIGINAL")) - webpg.inline_results.doResize(); - } - ) - } else { - webpg.jq('#original_text')[0].textContent = request.original_text; - webpg.jq('#signature_text')[0].textContent = request.original_text; - webpg.jq('#footer, #header').addClass("signature_no_pubkey"); - if (import_status.no_user_id > 0) - webpg.jq("" + _("UNUSABLE KEY") + "; " + _("NO USER ID") + "
      ").insertBefore(webpg.jq(webpg.jq('#footer .content')[0].firstChild)); - if (import_status.considered === 0) - webpg.jq("" + _("UNUSABLE KEY") + "
      ").insertBefore(webpg.jq(webpg.jq('#footer .content')[0].firstChild)); - webpg.jq('#footer .content, #header .content').append("" + _("COPY TO CLIPBOARD") + ""); - webpg.inline_results.doResize(); - } - webpg.jq('#original_text').hide(); - webpg.inline_results.doResize(); - webpg.jq('.import_key_link').off("click"); - webpg.jq('.import_key_link').click(function(){ - console.log("import link clicked..."); - webpg.utils.sendRequest({ - 'msg': 'doKeyImport', - 'data': request.original_text }, - function(response) { - window.location.reload(); - } - ); - }) - webpg.jq('.copy_to_clipboard').click(function(){ - webpg.jq('#clipboard_input')[0].select(); - var copyResult = webpg.utils.copyToClipboard(window, document, this); - }) - } - } - ); - break; - - } /* end switch */ - if (sendResponse) { - sendResponse({'result': "done"}); - } - webpg.jq('.original_text_link').off('click'); - webpg.jq('.original_text_link').click(function(){ - if (this.textContent === _("DISPLAY ORIGINAL")){ - webpg.jq('#signature_text').hide(); - webpg.jq('#original_text').show(); - webpg.jq('.original_text_link').text(_("HIDE ORIGINAL")); - webpg.inline_results.doResize((this.parentElement.parentElement.id !== 'header')); - } else { - webpg.jq('.original_text_link').text(_("DISPLAY ORIGINAL")); - webpg.jq('#signature_text').show(); - webpg.jq('#original_text').hide(); - webpg.inline_results.doResize((this.parentElement.parentElement.id !== 'header')); - } - }); - webpg.jq('.copy_to_clipboard').click(function(){ - webpg.jq('#clipboard_input')[0].select(); - var copyResult = webpg.utils.copyToClipboard(window, document, this); - }); - webpg.jq('.decrypt_message').off("click"); - webpg.jq('.decrypt_message').click(function(){ - webpg.utils.sendRequest({ - msg: 'decrypt', - data: webpg.jq('#clipboard_input')[0].value}, - function(response) { - webpg.jq('.decrypt_status').remove(); - if (response.result.error) { - if (response.result.gpg_error_code === 11 - || response.result.gpg_error_code === 152) { - webpg.jq("" + _("DECRYPTION FAILED") + "; " + _("BAD PASSPHRASE") + "
      ").insertBefore(webpg.jq(webpg.jq('#footer .content')[0].firstChild)); - } - } else { - webpg.jq('#signature_text').html(webpg.descript(response.result.data)); - if ((request.verify_result && - request.verify_result.signatures && - response.result.signatures.hasOwnProperty(0)) - || (response.result.signatures - && response.result.signatures.hasOwnProperty(0))) { - webpg.jq('#header .title').html("" + _("PGP ENCRYPTED AND SIGNED MESSAGE") + ""); - icon.src = "skin/images/badges/48x48/stock_decrypted-signature.png"; - var sig_ok = true; - sig_boxes = "
      "; - for (var sig in response.result.signatures) { - if (response.result.signatures[sig].status != "GOOD") { - sig_ok = false; - } - sig_boxes += webpg.inline_results. - createSignatureBox(response.result. - signatures[sig], sig); - } - sig_boxes += "
      "; - webpg.jq('#signature_text').append(sig_boxes); - if (sig_ok) { - webpg.jq('#footer, #header').addClass("signature_good"); - icon.src = "skin/images/badges/48x48/stock_decrypted-signature-ok.png"; - } - } else { - icon.src = "skin/images/badges/48x48/stock_decrypted.png"; - } - webpg.jq(icon).addClass('footer_icon'); - webpg.jq('#footer .icon, #header .icon').html(icon.outerHTML || new XMLSerializer().serializeToString(icon)); - webpg.jq('#footer .content, #header .content').html("" + _("DISPLAY ORIGINAL") + " | "); - webpg.jq('#footer .content, #header .content').append("" + _("COPY TO CLIPBOARD") + ""); - webpg.jq('.original_text_link').off('click'); - webpg.jq('.original_text_link').click(function(){ - if (this.textContent === _("DISPLAY ORIGINAL")){ - webpg.jq('#signature_text').hide(); - webpg.jq('#original_text').show(); - webpg.jq('.original_text_link').text(_("HIDE ORIGINAL")); - webpg.inline_results.doResize() - } else { - webpg.jq('.original_text_link').text(_("DISPLAY ORIGINAL")); - webpg.jq('#signature_text').show(); - webpg.jq('#original_text').hide(); - webpg.inline_results.doResize((this.parentElement.parentElement.id !== 'header')); - } - }); - webpg.jq('.copy_to_clipboard').click(function(){ - webpg.jq('#clipboard_input')[0].select(); - var copyResult = webpg.utils.copyToClipboard(window, document, this); - }) - webpg.jq('.webpg-link').click(function() { - webpg.utils.sendRequest({ - 'msg': "newtab", - 'url': this.id, - } - ); - }); - webpg.inline_results.doResize(); - } - } - ); - webpg.inline_results.doResize(); - }); - webpg.inline_results.doResize(false); - webpg.jq('.results-close-btn').find('a').off('click.webpg-link'); - webpg.jq('.results-close-btn').find('a').bind('click.webpg-link', function() { - webpg.utils.sendRequest({ - 'msg': 'sendtoiframe', - 'msg_to_pass': 'toggle', - 'target_id': webpg.inline_results.qs.id, - 'iframe_id': webpg.inline_results.qs.id - }); - }); - } - }, -} - -webpg.inline_results.init(); -/* ]]> */ +/* 10) + webpg.inline_results.mouseCount = 0; + }); + webpg.jq(window).bind("mouseout", + function(event) { + document.querySelector('.webpg-results-trusted-hover').textContent = ""; + webpg.utils.setStatusBarText(""); + } + ); + }, + + /* + Function: doResize + Resizes the parent iframe by sending a request to the listener of + the webpg.background object + + Parameters: + scrollTop - Indicates if the parent window should scroll to the top of the frame + */ + doResize: function(scrollTop) { + if (webpg.utils.isRTL()) { + webpg.jq(".signed_text_header").addClass("rtl"); + webpg.jq(".results-control").addClass("rtl"); + webpg.jq(".webpg-results-trusted-hover").addClass("rtl"); + webpg.jq(".signed_text").addClass("rtl"); + webpg.jq(".signature-box").addClass("rtl"); + webpg.jq(".footer").addClass("rtl"); + webpg.jq(".footer_icon").addClass("rtl"); + } + var block_height = webpg.jq(".pgp_block_container")[0].scrollHeight; + var body_height = document.body.scrollHeight; + var height = webpg.jq(".pgp_block_container")[0].scrollHeight + webpg.jq("#footer")[0].scrollHeight + 40; + height = (height < body_height) ? height : body_height; + + webpg.utils.sendRequest({ + 'msg': 'sendtoiframe', + 'iframe_id': webpg.inline_results.qs.id, + 'width': null, + 'height': height, + 'scrollTop': scrollTop + }); + }, + + /* + Function: createSignatureBox + Creates an HTML element with information concerning a signature + + Parameters: + sigObj - An object with information about a signature + sigIdx - The index of the signature within the keyring + */ + // TODO: Maybe move this to some place generic so we can use the same + // generator on the key manager + createSignatureBox: function(sigObj, sigIdx) { + sigObj.timestamp = parseInt(sigObj.timestamp, 10); + sigObj.expiration = parseInt(sigObj.expiration, 10); + var _ = webpg.utils.i18n.gettext, + scrub = webpg.utils.escape, + sig_keyid = sigObj.fingerprint.substr(-8), + subkey_index = 0, + key_name = sig_keyid, + sigkey_url = null, + email = null, + key; + + if (sigObj.status != "NO_PUBKEY") { + key = sigObj.public_key; + for (var subkey in key.subkeys) { + if (key.subkeys[subkey].subkey === sigObj.fingerprint) { + subkey_index = subkey; + } + } + email = (key.uids && key.uids[0].email.length > 1) ? "<" + scrub(key.uids[0].email) + + ">" : "(no email address provided)"; + sigkey_url = webpg.utils.resourcePath + "key_manager.html" + + "?auto_init=true&tab=-1&openkey=" + sigObj.public_key.id + "&opensubkey=" + subkey_index; + key_name = key.name; + } + var sig_class = ""; + var sig_image = "stock_signature.png"; + if (sigObj.status === "GOOD") { + sig_image = "stock_signature-ok.png"; + sig_class = "sign-good"; + } + if (sigObj.status === "BAD_SIG") { + sig_image = "stock_signature-bad.png"; + sig_class = "sign-revoked"; + } + var sig_box = "
      " + + "
      " + + key_name + ""; + + if (sigkey_url) + sig_box += "(" + sig_keyid + ")"; + + sig_box += "
      "; + + if (email) + sig_box += "" + email + "
      "; + + var date_created = (sigObj.timestamp === 0) ? + _('Unknown') : new Date(sigObj.timestamp * 1000).toJSON().substring(0, 10); + var date_expires = (sigObj.expiration === 0) ? + _('Never') : new Date(sigObj.expiration * 1000).toJSON().substring(0, 10); + sig_box += "" + _('Created') + ": " + date_created + "
      "; + sig_box += "" + _('Expires') + ": " + date_expires + "
      " + + "" + _('Status') + ": " + sigObj.validity + "
      " + + "" + _('Validity') + ": " + sigObj.status + "
      "; + return sig_box; + }, + + receiveMessage: function(event) { + webpg.inline_results.processRequest(event.data); + }, + + processRequest: function(request, sender, sendResponse) { + var _ = webpg.utils.i18n.gettext, + scrub = webpg.utils.escape, + descText = ""; + if (request.target_id === webpg.inline_results.qs.id) { + var icon = document.createElement("img"); + switch(request.block_type) { + case webpg.constants.PGPBlocks.PGP_ENCRYPTED: + icon.src = "skin/images/badges/48x48/stock_encrypted.png"; + webpg.jq(icon).addClass('footer_icon'); + var gpg_error_code = request.verify_result.gpg_error_code; + webpg.jq('#header .title').html("" + _("PGP ENCRYPTED OR SIGNED MESSAGE") + ""); + webpg.jq('#footer .content, #header .content').html(""); + if (gpg_error_code === 58) { + descText = _("UNABLE TO DECRYPT OR VERIFY THIS MESSAGE"); + webpg.jq('.watermark').text(descText) + webpg.jq('#footer, #header').addClass("signature_bad_sig"); + webpg.jq('#footer .content').html(descText + "
      "); + } + if (request.verify_result.error) { + webpg.jq('#signature_text')[0].textContent = request.verify_result.original_text; + } else { + webpg.jq('#signature_text')[0].textContent = request.verify_result.data; + } + if (request.message_event === "manual" && + request.verify_result.original_text.substr(0,5) === "-----") { + if (request.verify_result.signatures && + request.verify_result.signatures.hasOwnProperty(0)) { + webpg.jq('#header .title').html("" + _("PGP ENCRYPTED AND SIGNED MESSAGE") + ""); + icon.src = "skin/images/badges/48x48/stock_decrypted-signature.png"; + var sig_ok = true; + var sig_boxes = "
      "; + for (var sig in request.verify_result.signatures) { + if (request.verify_result.signatures[sig].status != "GOOD") { + sig_ok = false; + } + sig_boxes += webpg.inline_results. + createSignatureBox(request.verify_result. + signatures[sig], sig); + } + sig_boxes += "
      "; + webpg.jq('#signature_text').append(sig_boxes); + if (sig_ok) { + webpg.jq('#footer, #header').addClass("signature_good"); + icon.src = "skin/images/badges/48x48/stock_decrypted-signature-ok.png"; + } + } else { + icon.src = "skin/images/badges/48x48/stock_decrypted.png"; + } + } + webpg.jq('#footer .icon, #header .icon').html(icon.outerHTML || new XMLSerializer().serializeToString(icon)); + webpg.jq('#original_text')[0].textContent = request.verify_result.original_text; + webpg.jq('#clipboard_input')[0].textContent = request.verify_result.original_text; + webpg.jq('#original_text').hide(); + if (gpg_error_code === 11 || + gpg_error_code === 152) { + webpg.jq('#footer, #header').addClass("signature_no_pubkey"); + if (gpg_error_code === 152) { + webpg.jq('#footer .content').html(_("DECRYPTION FAILED") + "; " + _("NO SECRET KEY") + "
      "); + } + if (gpg_error_code === 11) { + if (request.message_type === "encrypted_message" && + request.message_event === "manual") { + webpg.jq('#footer .content').html(_("DECRYPTION FAILED") + "; " + _("BAD PASSPHRASE") + "
      "); + if (request.noninline) { + webpg.jq('#footer .content, #header .content').append("" + _("DECRYPT THIS MESSAGE") + " |"); + } + } else { + webpg.jq('#footer .content, #header .content').html("" + _("DECRYPT THIS MESSAGE") + " | "); + } + } + } else if (!request.verify_result.error) { + webpg.jq('#footer, #header').addClass("signature_good"); + } + if (!request.verify_result.error && + request.verify_result.original_text.length >0) { + webpg.jq('#footer .content, #header .content').html("" + _("DISPLAY ORIGINAL") + " | "); + } + webpg.jq('#footer .content, #header .content').append("" + _("COPY TO CLIPBOARD") + ""); + webpg.inline_results.doResize(); + break; + + case webpg.constants.PGPBlocks.PGP_SIGNED_MSG: + webpg.inline_results.missingKeys = []; + if (request.verify_result.message_type === "detached_signature") + var title = "" + _("DETACHED PGP SIGNATURE") + ""; + else + var title = "" + _("PGP SIGNED MESSAGE") + ""; + webpg.jq('#header .title').html(title); + webpg.jq('#header .content').html(""); + if (request.verify_result.error) { + webpg.jq('#signature_text')[0].textContent = request.verify_result.original_text; + } else { + var contents = webpg.utils.linkify(webpg.descript((request.verify_result.data || ""))) + .replace(/(<|<\/)(textarea|button|input|iframe|frame)(.*?)(>)/gm, "<$2$3>"); + webpg.jq('#signature_text').html(contents); + } + webpg.jq('#clipboard_input')[0].textContent = request.verify_result.original_text; + + gpg_error_code = request.verify_result.gpg_error_code; + if (gpg_error_code === 58) { + descText = _("THE SIGNATURE ON THIS MESSAGE IS INVALID") + "; " + _("THE SIGNATURE MIGHT BE TAMPERED WITH"); + webpg.jq('.watermark').text(descText) + webpg.jq('#footer, #header').addClass("signature_bad_sig"); + icon.src = "skin/images/badges/48x48/stock_signature-bad.png"; + webpg.jq(icon).addClass('footer_icon'); + webpg.jq('#footer .icon, #header .icon').html(icon.outerHTML || new XMLSerializer().serializeToString(icon)); + webpg.jq('#footer .content').html(descText + "
      "); + webpg.jq('#footer .content, #header .content').append("" + _("COPY TO CLIPBOARD") + ""); + } else { + webpg.jq('#footer, #header').addClass("signature_bad_sig"); + } + webpg.jq('#original_text').text(request.verify_result.original_text); + webpg.jq('#original_text').hide(); + sig_boxes = "
      "; + if (request.verify_result.signatures === null) { + descText = _("THE SIGNATURE ON THIS MESSAGE FAILED") + "; " + _("THE MESSAGE MAY BE TAMPERED WITH"); + webpg.jq('#footer, #header').addClass("signature_bad_sig"); + icon.src = "skin/images/badges/48x48/stock_signature-bad.png"; + webpg.jq(icon).addClass('footer_icon'); + webpg.jq('#footer .icon, #header .icon').html(icon.outerHTML || new XMLSerializer().serializeToString(icon)); + webpg.jq('.watermark').text(descText); + webpg.jq('#footer .content, #header .content').html(descText + "
      "); + webpg.jq('#footer .content').append("" + _("DISPLAY ORIGINAL") + " | "); + webpg.jq('#footer .content').append("" + _("COPY TO CLIPBOARD") + ""); + } + for (var sig in request.verify_result.signatures) { + sig_boxes += webpg.inline_results. + createSignatureBox(request.verify_result. + signatures[sig], sig); + if (request.verify_result.signatures[sig].status === "GOOD") { + icon.src = "skin/images/badges/48x48/stock_signature-ok.png"; + webpg.jq(icon).addClass('footer_icon'); + webpg.jq('#footer, #header').addClass("signature_good"); + webpg.jq('#footer .icon, #header .icon').html(icon.outerHTML || new XMLSerializer().serializeToString(icon)); + var key_id = request.verify_result.signatures[sig].fingerprint.substring(16, -1) + var sig_fp = request.verify_result.signatures[sig].fingerprint; + var public_key = request.verify_result.signatures[sig].public_key; + var sigkey_link = key_id; + if (public_key) { + for (var pubkey_subkey in public_key.subkeys) { + if (sig_fp === public_key.subkeys[pubkey_subkey].subkey) { + var sigkey_url = webpg.utils.resourcePath + "key_manager.html" + + "?auto_init=true&tab=-1&openkey=" + scrub(public_key.id) + "&opensubkey=" + + scrub(pubkey_subkey); + sigkey_link = "" + + public_key.id + ""; + } + } + } + descText = _("THIS MESSAGE WAS SIGNED WITH KEY") + " " + sigkey_link; + webpg.jq('#header .title').append(" | " + descText); + webpg.jq('#footer .content').html(descText + "
      "); + webpg.jq('#footer .content, #header .content').append("" + _("DISPLAY ORIGINAL") + " | " + _("COPY TO CLIPBOARD") + ""); + } + if (request.verify_result.signatures[sig].status === "GOOD_EXPKEY") { + descText = _("THIS MESSAGE WAS SIGNED WITH AN EXPIRED PUBLIC KEY"); + webpg.jq('.watermark').text(descText); + webpg.inline_results.missingKeys.push(request.verify_result.signatures[sig].fingerprint); + webpg.jq('#footer, #header').addClass("signature_no_pubkey"); + icon.src = "skin/images/badges/48x48/stock_signature.png"; + webpg.jq(icon).addClass('footer_icon'); + webpg.jq('#footer .icon, #header .icon').html(icon.outerHTML || new XMLSerializer().serializeToString(icon)); + webpg.jq('#footer .content, #header .content').html(""); + webpg.jq('#header .title').append(" | " + descText); + webpg.jq('#footer .content').append(descText + "
      "); + webpg.jq('#footer .content, #header .content').append("" + _("DISPLAY ORIGINAL") + " | "); + webpg.jq('#footer .content, #header .content').append("" + _("COPY TO CLIPBOARD") + " | "); + webpg.jq('#footer .content, #header .content').append("" + _("Refresh from Keyserver") + ""); + } + if (request.verify_result.signatures[sig].status === "NO_PUBKEY") { + descText = _("THIS MESSAGE WAS SIGNED WITH A PUBLIC KEY NOT IN YOUR KEYRING"); + webpg.jq('#footer, #header').addClass("signature_no_pubkey"); + icon.src = "skin/images/badges/48x48/stock_signature.png"; + webpg.jq(icon).addClass('footer_icon'); + webpg.jq('#footer .icon, #header .icon').html(icon.outerHTML || new XMLSerializer().serializeToString(icon)); + webpg.jq('.watermark').text(descText); + webpg.jq('#header .title').append(" | " + descText); + webpg.jq('#footer .content').html(descText + "
      "); + webpg.jq('#header .content').html(""); + webpg.jq('#footer .content, #header .content').append("" + _("DISPLAY ORIGINAL") + " | "); + webpg.inline_results.missingKeys.push(request.verify_result.signatures[sig].fingerprint); + webpg.jq('#footer .content, #header .content').append("" + _("COPY TO CLIPBOARD") + " | "); + webpg.jq('#footer .content, #header .content').append("" + _("SEARCH FOR KEYS ON KEYSERVER") + ""); + } + if (request.verify_result.signatures[sig].status === "BAD_SIG" || + request.verify_result.signatures[sig].status === "INVALID") { + descText = _("THE SIGNATURE ON THIS MESSAGE FAILED") + "; " + _("THE MESSAGE MAY BE TAMPERED WITH"); + webpg.jq('#footer, #header').addClass("signature_bad_sig"); + icon.src = "skin/images/badges/48x48/stock_signature-bad.png"; + webpg.jq(icon).addClass('footer_icon'); + webpg.jq('#footer .icon, #header .icon').html(icon.outerHTML || new XMLSerializer().serializeToString(icon)); + webpg.jq('.watermark').text(descText); + webpg.jq('#footer .content, #header .content').html(descText + "
      "); + webpg.jq('#footer .content').append("" + _("DISPLAY ORIGINAL") + " | "); + webpg.jq('#footer .content').append("" + _("COPY TO CLIPBOARD") + ""); + } + if (document.location.hash.indexOf("searched") > -1) + webpg.jq(document.createTextNode(" | " + _("Key not found on keyserver"))) + .insertBefore(webpg.jq('#footer .content').children().first()); + } + sig_boxes += "
      "; + webpg.jq('#signature_text').append(sig_boxes); + webpg.jq('.refresh_key_link').click(function(){ + webpg.utils.sendRequest({ + "temp_context": true, + "external": true, + "key_array": webpg.inline_results.missingKeys, + "msg": "doKeyImport" + }, function(response) { + if (response.result.import_status.error) + window.location.href = "#searched"; + window.location.reload(); + } + ); + }); + webpg.inline_results.doResize(); + webpg.jq('.webpg-link').click(function() { + webpg.utils.sendRequest({ + 'msg': "newtab", + 'url': this.id, + } + ); + }); + break; + + case webpg.constants.PGPBlocks.PGP_KEY: + webpg.jq('#header .title').html("" + _("PGP PUBLIC KEY") + ""); + webpg.jq('#original_text').text(request.original_text); + webpg.jq('#clipboard_input')[0].value = request.original_text; + icon.src = "skin/images/badges/48x48/stock_keypair.png"; + webpg.jq(icon).addClass('footer_icon'); + webpg.jq('#footer .icon, #header .icon').html(icon.outerHTML || new XMLSerializer().serializeToString(icon)); + var get_key_response = null; + var import_status = null; + webpg.utils.sendRequest({ + 'msg': 'doKeyImport', + 'data': request.original_text, + 'temp_context': true, + }, + function(response) { + var fpsi = {}; + fpsi.keys_found = []; + fpsi.keys_imported = []; + import_status = response.result.import_status; + for (var imported in import_status.imports) { + if (import_status.imports[imported].fingerprint != "unknown" + && import_status.imports[imported].result === "Success") { + key_id = import_status.imports[imported].fingerprint; + webpg.utils.sendRequest({ + 'msg': "getNamedKey", + 'key_id': key_id, + 'temp_context': true}, + function(get_key_response) { + var key = get_key_response.result; + fpsi.keys_found[fpsi.keys_found.length] = key; + if (import_status.imports[imported].new_key){ + fpsi.keys_imported[fpsi.keys_imported.length] = key; + webpg.utils.sendRequest({ + 'msg': 'deleteKey', + 'key_type': "public_key", + 'key_id': key_id, + 'temp_context': true, } + ); + } + keyobj = fpsi.keys_found[0]; + if (keyobj.in_real_keyring) { + var new_public_key = false; + var keyobj = keyobj.real_keyring_item; + } else { + var new_public_key = true; + } + webpg.jq('#signature_text').html(_("Names/UIDs on Key") + ":"); + if (keyobj.revoked || keyobj.expired) { + descText = (keyobj.revoked) ? _('REVOKED') : + (keyobj.expired) ? _('EXPIRED') : ''; + webpg.jq('#footer, #header').addClass("signature_bad_sig"); + webpg.jq('.watermark').text(descText); + } + webpg.jq('#signature_text').append("
        "); + for (var uid in keyobj.uids) { + uid_email = (keyobj.uids[uid].email.length > 1) ? "" + scrub(keyobj.uids[uid].email) + + "" : ""; + sig_class = "sig_class_normal"; + webpg.jq('#signature_text').append("
      • " + scrub(keyobj.uids[uid].uid) + + " <" + uid_email + ">
      • "); + } + webpg.jq('#signature_text').append("
      "); + webpg.jq('#signature_text').append("
      "); + key_algo = {} + key_algo.abbr = "?" + key_algo.name = keyobj.subkeys[0].algorithm_name; + if (key_algo.name in webpg.constants.algoTypes) { + key_algo.abbr = webpg.constants.algoTypes[key_algo.name]; + } + webpg.jq('#header .title').append(" (" + scrub(keyobj.subkeys[0].size) + scrub(key_algo.abbr) + "/" + keyobj.fingerprint.substr(-8) + ")
      "); + created = new Date(); + created.setTime(keyobj.subkeys[0].created*1000); +// expires = new Date(); +// expires.setTime(keyobj.subkeys[0].expires*1000); + webpg.jq('#signature_text').append(_("Created") + ": " + created.toUTCString() + "
      "); + var expires = (keyobj.subkeys[0].expires === 0) ? 'Never' : new Date(keyobj.subkeys[0].expires * 1000).toUTCString(); + webpg.jq('#signature_text').append(_("Expires") + ": " + expires + "
      "); + webpg.jq('#footer, #header').addClass("public_key"); + if (new_public_key) { + webpg.jq('#footer .content').append(_("THIS KEY IS NOT IN YOUR KEYRING") + "
      "); + } else { + key_url = webpg.utils.resourcePath + "key_manager.html" + + "?auto_init=true&tab=-1&openkey=" + keyobj.fingerprint.substr(-16); + key_link = "(" + keyobj.fingerprint.substr(-8) + ")"; + webpg.jq('#footer .content').append(_("THIS KEY IS IN YOUR KEYRING") + " " + key_link + "
      "); + } + webpg.jq('#footer .content, #header .content').append("" + _("DISPLAY ORIGINAL") + " | "); + if (new_public_key) { + // This is a key we don't already have, make import available + webpg.jq('#footer .content, #header .content').append("" + _("IMPORT THIS KEY") + " | "); + } else { + // This is a key we already have, make delete available + webpg.jq('#footer .content, #header .content').append("" + _("DELETE THIS KEY") + " | "); + } + webpg.jq('#footer .content, #header .content').append("" + _("COPY TO CLIPBOARD") + ""); + + webpg.jq('.delete_key_link').click(function(){ + webpg.utils.sendRequest({ + 'msg': 'deleteKey', + 'key_type': "public_key", + 'key_id': this.id }, + function(response) { + window.location.reload(); + } + ); + }) + webpg.jq('.webpg-link').click(function() { + webpg.utils.sendRequest({ + 'msg': "newtab", + 'url': this.id, + } + ); + }); + webpg.jq('.original_text_link').off('click'); + webpg.jq('.original_text_link').click(function(){ + if (this.textContent === _("DISPLAY ORIGINAL")){ + webpg.jq('#signature_text').hide(); + webpg.jq('#original_text').show(); + webpg.jq('.original_text_link').text(_("HIDE ORIGINAL")); + webpg.inline_results.doResize(); + } else { + webpg.jq('.original_text_link').text(_("DISPLAY ORIGINAL")); + webpg.jq('#signature_text').show(); + webpg.jq('#original_text').hide(); + webpg.inline_results.doResize((this.parentElement.parentElement.id !== 'header')); + } + }); + webpg.jq('.import_key_link').click(function(){ + console.log("import link clicked..."); + webpg.utils.sendRequest({ + 'msg': 'doKeyImport', + 'data': request.original_text }, + function(response) { + //TODO: this fails if the public keyring + // is unwritable (bad path/permissions). + // We should catch such events and act + // accordingly. This is what the return + // object looks like when it fails: + // Object {result: Object} + // result: Object + // import_status: Object + // considered: 0 + // imported: 0 + // imported_rsa: 0 + // imports: Object + // 0: Object + // fingerprint: "unknown" + // new_key: false + // new_revocations: 0 + // new_signatures: 0 + // new_sub_keys: 0 + // new_user_ids: 0 + // no_user_id: 0 + // not_imported: 0 + // secret_imported: 0 + // secret_read: 0 + // secret_unchanged: 0 + window.location.reload(); + } + ); + }) + webpg.jq('.copy_to_clipboard').click(function(){ + webpg.jq('#clipboard_input')[0].select(); + var copyResult = webpg.utils.copyToClipboard(window, document, this); + }) + if (webpg.jq('.original_text_link')[0].textContent === _("DISPLAY ORIGINAL")) + webpg.inline_results.doResize(); + } + ) + } else { + webpg.jq('#original_text')[0].textContent = request.original_text; + webpg.jq('#signature_text')[0].textContent = request.original_text; + webpg.jq('#footer, #header').addClass("signature_no_pubkey"); + if (import_status.no_user_id > 0) + webpg.jq("" + _("UNUSABLE KEY") + "; " + _("NO USER ID") + "
      ").insertBefore(webpg.jq(webpg.jq('#footer .content')[0].firstChild)); + if (import_status.considered === 0) + webpg.jq("" + _("UNUSABLE KEY") + "
      ").insertBefore(webpg.jq(webpg.jq('#footer .content')[0].firstChild)); + webpg.jq('#footer .content, #header .content').append("" + _("COPY TO CLIPBOARD") + ""); + webpg.inline_results.doResize(); + } + webpg.jq('#original_text').hide(); + webpg.inline_results.doResize(); + webpg.jq('.import_key_link').off("click"); + webpg.jq('.import_key_link').click(function(){ + console.log("import link clicked..."); + webpg.utils.sendRequest({ + 'msg': 'doKeyImport', + 'data': request.original_text }, + function(response) { + window.location.reload(); + } + ); + }) + webpg.jq('.copy_to_clipboard').click(function(){ + webpg.jq('#clipboard_input')[0].select(); + var copyResult = webpg.utils.copyToClipboard(window, document, this); + }) + } + } + ); + break; + + } /* end switch */ + if (sendResponse) { + sendResponse({'result': "done"}); + } + webpg.jq('.original_text_link').off('click'); + webpg.jq('.original_text_link').click(function(){ + if (this.textContent === _("DISPLAY ORIGINAL")){ + webpg.jq('#signature_text').hide(); + webpg.jq('#original_text').show(); + webpg.jq('.original_text_link').text(_("HIDE ORIGINAL")); + webpg.inline_results.doResize((this.parentElement.parentElement.id !== 'header')); + } else { + webpg.jq('.original_text_link').text(_("DISPLAY ORIGINAL")); + webpg.jq('#signature_text').show(); + webpg.jq('#original_text').hide(); + webpg.inline_results.doResize((this.parentElement.parentElement.id !== 'header')); + } + }); + webpg.jq('.copy_to_clipboard').click(function(){ + webpg.jq('#clipboard_input')[0].select(); + var copyResult = webpg.utils.copyToClipboard(window, document, this); + }); + webpg.jq('.decrypt_message').off("click"); + webpg.jq('.decrypt_message').click(function(){ + webpg.utils.sendRequest({ + msg: 'decrypt', + data: webpg.jq('#clipboard_input')[0].value}, + function(response) { + webpg.jq('.decrypt_status').remove(); + if (response.result.error) { + if (response.result.gpg_error_code === 11 + || response.result.gpg_error_code === 152) { + webpg.jq("" + _("DECRYPTION FAILED") + "; " + _("BAD PASSPHRASE") + "
      ").insertBefore(webpg.jq(webpg.jq('#footer .content')[0].firstChild)); + } + } else { + webpg.jq('#signature_text').html(webpg.descript(response.result.data)); + if ((request.verify_result && + request.verify_result.signatures && + response.result.signatures.hasOwnProperty(0)) + || (response.result.signatures + && response.result.signatures.hasOwnProperty(0))) { + webpg.jq('#header .title').html("" + _("PGP ENCRYPTED AND SIGNED MESSAGE") + ""); + icon.src = "skin/images/badges/48x48/stock_decrypted-signature.png"; + var sig_ok = true; + sig_boxes = "
      "; + for (var sig in response.result.signatures) { + if (response.result.signatures[sig].status != "GOOD") { + sig_ok = false; + } + sig_boxes += webpg.inline_results. + createSignatureBox(response.result. + signatures[sig], sig); + } + sig_boxes += "
      "; + webpg.jq('#signature_text').append(sig_boxes); + if (sig_ok) { + webpg.jq('#footer, #header').addClass("signature_good"); + icon.src = "skin/images/badges/48x48/stock_decrypted-signature-ok.png"; + } + } else { + icon.src = "skin/images/badges/48x48/stock_decrypted.png"; + } + webpg.jq(icon).addClass('footer_icon'); + webpg.jq('#footer .icon, #header .icon').html(icon.outerHTML || new XMLSerializer().serializeToString(icon)); + webpg.jq('#footer .content, #header .content').html("" + _("DISPLAY ORIGINAL") + " | "); + webpg.jq('#footer .content, #header .content').append("" + _("COPY TO CLIPBOARD") + ""); + webpg.jq('.original_text_link').off('click'); + webpg.jq('.original_text_link').click(function(){ + if (this.textContent === _("DISPLAY ORIGINAL")){ + webpg.jq('#signature_text').hide(); + webpg.jq('#original_text').show(); + webpg.jq('.original_text_link').text(_("HIDE ORIGINAL")); + webpg.inline_results.doResize() + } else { + webpg.jq('.original_text_link').text(_("DISPLAY ORIGINAL")); + webpg.jq('#signature_text').show(); + webpg.jq('#original_text').hide(); + webpg.inline_results.doResize((this.parentElement.parentElement.id !== 'header')); + } + }); + webpg.jq('.copy_to_clipboard').click(function(){ + webpg.jq('#clipboard_input')[0].select(); + var copyResult = webpg.utils.copyToClipboard(window, document, this); + }) + webpg.jq('.webpg-link').click(function() { + webpg.utils.sendRequest({ + 'msg': "newtab", + 'url': this.id, + } + ); + }); + webpg.inline_results.doResize(); + } + } + ); + webpg.inline_results.doResize(); + }); + webpg.inline_results.doResize(false); + webpg.jq('.results-close-btn').find('a').off('click.webpg-link'); + webpg.jq('.results-close-btn').find('a').bind('click.webpg-link', function() { + webpg.utils.sendRequest({ + 'msg': 'sendtoiframe', + 'msg_to_pass': 'toggle', + 'target_id': webpg.inline_results.qs.id, + 'iframe_id': webpg.inline_results.qs.id + }); + }); + } + }, +} + +webpg.inline_results.init(); +/* ]]> */