summaryrefslogtreecommitdiffstats
path: root/base/server
diff options
context:
space:
mode:
authorEndi S. Dewata <edewata@redhat.com>2016-08-24 18:42:05 +0200
committerEndi S. Dewata <edewata@redhat.com>2016-08-26 17:19:39 +0200
commitb8094e82c46f8d5f18d362404582304ad28407da (patch)
treec1f84cf23be09b73ed148172901a2bc68b0577db /base/server
parenta4d726098458225a0605faca9f11ebaa4dab036f (diff)
downloadpki-b8094e82c46f8d5f18d362404582304ad28407da.tar.gz
pki-b8094e82c46f8d5f18d362404582304ad28407da.tar.xz
pki-b8094e82c46f8d5f18d362404582304ad28407da.zip
Added upgrade script to fix deployment descriptors.
An upgrade script has been added to fix missing deployment descriptors or deployment descriptors that are pointing to non-existent or empty folders. https://fedorahosted.org/pki/ticket/2439
Diffstat (limited to 'base/server')
-rw-r--r--base/server/upgrade/10.3.5/03-FixDeploymentDescriptor110
1 files changed, 110 insertions, 0 deletions
diff --git a/base/server/upgrade/10.3.5/03-FixDeploymentDescriptor b/base/server/upgrade/10.3.5/03-FixDeploymentDescriptor
new file mode 100644
index 000000000..27c895980
--- /dev/null
+++ b/base/server/upgrade/10.3.5/03-FixDeploymentDescriptor
@@ -0,0 +1,110 @@
+#!/usr/bin/python
+# Authors:
+# Endi S. Dewata <edewata@redhat.com>
+#
+# 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) 2016 Red Hat, Inc.
+# All rights reserved.
+
+from __future__ import absolute_import
+from lxml import etree
+import os
+import shutil
+
+import pki.server.upgrade
+
+
+class FixDeploymentDescriptor(pki.server.upgrade.PKIServerUpgradeScriptlet):
+
+ def __init__(self):
+ super(FixDeploymentDescriptor, self).__init__()
+ self.message = 'Fix deployment descriptor'
+ self.parser = etree.XMLParser(remove_blank_text=True)
+
+ def upgrade_instance(self, instance):
+
+ self.fix_webapp(instance, 'ROOT.xml')
+ self.fix_webapp(instance, 'pki#admin.xml')
+ self.fix_webapp(instance, 'pki#js.xml')
+
+ self.fix_theme(instance, 'pki.xml')
+
+ def fix_webapp(self, instance, context_xml):
+
+ source_xml = pki.SHARE_DIR + '/server/conf/Catalina/localhost/' + context_xml
+ target_xml = instance.conf_dir + '/Catalina/localhost/' + context_xml
+
+ # if deployment descriptor doesn't exist, install the default
+ if not os.path.exists(target_xml):
+ self.copy_file(instance, source_xml, target_xml)
+ return
+
+ # get docBase from deployment descriptor
+ document = etree.parse(target_xml, self.parser)
+ context = document.getroot()
+ docBase = context.get('docBase')
+
+ # if docBase is absolute and pointing to non-empty folder, ignore
+ if docBase.startswith('/') and \
+ os.path.exists(docBase) and \
+ os.listdir(docBase):
+ return
+
+ # if docBase is relative and pointing to non-empty folder, ignore
+ if not docBase.startswith('/') and \
+ os.path.exists(instance.base_dir + '/webapps/' + docBase) and \
+ os.listdir(instance.base_dir + '/webapps/' + docBase):
+ return
+
+ # docBase is pointing to non-existent/empty folder, replace with default
+ self.copy_file(instance, source_xml, target_xml)
+
+ def fix_theme(self, instance, context_xml):
+
+ source_xml = pki.SHARE_DIR + '/server/conf/Catalina/localhost/' + context_xml
+ target_xml = instance.conf_dir + '/Catalina/localhost/' + context_xml
+
+ # if deployment descriptor doesn't exist, ignore (no theme)
+ if not os.path.exists(target_xml):
+ return
+
+ # get docBase from deployment descriptor
+ document = etree.parse(target_xml, self.parser)
+ context = document.getroot()
+ docBase = context.get('docBase')
+
+ # if docBase is absolute and pointing to non-empty folder, ignore
+ if docBase.startswith('/') and \
+ os.path.exists(docBase) and \
+ os.listdir(docBase):
+ return
+
+ # if docBase is relative and pointing to non-empty folder, ignore
+ if not docBase.startswith('/') and \
+ os.path.exists(instance.base_dir + '/webapps/' + docBase) and \
+ os.listdir(instance.base_dir + '/webapps/' + docBase):
+ return
+
+ # docBase is pointing to non-existent/empty folder
+
+ # if theme package is installed, replace deployment descriptor
+ if os.path.exists(pki.SHARE_DIR + '/common-ui'):
+ self.copy_file(instance, source_xml, target_xml)
+
+ def copy_file(self, instance, source, target):
+
+ self.backup(target)
+ shutil.copyfile(source, target)
+ os.chown(target, instance.uid, instance.gid)