On 03/29/2016 11:42 AM, Pavel Vomacka wrote:


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


Self NACK, css parts should be moved to less files. Attaching new patches.
>From 605bca736d2f7420b416a985fa89df38425081f0 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/less/widgets.less          | 4 +++-
 install/ui/src/freeipa/certificate.js | 3 ++-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/install/ui/less/widgets.less b/install/ui/less/widgets.less
index 0f9bc8c171d5c35d955c6b55d2e95ee105c35159..b1b7ea5e6bf69b61ec300611bc23b6bcc7a20327 100644
--- a/install/ui/less/widgets.less
+++ b/install/ui/less/widgets.less
@@ -138,7 +138,9 @@
         padding-right: 10px;
     }
     .certificate {
-        word-wrap: break-word;
+        font-family: monospace;
+        overflow-x: auto;
+        white-space: pre;
         padding-bottom: 10px;
     }
 }
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 a4027f60328857301f3839392340f714ab029e6b Mon Sep 17 00:00:00 2001
From: Pavel Vomacka <pvoma...@redhat.com>
Date: Wed, 30 Mar 2016 12:34:54 +0200
Subject: [PATCH] Add download button for certificates

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

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

diff --git a/install/ui/less/widgets.less b/install/ui/less/widgets.less
index b1b7ea5e6bf69b61ec300611bc23b6bcc7a20327..57de1724ebd7013635cb47c2aeb146d3aa9a9ad1 100644
--- a/install/ui/less/widgets.less
+++ b/install/ui/less/widgets.less
@@ -142,6 +142,11 @@
         overflow-x: auto;
         white-space: pre;
         padding-bottom: 10px;
+
+        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..c91428710f7916889ad9c69afe66bb047e935bc1 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,19 @@ 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..031c77f2649c0e887ab1478c74bb6f8bf57fcbaa 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..979604413fbb3c347bcee70362b2769bc85566ab 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