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

--
Endi S. Dewata
>From d0b86cbad1ed259a1c59fe72a3f0334197521059 Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <[email protected]>
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 once at the beginning of the SSL connection.

https://fedorahosted.org/pki/ticket/2582
---
 base/server/share/webapps/pki/js/pki-banner.js | 56 ++++++++++++++++++++++++++
 base/server/share/webapps/pki/js/pki.js        | 11 +++++
 base/server/share/webapps/pki/ui/index.jsp     |  8 +++-
 3 files changed, 73 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..f5f4da02a70d83ceb7b9cdfcd7562185b031ddfb
--- /dev/null
+++ b/base/server/share/webapps/pki/js/pki-banner.js
@@ -0,0 +1,56 @@
+/* --- 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 this is an SSL connection but banner is not displayed yet
+    if (location.protocol == "https:" && !sessionStorage.bannerDisplayed) {
+
+        // get server info including banner
+        PKI.getInfo({
+            success: function(data, textStatus, jqXHR) {
+
+                // if banner is disabled, do not check again
+                if (!data.Banner) {
+                    sessionStorage.bannerDisplayed = true;
+                    return;
+                }
+
+                // display the banner and ask for confirmation
+                var message = data.Banner.trim() + "\n\nDo you want to proceed?";
+
+                if (confirm(message)) {
+                    // mark that banner is already displayed
+                    sessionStorage.bannerDisplayed = true;
+
+                } else {
+                    // redirect to PKI UI welcome page
+                    window.location = '/pki';
+                }
+            },
+            error: function(jqXHR, textStatus, errorThrown) {
+                // unable to get server info, display error
+                alert(textStatus);
+            }
+        });
+    }
+
+});
diff --git a/base/server/share/webapps/pki/js/pki.js b/base/server/share/webapps/pki/js/pki.js
index 573d8819b35a7ba7bbab543026d940e6af843af4..fc1a9036de51d86ed60dc37d9f0551ec5562b401 100644
--- a/base/server/share/webapps/pki/js/pki.js
+++ b/base/server/share/webapps/pki/js/pki.js
@@ -47,6 +47,17 @@ 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);
+        });
+    },
     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

_______________________________________________
Pki-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/pki-devel

Reply via email to