Revisión 69
Añadido por Manu Mora Gordillo hace alrededor de 14 años
Groups.py | ||
---|---|---|
def __init__(self):
|
||
pass
|
||
|
||
def __init__(self,ldap,name,gidNumber):
|
||
def __init__(self,ldap,type,name):
|
||
self.ldap = ldap
|
||
self.type = type
|
||
self.name = name
|
||
self.gidNumber = gidNumber
|
||
|
||
def validation(self):
|
||
def validation(self,action):
|
||
|
||
if action == "add":
|
||
if self.type == "none":
|
||
return "type"
|
||
|
||
if self.name == "":
|
||
return "name"
|
||
|
||
if self.gidNumber == "":
|
||
return "gidNumber"
|
||
|
||
return "OK"
|
||
|
||
def process(self,action):
|
||
if action == "add":
|
||
val = self.validation()
|
||
val = self.validation(action)
|
||
|
||
if val != "OK":
|
||
return val
|
||
... | ... | |
return response
|
||
|
||
if action == "modify":
|
||
val = self.validation()
|
||
val = self.validation(action)
|
||
|
||
if val != "OK":
|
||
return val
|
||
else:
|
||
response = self.modify()
|
||
return response
|
||
|
||
if action == "delete":
|
||
response = self.delete()
|
||
return response
|
||
|
||
if action == "list":
|
||
response = self.list();
|
||
return response
|
||
return response
|
||
|
||
def list(self,args):
|
||
|
||
... | ... | |
|
||
if searchType == typeRow or searchType=="none":
|
||
row = {
|
||
"id":i[0][0],
|
||
"id":i[0][1]["cn"][0],
|
||
"cell":[typeRow, i[0][1]["cn"][0], i[0][1]["gidNumber"][0]],
|
||
"type": typeRow,
|
||
"cn": i[0][1]["cn"][0],
|
||
... | ... | |
|
||
|
||
def add(self):
|
||
record = [
|
||
('objectclass', ['person','organizationalperson','inetorgperson']),
|
||
('uid', ['francis']),
|
||
maxID = str(self.getMaxID())
|
||
|
||
attr = [
|
||
('objectclass', ['top','posixGroup','lisGroup','lisAclGroup']),
|
||
#('objectclass', ['top','posixGroup','lisGroup']),
|
||
('grouptype', [self.type] ),
|
||
('gidnumber', [maxID] ),
|
||
('cn', [self.name] ),
|
||
('sn', ['Bacon'] ),
|
||
('userpassword', [self.password]),
|
||
('ou', ['users'])
|
||
('description', [self.name+' department group']),
|
||
('memberuid', ['manuprofe']),
|
||
('member', ['uid=manuprofe,ou=People,dc=instituto,dc=extremadura,dc=es'])
|
||
]
|
||
try:
|
||
self.ldap.add("cn=Groups", record)
|
||
except ldap.ALREADY_EXISTS:
|
||
return "fail"
|
||
|
||
self.ldap.add("cn="+self.name+",ou=Group", attr)
|
||
|
||
return "OK"
|
||
|
||
... | ... | |
(ldap.MOD_ADD, 'description', 'Author of New Organon'),
|
||
(ldap.MOD_ADD, 'description', 'British empiricist')
|
||
]
|
||
self.ldap.modify_s('uid='+ uid +',cn=Groups', mod_attrs)
|
||
self.ldap.modify_s('uid='+ uid +',ou=Group', mod_attrs)
|
||
|
||
def delete(self,uid):
|
||
self.ldap.delete('uid='+ uid +',cn=Groups')
|
||
def delete(self):
|
||
self.ldap.delete('cn='+ self.name +',ou=Group')
|
||
|
||
|
||
def getMaxID(self): # find the maximum ID
|
||
result = self.ldap.search("ou=Group","cn=*",["gidNumber"])
|
||
numbers = []
|
||
for i in result:
|
||
numbers.append(int(i[0][1]['gidNumber'][0]))
|
||
|
||
result = self.ldap.search("ou=People","uid=*",["gidNumber","uidNumber"])
|
||
for i in result:
|
||
numbers.append(int(i[0][1]['gidNumber'][0]))
|
||
numbers.append(int(i[0][1]['uidNumber'][0]))
|
||
|
||
numbers.sort()
|
||
|
||
maxID = 1
|
||
if len(numbers) > 0:
|
||
maxID = numbers[len(numbers)-1] + 1
|
||
|
||
return maxID
|
Exportar a: Unified diff
Inserta y borra grupos