Fixes various issues with the TS3 plugin

This commit is contained in:
2010-10-15 14:44:56 +01:00
parent 97a82e07e7
commit 76f65a1cbf
2 changed files with 22 additions and 19 deletions

View File

@@ -19,13 +19,13 @@ class TS3Service(BaseService):
pass
@property
def _conn(self):
if not hasattr(self, '__conn'):
self.__conn = TS3Server(self.settings['host'], self.settings['port'])
self.__conn.login(self.settings['sa_login'], self.settings['sa_password'])
self.__conn.use(self.settings['vhost_id'])
def conn(self):
if not hasattr(self, '_conn'):
self._conn = TS3Server(self.settings['host'], self.settings['port'])
self._conn.login(self.settings['sa_login'], self.settings['sa_password'])
self._conn.use(self.settings['vhost_id'])
return self.__conn
return self._conn
def add_user(self, username, password, **kwargs):
""" Add a user, returns a UID for that user """
@@ -34,9 +34,9 @@ class TS3Service(BaseService):
'alliance': kwargs['character'].corporation.alliance.ticker,
'corporation': kwargs['character'].corporation.ticker }
self._create_groups(kwargs['user'].groups.all())
self._create_groups(kwargs['user'].groups.all().values_list('name', flat=True))
username = self.settings['name_format'] % details
ret = self._conn.send_command('tokenadd', {'tokentype': 0, 'tokenid1': self.settings['authed_sgid'], 'tokenid2': 0, 'tokendescription': "Auth Token for %s" % username, 'tokencustomset': "ident=sso_uid value=%s" % username })
ret = self.conn.send_command('tokenadd', {'tokentype': 0, 'tokenid1': self.settings['authed_sgid'], 'tokenid2': 0, 'tokendescription': "Auth Token for %s" % username, 'tokencustomset': "ident=sso_uid value=%s" % username })
if 'keys' in ret and 'token' in ret['keys']:
token = ret['keys']['token']
@@ -54,14 +54,14 @@ class TS3Service(BaseService):
""" Delete a user by uid """
user = self._get_userid(uid)
if user:
ret = self._conn.send_command('clientdbdelete', {'cldbid': user })
ret = self.conn.send_command('clientdbdelete', {'cldbid': user })
return True
def disable_user(self, uid):
""" Disable a user by uid """
user = self._get_userid(uid)
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
def enable_user(self, uid, password):
@@ -69,7 +69,7 @@ class TS3Service(BaseService):
user = self._get_userid(uid)
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
def reset_password(self, uid, password):
@@ -82,8 +82,7 @@ class TS3Service(BaseService):
def _group_by_name(self, groupname):
if not hasattr(self, '__group_cache') or not self.__group_cache:
self.__group_cache = self._conn.send_command('servergrouplist')
self.__group_cache = self.conn.send_command('servergrouplist')
for group in self.__group_cache:
if group['keys']['name'] == groupname:
return group['keys']['sgid']
@@ -93,32 +92,33 @@ class TS3Service(BaseService):
def _get_userid(self, uid):
""" Finds the TS3 ID of a user from their UID """
ret = self._conn.send_command('customsearch', {'ident': 'sso_uid', 'pattern': 'uid'})
ret = self.conn.send_command('customsearch', {'ident': 'sso_uid', 'pattern': uid})
if ret and type(ret) == type(list):
return ret[0]['cldbid']
def _create_group(groupname):
def _create_group(self, groupname):
""" Creates a Server Group and returns the SGID """
sgid = self._group_by_name(groupname)
if not sgid:
ret = self._conn.send_command('servergroupadd', { 'name': g })
ret = self._conn.send_command('servergroupadd', { 'name': groupname })
self.__group_cache = None
sgid = ret['keys']['sgid']
return sgid
def _create_groups(self, groups):
""" Creates groups from a list """
output = []
for g in groups:
ouput.append(self._create_group(g))
output.append(self._create_group(g))
return output
def update_groups(self, uid, groups):
""" Update the UID's groups based on the provided list """
if groups.count():
addgroups = self._create_groups(groups.values_list('name'))
addgroups = self._create_groups(groups.values_list('name', flat=True))
user = self._get_userid(uid)
for g in addgroups:
ret = self._conn.send_command('servergroupaddclient', {'sgid': g['sgid'], 'cldbid': user })
ret = self.conn.send_command('servergroupaddclient', {'sgid': g['sgid'], 'cldbid': user })
ServiceClass = 'TS3Service'

View File

@@ -1,3 +1,4 @@
import time
import socket
import logging
@@ -46,6 +47,7 @@ class TS3Proto():
data = self._sockfile.readline()
if data.strip() == "TS3":
self._sockfile.readline()
self._connected = True
return True
@@ -58,6 +60,7 @@ class TS3Proto():
def send_command(self, command, keys=None, opts=None):
cmd = self.construct_command(command, keys=keys, opts=opts)
print cmd
self.send('%s\n' % cmd)
data = []