def setup(self): super(RedHatPostgreSQL, self).setup() scl = "rh-postgresql95" pghome = self.get_option("pghome") # Copy PostgreSQL log files. for filename in find("*.log", pghome): self.add_copy_spec(filename) for filename in find("*.log", self.convert_copyspec_scl(scl, pghome)): self.add_copy_spec(filename) # Copy PostgreSQL config files. for filename in find("*.conf", pghome): self.add_copy_spec(filename) for filename in find("*.conf", self.convert_copyspec_scl(scl, pghome)): self.add_copy_spec(filename) self.add_copy_spec(os.path.join(pghome, "data", "PG_VERSION")) self.add_copy_spec(os.path.join(pghome, "data", "postmaster.opts")) self.add_copy_spec_scl(scl, os.path.join(pghome, "data", "PG_VERSION")) self.add_copy_spec_scl(scl, os.path.join( pghome, "data", "postmaster.opts" ) ) if scl in self.scls_matched: self.do_pg_dump(scl=scl, filename="pgdump-scl-%s.tar" % scl)
def postproc(self): """ Obfuscate passwords. """ for dir in self.__jbossServerConfigDirs: path = os.path.join(self.__jbossHome, "server", dir) ## Really annoying that there appears to be no vehicle to ## say I want ignore case...argh! self.doRegexSub( os.path.join(path, "conf", "login-config.xml"), r"\"[Pp][Aa][Ss][Ss][Ww][Oo][Rr][Dd]\".*>.*</[Mm][Oo][Dd][Uu][Ll][Ee]-[Oo][Pp][Tt][Ii][Oo][Nn].*>", r'"password">********</module-option>') tmp = os.path.join(path, "conf", "props") for propFile in find("*-users.properties", tmp): self.doRegexSub(propFile, r"=(.*)", r'=********') ## Remove PW from -ds.xml files tmp = os.path.join(path, "deploy") for dsFile in find("*-ds.xml", tmp): self.doRegexSub( dsFile, r"<[Pp][Aa][Ss][Ss][Ww][Oo][Rr][Dd].*>.*</[Pp][Aa][Ss][Ss][Ww][Oo][Rr][Dd].*>", r"<password>********</password>") return
def setup(self): super(RedHatPostgreSQL, self).setup() pghome = self.get_option("pghome") scl = None for pkg in self.packages[1:]: # The scl name, package name, and service name all differ slightly # but is at least consistent in doing so across versions, so we # need to do some mangling here if self.service_is_running(pkg.replace('-server', '')): scl = pkg.split('-postgresql-')[0] # Copy PostgreSQL log files. for filename in find("*.log", pghome): self.add_copy_spec(filename) for filename in find("*.log", self.convert_copyspec_scl(scl, pghome)): self.add_copy_spec(filename) # Copy PostgreSQL config files. for filename in find("*.conf", pghome): self.add_copy_spec(filename) for filename in find("*.conf", self.convert_copyspec_scl(scl, pghome)): self.add_copy_spec(filename) self.add_copy_spec(os.path.join(pghome, "data", "PG_VERSION")) self.add_copy_spec(os.path.join(pghome, "data", "postmaster.opts")) self.add_copy_spec_scl(scl, os.path.join(pghome, "data", "PG_VERSION")) self.add_copy_spec_scl(scl, os.path.join(pghome, "data", "postmaster.opts")) if scl and scl in self.scls_matched: self.do_pg_dump(scl=scl, filename="pgdump-scl-%s.tar" % scl)
def postproc(self): """ Obfuscate passwords. """ for dir in self.__jbossServerConfigDirs: path=os.path.join(self.__jbossHome, "server", dir) ## Really annoying that there appears to be no vehicle to ## say I want ignore case...argh! self.doRegexSub(os.path.join(path,"conf","login-config.xml"), r"\"[Pp][Aa][Ss][Ss][Ww][Oo][Rr][Dd]\".*>.*</[Mm][Oo][Dd][Uu][Ll][Ee]-[Oo][Pp][Tt][Ii][Oo][Nn].*>", r'"password">********</module-option>') tmp = os.path.join(path,"conf", "props") for propFile in find("*-users.properties", tmp): self.doRegexSub(propFile, r"=(.*)", r'=********') ## Remove PW from -ds.xml files tmp=os.path.join(path, "deploy") for dsFile in find("*-ds.xml", tmp): self.doRegexSub(dsFile, r"<[Pp][Aa][Ss][Ss][Ww][Oo][Rr][Dd].*>.*</[Pp][Aa][Ss][Ss][Ww][Oo][Rr][Dd].*>", r"<password>********</password>") return
def __getFiles(self, configDirAry): """ This function will collect files from JBOSS_HOME for analysis. The scope of files to be collected are determined by options to this SOS plug-in. """ for dir_ in configDirAry: path = os.path.join(self.__jbossHome, dir_) ## First add forbidden files self.addForbiddenPath(os.path.join(path, "tmp")) self.addForbiddenPath(os.path.join(path, "work")) self.addForbiddenPath(os.path.join(path, "data")) if os.path.exists(path): ## First get everything in the conf dir confDir = os.path.join(path, "configuration") self.addForbiddenPath(os.path.join(confDir, 'mgmt-users.properties')) self.doCopyFileOrDir(confDir, sub=(self.__jbossHome, 'JBOSSHOME')) ## Log dir next logDir = os.path.join(path, "log") for logFile in find("*", logDir): self.addCopySpecLimit(logFile, self.getOption("logsize"), sub=(self.__jbossHome, 'JBOSSHOME')) ## Deploy dir deployDir = os.path.join(path, "deployments") for deployFile in find("*", deployDir, max_depth=1): self.addCopySpec(deployFile, sub=(self.__jbossHome, 'JBOSSHOME'))
def postproc(self): """ Obfuscate passwords. """ password_xml_regex = re.compile(r'<password>.*</password>', re.IGNORECASE) for dir_ in self.__jbossServerConfigDirs: path = os.path.join(self.__jbossHome, dir_) self.doRegexSub(os.path.join(path,"configuration","*.xml"), password_xml_regex, r'<password>********</password>') tmp = os.path.join(path,"configuration") for propFile in find("*-users.properties", tmp): self.doRegexSub(propFile, r"=(.*)", r'=********') # Remove PW from -ds.xml files tmp = os.path.join(path, "deployments") for dsFile in find("*-ds.xml", tmp): self.doRegexSub(dsFile, password_xml_regex, r"<password>********</password>")
def __getFiles(self, configDirAry): """ This function will collect files from JBOSS_HOME for analysis. The scope of files to be collected are determined by options to this SOS plug-in. """ for dir_ in configDirAry: path = os.path.join(self.__jbossHome, dir_) ## First add forbidden files self.addForbiddenPath(os.path.join(path, "tmp")) self.addForbiddenPath(os.path.join(path, "work")) self.addForbiddenPath(os.path.join(path, "data")) if os.path.exists(path): ## First get everything in the conf dir confDir = os.path.join(path, "configuration") self.addForbiddenPath( os.path.join(confDir, 'mgmt-users.properties')) self.doCopyFileOrDir(confDir, sub=(self.__jbossHome, 'JBOSSHOME')) ## Log dir next logDir = os.path.join(path, "log") for logFile in find("*", logDir): self.addCopySpecLimit(logFile, self.getOption("logsize"), sub=(self.__jbossHome, 'JBOSSHOME')) ## Deploy dir deployDir = os.path.join(path, "deployments") for deployFile in find("*", deployDir, max_depth=1): self.addCopySpec(deployFile, sub=(self.__jbossHome, 'JBOSSHOME'))
def __getFiles(self, configDirAry): """ This function will collect files from JBOSS_HOME for analysis. The scope of files to be collected are determined by options to this SOS plug-in. """ for dir_ in configDirAry: path = os.path.join(self.__jbossHome, dir_) ## First add forbidden files self.addForbiddenPath(os.path.join(path, "tmp")) self.addForbiddenPath(os.path.join(path, "work")) self.addForbiddenPath(os.path.join(path, "data")) if os.path.exists(path): ## First get everything in the conf dir confDir = os.path.join(path, "configuration") self.addForbiddenPath(os.path.join(confDir, 'mgmt-users.properties')) self.addForbiddenPath(os.path.join(confDir, 'application-users.properties')) self.doCopyFileOrDir(confDir, sub=(self.__jbossHome, 'JBOSSHOME')) for logFile in find("*.log", path): self.addCopySpecLimit(logFile, self.getOption("logsize"), sub=(self.__jbossHome, 'JBOSSHOME')) for xml in find("*.xml", path): self.addCopySpec(xml) deployment_info = self.__get_deployment_info(confDir) deployments = self.__get_deployments(path) for deployment in deployments: self.__get_listing_from_deployment(deployment, deployment_info)
def setup(self): super(RedHatPostgreSQL, self).setup() pghome = self.get_option("pghome") dirs = [pghome] for pkg in self.packages[1:]: # The scl name, package name, and service name all differ slightly # but is at least consistent in doing so across versions, so we # need to do some mangling here scl = pkg.split('-postgresql-')[0] _dir = self.convert_copyspec_scl(scl, pghome) dirs.append(_dir) if self.path_isdir(_dir): self.add_cmd_output("du -sh %s" % _dir) if (self.is_service_running(pkg.replace('-server', '')) and scl in self.scls_matched): self.do_pg_dump(scl=scl, filename="pgdump-scl-%s.tar" % scl) for _dir in dirs: # Copy PostgreSQL log files. for filename in find("*.log", _dir): self.add_copy_spec(filename) # Copy PostgreSQL config files. for filename in find("*.conf", _dir): self.add_copy_spec(filename) # copy PG_VERSION and postmaster.opts for f in ["PG_VERSION", "postmaster.opts"]: self.add_copy_spec(self.path_join(_dir, "data", f))
def setup(self): super(RedHatPostgreSQL, self).setup() # Copy PostgreSQL log files. for file in find("*.log", self.get_option("pghome")): self.add_copy_spec(file) # Copy PostgreSQL config files. for file in find("*.conf", self.get_option("pghome")): self.add_copy_spec(file) self.add_copy_spec(os.path.join(self.get_option("pghome"), "data" , "PG_VERSION")) self.add_copy_spec(os.path.join(self.get_option("pghome"), "data" , "postmaster.opts"))
def setup(self): super(RedHatPostgreSQL, self).setup() # Copy PostgreSQL log files. for filename in find("*.log", self.get_option("pghome")): self.add_copy_spec(filename) # Copy PostgreSQL config files. for filename in find("*.conf", self.get_option("pghome")): self.add_copy_spec(filename) self.add_copy_spec( os.path.join(self.get_option("pghome"), "data", "PG_VERSION")) self.add_copy_spec( os.path.join(self.get_option("pghome"), "data", "postmaster.opts"))
def setup(self): if self.getOption("dbname"): if self.getOption("password"): self.tmp_dir = tempfile.mkdtemp() self.pg_dump() else: self.addAlert("WARN: password must be supplied to dump a database.") # Copy PostgreSQL log files. for file in find("*.log", self.getOption("pghome")): self.addCopySpec(file) # Copy PostgreSQL config files. for file in find("*.conf", self.getOption("pghome")): self.addCopySpec(file) self.addCopySpec(os.path.join(self.getOption("pghome"), "data" , "PG_VERSION")) self.addCopySpec(os.path.join(self.getOption("pghome"), "data" , "postmaster.opts"))
def __getServerConfigJarInfo(self, configDirAry): self.__jbossHTMLBody += """ <br/> <br/> <div id="profile-jar-info" style="font-weight: bold;">– JBoss Server Configurations Jar Information</div> """ for dir in configDirAry: serverDir = os.path.join("server", dir) path=os.path.join(self.__jbossHome, serverDir) if os.path.exists(path): nicePath=path.replace(os.sep, "-") self.__jbossHTMLBody += """ <div> — Summary of Jar Files in the <tt>%s</tt> JBoss Server Configuration ( <a href="javascript:show('%s')">Show</a> / <a href="javascript:hide('%s')">Hide</a> ): </div> <div id="%s" style="overflow: hidden; display: none"> <ul style="list-style-type: square"> """ % (dir, nicePath,nicePath,nicePath) found = False for jarFile in find("*.jar", path): found = True nicePath=jarFile.replace(os.sep, "-") self.__jbossHTMLBody += """ <li id="system-jar-info">Jar File: <tt>%s</tt><br/> MD5: <tt>%s</tt> <br /> Manifest File ( <a href="javascript:show('%s')">Show</a> / <a href="javascript:hide('%s')">Hide</a> ):<br /> <div id="%s" style="overflow: hidden; display: none"> <pre> %s </pre> </div> </li> """ % (jarFile, self.__getMd5(jarFile), nicePath, nicePath, nicePath, self.__getManifest(jarFile)) if not found: self.addAlert("WARN: No jars found in the JBoss server configuration (%s)." % (path)) self.__jbossHTMLBody += """ </ul> </div> """ else: self.addAlert("ERROR: JBoss server configuration path (" + path + ") does not exist.") return
def __getFiles(self, configDirAry): """ This function will collect files from JBOSS_HOME for analysis. The scope of files to be collected are determined by options to this SOS plug-in. """ for dir in configDirAry: path = os.path.join(self.__jbossHome, "server", dir) ## First add forbidden files self.add_forbidden_path(os.path.join(path, "tmp")) self.add_forbidden_path(os.path.join(path, "work")) self.add_forbidden_path(os.path.join(path, "data")) if os.path.exists(path): ## First get everything in the conf dir confDir = os.path.join(path, "conf") self.do_copy_file_or_dir(confDir) ## Log dir next logDir = os.path.join(path, "log") for logFile in find("*", logDir): self.add_copy_spec_limit(logFile, self.get_option("logsize")) ## Deploy dir deployDir = os.path.join(path, "deploy") for deployFile in find("*", deployDir, max_depth=1): self.add_copy_spec(deployFile) ## Get application deployment descriptors if designated. if self.option_enabled("appxml"): appxml = self.get_option("appxml") ## I'd rather use comma as the delimiter but get_option doesn't seem to be passing it through. ## Since we are using spaces as the delimiter, we need to filter out empty list elements ## if the user did something like ' all default web '. appxml = appxml.split(' ') ## Flter(None doesn't work. Allows 0. appxml = filter(lambda x: len(x), appxml) for app in appxml: pat = os.path.join("*%s*" % (app, ), "WEB-INF") for file in find("*.xml", deployDir, path_pattern=pat): self.add_copy_spec(file) return
def __getServerConfigJarInfo(self, configDirAry): self.__jbossHTMLBody += """ <br/> <br/> <div id="profile-jar-info" style="font-weight: bold;">– JBoss Server Configurations Jar Information</div> """ for dir in configDirAry: serverDir = os.path.join("server", dir) path = os.path.join(self.__jbossHome, serverDir) if os.path.exists(path): nicePath = path.replace(os.sep, "-") self.__jbossHTMLBody += """ <div> — Summary of Jar Files in the <tt>%s</tt> JBoss Server Configuration ( <a href="javascript:show('%s')">Show</a> / <a href="javascript:hide('%s')">Hide</a> ): </div> <div id="%s" style="overflow: hidden; display: none"> <ul style="list-style-type: square"> """ % (dir, nicePath, nicePath, nicePath) found = False for jarFile in find("*.jar", path): found = True nicePath = jarFile.replace(os.sep, "-") self.__jbossHTMLBody += """ <li id="system-jar-info">Jar File: <tt>%s</tt><br/> MD5: <tt>%s</tt> <br /> Manifest File ( <a href="javascript:show('%s')">Show</a> / <a href="javascript:hide('%s')">Hide</a> ):<br /> <div id="%s" style="overflow: hidden; display: none"> <pre> %s </pre> </div> </li> """ % (jarFile, self.__getMd5(jarFile), nicePath, nicePath, nicePath, self.__getManifest(jarFile)) if not found: self.addAlert( "WARN: No jars found in the JBoss server configuration (%s)." % (path)) self.__jbossHTMLBody += """ </ul> </div> """ else: self.addAlert("ERROR: JBoss server configuration path (" + path + ") does not exist.") return
def __getFiles(self, configDirAry): """ This function will collect files from JBOSS_HOME for analysis. The scope of files to be collected are determined by options to this SOS plug-in. """ for dir in configDirAry: path=os.path.join(self.__jbossHome, "server", dir) ## First add forbidden files self.addForbiddenPath(os.path.join(path, "tmp")) self.addForbiddenPath(os.path.join(path, "work")) self.addForbiddenPath(os.path.join(path, "data")) if os.path.exists(path): ## First get everything in the conf dir confDir=os.path.join(path, "conf") self.doCopyFileOrDir(confDir) ## Log dir next logDir=os.path.join(path, "log") for logFile in find("*", logDir): self.addCopySpecLimit(logFile, self.getOption("logsize")) ## Deploy dir deployDir=os.path.join(path, "deploy") for deployFile in find("*", deployDir, max_depth=1): self.addCopySpec(deployFile) ## Get application deployment descriptors if designated. if self.isOptionEnabled("appxml"): appxml=self.getOption("appxml") ## I'd rather use comma as the delimiter but getOption doesn't seem to be passing it through. ## Since we are using spaces as the delimiter, we need to filter out empty list elements ## if the user did something like ' all default web '. appxml=appxml.split(' ') ## Flter(None doesn't work. Allows 0. appxml=filter(lambda x: len(x), appxml) for app in appxml: pat = os.path.join("*%s*" % (app,), "WEB-INF") for file in find("*.xml", deployDir, path_pattern=pat): self.addCopySpec(file) return
def setup(self): if self.get_option("dbname"): if self.get_option("password"): self.tmp_dir = tempfile.mkdtemp() self.pg_dump() else: self.add_alert( "WARN: password must be supplied to dump a database.") # Copy PostgreSQL log files. for file in find("*.log", self.get_option("pghome")): self.add_copy_spec(file) # Copy PostgreSQL config files. for file in find("*.conf", self.get_option("pghome")): self.add_copy_spec(file) self.add_copy_spec( os.path.join(self.get_option("pghome"), "data", "PG_VERSION")) self.add_copy_spec( os.path.join(self.get_option("pghome"), "data", "postmaster.opts"))
def setup(self): super(RedHatPostgreSQL, self).setup() pghome = self.get_option("pghome") scl = None for pkg in self.packages[1:]: # The scl name, package name, and service name all differ slightly # but is at least consistent in doing so across versions, so we # need to do some mangling here if self.service_is_running(pkg.replace('-server', '')): scl = pkg.split('-postgresql-')[0] # Copy PostgreSQL log files. for filename in find("*.log", pghome): self.add_copy_spec(filename) for filename in find("*.log", self.convert_copyspec_scl(scl, pghome)): self.add_copy_spec(filename) # Copy PostgreSQL config files. for filename in find("*.conf", pghome): self.add_copy_spec(filename) for filename in find("*.conf", self.convert_copyspec_scl(scl, pghome)): self.add_copy_spec(filename) self.add_copy_spec(os.path.join(pghome, "data", "PG_VERSION")) self.add_copy_spec(os.path.join(pghome, "data", "postmaster.opts")) self.add_copy_spec_scl(scl, os.path.join(pghome, "data", "PG_VERSION")) self.add_copy_spec_scl(scl, os.path.join( pghome, "data", "postmaster.opts" ) ) if scl and scl in self.scls_matched: self.do_pg_dump(scl=scl, filename="pgdump-scl-%s.tar" % scl)
def __get_deployment_info(self, dir_): """Gets the deployment name to sha1 mapping for all deployments defined in configs under dir_""" deployment_info = {} for config in find("*.xml", dir_): root = ElementTree.parse(config).getroot() # the namespace is harder to fetch than it should be ns = root.tag.rpartition("}")[0] ns += "}" for deployment in root.findall("./%sdeployments/%sdeployment" % (ns, ns)): name = deployment.attrib.get("name") sha1 = deployment.getchildren()[0].attrib.get("sha1") deployment_info[sha1] = name return deployment_info
def __getFiles(self, configDirAry): """ This function will collect files from JBOSS_HOME for analysis. The scope of files to be collected are determined by options to this SOS plug-in. """ for dir_ in configDirAry: path = os.path.join(self.__jbossHome, dir_) ## First add forbidden files self.addForbiddenPath(os.path.join(path, "tmp")) self.addForbiddenPath(os.path.join(path, "work")) self.addForbiddenPath(os.path.join(path, "data")) if os.path.exists(path): ## First get everything in the conf dir confDir = os.path.join(path, "configuration") self.addForbiddenPath( os.path.join(confDir, 'mgmt-users.properties')) self.addForbiddenPath( os.path.join(confDir, 'application-users.properties')) for logFile in find("*.log", path): self.addCopySpecLimit(logFile, self.getOption("logsize"), sub=(self.__jbossHome, 'JBOSSHOME')) for xml in find("*.xml", path): self.addCopySpec(xml, sub=(self.__jbossHome, 'JBOSSHOME')) for prop in find("*.properties", path): self.addCopySpec(prop, sub=(self.__jbossHome, 'JBOSSHOME')) deployment_info = self.__get_deployment_info(confDir) deployments = self.__get_deployments(path) for deployment in deployments: self.__get_listing_from_deployment(deployment, deployment_info)
def postproc(self): """ Obfuscate passwords. """ for dir_ in self.__jbossServerConfigDirs: path = os.path.join(self.__jbossHome, dir_) self.doRegexSub(os.path.join(path,"configuration","login-config.xml"), re.compile(r'"password".*>.*</module-option>', re.IGNORECASE), r'"password">********</module-option>') tmp = os.path.join(path,"conf", "props") for propFile in find("*-users.properties", tmp): self.doRegexSub(propFile, r"=(.*)", r'=********') # Remove PW from -ds.xml files tmp = os.path.join(path, "deploy") for dsFile in find("*-ds.xml", tmp): self.doRegexSub(dsFile, re.compile(r"<password.*>.*</password.*>", re.IGNORECASE), r"<password>********</password>")
def __getStdJarInfo(self): found = False jar_info_list = [] for jarFile in find("*.jar", self.__jbossHome): checksum = self.__getMd5(jarFile) manifest = self.__getManifest(jarFile) path = jarFile.replace(self.__jbossHome, 'JBOSSHOME') if manifest: manifest = manifest.strip() jar_info_list.append((path, checksum, manifest)) found = True if found: jar_info_list.sort() self.addStringAsFile("\n".join([ "%s\n%s\n%s\n" % (name, checksum, manifest) for (name, checksum, manifest) in jar_info_list]), 'jarinfo.txt') else: self.addAlert("WARN: No jars found in JBoss system path (" + self.__jbossHome + ").")
def test_find_leaf(self): leaves = find("leaf", TEST_DIR) self.assertTrue(any(name.endswith("leaf") for name in leaves))
def test_not_in_pattern(self): leaves = find("leaf", TEST_DIR, path_pattern="tests/path") self.assertFalse(any(name.endswith("leaf") for name in leaves))
def test_too_shallow(self): leaves = find("leaf", TEST_DIR, max_depth=1) self.assertFalse(any(name.endswith("leaf") for name in leaves))
def __get_deployments(self, path): return list( chain(find("*", os.path.join(path, "deployments")), find("content", path)))
def __get_deployments(self, path): return list(chain( find("*", os.path.join(path, "deployments")), find("content", path)))