Reworking of the TS3 module, enable group removal

This commit is contained in:
2010-11-02 11:20:05 +00:00
parent fc66668c6c
commit e1beff8845

View File

@@ -14,7 +14,8 @@ class TS3Service(BaseService):
'vhost_id': 0, 'vhost_id': 0,
'authed_sgid': 12, 'authed_sgid': 12,
'name_format': '%(alliance)s - %(corporation)s - %(name)s', 'name_format': '%(alliance)s - %(corporation)s - %(name)s',
'bookmark_name': 'TEST Alliance TS3'} 'bookmark_name': 'TEST Alliance TS3',
'ignore_groups': [6]}
def __init__(self): def __init__(self):
pass pass
@@ -35,7 +36,6 @@ class TS3Service(BaseService):
'alliance': kwargs['character'].corporation.alliance.ticker, 'alliance': kwargs['character'].corporation.alliance.ticker,
'corporation': kwargs['character'].corporation.ticker } 'corporation': kwargs['character'].corporation.ticker }
self._create_groups(kwargs['user'].groups.all().values_list('name', flat=True))
username = self.settings['name_format'] % details username = self.settings['name_format'] % details
ret = self.conn.send_command('tokenadd', {'tokentype': 0, 'tokenid1': self.settings['authed_sgid'], 'tokenid2': 0, 'tokendescription': kwargs['character'].name.replace(' ', ''), 'tokencustomset': "ident=sso_uid value=%s|ident=sso_userid value=%s|ident=eve_charid value=%s" % (kwargs['character'].name.replace(' ', ''), kwargs['user'].id, kwargs['character'].id) }) ret = self.conn.send_command('tokenadd', {'tokentype': 0, 'tokenid1': self.settings['authed_sgid'], 'tokenid2': 0, 'tokendescription': kwargs['character'].name.replace(' ', ''), 'tokencustomset': "ident=sso_uid value=%s|ident=sso_userid value=%s|ident=eve_charid value=%s" % (kwargs['character'].name.replace(' ', ''), kwargs['user'].id, kwargs['character'].id) })
if 'keys' in ret and 'token' in ret['keys']: if 'keys' in ret and 'token' in ret['keys']:
@@ -54,20 +54,21 @@ class TS3Service(BaseService):
""" Delete a user by uid """ """ Delete a user by uid """
user = self._get_userid(uid) user = self._get_userid(uid)
if user: if user:
for client in self.conn.send_command('clientlist'): for client in self.conn.send_command('clientlist'):
if client['keys']['client_database_id'] == user: if client['keys']['client_database_id'] == user:
self.conn.send_command('clientkick', {'clid': client['keys']['clid'], 'reasonid': 5, 'reasonmsg': 'Auth service deleted'}) self.conn.send_command('clientkick', {'clid': client['keys']['clid'], 'reasonid': 5, 'reasonmsg': 'Auth service deleted'})
ret = self.conn.send_command('clientdbdelete', {'cldbid': user }) ret = self.conn.send_command('clientdbdelete', {'cldbid': user })
return True if ret['id'] == 0:
return True
def disable_user(self, uid): def disable_user(self, uid):
""" Disable a user by uid """ """ Disable a user by uid """
user = self._get_userid(uid) user = self._get_userid(uid)
if user: if user:
ret = self.conn.send_command('servergroupdelclient', {'sgid': self.settings['authed_sgid'], 'cldbid': user }) ret = self.conn.send_command('servergroupdelclient', {'sgid': self.settings['authed_sgid'], 'cldbid': user })
return True if ret['id'] == 0:
return True
def enable_user(self, uid, password): def enable_user(self, uid, password):
""" Enable a user by uid """ """ Enable a user by uid """
@@ -75,7 +76,8 @@ class TS3Service(BaseService):
user = self._get_userid(uid) user = self._get_userid(uid)
if user: if user:
ret = self.conn.send_command('servergroupaddclient', {'sgid': self.settings['authed_sgid'], 'cldbid': user }) ret = self.conn.send_command('servergroupaddclient', {'sgid': self.settings['authed_sgid'], 'cldbid': user })
return True if ret['id'] == 0:
return True
def reset_password(self, uid, password): def reset_password(self, uid, password):
""" Reset the user's password """ """ Reset the user's password """
@@ -103,6 +105,7 @@ class TS3Service(BaseService):
def _create_group(self, groupname): def _create_group(self, groupname):
""" Creates a Server Group and returns the SGID """ """ Creates a Server Group and returns the SGID """
sgid = self._group_by_name(groupname) sgid = self._group_by_name(groupname)
if not sgid: if not sgid:
ret = self.conn.send_command('servergroupadd', { 'name': groupname }) ret = self.conn.send_command('servergroupadd', { 'name': groupname })
@@ -113,12 +116,25 @@ class TS3Service(BaseService):
self.conn.send_command('servergroupaddperm', { 'sgid': sgid, 'permsid': 'i_group_needed_member_remove_power', 'permvalue': 100, 'permnegated': 0, 'permskip': 0 }) self.conn.send_command('servergroupaddperm', { 'sgid': sgid, 'permsid': 'i_group_needed_member_remove_power', 'permvalue': 100, 'permnegated': 0, 'permskip': 0 })
return sgid return sgid
def _create_groups(self, groups): def _group_list(self):
""" Creates groups from a list """ """ List of all groups on the TS server """
output = []
for g in groups: if not hasattr(self, '__group_cache') or not self.__group_cache:
output.append(self._create_group(g)) self.__group_cache = self.conn.send_command('servergrouplist')
return output outlist = {}
for group in self.__group_cache:
outlist[group['keys']['name']] = group['keys']['sgid']
return outlist
def _user_group_list(self, cldbid):
""" List of all groups assigned to a user """
groups = self.conn.send_command('servergroupsbyclientid', {'cldbid': cldbid })
outlist = {}
for group in groups:
outlist[group['keys']['name']] = group['keys']['sgid']
return outlist
def update_groups(self, uid, groups): def update_groups(self, uid, groups):
""" Update the UID's groups based on the provided list """ """ Update the UID's groups based on the provided list """
@@ -126,23 +142,28 @@ class TS3Service(BaseService):
cldbid = self._get_userid(uid) cldbid = self._get_userid(uid)
if cldbid: if cldbid:
tsglist = self.conn.send_command('servergroupsbyclientid', {'cldbid': cldbid }) tsgrplist = self._group_list()
donelist = [] usrgrplist = self._user_group_list(cldbid)
if type(tsglist) == type(list()):
for g in tsglist:
donelist.append(g['keys']['sgid'])
else:
donelist.append(tsglist['keys']['sgid'])
# Add groups
if groups.count(): if groups.count():
addgroups = self._create_groups(groups.values_list('name', flat=True)) for g in groups:
for g in addgroups: if not g.name in tsgrplist:
if not g in donelist: tsgrplist[g.name] = self._create_group(g.name)
ret = self.conn.send_command('servergroupaddclient', {'sgid': g, 'cldbid': cldbid }) if not group.name in usrgrplist:
self.conn.send_command('servergroupaddclient', {'sgid': tsgrplist[g.name], 'cldbid': cldbid })
usrgrplist[g.name] = tsgrplist[g.name]
# Remove OKed groups from the delete list
for g in groups:
if g.name in usrgrplist:
del usrgrplist[g.name]
# Remove ignored and admin groups
for k, v in usrgrplist.items():
if not v == self.settings['auth_sgid'] and not v in self.settings['ignore_groups']:
self.conn.send_command('servergroupdelclient', {'sgid': v, 'cldbid': cldbid })
#remv = set(donelist) - set(addgroups)
#if int(self.settings['authed_sgid']) in remv:
# ret = self.conn.send_command('servergroupdelclient', {'sgid': g, 'cldbid': cldbid })
return True return True
ServiceClass = 'TS3Service' ServiceClass = 'TS3Service'