Добавлены методы для вывода информации о машинах

git-svn-id: http://svn.calculate.ru/calculate2/calculate-server/trunk@1272 c91db197-33c1-4113-bf15-f8a5c547ca64
develop
asamoukin 15 years ago
parent ef3773692e
commit d8afa587af

@ -8196,6 +8196,18 @@ the password will be changed only for Samba account")
'helpChapter':_("Common options"),
'help':_("replication off")
},
{'progAccess':(14,),
'shortOption':"m",
'longOption':"machines",
'helpChapter':_("Common options"),
'help':_("information about machines")
},
{'progAccess':(14,),
'shortOption':"M",
'optVal':"MACHINE",
'helpChapter':_("Common options"),
'help':_("information about machine")
},
{'progAccess':(14,),
'shortOption':"u",
'longOption':"users",
@ -8224,6 +8236,11 @@ the password will be changed only for Samba account")
'longOption':"full",
'helpChapter':_("Unix service options"),
'help':_("full information (аll fields)")
},
{'progAccess':(14,),
'longOption':"full",
'helpChapter':_("Samba service options"),
'help':_("full information (аll fields)")
},
{'progAccess':(14,),
'longOption':"full",
@ -10502,8 +10519,17 @@ class cl_info(cl_utils2.cl_smartcon):
strService = service.capitalize()
if service == "ftp":
strService = service.upper()
# Информация о компьютере
if options.has_key("M"):
machineName = options["M"]
data = self.getMachine(machineName, service)
if not data:
return False
headerList, dataList = data
title=_("Information about machine %s") %machineName + " " +\
_("for service %s") %strService
# Информация о пользователе
if options.has_key("U"):
elif options.has_key("U"):
userName = options["U"]
data = self.getUser(userName, service)
if not data:
@ -10512,7 +10538,7 @@ class cl_info(cl_utils2.cl_smartcon):
title=_("Information about user %s") %userName + " " +\
_("for service %s") %strService
# Информация о группе
if options.has_key("G"):
elif options.has_key("G"):
groupName = options["G"]
data = self.getGroup(groupName, service)
if not data:
@ -10520,8 +10546,19 @@ class cl_info(cl_utils2.cl_smartcon):
headerList, dataList = data
title=_("Information about group %s") %groupName + " " +\
_("for service %s") %strService
# Информация о компьютерах
elif options.has_key("m"):
fields = "short"
if options.has_key("full"):
fields = "full"
data = self.getAllMachines(fields, service)
if not data:
return False
headerList, dataList = data
title=_("All machines in LDAP for service %s")%strService
# Информация о пользователях
if options.has_key("u"):
elif options.has_key("u"):
fields = "short"
if options.has_key("full"):
fields = "full"
@ -10541,7 +10578,8 @@ class cl_info(cl_utils2.cl_smartcon):
headerList, dataList = data
title=_("All groups in LDAP for service %s")%strService
if options.has_key("U") or options.has_key("G") or\
if options.has_key("M") or options.has_key("m") or\
options.has_key("U") or options.has_key("G") or\
options.has_key("u") or options.has_key("g"):
repObj = report(title, headerList, dataList)
repObj.printReport()
@ -10589,6 +10627,53 @@ with another option."))
return (servObj.clVars, searchRes)
return searchRes
def getMachine(self, machineName, service):
"""Информация о компьютере"""
searchAttr = "uid"
machName = machineName.split("$")
machName = "".join(machName)
machName += "$"
searchStr = machName
data, delData = self.genDataMachines(service)
if not data:
self.printERROR(_("Incorrect service %s") %service.capitalize())
return False
headers = [_("Field"),_("Value")]
attributes = map(lambda x: x[0], data)
retrAttrs = map(lambda x: x[1], data)
retClVars=False
searchRes = self.getQueryLDAP(service, "computers", searchAttr,
searchStr, retrAttrs)
if searchRes == False:
return False
if not searchRes:
return (headers , [])
data = []
lenRetrAttrs = len(retrAttrs)
for info in searchRes:
for i in range(lenRetrAttrs):
attr = retrAttrs[i]
attrName = attributes[i]
if attr in info[0][1]:
ldapValue = info[0][1][attr]
# Изменяем значения аттрибутов для вывода на печать
serviceMod = service
if service == "samba":
serviceMod = "unix"
ldapValue[0] = self.modUserAttr(attr, ldapValue[0],
serviceMod)
flagFirst = False
for value in ldapValue:
if not flagFirst:
data.append((attrName, value))
flagFirst = True
else:
data.append(("", value))
else:
data.append((attrName, "No"))
return (headers, data)
def getGroup(self, groupName, service):
"""Информация о группе"""
searchAttr = "cn"
@ -10597,12 +10682,14 @@ with another option."))
if not data:
self.printERROR(_("Incorrect service %s") %service.capitalize())
return False
headers = ["ATTR","VALUE"]
headers = [_("Field"),_("Value")]
attributes = map(lambda x: x[0], data)
retrAttrs = map(lambda x: x[1], data)
retClVars=False
searchRes = self.getQueryLDAP(service, "groups", searchAttr,
searchStr, retrAttrs)
if searchRes == False:
return False
if not searchRes:
return (headers , [])
if service == "jabber":
@ -10614,7 +10701,7 @@ with another option."))
memberUid.append(dataGroup[0][1]['uid'][0])
for i in searchRes:
i[0][1]['memberUid'] = memberUid
data.append(("MEMBER_UID","memberUid"))
data.append((_("Member uid"),"memberUid"))
attributes = map(lambda x: x[0], data)
retrAttrs = map(lambda x: x[1], data)
data = []
@ -10635,9 +10722,10 @@ with another option."))
else:
data.append(("", value))
else:
data.append((attrName, "N"))
data.append((attrName, "No"))
return (headers, data)
def getUser(self, userName, service):
"""Информация о пользователе"""
searchAttr = "uid"
@ -10646,7 +10734,7 @@ with another option."))
if not data:
self.printERROR(_("Incorrect service %s") %service.capitalize())
return False
headers = ["ATTR","VALUE"]
headers = [_("Field"), _("Value")]
attributes = map(lambda x: x[0], data)
retrAttrs = map(lambda x: x[1], data)
retClVars=False
@ -10654,6 +10742,8 @@ with another option."))
retClVars=True
searchRes = self.getQueryLDAP(service, "users", searchAttr,
searchStr, retrAttrs, retClVars)
if searchRes == False:
return False
if not searchRes:
return (headers , [])
if service in ["mail", "samba"]:
@ -10665,29 +10755,37 @@ with another option."))
for i in searchRes:
i[0][1]['homeDirectory'] = [os.path.join(\
clVars.Get("sr_mail_path"),i[0][1]['uid'][0])]
data.append(("HOME","homeDirectory"))
data.append((_("Home directory"),"homeDirectory"))
if service == "samba":
for i in searchRes:
i[0][1]['winProfPath'] = [os.path.join(\
winProfPath = os.path.join(\
clVars.Get("sr_samba_winprof_path"),
i[0][1]['uid'][0])]
i[0][1]['linProfPath'] = [os.path.join(\
i[0][1]['uid'][0])
if os.path.exists(winProfPath):
i[0][1]['winProfPath'] = [winProfPath]
data.append((_("Windows profile"),"winProfPath"))
linProfPath = os.path.join(\
clVars.Get("sr_samba_linprof_path"),
i[0][1]['uid'][0])]
i[0][1]['homePath'] = [os.path.join(\
i[0][1]['uid'][0])
if os.path.exists(linProfPath):
i[0][1]['linProfPath'] = [linProfPath]
data.append((_("Linux profile"),"linProfPath"))
homePath = os.path.join(\
clVars.Get("sr_samba_home_path"),
i[0][1]['uid'][0])]
i[0][1]['winLogonPath'] = [os.path.join(\
i[0][1]['uid'][0])
if os.path.exists(homePath):
i[0][1]['homePath'] = [homePath]
data.append((_("Home directory"),"homePath"))
winLogonPath = os.path.join(\
clVars.Get("sr_samba_winlogon_path"),
i[0][1]['uid'][0])]
i[0][1]['sharePath'] = [os.path.join(\
clVars.Get("sr_samba_share_path"),
i[0][1]['uid'][0])]
data.append(("WIN_PROF","winProfPath"))
data.append(("LIN_PROF","linProfPath"))
data.append(("HOME","homePath"))
data.append(("WIN_LOGON","winLogonPath"))
data.append(("SHARE","sharePath"))
i[0][1]['uid'][0])
if os.path.exists(winLogonPath):
i[0][1]['winLogonPath'] = [winLogonPath]
data.append((_("Windows logon"),"winLogonPath"))
sharePath = clVars.Get("sr_samba_share_path")
if os.path.exists(sharePath):
i[0][1]['sharePath'] = [sharePath]
data.append((_("Share directory"),"sharePath"))
attributes = map(lambda x: x[0], data)
retrAttrs = map(lambda x: x[1], data)
@ -10712,11 +10810,11 @@ with another option."))
(service == "mail" and attr == "mailAlternateAddress"):
memberGroups = self._getUserMemberGroups(userName,
service)
attrApp = "GROUPS"
attrApp = _("Groups")
if service == "unix":
memberGroups.insert(0,value)
elif service == "mail":
attrApp = "GROUP_MAIL"
attrApp = _("Group mail")
flagFirst = False
for value in memberGroups:
if not flagFirst:
@ -10725,9 +10823,50 @@ with another option."))
else:
data.append(("", value))
else:
data.append((attrName, "N"))
data.append((attrName, "No"))
return (headers, data)
def getAllMachines(self, fields, service):
"""Выдает список компьютеров"""
searchAttr = "uid"
searchStr = "*"
data, delData = self.genDataMachines(service, fields)
if not data:
self.printWARNING(_("Service %s has no machines")\
%service.capitalize())
return False
if fields == "short":
data = filter(lambda x: not x[0] in delData, data)
headers = map(lambda x: x[0], data)
retrAttrs = map(lambda x: x[1], data)
machines = []
searchRes = self.getQueryLDAP(service, "computers", searchAttr,
searchStr, retrAttrs)
if searchRes == False:
return False
if not searchRes:
return (headers , [])
for info in searchRes:
listAttr = []
for attr in retrAttrs:
if attr in info[0][1]:
ldapValue = info[0][1][attr]
# Изменяем значения аттрибутов для вывода на печать
serviceMod = service
if service == "samba":
serviceMod = "unix"
ldapValue[0] = self.modUserAttr(attr, ldapValue[0],
serviceMod)
# Если несколько значений то разделяем их запятыми
value = reduce(lambda x,y: ",".join([x,y])[0] == "," and\
",".join([x,y])[1:] or ",".join([x,y])[1:]\
and ",".join([x,y]) , ldapValue, "")
listAttr.append(value)
else:
listAttr.append("No")
machines.append(listAttr)
return (headers, machines)
def getAllGroups(self, fields, service):
"""Выдает список всех групп и пользователей"""
searchAttr = "cn"
@ -10744,6 +10883,8 @@ with another option."))
groups = []
searchRes = self.getQueryLDAP(service, "groups", searchAttr,
searchStr, retrAttrs)
if searchRes == False:
return False
if not searchRes:
return (headers , [])
for info in searchRes:
@ -10757,7 +10898,7 @@ with another option."))
and ",".join([x,y]) , ldapValue, "")
listAttr.append(value)
else:
listAttr.append("N")
listAttr.append("No")
groups.append(listAttr)
return (headers, groups)
@ -10766,23 +10907,40 @@ with another option."))
data = []
delData = []
if service == "unix":
data = [("GROUP","cn"),
("NAME","description"),
("GID","gidNumber"),
("MEMBER_UID","memberUid")]
data = [(_("Group"),"cn"),
(_("Name"),"description"),
("gid","gidNumber"),
(_("Member uid"),"memberUid")]
if fields == "short":
delData = ["MEMBER_UID"]
delData = [_("Member uid")]
elif service == "mail":
data = [("GROUP","cn"),
("NAME","description"),
("MAIL","mail"),
("ALT_MAIL","mailAlternateAddress"),
("MEMBER_UID","rfc822member")]
data = [(_("Group"),"cn"),
(_("Name"),"description"),
(_("Mail"),"mail"),
(_("Alternate mail"),"mailAlternateAddress"),
(_("Member uid"),"rfc822member")]
if fields == "short":
delData = ["MAIL", "MEMBER_UID"]
delData = [_("Mail"), _("Member uid")]
elif service == "jabber":
data = [("GROUP","cn"),
("COMMENT","description")]
data = [(_("Group"),"cn"),
(_("Comment"),"description")]
return (data, delData)
def genDataMachines(self, service, fields='full'):
"""Формирует поля нужные для вывода информации о компьютере"""
data = []
delData = []
if service == "samba":
data = [("Login","uid"),
(_("Name"),"cn"),
("uid","uidNumber"),
(_("Group"),"gidNumber"),
(_("Home directory"),"homeDirectory"),
(_("Password"),"sambaNTPassword"),
(_("Last change password"),"sambaPwdLastSet")]
if fields == "short":
delData = [_("Name"), _("Home directory"), _("Password"),
_("Last change password")]
return (data, delData)
def genDataUsers(self, service, fields='full'):
@ -10790,52 +10948,55 @@ with another option."))
data = []
delData = []
if service == "unix":
data = [("LOGIN","uid"),
("NAME","cn"),
("LOCK","shadowExpire"),
("VISIBLE","shadowFlag"),
("UID","uidNumber"),
("GROUP","gidNumber"),
("HOME","homeDirectory"),
("PWD","userPassword"),
("DATE_PWD","shadowLastChange"),
("JID","registeredAddress"),
("MAIL","mail")]
data = [("Login","uid"),
(_("Name"),"cn"),
(_("Lock"),"shadowExpire"),
(_("Visible"),"shadowFlag"),
("uid","uidNumber"),
(_("Group"),"gidNumber"),
(_("Home directory"),"homeDirectory"),
(_("Password"),"userPassword"),
(_("Last change password"),"shadowLastChange"),
("Jabber id","registeredAddress"),
(_("Mail"),"mail")]
if fields == "short":
delData = ["LOCK","VISIBLE","PWD","DATE_PWD","JID","MAIL"]
delData = [_("Lock"),_("Visible"),_("Password"),
_("Last change password"),"Jabber id",_("Mail")]
elif service == "samba":
data = [("LOGIN","uid"),
("NAME","displayName"),
("LOCK","accountStatus"),
("PWD","sambaNTPassword"),
("DATE_PWD","sambaPwdLastSet")]
data = [("Login","uid"),
(_("Name"),"displayName"),
(_("Lock"),"accountStatus"),
(_("Password"),"sambaNTPassword"),
(_("Last change password"),"sambaPwdLastSet")]
if fields == "short":
delData = [_("Last change password")]
elif service == "mail":
data = [("LOGIN","uid"),
("NAME","cn"),
("LOCK","accountStatus"),
("PWD","userPassword"),
("MAIL","mail"),
("ALT_MAIL","mailAlternateAddress")]
data = [("Login","uid"),
(_("Name"),"cn"),
(_("Lock"),"accountStatus"),
(_("Password"),"userPassword"),
(_("Mail"),"mail"),
(_("Alternate mail"),"mailAlternateAddress")]
if fields == "short":
delData = ["LOCK", "PWD", "MAIL"]
delData = [_("Lock"), _("Password"), _("Mail")]
elif service == "jabber":
data = [("LOGIN","uid"),
("NAME","cn"),
("LOCK","initials"),
("GROUP","departmentNumber"),
("PWD","userPassword"),
("JID","mail")]
data = [("Login","uid"),
(_("Name"),"cn"),
(_("Lock"),"initials"),
(_("Group"),"departmentNumber"),
(_("Password"),"userPassword"),
("Jabber id","mail")]
if fields == "short":
delData = ["LOCK", "GROUP", "PWD"]
delData = [_("Lock"), _("Group"), _("Password")]
elif service == "ftp":
data = [("LOGIN","uid"),
("NAME","cn"),
("UID","uidNumber"),
("GROUP","gidNumber"),
("HOME","homeDirectory"),
("PWD","userPassword")]
data = [("Login","uid"),
(_("Name"),"cn"),
("uid","uidNumber"),
(_("Group"),"gidNumber"),
(_("Home directory"),"homeDirectory"),
(_("Password"),"userPassword")]
if fields == "short":
delData = ["UID", "PWD", "GROUP"]
delData = ["uid", _("Password"), _("Group")]
return (data, delData)
def getAllUsers(self, fields, service):
@ -10857,6 +11018,8 @@ with another option."))
retClVars=True
searchRes = self.getQueryLDAP(service, "users", searchAttr,
searchStr, retrAttrs, retClVars)
if searchRes == False:
return False
if not searchRes:
return (headers , [])
if service == "mail":
@ -10867,8 +11030,8 @@ with another option."))
for i in searchRes:
i[0][1]['homeDirectory'] = [os.path.join(\
clVars.Get("sr_mail_path"),i[0][1]['uid'][0])]
data.append(("HOME","homeDirectory"))
delData.append("HOME")
data.append((_("Home directory"),"homeDirectory"))
delData.append(_("Home directory"))
if fields == "short":
data = filter(lambda x: not x[0] in delData, data)
headers = map(lambda x: x[0], data)
@ -10886,7 +11049,7 @@ with another option."))
and ",".join([x,y]) , ldapValue, "")
listAttr.append(value)
else:
listAttr.append("N")
listAttr.append("No")
loginsUsers.append(listAttr)
return (headers, loginsUsers)
@ -10916,36 +11079,36 @@ with another option."))
# Ставим Y в случае выставленного флага
elif attr == "initials":
if value == "No":
retValue = "Y"
retValue = "Yes"
else:
retValue = "N"
retValue = "No"
elif attr == "accountStatus":
if value == "passive":
retValue = "Y"
retValue = "Yes"
else:
retValue = "N"
retValue = "No"
elif attr == "shadowExpire":
if value == "1":
retValue = "Y"
retValue = "Yes"
else:
retValue = "N"
retValue = "No"
elif attr == "sambaAcctFlags":
if value == "[DU ]":
retValue = "Y"
retValue = "Yes"
else:
retValue = "N"
retValue = "No"
elif attr == "userPassword":
if value == "crypt{xxx}":
retValue = "N"
retValue = "No"
else:
retValue = "Y"
retValue = "Yes"
elif attr == "shadowFlag":
if value == "1":
retValue = "Y"
retValue = "Yes"
else:
retValue = "N"
retValue = "No"
elif attr == "sambaNTPassword":
retValue = "Y"
retValue = "Yes"
return retValue
def _convDatatoStr(self, dataDays):
@ -10977,7 +11140,7 @@ with another option."))
#Имя группы пользователя
groupName = userGidNamesLdap[0]
else:
groupName = "Not found"
groupName = userGid
return groupName
return userGid
@ -10990,21 +11153,22 @@ with another option."))
_("ERROR: _getUserGroupsNames incorrect service=%s")%service)
return False
memberGroups = []
userInGroups = []
if service == "unix":
userInGroups = servObj.searchUnixMemberGid(userName)
for group in userInGroups:
memberGroups.append(group[0][1]['cn'][0])
if service == "mail":
resSearch = servObj.searchMailMember(userName)
if not resSearch:
return []
userMail, userInGroups = resSearch
for group in userInGroups:
mailGroup = group[0][1]['mail']
altMailGroup = group[0][1]['mailAlternateAddress']
listMail = mailGroup + altMailGroup
for mail in listMail:
if not mail in memberGroups:
memberGroups.append(mail)
for group in userInGroups:
mailGroup = group[0][1]['mail']
altMailGroup = group[0][1]['mailAlternateAddress']
listMail = mailGroup + altMailGroup
for mail in listMail:
if not mail in memberGroups:
memberGroups.append(mail)
return memberGroups
class tsOpt(cl_base.opt):

Loading…
Cancel
Save