diff options
| author | Endi S. Dewata <edewata@redhat.com> | 2017-02-21 19:50:37 +0100 |
|---|---|---|
| committer | Endi S. Dewata <edewata@redhat.com> | 2017-02-24 00:20:12 +0100 |
| commit | 580103a50bf360202a6626f8bbd5e1e41dcde89d (patch) | |
| tree | 2735947841b615a2fc597a5e318028968bf55246 /base/server | |
| parent | 2d2f2232219c30c14c247a393f02414dc56c4111 (diff) | |
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
Diffstat (limited to 'base/server')
| -rw-r--r-- | base/server/share/webapps/pki/js/pki-banner.js | 77 | ||||
| -rw-r--r-- | base/server/share/webapps/pki/js/pki.js | 22 | ||||
| -rw-r--r-- | base/server/share/webapps/pki/ui/index.jsp | 8 |
3 files changed, 105 insertions, 2 deletions
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 000000000..e88220e7d --- /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 573d8819b..cb1c71efc 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 ade01bc9e..17f8d18df 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() { |
