[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [Pki-devel] [PATCH] 957 Added access banner for PKI UI.



On 2/22/2017 1:57 PM, Endi Sukma Dewata wrote:
The PKI UI main page has been modified to retrieve access banner
and display it once at the beginning of the SSL connection.

https://fedorahosted.org/pki/ticket/2582

New patch #957-1 attached. It's now using the two REST services added in patch #956-1.

--
Endi S. Dewata
>From 0da4726ffbc6893a4c8d591c07d19c5339192d38 Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata redhat com>
Date: Tue, 21 Feb 2017 19:50:37 +0100
Subject: [PATCH] Added access banner for PKI UI.

The PKI UI main page has been modified to retrieve access banner
and display it in a dialog box. After displaying the banner it
will notify the server such that the banner is not returned again
in the same server session.

To prevent displaying multiple dialog boxes in pages with frames
the critical code is locked such that only one frame can actually
display the banner.

https://fedorahosted.org/pki/ticket/2582
---
 base/server/share/webapps/pki/js/pki-banner.js | 77 ++++++++++++++++++++++++++
 base/server/share/webapps/pki/js/pki.js        | 22 ++++++++
 base/server/share/webapps/pki/ui/index.jsp     |  8 ++-
 3 files changed, 105 insertions(+), 2 deletions(-)
 create mode 100644 base/server/share/webapps/pki/js/pki-banner.js

diff --git a/base/server/share/webapps/pki/js/pki-banner.js b/base/server/share/webapps/pki/js/pki-banner.js
new file mode 100644
index 0000000000000000000000000000000000000000..e88220e7d841c3a2114d47f9bc7b1cca6b74be74
--- /dev/null
+++ b/base/server/share/webapps/pki/js/pki-banner.js
@@ -0,0 +1,77 @@
+/* --- BEGIN COPYRIGHT BLOCK ---
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Copyright (C) 2017 Red Hat, Inc.
+ * All rights reserved.
+ * --- END COPYRIGHT BLOCK ---
+ *
+ * @author Endi S. Dewata
+ */
+
+$(function() {
+
+// if secure connection
+if (location.protocol == "https:" && !sessionStorage.bannerLock) {
+
+    sessionStorage.bannerLock = true;
+
+    // get server info (including banner)
+    PKI.getInfo({
+        success: function(data, textStatus, jqXHR) {
+
+            // if banner not available, skip
+            if (!data.Banner) {
+                delete sessionStorage.bannerLock;
+                return;
+            }
+
+            // display the banner and ask for confirmation
+            var message = $.trim(data.Banner) + "\n\nDo you want to proceed?";
+
+            // if banner accepted
+            if (confirm(message)) {
+
+                // perform login
+                PKI.login({
+                    success: function(data, textStatus, jqXHR) {
+
+                        // done
+                        delete sessionStorage.bannerLock;
+                    },
+                    error: function(jqXHR, textStatus, errorThrown) {
+
+                        // unable to login, display error
+                        alert(textStatus);
+
+                        delete sessionStorage.bannerLock;
+                    }
+                });
+
+            } else {
+                delete sessionStorage.bannerLock;
+
+                // redirect to PKI UI welcome page
+                window.location = '/pki';
+            }
+        },
+        error: function(jqXHR, textStatus, errorThrown) {
+
+            // unable to get server info, display error
+            alert(textStatus);
+
+            delete sessionStorage.bannerLock;
+        }
+    });
+}
+});
diff --git a/base/server/share/webapps/pki/js/pki.js b/base/server/share/webapps/pki/js/pki.js
index 573d8819b35a7ba7bbab543026d940e6af843af4..cb1c71efc675245d37213905644697c0a46f9227 100644
--- a/base/server/share/webapps/pki/js/pki.js
+++ b/base/server/share/webapps/pki/js/pki.js
@@ -47,6 +47,28 @@ var PKI = {
 
         return newContent;
     },
+    getInfo: function(options) {
+        $.ajax({
+            type: "GET",
+            url: "/pki/rest/info",
+            dataType: "json"
+        }).done(function(data, textStatus, jqXHR) {
+            if (options.success) options.success.call(self, data, textStatus, jqXHR);
+        }).fail(function(jqXHR, textStatus, errorThrown) {
+            if (options.error) options.error.call(self, jqXHR, textStatus, errorThrown);
+        });
+    },
+    login: function(options) {
+        $.ajax({
+            type: "POST",
+            url: "/pki/rest/login",
+            dataType: "json"
+        }).done(function(data, textStatus, jqXHR) {
+            if (options.success) options.success.call(self, data, textStatus, jqXHR);
+        }).fail(function(jqXHR, textStatus, errorThrown) {
+            if (options.error) options.error.call(self, jqXHR, textStatus, errorThrown);
+        });
+    },
     logout: function(options) {
         options = options || {};
         if (window.crypto && typeof window.crypto.logout === "function") { // Firefox
diff --git a/base/server/share/webapps/pki/ui/index.jsp b/base/server/share/webapps/pki/ui/index.jsp
index ade01bc9e29419c725651546059dc0350afa0084..17f8d18df9b7344f1ac8bbf37e06bf2da84e070d 100644
--- a/base/server/share/webapps/pki/ui/index.jsp
+++ b/base/server/share/webapps/pki/ui/index.jsp
@@ -18,8 +18,12 @@
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd";>
 <html>
 <head>
-<script type="text/javascript" language="JavaScript" src="/pki/js/jquery.js"></script>
-<script type="text/javascript" language="JavaScript" src="/pki/js/jquery.i18n.properties.js"></script>
+<script src="/pki/js/jquery.js"></script>
+<script src="/pki/js/jquery.i18n.properties.js"></script>
+<script src="/pki/js/underscore.js"></script>
+<script src="/pki/js/backbone.js"></script>
+<script src="/pki/js/pki.js"></script>
+<script src="/pki/js/pki-banner.js"></script>
 
 <script type="text/javascript" language="JavaScript">
 $(function() {
-- 
2.9.3


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]