From c29345414e8060c75347f851f0836eeb77c4a407 Mon Sep 17 00:00:00 2001
From: Endi Sukma Dewata <edewata@redhat.com>
Date: Tue, 28 Aug 2012 14:14:54 -0500
Subject: [PATCH] Added common ROOT webapp.

The current ROOT webapp will redirect users coming to the root
URL path to the proper path of the subsystem's webapp.

Since now a single Tomcat instance may have multiple subsystems,
a new ROOT webapp has been added to present the user with a menu
of all available webapps from all subsystems in the instance.

Ticket #89
---
 base/ca/shared/webapps/ca/WEB-INF/web.xml          |   2 +
 base/common/CMakeLists.txt                         |   2 +-
 .../shared/webapps/ROOT/META-INF/context.xml       |  27 +++
 base/common/shared/webapps/ROOT/WEB-INF/web.xml    |  25 +++
 base/common/shared/webapps/ROOT/index.jsp          | 209 +++++++++++++++++++++
 base/deploy/src/scriptlets/instance_layout.py      |  25 ++-
 base/deploy/src/scriptlets/pkiparser.py            |  22 +--
 base/deploy/src/scriptlets/slot_substitution.py    |   8 -
 base/kra/shared/webapps/kra/WEB-INF/web.xml        |   2 +
 base/ocsp/shared/webapps/ocsp/WEB-INF/web.xml      |   2 +
 base/tks/shared/webapps/tks/WEB-INF/web.xml        |   2 +
 specs/pki-core.spec                                |   7 +-
 12 files changed, 294 insertions(+), 39 deletions(-)
 create mode 100644 base/common/shared/webapps/ROOT/META-INF/context.xml
 create mode 100644 base/common/shared/webapps/ROOT/WEB-INF/web.xml
 create mode 100644 base/common/shared/webapps/ROOT/index.jsp

diff --git a/base/ca/shared/webapps/ca/WEB-INF/web.xml b/base/ca/shared/webapps/ca/WEB-INF/web.xml
index af474872e94e2ade596bfb1ed44b0d70069b3b20..c1b2738c833024a33f73e1ab5669340bc644f63b 100644
--- a/base/ca/shared/webapps/ca/WEB-INF/web.xml
+++ b/base/ca/shared/webapps/ca/WEB-INF/web.xml
@@ -3,6 +3,8 @@
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "file:///usr/share/pki/setup/web-app_2_3.dtd">
 <web-app>
 
+    <display-name>Certificate Authority</display-name>
+
     <servlet>
         <servlet-name>csadmin-wizard</servlet-name>
         <servlet-class>com.netscape.cms.servlet.wizard.WizardServlet</servlet-class>
diff --git a/base/common/CMakeLists.txt b/base/common/CMakeLists.txt
index f602ae9437811ace4be5bcd7708662efeb2381fc..1a308ebb9284748cd47ff4adc0d20569d8dc5216 100644
--- a/base/common/CMakeLists.txt
+++ b/base/common/CMakeLists.txt
@@ -33,7 +33,7 @@ install(
     DESTINATION
         ${DATA_INSTALL_DIR}/shared/
     PATTERN
-        "lib/" EXCLUDE
+        "lib/*" EXCLUDE
 )
 
 # install empty directories
diff --git a/base/common/shared/webapps/ROOT/META-INF/context.xml b/base/common/shared/webapps/ROOT/META-INF/context.xml
new file mode 100644
index 0000000000000000000000000000000000000000..c29b4586e30e9bd8a6fc5c8c3de2027062382219
--- /dev/null
+++ b/base/common/shared/webapps/ROOT/META-INF/context.xml
@@ -0,0 +1,27 @@
+<?xml version='1.0' encoding='utf-8'?>
+<!-- BEGIN COPYRIGHT BLOCK
+     Copyright (C) 2012 Red Hat, Inc.
+     All rights reserved.
+     Modifications: configuration parameters
+     END COPYRIGHT BLOCK
+-->
+
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<Context crossContext="true" allowLinking="true">
+
+</Context>
diff --git a/base/common/shared/webapps/ROOT/WEB-INF/web.xml b/base/common/shared/webapps/ROOT/WEB-INF/web.xml
new file mode 100644
index 0000000000000000000000000000000000000000..54e8806103660d5ab2061085fa0987f363bd2650
--- /dev/null
+++ b/base/common/shared/webapps/ROOT/WEB-INF/web.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+  Copyright 2004 The Apache Software Foundation
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
+    version="2.4">
+
+  <display-name>PKI</display-name>
+
+</web-app>
diff --git a/base/common/shared/webapps/ROOT/index.jsp b/base/common/shared/webapps/ROOT/index.jsp
new file mode 100644
index 0000000000000000000000000000000000000000..f45272f54eaf1d47ac319d2e5fb3a34e6ae42ffd
--- /dev/null
+++ b/base/common/shared/webapps/ROOT/index.jsp
@@ -0,0 +1,209 @@
+<!-- --- 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) 2012 Red Hat, Inc.
+     All rights reserved.
+     --- END COPYRIGHT BLOCK --- -->
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+<title>Certificate System</title>
+<meta http-equiv=Content-Type content="text/html; charset=UTF-8">
+<link rel="shortcut icon" href="/pki/img/favicon.ico" />
+<link rel="stylesheet" href="/pki/css/pki-base.css" type="text/css" />
+</head>
+<body bgcolor="#FFFFFF" link="#666699" vlink="#666699" alink="#333366">
+
+<div id="header">
+    <a href="http://pki.fedoraproject.org/" title="Visit pki.fedoraproject.org for more information about Dogtag products and services"><img src="/pki/img/logo_header.gif" alt="Dogtag" id="myLogo" /></a>
+    <div id="headertitle">
+    <a href="/" title="Dogtag Network homepage">Dogtag<sup><font size="-2">&reg;</font></sup> Certificate System</a>
+    </div>
+    <div id="account">
+          <dl><dt><span></span></dt><dd></dd></dl>
+    </div>
+</div>
+
+<div id="mainNavOuter">
+<div id="mainNav">
+<div id="mainNavInner">
+
+</div><!-- end mainNavInner -->
+</div><!-- end mainNav -->
+</div><!-- end mainNavOuter -->
+
+
+<div id="bar">
+
+<div id="systembar">
+<div id="systembarinner">
+
+<div>
+  -
+</div>
+
+
+</div>
+</div>
+
+</div>
+
+
+<center>
+
+<%
+    ServletContext caContext = getServletContext().getContext("/ca");
+    String caName = caContext.getServletContextName();
+    String caPath = caContext.getContextPath();
+    if (!"".equals(caPath)) {
+%>
+<p>
+<font size="+1" face="PrimaSans BT, Verdana, Arial, Helvetica, sans-serif">
+<%= caName %>
+</font>
+</p>
+
+<table border="0" cellspacing="0" cellpadding="0">
+<tr valign="TOP">
+    <td>
+        <li><font size=4 face="PrimaSans BT, Verdana, sans-serif">
+        <a href="/ca/ee/ca">End Users Services</a></font>
+    </td>
+</tr>
+<%
+        if (request.isSecure()) {
+%>
+<tr valign="TOP">
+    <td>
+        <li><font size=4 face="PrimaSans BT, Verdana, sans-serif">
+        <a href="/ca/agent/ca">Agent Services</a></font>
+    </td>
+</tr>
+<tr valign="TOP">
+    <td>
+        <li><font size=4 face="PrimaSans BT, Verdana, sans-serif">
+        <a href="/ca/services">Admin Services</a></font>
+    </td>
+</tr>
+<%
+        }
+%>
+</table>
+
+<br>
+
+<%
+    }
+
+    ServletContext kraContext = getServletContext().getContext("/kra");
+    String kraName = kraContext.getServletContextName();
+    String kraPath = kraContext.getContextPath();
+    if (!"".equals(kraPath) && request.isSecure()) {
+%>
+<p>
+<font size="+1" face="PrimaSans BT, Verdana, Arial, Helvetica, sans-serif">
+<%= kraName %>
+</font>
+</p>
+
+<table border="0" cellspacing="0" cellpadding="0">
+<tr valign="TOP">
+    <td>
+        <li><font size=4 face="PrimaSans BT, Verdana, sans-serif">
+        <a href="/kra/agent/kra">Agent Services</a></font>
+    </td>
+</tr>
+<tr valign="TOP">
+    <td>
+        <li><font size=4 face="PrimaSans BT, Verdana, sans-serif">
+        <a href="/kra/services">Admin Services</a></font>
+    </td>
+</tr>
+</table>
+
+<br>
+
+<%
+    }
+
+    ServletContext ocspContext = getServletContext().getContext("/ocsp");
+    String ocspName = ocspContext.getServletContextName();
+    String ocspPath = ocspContext.getContextPath();
+    if (!"".equals(ocspPath) && request.isSecure()) {
+%>
+<p>
+<font size="+1" face="PrimaSans BT, Verdana, Arial, Helvetica, sans-serif">
+<%= ocspName %>
+</font>
+</p>
+
+<table border="0" cellspacing="0" cellpadding="0">
+<tr valign="TOP">
+    <td>
+        <li><font size=4 face="PrimaSans BT, Verdana, sans-serif">
+        <a href="/ocsp/agent/ocsp">Agent Services</a></font>
+    </td>
+</tr>
+<tr valign="TOP">
+    <td>
+        <li><font size=4 face="PrimaSans BT, Verdana, sans-serif">
+        <a href="/ocsp/services">Admin Services</a></font>
+    </td>
+</tr>
+</table>
+
+<br>
+
+<%
+    }
+
+    ServletContext tksContext = getServletContext().getContext("/tks");
+    String tksName = tksContext.getServletContextName();
+    String tksPath = tksContext.getContextPath();
+    if (!"".equals(tksPath) && request.isSecure()) {
+%>
+<p>
+<font size="+1" face="PrimaSans BT, Verdana, Arial, Helvetica, sans-serif">
+<%= tksName %>
+</font>
+</p>
+
+<table border="0" cellspacing="0" cellpadding="0">
+<tr valign="TOP">
+    <td>
+        <li><font size=4 face="PrimaSans BT, Verdana, sans-serif">
+        <a href="/tks/agent/tks">Agent Services</a></font>
+    </td>
+</tr>
+<tr valign="TOP">
+    <td>
+        <li><font size=4 face="PrimaSans BT, Verdana, sans-serif">
+        <a href="/tks/services">Admin Services</a></font>
+    </td>
+</tr>
+</table>
+
+<br>
+
+<%
+    }
+%>
+
+</center>
+
+<div id="footer">
+</div>
+
+</body>
+</html>
diff --git a/base/deploy/src/scriptlets/instance_layout.py b/base/deploy/src/scriptlets/instance_layout.py
index 72ccad16aaa170bad6dfa9e534678301231300be..245df5a5f4563eb4308cf926f556bf24d0edb9cd 100644
--- a/base/deploy/src/scriptlets/instance_layout.py
+++ b/base/deploy/src/scriptlets/instance_layout.py
@@ -50,11 +50,6 @@ class PkiScriptlet(pkiscriptlet.AbstractBasePkiScriptlet):
             util.directory.create(master['pki_tomcat_common_lib_path'])
             util.directory.create(master['pki_tomcat_tmpdir_path'])
             util.directory.create(master['pki_tomcat_webapps_path'])
-            util.directory.create(master['pki_tomcat_webapps_root_path'])
-            util.directory.create(master['pki_tomcat_webapps_root_webinf_path'])
-            util.file.copy(master['pki_source_webapps_root_web_xml'],
-                           master['pki_tomcat_webapps_root_webinf_web_xml'],
-                           overwrite_flag=True)
             util.directory.create(master['pki_tomcat_webapps_common_path'])
             util.directory.copy(
                 os.path.join(
@@ -62,6 +57,15 @@ class PkiScriptlet(pkiscriptlet.AbstractBasePkiScriptlet):
                     "common-ui"),
                 master['pki_tomcat_webapps_common_path'],
                 overwrite_flag=True)
+            util.directory.create(master['pki_tomcat_webapps_root_path'])
+            util.directory.copy(
+                os.path.join(
+                    config.PKI_DEPLOYMENT_SOURCE_ROOT,
+                    "shared",
+                    "webapps",
+                    "ROOT"),
+                master['pki_tomcat_webapps_root_path'],
+                overwrite_flag=True)
             util.directory.create(master['pki_tomcat_work_path'])
             util.directory.create(master['pki_tomcat_work_catalina_path'])
             util.directory.create(master['pki_tomcat_work_catalina_host_path'])
@@ -168,11 +172,16 @@ class PkiScriptlet(pkiscriptlet.AbstractBasePkiScriptlet):
                     "common-ui"),
                 master['pki_tomcat_webapps_common_path'],
                 overwrite_flag=True)
+            util.directory.copy(
+                os.path.join(
+                    config.PKI_DEPLOYMENT_SOURCE_ROOT,
+                    "shared",
+                    "webapps",
+                    "ROOT"),
+                master['pki_tomcat_webapps_root_path'],
+                overwrite_flag=True)
             util.directory.modify(master['pki_tomcat_webapps_root_path'])
             util.directory.modify(master['pki_tomcat_webapps_root_webinf_path'])
-            util.file.copy(master['pki_source_webapps_root_web_xml'],
-                           master['pki_tomcat_webapps_root_webinf_web_xml'],
-                           overwrite_flag=True)
             util.directory.modify(master['pki_tomcat_work_path'])
             util.directory.modify(master['pki_tomcat_work_catalina_path'])
             util.directory.modify(master['pki_tomcat_work_catalina_host_path'])
diff --git a/base/deploy/src/scriptlets/pkiparser.py b/base/deploy/src/scriptlets/pkiparser.py
index 64852f4335753499f11b4ccda3fe183cc118f438..dd70874feee1f1f9c0e048347223a524ccce56dd 100644
--- a/base/deploy/src/scriptlets/pkiparser.py
+++ b/base/deploy/src/scriptlets/pkiparser.py
@@ -406,9 +406,9 @@ def compose_pki_master_dictionary():
                              "lib")
             config.pki_master_dict['pki_tomcat_systemd'] =\
                 config.PKI_DEPLOYMENT_TOMCAT_SYSTEMD
-            config.pki_master_dict['pki_source_webapps_path'] =\
+            config.pki_master_dict['pki_shared_webapps_path'] =\
                 os.path.join(config.PKI_DEPLOYMENT_SOURCE_ROOT,
-                             config.pki_master_dict['pki_subsystem'].lower(),
+                             "shared",
                              "webapps")
             config.pki_master_dict['pki_source_catalina_properties'] =\
                 os.path.join(config.pki_master_dict['pki_source_shared_path'],
@@ -425,15 +425,6 @@ def compose_pki_master_dictionary():
             config.pki_master_dict['pki_source_tomcat_conf'] =\
                 os.path.join(config.pki_master_dict['pki_source_shared_path'],
                              "tomcat.conf")
-            config.pki_master_dict['pki_source_index_jsp'] =\
-                os.path.join(config.pki_master_dict['pki_source_webapps_path'],
-                             "ROOT",
-                             "index.jsp")
-            config.pki_master_dict['pki_source_webapps_root_web_xml'] =\
-                os.path.join(config.pki_master_dict['pki_source_webapps_path'],
-                             "ROOT",
-                             "WEB-INF",
-                             "web.xml")
             if config.pki_master_dict['pki_subsystem'] == "CA":
                 config.pki_master_dict['pki_source_emails'] =\
                     os.path.join(config.PKI_DEPLOYMENT_SOURCE_ROOT,
@@ -573,11 +564,6 @@ def compose_pki_master_dictionary():
                 os.path.join(
                     config.pki_master_dict['pki_tomcat_webapps_root_path'],
                     "WEB-INF")
-            config.pki_master_dict['pki_tomcat_webapps_root_webinf_web_xml'] =\
-                os.path.join(
-                    config.pki_master_dict\
-                    ['pki_tomcat_webapps_root_webinf_path'],
-                    "web.xml")
             config.pki_master_dict['pki_tomcat_work_path'] =\
                 os.path.join(config.pki_master_dict['pki_instance_path'],
                              "work")
@@ -1012,10 +998,6 @@ def compose_pki_master_dictionary():
                 os.path.join(
                     config.pki_master_dict['pki_instance_configuration_path'],
                     "tomcat.conf")
-            config.pki_master_dict['pki_target_index_jsp'] =\
-                os.path.join(
-                    config.pki_master_dict['pki_tomcat_webapps_root_path'],
-                    "index.jsp")
             # in-place slot substitution name/value pairs
             config.pki_master_dict['pki_target_auth_properties'] =\
                 os.path.join(
diff --git a/base/deploy/src/scriptlets/slot_substitution.py b/base/deploy/src/scriptlets/slot_substitution.py
index 482d1d9cbc4916587a337288e5fd3eb930987e55..39887611a35695dc5039451b48d8181f3b7169fe 100644
--- a/base/deploy/src/scriptlets/slot_substitution.py
+++ b/base/deploy/src/scriptlets/slot_substitution.py
@@ -65,10 +65,6 @@ class PkiScriptlet(pkiscriptlet.AbstractBasePkiScriptlet):
                 master['pki_source_tomcat_conf'],
                 master['pki_target_tomcat_conf'],
                 overwrite_flag=True)
-            util.file.copy_with_slot_substitution(
-                master['pki_source_index_jsp'],
-                master['pki_target_index_jsp'],
-                overwrite_flag=True)
             util.file.apply_slot_substitution(
                 master['pki_target_auth_properties'])
             util.file.apply_slot_substitution(
@@ -126,10 +122,6 @@ class PkiScriptlet(pkiscriptlet.AbstractBasePkiScriptlet):
                 master['pki_source_tomcat_conf'],
                 master['pki_target_tomcat_conf'],
                 overwrite_flag=True)
-            util.file.copy_with_slot_substitution(
-                master['pki_source_index_jsp'],
-                master['pki_target_index_jsp'],
-                overwrite_flag=True)
             util.file.apply_slot_substitution(
                 master['pki_target_auth_properties'])
             util.file.apply_slot_substitution(
diff --git a/base/kra/shared/webapps/kra/WEB-INF/web.xml b/base/kra/shared/webapps/kra/WEB-INF/web.xml
index 9208507c3a17a14ff2d2e0af46c5b36ac924e053..1a5b6aaf549aac593dffaa4221fd7327c3f9a6f1 100644
--- a/base/kra/shared/webapps/kra/WEB-INF/web.xml
+++ b/base/kra/shared/webapps/kra/WEB-INF/web.xml
@@ -3,6 +3,8 @@
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "file:///usr/share/pki/setup/web-app_2_3.dtd">
 <web-app>
 
+    <display-name>Key Recovery Authority</display-name>
+
     <servlet>
         <servlet-name>csadmin-wizard</servlet-name>
         <servlet-class>com.netscape.cms.servlet.wizard.WizardServlet</servlet-class>
diff --git a/base/ocsp/shared/webapps/ocsp/WEB-INF/web.xml b/base/ocsp/shared/webapps/ocsp/WEB-INF/web.xml
index b1e625975783055811e09cfc7611d83d8e000ff9..040e7f7ed1e64c25e55d41679243309cef3ddef5 100644
--- a/base/ocsp/shared/webapps/ocsp/WEB-INF/web.xml
+++ b/base/ocsp/shared/webapps/ocsp/WEB-INF/web.xml
@@ -7,6 +7,8 @@
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "file:///usr/share/pki/setup/web-app_2_3.dtd">
 <web-app>
 
+    <display-name>Online Certificate Status Protocol Manager</display-name>
+
     <servlet>
         <servlet-name>csadmin-wizard</servlet-name>
         <servlet-class>com.netscape.cms.servlet.wizard.WizardServlet</servlet-class>
diff --git a/base/tks/shared/webapps/tks/WEB-INF/web.xml b/base/tks/shared/webapps/tks/WEB-INF/web.xml
index 80bb24bc12117bfe9730ceca9a64bca15b0e581c..a06b2f213f840e0cf49658333cd3112ff8b1918e 100644
--- a/base/tks/shared/webapps/tks/WEB-INF/web.xml
+++ b/base/tks/shared/webapps/tks/WEB-INF/web.xml
@@ -7,6 +7,8 @@
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "file:///usr/share/pki/setup/web-app_2_3.dtd">
 <web-app>
 
+    <display-name>Token Key Service</display-name>
+
     <servlet>
         <servlet-name>csadmin-wizard</servlet-name>
         <servlet-class>com.netscape.cms.servlet.wizard.WizardServlet</servlet-class>
diff --git a/specs/pki-core.spec b/specs/pki-core.spec
index 0986ab3b12922eb2db003041cfb2644698bad216..4d4d54c0440d7eeff9a242f9871f3217e9b121aa 100644
--- a/specs/pki-core.spec
+++ b/specs/pki-core.spec
@@ -14,7 +14,7 @@ distutils.sysconfig import get_python_lib; print(get_python_lib(1))")}
 
 Name:             pki-core
 Version:          10.0.0
-Release:          %{?relprefix}30%{?prerel}%{?dist}
+Release:          %{?relprefix}31%{?prerel}%{?dist}
 Summary:          Certificate System - PKI Core Components
 URL:              http://pki.fedoraproject.org/
 License:          GPLv2
@@ -1163,7 +1163,7 @@ fi
 
 %{_datadir}/pki/setup/
 %dir %{_datadir}/pki/shared
-%{_datadir}/pki/shared/conf/
+%{_datadir}/pki/shared/
 
 
 %files -n pki-selinux
@@ -1304,6 +1304,9 @@ fi
 
 
 %changelog
+* Wed Sep 12 2012 Endi S. Dewata <edewata@redhat.com> 10.0.0-0.31.a1
+- Fixed pki-server to include everything in shared dir.
+
 * Tue Sep 11 2012 Endi S. Dewata <edewata@redhat.com> 10.0.0-0.30.a1
 - Added build dependency on redhat-rpm-config.
 
-- 
1.7.11.2

