Ejemplo n.º 1
0
class NonEncryptedPropertiesFile:
	""" transform any non encrypted password properties int encrypted form
	return a PropertiesFile object of the new (rewritten) file
	"""
	
	def __init__(self, fileName):
		ep = EncryptedPassword()
		self.rep = SimpleReporter()
		self.fileName = fileName
		try:
			inf = open(fileName, "r")
		except:
			self.rep.report("problem opening %s" % (fileName), "e")
		self.origProps = inf.readlines()
		inf.close()
		newLines = []
		dirtyFile = 0
		for line in self.origProps:
			if line.strip().startswith("#"):
				newLines.append(line)
				continue
			lineBits = line.split("=")
			if len(lineBits) < 2:
				newLines.append(line)
				continue
			if not lineBits[0].find("password") > -1:
				newLines.append(line)
				continue
			key = lineBits[0]
			origVal = "=".join(lineBits[1:]).rstrip()
			try:
				ep.decrypt(origVal)
				newLines.append(line)
			except:
				newVal = ep.encrypt(origVal)
				newLines.append(key + "=" + newVal + "\n")
				dirtyFile = 1
		if dirtyFile:
			outf = open(fileName, "w")
			outf.writelines(newLines)
			outf.close()
	def getFile(self):
		pf = PropertiesFile(self.fileName)
		return pf
Ejemplo n.º 2
0
	def __init__(self, fileName):
		ep = EncryptedPassword()
		self.rep = SimpleReporter()
		self.fileName = fileName
		try:
			inf = open(fileName, "r")
		except:
			self.rep.report("problem opening %s" % (fileName), "e")
		self.origProps = inf.readlines()
		inf.close()
		newLines = []
		dirtyFile = 0
		for line in self.origProps:
			if line.strip().startswith("#"):
				newLines.append(line)
				continue
			lineBits = line.split("=")
			if len(lineBits) < 2:
				newLines.append(line)
				continue
			if not lineBits[0].find("password") > -1:
				newLines.append(line)
				continue
			key = lineBits[0]
			origVal = "=".join(lineBits[1:]).rstrip()
			try:
				ep.decrypt(origVal)
				newLines.append(line)
			except:
				newVal = ep.encrypt(origVal)
				newLines.append(key + "=" + newVal + "\n")
				dirtyFile = 1
		if dirtyFile:
			outf = open(fileName, "w")
			outf.writelines(newLines)
			outf.close()
Ejemplo n.º 3
0
""" take a list of properties files and open them
"""
import sys, os
from propertiesutils import PropertiesFile
from propertiesutils import NonEncryptedPropertiesFile
from loggingutils import SimpleReporter
from propertiesutils import XmlProperties
logger = SimpleReporter()
xpf = XmlProperties("tmp/ant-properties.xml")
xpf.transformProperties("tmp/ant-properties.properties")
pf = PropertiesFile("tmp/ant-properties.properties")
fileList = pf.get("property.files").split(",")
for file in fileList:
	logger.report("Processing %s" % (file))
	enc = NonEncryptedPropertiesFile(file)
Ejemplo n.º 4
0
""" get all of the properties files in the current directory and open them
"""
import os
from propertiesutils import NonEncryptedPropertiesFile
from loggingutils import SimpleReporter
logger = SimpleReporter()
listDir = os.listdir(".")
for entry in listDir:
	if os.path.isfile(entry):
		if entry.endswith(".properties"):
			logger.report("Processing %s" % (entry))
			pf = NonEncryptedPropertiesFile(entry)