On 03/16/2016 06:56 PM, Petr Vobornik wrote:
On 03/15/2016 01:23 PM, Pavel Vomacka wrote:
Hello,

patch for https://fedorahosted.org/freeipa/ticket/5311 is attached.

--
Pavel^3 Vomacka


Not tested, but can we avoid using <br> s with "white-space: pre" and therefore use only IPA.cert.pem_cert_format(text).

Also, it should be displayed in monospaced, so probably add:

.certificate-widget .certificate {
    font-family: monospace;
    overflow-x: auto;
    white-space: pre;
}
Fixed.


Probably as a separate patch or ticket: we can add "download" button which would offer the certificate in form of data uri[1] with 'download' attribute of 'a' element [2]. So user will get pem encoded file without any hassle.

[1] https://developer.mozilla.org/en-US/docs/Web/HTTP/data_URIs
[2] https://developer.mozilla.org/en/docs/Web/HTML/Element/a
The download button is really good idea. There is attached another patch which adds this button. If we need new ticket let me know and I will file it.

--
Pavel^3 Vomacka
>From d50fcd65531efa56b17cd8e63e1be518cf3fbcba Mon Sep 17 00:00:00 2001
From: Pavel Vomacka <pvoma...@redhat.com>
Date: Tue, 15 Mar 2016 11:51:35 +0100
Subject: [PATCH] Show certificate in useful format

Certificates are shown in PEM format which includes BEGIN and END CERTIFICATE string
and all lines are wrapped at 64 characters.

https://fedorahosted.org/freeipa/ticket/5311
---
 install/ui/ipa.css                    | 8 ++++++++
 install/ui/src/freeipa/certificate.js | 3 ++-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/install/ui/ipa.css b/install/ui/ipa.css
index f419eb224252aa03eaf4b25bb03435f4c9a6de9b..a1910560641d703557b06cd7ce8efa73296950d4 100644
--- a/install/ui/ipa.css
+++ b/install/ui/ipa.css
@@ -555,3 +555,11 @@ table.scrollable tbody {
     font-weight: bold;
     font-size: 1.1em;
 }
+
+/* --- Certificates --- */
+
+.certificate-widget .certificate {
+    font-family: monospace;
+    overflow-x: auto;
+    white-space: pre;
+}
diff --git a/install/ui/src/freeipa/certificate.js b/install/ui/src/freeipa/certificate.js
index ae05ebb3d45974cd1df50c16e19d0ab9fd27a19b..670bc3b0902bc87b1a6fbcb6e34d23ed8fa31b8d 100755
--- a/install/ui/src/freeipa/certificate.js
+++ b/install/ui/src/freeipa/certificate.js
@@ -1056,9 +1056,10 @@ IPA.cert.cert_widget = function(spec) {
 
         if (l && that.certs_visible) {
             for (var i=0; i<l; i++) {
+                var cert = IPA.cert.pem_cert_format(that.certificates[i]);
                 $('<div/>', {
                     'class': 'certificate',
-                    text: that.certificates[i]
+                    text: cert
                 }).appendTo(that.content_el);
             }
             $('<div/>').append(
-- 
2.5.5

>From ca9e0eaf930ac9d5344404fd0737fd1876477513 Mon Sep 17 00:00:00 2001
From: Pavel Vomacka <pvoma...@redhat.com>
Date: Tue, 29 Mar 2016 11:24:50 +0200
Subject: [PATCH] Add download button for certificates

Add button for each certificate which allows user to download certificate to PEM
formatted file.

https://fedorahosted.org/freeipa/ticket/5311
---
 install/ui/ipa.css                    |  5 +++++
 install/ui/src/freeipa/certificate.js | 19 ++++++++++++++++++-
 install/ui/test/data/ipa_init.json    |  2 ++
 ipalib/plugins/internal.py            |  2 ++
 4 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/install/ui/ipa.css b/install/ui/ipa.css
index a1910560641d703557b06cd7ce8efa73296950d4..99a09132a7e81493316ce790f3a5c31fcd1d8bee 100644
--- a/install/ui/ipa.css
+++ b/install/ui/ipa.css
@@ -563,3 +563,8 @@ table.scrollable tbody {
     overflow-x: auto;
     white-space: pre;
 }
+
+.certificate-widget .certificate a {
+    font-family: 'Open Sans', Helvetica, Arial, sans-serif;
+    float: right;
+}
diff --git a/install/ui/src/freeipa/certificate.js b/install/ui/src/freeipa/certificate.js
index 670bc3b0902bc87b1a6fbcb6e34d23ed8fa31b8d..8edbba5d800dae075282a27191119d3881961bb9 100755
--- a/install/ui/src/freeipa/certificate.js
+++ b/install/ui/src/freeipa/certificate.js
@@ -1049,6 +1049,13 @@ IPA.cert.cert_widget = function(spec) {
         return status;
     };
 
+    that.create_data_uri = function(cert) {
+        var format = 'data:,';
+        var uri_new_line = '%0A';
+
+        return format + cert.replace(/\n/g, uri_new_line);
+    };
+
     that.create_certs = function() {
 
         that.content_el.empty();
@@ -1057,10 +1064,20 @@ IPA.cert.cert_widget = function(spec) {
         if (l && that.certs_visible) {
             for (var i=0; i<l; i++) {
                 var cert = IPA.cert.pem_cert_format(that.certificates[i]);
+                var data_uri = that.create_data_uri(cert);
                 $('<div/>', {
                     'class': 'certificate',
                     text: cert
-                }).appendTo(that.content_el);
+                }).append(
+                    $('<a/>', {
+                        name: 'download',
+                        text: text.get('@i18n:buttons.download'),
+                        title: text.get('@i18n:buttons.download_title'),
+                        'class': 'btn btn-default',
+                        href: data_uri,
+                        download: 'cert.pem'
+                    })
+                ).appendTo(that.content_el);
             }
             $('<div/>').append(
                 IPA.button({
diff --git a/install/ui/test/data/ipa_init.json b/install/ui/test/data/ipa_init.json
index 852b953736da0ccb8a7803259e2bd5d4c4108ab9..f7ddee2999ddc0c47d1cf3364f6620d59680a76d 100644
--- a/install/ui/test/data/ipa_init.json
+++ b/install/ui/test/data/ipa_init.json
@@ -68,6 +68,8 @@
                         "cancel": "Cancel",
                         "close": "Close",
                         "disable": "Disable",
+                        "download": "Download",
+                        "download_title": "Download certificate as pem formatted file.",
                         "edit": "Edit",
                         "enable": "Enable",
                         "filter": "Filter",
diff --git a/ipalib/plugins/internal.py b/ipalib/plugins/internal.py
index 7156d4f47004dd702d3896ca736cc1f42227a321..5a57a49f2d3db19d7970eaf6ebfad0a1039ebb11 100644
--- a/ipalib/plugins/internal.py
+++ b/ipalib/plugins/internal.py
@@ -211,6 +211,8 @@ class i18n_messages(Command):
             "cancel": _("Cancel"),
             "close": _("Close"),
             "disable": _("Disable"),
+            "download": _("Download"),
+            "download_title": _("Download certificate as pem formatted file."),
             "edit": _("Edit"),
             "enable": _("Enable"),
             "filter": _("Filter"),
-- 
2.5.5

-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to