|
|
|
@ -2182,7 +2182,11 @@ class profile(_file, _terms, xmlShare):
|
|
|
|
|
# Название файла профиля директории
|
|
|
|
|
profDirNameFile = ".calculate_directory"
|
|
|
|
|
|
|
|
|
|
def __init__(self, objVar, servDir=False):
|
|
|
|
|
def __init__(self, objVar, servDir=False, dirsFilter=[], filesFilter=[]):
|
|
|
|
|
# Необрабатываемые директории
|
|
|
|
|
self.dirsFilter = dirsFilter
|
|
|
|
|
# Необрабатываемые файлы
|
|
|
|
|
self.filesFilter = filesFilter
|
|
|
|
|
_file.__init__(self)
|
|
|
|
|
# Словарь для создания объектов новых классов по образцу
|
|
|
|
|
self.newObjProt = {'proftpd':(apache,),}
|
|
|
|
@ -2855,9 +2859,10 @@ class profile(_file, _terms, xmlShare):
|
|
|
|
|
#созданные директории
|
|
|
|
|
createdDirs = []
|
|
|
|
|
# Получаем общее количество профилей (нужно для прогресбара)
|
|
|
|
|
numberAllProfiles = 0
|
|
|
|
|
for dirObj in dirObjs:
|
|
|
|
|
numberAllProfiles += len(dirObj.files)
|
|
|
|
|
allApplyFiles = self.scanProfiles(False, dirObjs)
|
|
|
|
|
if allApplyFiles == False:
|
|
|
|
|
return False
|
|
|
|
|
numberAllProfiles = len(allApplyFiles)
|
|
|
|
|
# Вызываем пустой метод с параметром общее количество профилей
|
|
|
|
|
self.numberAllProfiles(numberAllProfiles)
|
|
|
|
|
# номер обрабатываемого файла
|
|
|
|
@ -2885,7 +2890,10 @@ class profile(_file, _terms, xmlShare):
|
|
|
|
|
pathDir, objHeadDir = self.__getApplyHeadDir(newDir,
|
|
|
|
|
dirInfoFile,
|
|
|
|
|
changeDirs)
|
|
|
|
|
|
|
|
|
|
# Фильтрация профилей по названию директории
|
|
|
|
|
if pathDir in self.dirsFilter:
|
|
|
|
|
blockDirs.append(dirProfile)
|
|
|
|
|
continue
|
|
|
|
|
if objHeadDir:
|
|
|
|
|
if isinstance(objHeadDir, dirHeader):
|
|
|
|
|
if not objHeadDir.headerCorrect:
|
|
|
|
@ -2936,21 +2944,17 @@ class profile(_file, _terms, xmlShare):
|
|
|
|
|
findChangeDir = True
|
|
|
|
|
break
|
|
|
|
|
if findChangeDir:
|
|
|
|
|
#end = "/".join(map(lambda x:x.split("?")[0],\
|
|
|
|
|
#end.split("/")))
|
|
|
|
|
oldFile = dirChangeOut + end
|
|
|
|
|
else:
|
|
|
|
|
oldFile = fileProfile.partition(dirObj.baseDir)[2]
|
|
|
|
|
|
|
|
|
|
#dirName,fileName = os.path.split(oldFile)
|
|
|
|
|
#fileName = fileName.split("?")[0]
|
|
|
|
|
#if dirName == "/":
|
|
|
|
|
#dirName = ""
|
|
|
|
|
# файл в системе без условий
|
|
|
|
|
oldFile = "/".join(map(lambda x:x.split("?")[0],\
|
|
|
|
|
oldFile.split("/")))
|
|
|
|
|
if not findChangeDir:
|
|
|
|
|
oldFile = self._baseDir + oldFile
|
|
|
|
|
# Фильтрация профилей по названию файла
|
|
|
|
|
if oldFile in self.filesFilter:
|
|
|
|
|
continue
|
|
|
|
|
listProfTitle = dirObj.baseDir.split("/")[-2:]
|
|
|
|
|
profTitle = '"' + "/".join(listProfTitle) + '"'
|
|
|
|
|
# Записываем в переменную обрабатываемый файл
|
|
|
|
@ -2966,6 +2970,186 @@ class profile(_file, _terms, xmlShare):
|
|
|
|
|
self.closeFiles()
|
|
|
|
|
return (createdDirs, filesApply)
|
|
|
|
|
|
|
|
|
|
def __getGenHeadDir(self, newDir, profileDirFile, changeDirs):
|
|
|
|
|
"""Определяет название создаваемой директории"""
|
|
|
|
|
|
|
|
|
|
def function(text):
|
|
|
|
|
"""Функция обработки функций в заголовке"""
|
|
|
|
|
return self.applyFuncProfile(text, newDir, profileDirFile)
|
|
|
|
|
|
|
|
|
|
newDirMv = newDir
|
|
|
|
|
findChangeDir = False
|
|
|
|
|
#Меняем путь к директории
|
|
|
|
|
listD = changeDirs.items()
|
|
|
|
|
listD.reverse()
|
|
|
|
|
for dirChangeIn, dirChangeOut in listD:
|
|
|
|
|
st,mid,end = profileDirFile.partition(dirChangeIn)
|
|
|
|
|
if (not st) and mid:
|
|
|
|
|
findChangeDir = True
|
|
|
|
|
break
|
|
|
|
|
if findChangeDir:
|
|
|
|
|
pathRel = dirChangeOut
|
|
|
|
|
lenPathRel = len(pathRel.split("/"))
|
|
|
|
|
lenNewDir = len(newDir.split("/"))
|
|
|
|
|
lenEndDir = lenNewDir - lenPathRel
|
|
|
|
|
tmpDir = newDir
|
|
|
|
|
namesDirs = []
|
|
|
|
|
for i in range(lenEndDir):
|
|
|
|
|
namesDirs.append(os.path.split(tmpDir)[1])
|
|
|
|
|
tmpDir = os.path.split(tmpDir)[0]
|
|
|
|
|
namesDirs.reverse()
|
|
|
|
|
nameDir = "/".join(namesDirs)
|
|
|
|
|
newDirMv = os.path.join(pathRel, nameDir)
|
|
|
|
|
applyDir = newDirMv
|
|
|
|
|
if not os.path.exists(profileDirFile):
|
|
|
|
|
return (applyDir, True)
|
|
|
|
|
try:
|
|
|
|
|
FD = open(profileDirFile)
|
|
|
|
|
textProfile = FD.read()
|
|
|
|
|
FD.close()
|
|
|
|
|
except:
|
|
|
|
|
self.setError(_("Error open profile#: " ) +\
|
|
|
|
|
profileDirFile)
|
|
|
|
|
return (applyDir, False)
|
|
|
|
|
objHead = dirHeader(textProfile, self.objVar,function)
|
|
|
|
|
if not objHead.headerCorrect:
|
|
|
|
|
self.setError(_("Incorrect profile: " ) +\
|
|
|
|
|
profileDirFile)
|
|
|
|
|
self.setError(objHead.errorMessage)
|
|
|
|
|
return (applyDir, False)
|
|
|
|
|
if not objHead.headerTerm:
|
|
|
|
|
if objHead.getError():
|
|
|
|
|
self.setError(_("Incorrect profile: " ) +\
|
|
|
|
|
profileDirFile)
|
|
|
|
|
return (applyDir, False)
|
|
|
|
|
# Изменяем название директории
|
|
|
|
|
if objHead.params.has_key("name"):
|
|
|
|
|
nameDir = objHead.params['name']
|
|
|
|
|
if "/" in nameDir:
|
|
|
|
|
self.setError (_("False value 'name' in profile: " ) +\
|
|
|
|
|
profileDirFile)
|
|
|
|
|
return (applyDir, False)
|
|
|
|
|
if not findChangeDir:
|
|
|
|
|
pathRel = os.path.split(os.path.abspath(newDirMv))[0]
|
|
|
|
|
# Новый путь к оригинальному файлу
|
|
|
|
|
newDirMv = os.path.join(pathRel, nameDir)
|
|
|
|
|
applyDir = newDirMv
|
|
|
|
|
# При удаленнии директории
|
|
|
|
|
if objHead.typeAppend == "remove":
|
|
|
|
|
return (applyDir, False)
|
|
|
|
|
return (applyDir, objHead)
|
|
|
|
|
|
|
|
|
|
def scanProfiles(self, serviceName=False, dirObjs=False):
|
|
|
|
|
"""Сканирует директории профилей - выводит список файлов"""
|
|
|
|
|
if not self.objVar.defined("cl_profile_path"):
|
|
|
|
|
self.setError (_("not defined Var: ") + "cl_profile_path")
|
|
|
|
|
return False
|
|
|
|
|
if not dirObjs:
|
|
|
|
|
if serviceName :
|
|
|
|
|
self._servDir = serviceName
|
|
|
|
|
if self._servDir:
|
|
|
|
|
if self._servDir[0] != "/":
|
|
|
|
|
self._servDir = "/" + self._servDir
|
|
|
|
|
if self._servDir[-1] != "/":
|
|
|
|
|
self._servDir += "/"
|
|
|
|
|
self._servDir = os.path.split(self._servDir)[0]
|
|
|
|
|
dirsProfiles = self.objVar.Get("cl_profile_path")
|
|
|
|
|
if self._servDir:
|
|
|
|
|
tmpDirsProfiles = []
|
|
|
|
|
for dirP in dirsProfiles:
|
|
|
|
|
dirProf = dirP + self._servDir
|
|
|
|
|
if os.access(dirProf, os.F_OK):
|
|
|
|
|
# Если директория существует
|
|
|
|
|
tmpDirsProfiles.append(dirProf)
|
|
|
|
|
else:
|
|
|
|
|
tmpDirsProfiles.append(False)
|
|
|
|
|
dirsProfiles = tmpDirsProfiles
|
|
|
|
|
dirObjs = self.scanDirs(dirsProfiles,self.objVar)
|
|
|
|
|
#файлы к которым были применены профили
|
|
|
|
|
filesApply = []
|
|
|
|
|
# Словарь измененных директорий
|
|
|
|
|
changeDirs = {}
|
|
|
|
|
|
|
|
|
|
for dirObj in dirObjs:
|
|
|
|
|
# сортируем файлы по названию
|
|
|
|
|
if dirObj.files:
|
|
|
|
|
dirObj.files.sort()
|
|
|
|
|
# сортируем директории по названию
|
|
|
|
|
if dirObj.dirs:
|
|
|
|
|
dirObj.dirs.sort()
|
|
|
|
|
blockDirs = []
|
|
|
|
|
for dirProfile in dirObj.dirs:
|
|
|
|
|
newDir = self._baseDir + dirProfile.partition(dirObj.baseDir)[2]
|
|
|
|
|
newDir = "/".join(map(lambda x:x.split("?")[0],\
|
|
|
|
|
newDir.split("/")))
|
|
|
|
|
# Проверяем условие на директорию
|
|
|
|
|
dirInfoFile = os.path.join(dirProfile, self.profDirNameFile)
|
|
|
|
|
pathDir, objHeadDir = self.__getGenHeadDir(newDir,
|
|
|
|
|
dirInfoFile,
|
|
|
|
|
changeDirs)
|
|
|
|
|
# Фильтрация профилей по названию директории
|
|
|
|
|
if pathDir in self.dirsFilter:
|
|
|
|
|
blockDirs.append(dirProfile)
|
|
|
|
|
continue
|
|
|
|
|
if objHeadDir:
|
|
|
|
|
if isinstance(objHeadDir, dirHeader):
|
|
|
|
|
if not objHeadDir.headerCorrect:
|
|
|
|
|
self.setError(_("Incorrect profile: " ) +\
|
|
|
|
|
dirInfoFile)
|
|
|
|
|
self.setError(objHeadDir.errorMessage)
|
|
|
|
|
return False
|
|
|
|
|
if not objHeadDir.headerTerm:
|
|
|
|
|
if objHeadDir.getError():
|
|
|
|
|
self.setError(_("Incorrect profile: " ) +\
|
|
|
|
|
dirInfoFile)
|
|
|
|
|
return False
|
|
|
|
|
if objHeadDir.params.has_key("name"):
|
|
|
|
|
changeDirs[dirProfile] = pathDir
|
|
|
|
|
else:
|
|
|
|
|
if self.getError():
|
|
|
|
|
self.setError(_("Incorrect profile: " ) +\
|
|
|
|
|
dirInfoFile)
|
|
|
|
|
return False
|
|
|
|
|
blockDirs.append(dirProfile)
|
|
|
|
|
for fileProfile in dirObj.files:
|
|
|
|
|
findBlock = False
|
|
|
|
|
for blDir in blockDirs:
|
|
|
|
|
st,mid,end = fileProfile.partition(blDir)
|
|
|
|
|
if (not st) and mid and end:
|
|
|
|
|
findBlock = True
|
|
|
|
|
break
|
|
|
|
|
if findBlock:
|
|
|
|
|
continue
|
|
|
|
|
if self.getNeedProfile(fileProfile):
|
|
|
|
|
if self.getError():
|
|
|
|
|
#print self.getError()
|
|
|
|
|
return False
|
|
|
|
|
fileProfileChange = fileProfile
|
|
|
|
|
findChangeDir = False
|
|
|
|
|
listD = changeDirs.items()
|
|
|
|
|
listD.reverse()
|
|
|
|
|
for dirChangeIn, dirChangeOut in listD:
|
|
|
|
|
st,mid,end = fileProfile.partition(dirChangeIn)
|
|
|
|
|
if (not st) and mid and end:
|
|
|
|
|
findChangeDir = True
|
|
|
|
|
break
|
|
|
|
|
if findChangeDir:
|
|
|
|
|
oldFile = dirChangeOut + end
|
|
|
|
|
else:
|
|
|
|
|
oldFile = fileProfile.partition(dirObj.baseDir)[2]
|
|
|
|
|
# файл в системе без условий
|
|
|
|
|
oldFile = "/".join(map(lambda x:x.split("?")[0],\
|
|
|
|
|
oldFile.split("/")))
|
|
|
|
|
if not findChangeDir:
|
|
|
|
|
oldFile = self._baseDir + oldFile
|
|
|
|
|
# Фильтрация профилей по названию файла
|
|
|
|
|
if oldFile in self.filesFilter:
|
|
|
|
|
continue
|
|
|
|
|
filesApply.append(oldFile)
|
|
|
|
|
else:
|
|
|
|
|
if self.getError():
|
|
|
|
|
return False
|
|
|
|
|
return filesApply
|
|
|
|
|
|
|
|
|
|
def __getApplyHeadDir(self, newDir, profileDirFile, changeDirs):
|
|
|
|
|
"""Применяет профиль к директории (права, владелец, и.т. д)"""
|
|
|
|
@ -5145,17 +5329,7 @@ class plasma(samba):
|
|
|
|
|
findAreaPrev = findAreaPrev.fields[-1]
|
|
|
|
|
else:
|
|
|
|
|
findAreaPrev = findArea
|
|
|
|
|
|
|
|
|
|
#print namesBlock, fieldsTmp
|
|
|
|
|
#if namesBlock[:-1]:
|
|
|
|
|
#pass
|
|
|
|
|
#findPrArea = findPathArea(namesBlock[:-1], areas)
|
|
|
|
|
#findPrFields = findPrArea.fields
|
|
|
|
|
#else:
|
|
|
|
|
#findPrFields = areas
|
|
|
|
|
#findPrFields += fieldsTmp
|
|
|
|
|
fieldsTmp = []
|
|
|
|
|
|
|
|
|
|
i = 0
|
|
|
|
|
delt = 0
|
|
|
|
|
# Добавляем тела
|
|
|
|
@ -5169,11 +5343,6 @@ class plasma(samba):
|
|
|
|
|
## В случае последнего комментария не добавляем перевод строки
|
|
|
|
|
#if self.reComment.search(body.splitlines()[-1]):
|
|
|
|
|
body = "\n" + body
|
|
|
|
|
#else:
|
|
|
|
|
#if body[-1] == "\n":
|
|
|
|
|
#body = "\n" + body + "\n"
|
|
|
|
|
#else:
|
|
|
|
|
#body = "\n" + body
|
|
|
|
|
|
|
|
|
|
namesBlock = namesBlockList[i-delt]
|
|
|
|
|
findArea = findPathArea(copy.copy(namesBlock), areas)
|
|
|
|
|