develop
mhiretskiy 16 years ago
parent 8ec927f6da
commit 8279d0e788

@ -390,7 +390,7 @@ class shareLdap(imp_cl_err, imp_cl_xml, imp_cl_help, imp_cl_smcon):
def createLdif(self, ldifFile):
"""Cоздает ldif из ldif - профиля"""
if not os.access(ldifFile, os.F_OK):
self.setError(_("Not found file:") + "\n " + ldifFile)
self.setError(_("File not found:") + "\n " + ldifFile)
return False
FD = open (ldifFile)
ldifProfile = FD.read()
@ -668,8 +668,9 @@ class servUnix(shareLdap):
userGroupNames.append(res[0][0][1]['cn'][0])
if flagError:
if printError:
self.printERROR(_("Group number") + " " + str(gidNumber) +\
" " + _("not found in LDAP") + " ...")
self.printERROR(\
_("Group number %s is not found in Unix service") %\
str(gidNumber) + "...")
return False
else:
for groupName in userGroups:
@ -679,8 +680,9 @@ class servUnix(shareLdap):
break
if flagError:
if printError:
self.printERROR(_("Group name") + " " + str(groupName) +\
" " + _("not found in LDAP") + " ...")
self.printERROR(\
_("Group name %s is not found in Unix service") %\
str(groupName) + "...")
return False
userGroupNames = userGroups
return userGroupNames
@ -709,8 +711,9 @@ class servUnix(shareLdap):
userGroupNames.append(res.split(':')[0])
if flagError:
if printError:
self.printERROR(_("Group number") + " " + str(gidNumber) +\
" " + _("not found in /etc/group") + " ...")
self.printERROR(
_("Group number %s is not found in") %\
str(gidNumber) + " /etc/group ...")
return False
else:
for groupName in userGroups:
@ -720,14 +723,15 @@ class servUnix(shareLdap):
break
if flagError:
if printError:
self.printERROR(_("Group name") + " " + str(groupName) +\
" " + _("not found in /etc/group") + " ...")
self.printERROR(
_("Group name %s is not found in") %\
str(groupName) + " /etc/group ...")
return False
userGroupNames = userGroups
return userGroupNames
def searchUsersInGroupUnix(self, usersNames, groupName):
"""Ищет спиcок пользователей в группе, ищет в LDAP
"""Ищет спиcок пользователей в группе, ищет в Unix
В случае успеха выводит список найденных пользователей
если нет группы False
@ -769,28 +773,32 @@ class servUnix(shareLdap):
@adminConnectLdap
def addGroupUnixServer(self, groupName, options):
"""Добавляет группу пользователей LDAP"""
"""Добавляет группу пользователей Unix"""
# Если группа существует выходим без ошибки
flagErrGrExist = True
if options.has_key('f'):
flagErrGrExist = False
if self.searchGroupGroupName(groupName):
if flagErrGrExist:
self.printERROR(_("group name")+ " " + str(groupName) + " " +\
_("found in /etc/group") + " ...")
self.printERROR(\
_("group name % is found in") % str(groupName) +\
" /etc/group ...")
return False
else:
self.printSUCCESS(_("group name")+ " " + str(groupName) +\
" " + _("found in /etc/group") + " ...")
self.printSUCCESS(\
_("group name % is found in") % str(groupName) +\
" /etc/group ...")
return True
if self.searchUnixGroupName(groupName):
if flagErrGrExist:
self.printERROR(_("group name")+ " " + str(groupName) + " " +\
_("found in LDAP") + " ...")
self.printERROR(\
_("group name %s is found in Unix service") %\
str(groupName) + " ...")
return False
else:
self.printSUCCESS(_("group name")+ " " + str(groupName) +\
" " + _("found in LDAP") + " ...")
self.printSUCCESS(\
_("group name %s is found in Unix service") %\
str(groupName) + " ...")
return True
self.clVars.Set("soft_ldap_group_name",groupName)
# номер группы
@ -800,13 +808,13 @@ class servUnix(shareLdap):
try:
int(gid)
except:
self.printERROR(_("gid not number ..."))
self.printERROR(_("gid is not number ..."))
return False
if self.searchGroupGid(gid):
self.printERROR(_("gid found in /etc/group ..."))
self.printERROR(_("gid is found in") + " /etc/group ...")
return False
if self.searchUnixGid(gid):
self.printERROR(_("gid found in LDAP ..."))
self.printERROR(_("gid is found in Unix service") + " ...")
return False
self.clVars.Set("soft_ldap_group_id", gid)
# Коментарий к группе
@ -823,17 +831,17 @@ class servUnix(shareLdap):
if not self.ldapObj.getError():
self.ldapObj.ldapAdd(groupLdif)
if self.ldapObj.getError():
print _("LDAP Error") + ": " + self.ldapObj.getError()
print _("Unix Error") + ": " + self.ldapObj.getError()
return False
if options.has_key('p'):
sys.stdout.write(gid)
else:
self.printSUCCESS(_("Add group in unix service") + " ...")
self.printSUCCESS(_("Added group in Unix service") + " ...")
return True
@adminConnectLdap
def addMachineLdapServer(self, machineName, options):
"""Добавляет LDAP машину в LDAP-сервер"""
"""Добавляет Unix машину в LDAP-сервер"""
machineLogin = machineName.replace('$','') + "$"
groupName = self.clVars.Get('soft_ldap_machine_group_name')
@ -856,7 +864,8 @@ class servUnix(shareLdap):
break
if flagMaxGidError:
self.printERROR (_("ERROR") + ": " +\
_("not foung free GID in ldap") + userGid)
_("free GID %s is not found in Unix service") %\
str(userGid))
return False
groupId = str(numberGid)
options = {'g':groupId,'c':self.groupCompGecos}
@ -873,15 +882,15 @@ class servUnix(shareLdap):
#Добавляем пользователя в LDAP
self.ldapObj.ldapAdd(userLdif)
if self.ldapObj.getError():
print _("LDAP Error") + ": " + self.ldapObj.getError()
print _("Unix Error") + ": " + self.ldapObj.getError()
return False
#clVars.Write("soft_ldap_user_id",str(int(userId)+1))
self.printSUCCESS(_("Add machine ..."))
self.printSUCCESS(_("Added machine") + "...")
return True
@adminConnectLdap
def addUserUnixServer(self,userName,options):
"""Добавляет LDAP пользователя в LDAP-сервер"""
"""Добавляет Unix пользователя в LDAP-сервер"""
# id нового пользователя
userId = str(self.getMaxUid())
self.clVars.Set("soft_ldap_user_login", userName)
@ -908,10 +917,10 @@ class servUnix(shareLdap):
self.clVars.Set("soft_ldap_user_full_name",fullNameUser)
if self.searchUnixUser(userName):
self.printERROR(_("User exists in LDAP"))
self.printERROR(_("User exists in Unix service"))
return False
elif self.searchPasswdUser(userName):
self.printERROR(_("User exists in /etc/passwd"))
self.printERROR(_("User exists in") + " /etc/passwd")
return False
userShell = self.userShell
@ -926,15 +935,15 @@ class servUnix(shareLdap):
try:
int(userId)
except:
self.printERROR(_("UID not number") + " ...")
self.printERROR(_("UID is not number") + " ...")
return False
if self.searchUidUnix(userId):
self.printERROR("UID %s "%userId + _("exists in LDAP") +\
" ...")
self.printERROR("UID %s "%userId + " " + \
_("exists in Unix service") + " ...")
return False
if self.searchUidPasswd(userId):
self.printERROR("UID %s "%userId+_("exists in /etc/passwd")+\
" ...")
self.printERROR("UID %s "%userId+_("exists in") + \
" /etc/passwd"+ " ...")
return False
self.clVars.Set("soft_ldap_user_id",userId)
@ -960,17 +969,19 @@ class servUnix(shareLdap):
#Имя группы пользователя
groupName = userGidNamesLdap[0]
else:
self.printERROR(_("Group") + " " + str(userGid) + " " +\
_("not found") + " ...")
self.printERROR(
_("Group %s is not found") % str(userGid) + " ...")
return False
else:
if self.searchGroupGroupName(userName):
self.printERROR(_("group name")+ " " + str(userName) + " " +\
_("found in /etc/group") + " ...")
self.printERROR(
_("Group name %s is found")%str(userName) +\
" /etc/group ...")
return False
if self.searchUnixGroupName(userName):
self.printERROR(_("group name")+ " " + str(userName) + " " +\
_("found in LDAP") + " ...")
self.printERROR(
_("Group name %s is found in Unix serivce")%str(userName) +\
" ...")
return False
userPwd = self.getUserPassword(options, "p", "P")
@ -993,7 +1004,7 @@ class servUnix(shareLdap):
resGroup = self.searchGroupGroupName(groupName)
if not (resLdap or resGroup):
self.printERROR (_("ERROR") + ": " +\
_("not found gid=") + userGid)
"gid=" + userGid + _("is not found"))
return False
if resGroup:
userGid = resGroup.split(":")[2]
@ -1016,7 +1027,7 @@ class servUnix(shareLdap):
self.addUserGroupUnix([userName],group)
# не переделывать на else
if self.ldapObj.getError():
print _("LDAP Error") + ": " + self.ldapObj.getError()
print _("Unix Error") + ": " + self.ldapObj.getError()
return False
# Изменим время последнего измения пароля пользователя
if not self.setShadowLastChange(userName):
@ -1025,23 +1036,24 @@ class servUnix(shareLdap):
if options.has_key('m'):
if not os.path.exists(homeDir):
if not self.createHomeDir(userName, homeDir, skelDir):
self.printERROR (_("ERROR") + ": " + _("create HOME dir"))
self.printERROR (_("ERROR") + ": " + _("cannot create HOME dir"))
return False
self.printSUCCESS(_("Create home dir")+ " " + homeDir + " ...")
self.printSUCCESS(_("Add user in unix service") + " ...")
self.printSUCCESS(_("Created home dir")+ " " + homeDir + " ...")
self.printSUCCESS(_("Added user in Unix service") + " ...")
return True
def addUserGroupUnix(self, users, groupName):
"""Добавляет пользователей из списка в LDAP группу"""
"""Добавляет пользователей из списка в Unix группу"""
if not self.searchUnixGroupName(groupName):
self.printERROR(_("group name not found in LDAP ..."))
self.printERROR(_("group name is not found in Unix service") +\
" ...")
return False
flagFalse = False
for userName in users:
if not (self.searchUnixUser(userName) or\
self.searchPasswdUser(userName)):
self.printERROR(_("User") + " " + str(userName) + " " +\
_("not found ..."))
self.printERROR(\
_("User %s is not found")%str(userName) + " ..." )
flagFalse = True
break
if flagFalse:
@ -1068,7 +1080,7 @@ class servUnix(shareLdap):
return True
def getMaxGidUnix(self):
"""Находит максимальный добавленный gid в LDAP"""
"""Находит максимальный добавленный gid в Unix"""
return self.getMaxAttrDN(self.relGroupsDN, "*", "cn",
self.minGid, self.maxGid, "gidNumber")
@ -1193,22 +1205,22 @@ class servUnix(shareLdap):
return maxUid+1
def delUserUnixServer(self, userName, options):
"""Удаляем LDAP пользователя"""
"""Удаляем Unix пользователя"""
# Ищем пользователя в Samba
if self.servSambaObj.searchSambaUser(userName):
self.printERROR (_("ERROR") + ": " +\
_("Samba user") + " " + str(userName) + " " +\
_("foung in LDAP"))
_("Samba user %s is found in Unix service") %\
str(userName) + " ...")
self.printWARNING(\
_("First remove user from the service Samba")
_("At first, need remove user from Samba service")
)
return False
# Ищем пользователя в LDAP
# Ищем пользователя в Unix
resLdap = self.searchUnixUser(userName)
if not resLdap:
self.printERROR (_("ERROR") + ": " +\
_("User") + " " + str(userName) + " " +\
_("not foung in LDAP"))
_("User %s is not found in Unix service") % str(userName) +\
" ...")
return False
delDN = self.addDN("uid=" + userName, self.relUsersDN)
@ -1239,18 +1251,19 @@ class servUnix(shareLdap):
#Домашняя директория пользователя
homeDir = resLdap[0][0][1]['homeDirectory'][0]
if self.removeHomeDir(homeDir):
self.printSUCCESS(_("Home dir") + " " + str(homeDir) + " " +\
_("deleted") + " ...")
self.printSUCCESS(_("User") + " " + userName + " " + _("deleted") +\
" ...")
self.printSUCCESS(
_("Home directory %s is removed")% str(homeDir) +\
" ...")
self.printSUCCESS(_("User %s is deleted")%userName + " ...")
return True
def delGroupUnixServer(self, groupName, options):
"""Удаляет группу пользователей LDAP"""
"""Удаляет группу пользователей Unix"""
res = self.searchUnixGroupName(groupName)
if not res:
self.printERROR(_("Group") + " " + groupName + " "+\
_("not found in LDAP ..."))
self.printERROR(
_("Group %s is not found in Unix service")%groupName +\
" ...")
return False
groupId = res[0][0][1]['gidNumber'][0]
if self.searchUnixUserPrimGroup(groupId):
@ -1258,20 +1271,19 @@ class servUnix(shareLdap):
return True
delDN = self.addDN("cn="+groupName, self.relGroupsDN)
res = self.delDN(delDN)
if res:
self.printSUCCESS(_("Group") + " " + groupName + " " +\
_("deleted") + " ...")
if res: # Group %s deleted # Группа %s удалена
self.printSUCCESS( _("Group %s is deleted")%groupName+" ...")
return True
else:
self.printERROR(_("Not delete group") + " " + groupName + " ...")
self.printERROR(_("Can not delete group") + " " + groupName + " ...")
return False
def modUserUnixServer(self,userName, options):
"""Модифицирует настройки пользователя Unix в LDAP"""
res = self.searchUnixUser(userName)
if not res:
self.printERROR(_("User") + " " + str(userName) + " " +\
_("not found in LDAP") + " ...")
self.printERROR(
_("User %s is not found in Unix service")%str(userName) + "...")
return False
# Новые группы в которые входит пользователь
if options.has_key('G'):
@ -1290,7 +1302,7 @@ class servUnix(shareLdap):
break
if flagError:
return False
self.printSUCCESS(_("Replace list of supplementary group") +\
self.printSUCCESS(_("Replaced list of supplementary group") +\
" ...")
# Добавляем группы в которые входит пользователь
if options.has_key('a'):
@ -1306,7 +1318,7 @@ class servUnix(shareLdap):
break
if flagError:
return False
self.printSUCCESS(_("Append list of supplementary group") +\
self.printSUCCESS(_("Appended list of supplementary group") +\
" ...")
# Изменяемые аттрибуты пользователя
modAttrs = []
@ -1370,29 +1382,30 @@ class servUnix(shareLdap):
homeDirNew = homeDir
textLine = self.execProg("mv %s %s" %(homeDirOld, homeDirNew))
if not (textLine == None):
self.printERROR(_("Not move home directory") + " ...")
self.printERROR(_("Can not move home directory") + " ...")
modAttrs = ((ldap.MOD_REPLACE, 'homeDirectory',
homeDirOld),)
self.modAttrsDN(DN, modAttrs)
return False
else:
self.printSUCCESS(_("Move home directory") + " ...")
self.printSUCCESS(_("Moved home directory") + " ...")
if options.has_key('c'):
self.printSUCCESS(_("Modify comment") + " ...")
self.printSUCCESS(_("Modified comment") + " ...")
if options.has_key('s'):
self.printSUCCESS(_("Modify shell") + " ...")
self.printSUCCESS(_("Modified shell") + " ...")
if options.has_key('d'):
self.printSUCCESS(_("Modify home directory") + " ...")
self.printSUCCESS(_("Modified home directory") + " ...")
if options.has_key('P') or options.has_key('p'):
# Изменим время последнего измения пароля пользователя
if not self.setShadowLastChange(userName):
return False
self.printSUCCESS(_("Modify LDAP user password") + " ...")
self.printSUCCESS(_("Modified user password of Unix service") +\
" ...")
if options.has_key('U'):
self.printSUCCESS(_("Unlock user") + " " + str(userName) +\
self.printSUCCESS(_("Unlocked user") + " " + str(userName) +\
" ...")
if options.has_key('L'):
self.printSUCCESS(_("Lock user") + " " + str(userName) +\
self.printSUCCESS(_("Locked user") + " " + str(userName) +\
" ...")
return True
@ -1400,8 +1413,9 @@ class servUnix(shareLdap):
"""Устанавливает пароль LDAP пользователя и меняет его опции"""
res = self.searchUnixUser(userName)
if not res:
self.printERROR(_("User") + " " + str(userName) + " " +\
_("not found in LDAP") + " ...")
self.printERROR(
_("User %s is not found in Unix service")%str(userName) +\
" ...")
return False
# Изменяемые аттрибуты пользователя
modAttrs = []
@ -1410,8 +1424,9 @@ class servUnix(shareLdap):
if res[0][0][1].has_key('userPassword'):
modAttrs += [(ldap.MOD_DELETE, 'userPassword', None)]
else:
self.printERROR(_("Not found LDAP password from user") + " "+\
str(userName) + " ...")
self.printERROR(\
_("User %s has not password for Unix service")%\
str(userName) + " ...")
# Включаем пользователя
if options.has_key('u'):
modAttrs += [(ldap.MOD_REPLACE, 'shadowExpire', "-1")]
@ -1438,16 +1453,18 @@ class servUnix(shareLdap):
if not self.modAttrsDN(DN, modAttrs):
return False
if options.has_key('d'):
self.printSUCCESS(_("Deleted LDAP password from user") +\
" "+ str(userName) + " ...")
self.printSUCCESS(
_("Deleted password of Unix service for user") +\
str(userName) + " ...")
if options.has_key('l'):
self.printSUCCESS(_("Lock LDAP user") + " " + str(userName) +\
" ...")
self.printSUCCESS(_("Locked user") + " " + str(userName) +\
" " +_("of Unix service") + " ...")
if options.has_key('u'):
self.printSUCCESS(_("Unlock LDAP user") + " " +\
str(userName) + " ...")
self.printSUCCESS(_("Unlocked user") + " " + str(userName) +\
" " +_("of Unix service") + " ...")
if not options:
self.printSUCCESS(_("Change LDAP user password") + " ...")
self.printSUCCESS(_("User password of Unix service changed") +\
" ...")
# Изменим время последнего измения пароля пользователя
if not self.setShadowLastChange(userName):
return False
@ -1457,7 +1474,7 @@ class servUnix(shareLdap):
def modGroupUnixServer(self, groupName, options):
"""Модифицирует настройки группы пользователей LDAP"""
if not self.searchUnixGroupName(groupName):
self.printERROR(_("group name not found in LDAP ..."))
self.printERROR(_("group name not found in Unix service ..."))
return False
# Добавляем список пользователей в группу
if options.has_key('a'):
@ -1465,38 +1482,39 @@ class servUnix(shareLdap):
users = options['a'].split(',')
res = self.addUserGroupUnix(users, groupName)
if res:
self.printSUCCESS(_("Append list users to a group") + " " +\
self.printSUCCESS(_("Appended list users to group") + " " +\
str(groupName) + " ...")
else:
self.printERROR(_("Not append list users to a group") +\
self.printERROR(_("Can not append list users to group") +\
" " + str(groupName) + " ...")
return False
# Удаляем список пользователей из группы
if options.has_key('d'):
# удаляемые пользователи из группы
users = options['d'].split(',')
res = self.delUserGroupLdap(users, groupName)
res = self.delUserGroupUnix(users, groupName)
if res:
self.printSUCCESS(_("Deleted list users to a group") + " " +\
self.printSUCCESS(_("Deleted list users from group") + " " +\
str(groupName) + " ...")
else:
self.printERROR(_("Not delete list users to a group") +\
" " + str(groupName) + " ...")
self.printERROR(_("Can not delete list users from group") +\
" " + str(groupName) + " ...")
return False
# Изменяем имя группы
if options.has_key('n'):
newGroupName = options['n']
if self.searchUnixGroupName(newGroupName):
self.printERROR(_("group name")+ " " + str(newGroupName) +\
" " + _("found in LDAP") + " ...")
self.printERROR(
_("group name %s is found in Unix service")%\
str(newGroupName) + " ...")
return False
newFirstDn = "cn=" + newGroupName
oldDN = self.addDN("cn=" + groupName, self.relGroupsDN)
res = self.modifyElemDN(oldDN, newFirstDn)
if res:
self.printSUCCESS(_("Rename group") + " ...")
self.printSUCCESS(_("Group renamed") + " ...")
else:
self.printERROR(_("Not rename group") + "...")
self.printERROR(_("Can not rename group") + "...")
return False
modAttrs = []
# Изменяем коментарий к группе
@ -1512,7 +1530,8 @@ class servUnix(shareLdap):
return True
else:
if options.has_key('c'):
self.printSUCCESS(_("Not modify group comment") + " ...")
self.printSUCCESS(_("Can not modify group comment") +\
" ...")
return False
return True
@ -1533,15 +1552,16 @@ class servUnix(shareLdap):
else:
return True
def delUserGroupLdap(self, users, groupName):
"""Удаление пользователей из списка из группы LDAP"""
def delUserGroupUnix(self, users, groupName):
"""Удаление пользователей из списка из группы Unix"""
res = self.searchUnixGroupName(groupName)
if not res :
self.printERROR(_("group name not found in LDAP") + " ...")
self.printERROR(_("group name is not found in Unix service") +\
" ...")
return False
if not res[0][0][1].has_key("memberUid"):
self.printERROR(_("Member list empty in group") + " " +\
str(groupName) + " ...")
self.printERROR(
_("Member list of group %s is empty")%str(groupName)+" ...")
return False
memberUsers = res[0][0][1]["memberUid"]
flagError =False
@ -1550,8 +1570,9 @@ class servUnix(shareLdap):
flagError = True
break
if flagError:
self.printERROR(_("User") + " " +str(user)+ " " +\
_("not found in group") +" "+ str(groupName) + " ...")
self.printERROR(
_("User %s is not found in group")%str(user)+" "+\
str(groupName) + " ...")
return False
modAttrs = []
for userName in users:
@ -1562,7 +1583,7 @@ class servUnix(shareLdap):
def setupUnixServer(self, options):
"""Начальная настройка LDAP сервиса"""
"""Начальная настройка Unix сервиса"""
# Принудительная установка
forceOptions = False
# Cоздаем объект переменные
@ -1576,13 +1597,13 @@ class servUnix(shareLdap):
_("Unix service is configured")+ ".")
return True
if not self.clVars.Get("soft_ldap_setup") == "yes":
self.printERROR(_("Service LDAP not setup ..."))
self.printERROR(_("LDAP service not setup ..."))
return False
# Проверим запущен ли ldap
if not self.getRunService("ldap"):
self.printWARNING (_("WARNING") + ": " +\
_("The LDAP service is not running") + ".")
print "1. " +_("Start the LDAP service")
_("LDAP service is not running") + ".")
print "1. " +_("Start LDAP service")
print " /etc/init.d/slapd start"
return True
#Cоединение с Ldap (администратор)
@ -1603,9 +1624,10 @@ class servUnix(shareLdap):
delDN = self.relDN
ret = self.deleteDN(delDN)
if ret:
self.printOK(_("Remove Unix DN in LDAP Database ..."))
self.printOK(_("Removed Unix DN in LDAP Database ..."))
else:
self.printERROR(_("Not remove Unix DN in LDAP Database ..."))
self.printERROR(\
_("Can not remove Unix DN in LDAP Database ..."))
if not ret:
return False
ldifFile = self.ldifFileBase
@ -1615,7 +1637,7 @@ class servUnix(shareLdap):
if self.ldapObj.getError():
print _("LDAP Error") + ": " + self.ldapObj.getError()
return False
self.printOK(_("Add ldif file ..."))
self.printOK(_("Added ldif file ..."))
# Записываем данные администратора сервиса Unix
ldapParser = iniLdapParser()
ldapParser.setVar("unix",
@ -1632,7 +1654,7 @@ class servUnix(shareLdap):
modAttrs = [(ldap.MOD_REPLACE, 'shadowLastChange', str(date))]
userDN = self.addDN('uid='+userName,self.relUsersDN)
if not self.modAttrsDN(userDN, modAttrs):
self.printERROR(_("Not modify shadowLastChange attribute"))
self.printERROR(_("Can not modify shadowLastChange attribute"))
return False
return True
@ -1675,8 +1697,9 @@ class servMail(shareLdap):
"""Устанавливает пароль Mail пользователя и меняет его опции"""
res = self.searchMailUser(userName)
if not res:
self.printERROR(_("User") + " " + str(userName) + " " +\
_("not found in Mail service") + " ...")
self.printERROR(
_("User %s is not found in Mail service") % str(userName) +\
" ...")
return False
# Изменяемые аттрибуты пользователя
modAttrs = []
@ -1705,13 +1728,13 @@ class servMail(shareLdap):
if not self.modAttrsDN(DN, modAttrs):
return False
if options.has_key('l'):
self.printSUCCESS(_("Lock Mail user") + " " + str(userName) +\
self.printSUCCESS(_("Locked Mail user") + " " + str(userName) +\
" ...")
if options.has_key('u'):
self.printSUCCESS(_("Unlock Mail user") + " " +\
self.printSUCCESS(_("Unlocked Mail user") + " " +\
str(userName) + " ...")
if not options:
self.printSUCCESS(_("Change Mail user password") + " ...")
self.printSUCCESS(_("Changed Mail user password") + " ...")
return True
return False
@ -1762,7 +1785,8 @@ class servMail(shareLdap):
if self.searchUserToMail(mail) or\
self.searchGroupToMail(mail):
self.printERROR(_("Alternate email address") + ": " +\
str(mail) + " " + _("found in Mail service") + " ...")
str(mail) + " " + _("is found in Mail service") +\
" ...")
return False
modAttrs.append((ldap.MOD_ADD, 'mailAlternateAddress', mail))
resUnix = self.servUnixObj.searchUnixUser(userName)
@ -1785,16 +1809,18 @@ class servMail(shareLdap):
return False
resUnix = self.servUnixObj.searchUnixUser(userName)
else:
self.printERROR(_("Not found user") + " " + str(userName) +\
" " + _("in Unix service" + " ..."))
self.printERROR(
_("User %s is not found in Mail service") % str(userName) +\
" ...")
return False
if self.searchMailUser(userName):
self.printERROR(_("User exists in Mail service"))
return False
elif self.searchUserToMail(userName) or\
self.searchGroupToMail(userName):
self.printERROR(_("User name") + ": " + str(userName) + " " +\
_("is found in Mail service") + " ...")
self.printERROR(\
_("User name %s is found in Mail service") %\
str(userName) + "...")
return False
self.clVars.Set("soft_ldap_user_login", userName)
#Полное имя пользователя
@ -1832,7 +1858,7 @@ class servMail(shareLdap):
uid = int(resPwd.split(":")[2])
gid = int(resPwd.split(":")[3])
else:
self.printERROR(_("Not found uid and gid user"))
self.printERROR(_("Uid and gid user is not found"))
return False
self.createMailDir(userName, uid, gid)
#Добавляем альтернативные почтовые адреса
@ -1840,7 +1866,7 @@ class servMail(shareLdap):
DN = self.addDN("uid="+userName, self.relUsersDN)
if not self.modAttrsDN(DN, modAttrs):
return False
self.printSUCCESS(_("Add user in mail service") + " ...")
self.printSUCCESS(_("Added user in mail service") + " ...")
return True
def setupMailServer(self, options):
@ -1856,32 +1882,34 @@ class servMail(shareLdap):
if self.clVars.Get("soft_unix_setup") != "yes":
self.printERROR (_("ERROR") + ": " +\
_("LDAP server is not configured")+ ".")
self.printWARNING(_("Not setup service Unix"))
self.printWARNING(_("Unix service is not setuped"))
print _("Setup Unix service")
print " cl-setup unix"
return False
# В случае если сервер установлен
if self.clVars.Get("soft_mail_setup") == "yes" and\
not forceOptions:
self.printWARNING (_("WARNING") + ": " +\
_("Mail server is configured")+ ".")
_("Mail server is configured")+ ".")
return True
# Проверим запущен ли сервис Mail
if self.getRunService("mail"):
self.printWARNING (_("WARNING") + ": " +\
_("The Mail service is running") + ".")
print "1. " +_("Stop the Mail service")
_("Mail service is running") + ".")
print "1. " +_("Stop Mail service")
print " /etc/init.d/postfix stop"
print "2. " + _("You can save configuration files \
Postfix in backup directory")
print "2. " +\
_("You can save configuration files Postfix in backup directory")
print "3. " + _("Restart the program")
return True
# Проверим запущен ли сервис Dovecot
if self.getRunService("dovecot"):
self.printWARNING (_("WARNING") + ": " +\
_("The Dovecot is running") + ".")
print "1. " +_("Stop the Dovecot")
_("Dovecot is running") + ".")
print "1. " +_("Stop Dovecot")
print " /etc/init.d/dovecot stop"
print "2. " + _("You can save configuration files \
Dovecot in backup directory")
print "2. " +\
_("You can save configuration files Dovecot in backup directory")
print "3. " + _("Restart the program")
return True
# Подключаемся к LDAP cерверу
@ -1897,7 +1925,7 @@ Dovecot in backup directory")
if ret:
self.printOK(_("Remove Mail DN in LDAP Database ..."))
else:
self.printERROR(_("Not remove Mail DN in LDAP Database ..."))
self.printERROR(_("Can not remove Mail DN in LDAP Database ..."))
if not ret:
return False
ldifFile = self.ldifFileBase
@ -1923,10 +1951,10 @@ Dovecot in backup directory")
ldapParser.setVar("mail",
{"DN":self.clVars.Get("soft_ldap_admin_mail"),
"PASS":self.clVars.Get("soft_ldap_admin_mailpw")})
self.printOK(_("Add ldif file ..."))
self.printOK(_("Added ldif file ..."))
textLine = self.execProg("newaliases")
if not (textLine == None):
self.printERROR(_("Not create Postfix aliases") + " ...")
self.printERROR(_("Can not create Postfix aliases") + " ...")
return False
textLine = self.execProg("/etc/init.d/postfix start")
if "ok" in textLine:
@ -1975,23 +2003,23 @@ class servSamba(shareLdap):
def delUserSambaServer(self, userName, options):
"""Удаляем Samba пользователя"""
if options.has_key('r'):
self.printERROR (_("Options r not valid in service Samba"))
self.printERROR (_("Option 'r' is not valid for Samba service"))
return False
if "$" in userName:
# удаляемая машина
delUser = userName.replace('$','') + "$"
if not self.searchSambaMachine(delUser):
self.printERROR (_("ERROR") + ": " +\
_("Samba machine") + " " + str(delUser) + " " +\
_("not foung in LDAP"))
_("Samba machine %s is not found in Samba service")%\
str(delUser))
return False
else:
# удаляемый пользователь
delUser = userName
if not self.searchSambaUser(delUser):
self.printERROR (_("ERROR") + ": " +\
_("Samba user") + " " + str(delUser) + " " +\
_("not foung in LDAP"))
_("Samba user %s is not found in Samba service") %\
str(delUser))
return False
textLine = self.execProg("smbpasswd -x %s" %(delUser),False,False)
flagError = False
@ -2007,7 +2035,7 @@ class servSamba(shareLdap):
flagError = True
if flagError:
self.printERROR(_("ERROR") + ": " +\
_("Delete Samba user") + " " + str(delUser) + " ...")
_("Can not delete Samba user") + " " + str(delUser) + " ...")
return False
else:
self.printSUCCESS(_("Deleted Samba user") + " " +\
@ -2028,8 +2056,9 @@ class servSamba(shareLdap):
resSearch = self.servUnixObj.searchPasswdUser(userName)
# создание пользователя Unix опция f
if not resSearch and not options.has_key('f'):
self.printERROR(_("Not found user") + " " + str(userName) +\
" " + _("in unix service" + " ..."))
self.printERROR(
_("User %s is not found in Unix service")%\
str(userName) + " ...")
return False
if self.searchSambaUser(userName):
self.printERROR(_("Samba user exists"))
@ -2059,10 +2088,10 @@ class servSamba(shareLdap):
else:
textLine = self.execProg("smbpasswd -a -n %s" %(userName))
if "Added" in str(textLine):
self.printSUCCESS(_("Add user in samba service ..."))
self.printSUCCESS(_("Added user in samba service ..."))
return True
else:
self.printERROR(_("Not add user ..."))
self.printERROR(_("Can not add user") + " ...")
return False
def searchSambaUser(self, userName):
@ -2082,15 +2111,15 @@ class servSamba(shareLdap):
if res:
if res[0][0][1].has_key('sambaSID'):
self.printERROR(_("machine")+" "+machineLogin+" "+\
"found in LDAP")
"is found in Samba service")
return True
# добавляем Samba машину
textLine = self.execProg("smbpasswd -a -m %s" %machineLogin)
if "Added" in str(textLine):
self.printSUCCESS(_("Add machine in samba service ..."))
self.printSUCCESS(_("Added machine in samba service") + " ...")
return True
else:
self.printERROR(_("Not add machine ..."))
self.printERROR(_("Can not add machine ..."))
return False
else:
# добавляем LDAP машину
@ -2100,10 +2129,10 @@ class servSamba(shareLdap):
# добавляем Samba машину
textLine = self.execProg("smbpasswd -a -m %s" %machineLogin)
if "Added" in str(textLine):
self.printSUCCESS(_("Add machine in samba service ..."))
self.printSUCCESS(_("Added machine in Samba service") + " ...")
return True
else:
self.printERROR(_("Not add machine ..."))
self.printERROR(_("Can not add machine ..."))
return False
@ -2118,7 +2147,7 @@ class servSamba(shareLdap):
if self.clVars.Get("soft_unix_setup") != "yes":
self.printERROR (_("ERROR") + ": " +\
_("LDAP server is not configured")+ ".")
self.printWARNING(_("Not setup service Unix"))
self.printWARNING(_("Unix service is not setuped"))
return False
# В случае если сервер установлен
if self.clVars.Get("soft_samba_setup") == "yes" and\
@ -2131,10 +2160,10 @@ class servSamba(shareLdap):
if self.getRunService("samba"):
self.printWARNING (_("WARNING") + ": " +\
_("The Samba service is running") + ".")
print "1. " +_("Stop the Samba service")
print "1. " +_("Stop Samba service")
print " /etc/init.d/samba stop"
print "2. " + _("You can save configuration files \
Samba in backup directory")
print "2. " +\
_("You can save configuration files Samba in backup directory")
print "3. " + _("Restart the program")
return True
@ -2164,12 +2193,12 @@ Samba in backup directory")
pswd = ldapParser.getVar("samba","PASS")
if not pswd:
self.printERROR(_("ERROR") + ": " +\
_("Not find Ldap Samba admin password"))
_("Samba admin password is not found"))
return False
textLine = self.execProg("smbpasswd -w %s" %(pswd))
if not "stored" in textLine:
self.printERROR(_("ERROR") + ": " +\
_("Add Ldap admin password"))
_("Can not add Samba admin password"))
return False
textLine = self.execProg("/etc/init.d/slapd restart")
@ -2185,9 +2214,10 @@ Samba in backup directory")
delDN = self.relDN
ret = self.deleteDN(delDN)
if ret:
self.printOK(_("Remove Samba DN in LDAP Database ..."))
self.printOK(_("Removed Samba DN in LDAP Database ..."))
else:
self.printERROR(_("Not remove Samba DN in LDAP Database ..."))
self.printERROR(\
_("Can not remove Samba DN in LDAP Database ..."))
if not ret:
return False
ldifFile = self.ldifFileBase
@ -2197,7 +2227,7 @@ Samba in backup directory")
if self.ldapObj.getError():
print _("LDAP Error") + ": " + self.ldapObj.getError()
return False
self.printOK(_("Add ldif file ..."))
self.printOK(_("Added ldif file ..."))
textLine = self.execProg("/etc/init.d/samba start")
if "ok" in textLine:
self.printOK(_("Samba start ..."))
@ -2213,8 +2243,8 @@ Samba in backup directory")
def modUserSambaPasswd(self, userName, options):
if not self.searchSambaUser(userName):
self.printERROR(_("Samba user") + " " +str(userName) + " " +\
_("not found") + " ...")
self.printERROR(
_("Samba user %s is not found")%str(userName) + " ...")
return False
# отключаем samba account
if options.has_key('l'):
@ -2223,7 +2253,7 @@ Samba in backup directory")
self.printSUCCESS(_("Disabled samba user")+ " " +\
str(userName) + " ...")
else:
self.printERROR(_("Not disable samba user")+ " "+\
self.printERROR(_("Can not disable samba user")+ " "+\
str(userName) + " ...")
return False
# включаем samba account
@ -2233,7 +2263,7 @@ Samba in backup directory")
self.printSUCCESS(_("Enabled samba user")+ " " +\
str(userName) + " ...")
else:
self.printERROR(_("Not enable samba user")+ " "+\
self.printERROR(_("Can not enable samba user")+ " "+\
str(userName) + " ...")
return False
if not options:
@ -2245,13 +2275,13 @@ Samba in backup directory")
textLine = self.execProg("smbpasswd -a -s %s" %(userName),
"%s\n%s\n" %(userPwd,userPwd))
if not (textLine == None):
self.printERROR(_("Not change samba user password") +\
self.printERROR(_("Can not change samba user password") +\
" ...")
return False
else:
self.printSUCCESS(_("Password Samba user") +\
" " + userName + " "+\
_("changed") + " ...")
self.printSUCCESS(
_("Samba password of user %s is changed")%\
str(userName) + " ...")
return True
return True
@ -2261,8 +2291,9 @@ Samba in backup directory")
# Находим Samba пользователя
res = self.searchSambaUser(userName)
if not res:
self.printERROR(_("Samba user") + " " + str(userName) + " " +\
_("not found in LDAP") + " ...")
self.printERROR(
_("Samba user %s is not found in Samba service")%\
str(userName) + " ...")
return False
# отключаем samba account
if options.has_key('L'):
@ -2271,7 +2302,7 @@ Samba in backup directory")
self.printSUCCESS(_("Disabled samba user")+ " " +\
str(userName) + " ...")
else:
self.printERROR(_("Not disable samba user")+ " "+\
self.printERROR(_("Can not disable samba user")+ " "+\
str(userName) + " ...")
return False
# включаем samba account
@ -2281,7 +2312,7 @@ Samba in backup directory")
self.printSUCCESS(_("Enabled samba user")+ " " +\
str(userName) + " ...")
else:
self.printERROR(_("Not enable samba user")+ " "+\
self.printERROR(_("Can not enable samba user")+ " "+\
str(userName) + " ...")
return False
# модифицируем пароль
@ -2298,9 +2329,10 @@ Samba in backup directory")
textLine = self.execProg("smbpasswd -s %s" %(userName),
"%s\n%s\n" %(userPwd,userPwd))
if not (textLine == None):
self.printERROR(_("Not modify samba user password") + " ...")
self.printERROR(_("Can not modify samba user password") +\
" ...")
return False
self.printSUCCESS(_("Modify samba user password") + " ...")
self.printSUCCESS(_("Modified samba user password") + " ...")
else:
if not self.modUserUnixServer(userName, options):
return False

Loading…
Cancel
Save