def getClientPenalties(self, client, type='Ban'): self.console.debug('Storage: getClientPenalties %s' % client) where = QueryBuilder(self.db).WhereClause({ 'type': type, 'client_id': client.id, 'inactive': 0 }) where += ' and (time_expire = -1 or time_expire > %s)' % int( time.time()) cursor = self.query( QueryBuilder(self.db).SelectQuery('*', 'penalties', where, 'time_add DESC')) if not cursor: return () penalties = [] while not cursor.EOF: penalties.append(self._createPenaltyFromRow(cursor.getRow())) cursor.moveNext() cursor.close() return penalties
def getClientIpAddress(self, ipalias): """ Return an ipalias object fetching data from the storage. :param ipalias: The ipalias object to fill with fetch data. :return: The ip alias object given in input with all the fields set. """ self.console.debug('Storage: getClientIpAddress %s' % ipalias) if hasattr(ipalias, 'id') and ipalias.id > 0: query = QueryBuilder(self.db).SelectQuery('*', 'ipaliases', {'id': ipalias.id}, None, 1) elif hasattr(ipalias, 'ip') and hasattr(ipalias, 'clientId'): query = QueryBuilder(self.db).SelectQuery( '*', 'ipaliases', { 'ip': ipalias.ip, 'client_id': ipalias.clientId }, None, 1) else: raise KeyError('no ip found matching %s' % ipalias) cursor = self.query(query) if cursor.EOF: cursor.close() raise KeyError('no ip found matching %s' % ipalias) row = cursor.getOneRow() ipalias.id = int(row['id']) ipalias.ip = row['ip'] ipalias.timeAdd = int(row['time_add']) ipalias.timeEdit = int(row['time_edit']) ipalias.clientId = int(row['client_id']) ipalias.numUsed = int(row['num_used']) return ipalias
def getGroup(self, group): if hasattr(group, 'keyword') and group.keyword: q = QueryBuilder(self.db).SelectQuery('*', 'groups', { 'keyword' : group.keyword }, None, 1) self.console.verbose2(q) cursor = self.query(q) g = cursor.getOneRow() if not g: raise KeyError, 'No group matching keyword %s' % group.keyword elif hasattr(group, 'level') and group.level: q = QueryBuilder(self.db).SelectQuery('*', 'groups', { 'level' : group.level }, None, 1) self.console.verbose2(q) cursor = self.query(q) g = cursor.getOneRow() if not g: raise KeyError, 'No group matching level %s' % group.level else: raise KeyError("cannot find Group as no keyword/level provided") group.id = int(g['id']) group.name = g['name'] group.keyword = g['keyword'] group.level = int(g['level']) group.timeAdd = int(g['time_add']) group.timeEdit = int(g['time_edit']) return group
def getClientPenalties(self, client, type='Ban'): """ Return the penalties of the given client. :param client: The client whose penalties we want to retrieve. :param type: The type of the penalties we want to retrieve. :return: List of penalties """ self.console.debug('Storage: getClientPenalties %s' % client) where = QueryBuilder(self.db).WhereClause({ 'type': type, 'client_id': client.id, 'inactive': 0 }) where += ' AND (time_expire = -1 OR time_expire > %s)' % int(time()) cursor = self.query( QueryBuilder(self.db).SelectQuery('*', 'penalties', where, 'time_add DESC')) penalties = [] while not cursor.EOF: penalties.append(self._createPenaltyFromRow(cursor.getRow())) cursor.moveNext() cursor.close() return penalties
def save_command_grants(self, client): """ Save client command grants in the storage. :param client: The client whose command grants needs to be stored """ if not hasattr(client, GRANT_SET_ATTR): self.debug( 'not storing command grants for %s [@%s]: no command grant found in client object', client.name, client.id) return cursor = None try: grantlist = GRANT_SET_JOIN.join(getattr(client, GRANT_SET_ATTR)) data = {'id': client.id, 'commands': grantlist} query = QueryBuilder(self.console.storage.db).SelectQuery( ('id', 'commands'), 'cmdgrants', {'id': client.id}) cursor = self.console.storage.query(query) if cursor.EOF: self.console.storage.query( QueryBuilder(self.console.storage.db).InsertQuery( data, 'cmdgrants')) else: self.console.storage.query( QueryBuilder(self.console.storage.db).UpdateQuery( data, 'cmdgrants', {'id': client.id})) self.debug('stored command grants for %s [@%s]', client.name, client.id) except Exception, e: self.error('could not store command grants for %s [@%s]: %s', client.name, client.id, e)
def getClientAlias(self, alias): self.console.debug('Storage: getClientAlias %s' % alias) cursor = None if hasattr(alias, 'id') and alias.id > 0: cursor = self.query( QueryBuilder(self.db).SelectQuery('*', 'aliases', {'id': alias.id}, None, 1)) elif hasattr(alias, 'alias') and hasattr(alias, 'clientId'): cursor = self.query( QueryBuilder(self.db).SelectQuery('*', 'aliases', { 'alias': alias.alias, 'client_id': alias.clientId }, None, 1)) if not cursor or cursor.EOF: raise KeyError, 'No alias matching %s' % alias g = cursor.getOneRow() alias.id = int(g['id']) alias.alias = g['alias'] alias.timeAdd = int(g['time_add']) alias.timeEdit = int(g['time_edit']) alias.clientId = int(g['client_id']) alias.numUsed = int(g['num_used']) alias.ip = g['ip'] return alias
def setMapResult(self, mapresult): """ Insert/update a mapresult in the storage. NOTE: there's no reason this should ever update :param mapresult: the map details for the record. :return: The ID of the record stored into the database. """ # self.console.debug('Storage: setMapResult %s. %s, %s. %s' % (mapresult.mapname, mapresult.redscore, mapresult.bluescore, mapresult.maptime)) fields = ('mapname', 'redscore', 'bluescore', 'maptime', 'lowplayer', 'highplayer', 'createddate') data = {'id': mapresult.id} if mapresult.id > 0 else {} for f in fields: if hasattr(mapresult, self.getVar(f)): data[f] = getattr(mapresult, self.getVar(f)) self.console.debug('Storage: setMapResult data %s' % data) if mapresult.id > 0: self.query( QueryBuilder(self.db).UpdateQuery(data, 'mapresult', {'id': mapresult.id})) else: cursor = self.query( QueryBuilder(self.db).InsertQuery(data, 'mapresult')) mapresult.id = cursor.lastrowid cursor.close() return mapresult.id
def cmd_auth(self, data, client, cmd=None): """\ <auth> [<name>] - set a login name for a client """ if data: cursor = self.console.storage.query( QueryBuilder(self.console.storage.db).SelectQuery( '*', 'clients', {'login': data})) if cursor.rowcount: while not cursor.EOF: g = cursor.getRow() if not g['id'] == client.id: client.message( 'Username already registered. Choose another one.') return self.console.storage.query( QueryBuilder(self.console.storage.db).UpdateQuery( {'login': data}, 'clients', {'id': client.id})) client.message('Your login name has been set.') client.message( 'Open the console and type: \'%s %s !setpassword yourpassword\' to set your password' % (self._pmcomm, client.cid)) else: client.message( 'Enter a login name. Type !help auth for more info.') return
def getClientIpAddress(self, ipalias): self.console.debug('Storage: getClientIpAddress %s' % ipalias) cursor = None if hasattr(ipalias, 'id') and ipalias.id > 0: cursor = self.query( QueryBuilder(self.db).SelectQuery('*', 'ipaliases', {'id': ipalias.id}, None, 1)) elif hasattr(ipalias, 'ip') and hasattr(ipalias, 'clientId'): cursor = self.query( QueryBuilder(self.db).SelectQuery('*', 'ipaliases', { 'ip': ipalias.ip, 'client_id': ipalias.clientId }, None, 1)) if not cursor or cursor.EOF: raise KeyError, 'No ip matching %s' % ipalias g = cursor.getOneRow() ipalias.id = int(g['id']) ipalias.ip = g['ip'] ipalias.timeAdd = int(g['time_add']) ipalias.timeEdit = int(g['time_edit']) ipalias.clientId = int(g['client_id']) ipalias.numUsed = int(g['num_used']) return ipalias
def getGroup(self, group): """ Return a group object fetching data from the storage layer. :param group: A group object with level or keyword filled. :return: The group instance given in input with all the fields set. """ if hasattr(group, 'keyword') and group.keyword: query = QueryBuilder(self.db).SelectQuery( '*', 'groups', dict(keyword=group.keyword), None, 1) self.console.verbose2(query) cursor = self.query(query) row = cursor.getOneRow() if not row: raise KeyError('no group matching keyword: %s' % group.keyword) elif hasattr(group, 'level') and group.level >= 0: query = QueryBuilder(self.db).SelectQuery('*', 'groups', dict(level=group.level), None, 1) self.console.verbose2(query) cursor = self.query(query) row = cursor.getOneRow() if not row: raise KeyError('no group matching level: %s' % group.level) else: raise KeyError("cannot find Group as no keyword/level provided") group.id = int(row['id']) group.name = row['name'] group.keyword = row['keyword'] group.level = int(row['level']) group.timeAdd = int(row['time_add']) group.timeEdit = int(row['time_edit']) return group
def getClientPenalties(self, client, type='Ban'): """ Return the penalties of the given client. :param client: The client whose penalties we want to retrieve. :param type: The type of the penalties we want to retrieve. :return: List of penalties """ # self.console.debug('Storage: getClientPenalties %s' % client) # where = QueryBuilder(self.db).WhereClause({'type': type, 'client_id': client.id, 'inactive': 0}) # where += ' AND (time_expire = -1 OR time_expire > %s)' % int(time()) # cursor = self.query(QueryBuilder(self.db).SelectQuery('*', 'penalties', where, 'time_add DESC')) # DK: testing get client penalties by IP self.console.debug('Storage: getClientPenalties %s' % client) where = QueryBuilder(self.db).WhereClause({ 'type': type, 'inactive': 0 }) where += ' AND (time_expire = -1 OR time_expire > %s)' % int(time()) where += ' AND client_id IN (SELECT id FROM clients WHERE ip = "%s")' % client.ip cursor = self.query( QueryBuilder(self.db).SelectQuery('*', 'penalties', where, 'time_add DESC')) penalties = [] while not cursor.EOF: penalties.append(self._createPenaltyFromRow(cursor.getRow())) cursor.moveNext() cursor.close() # self.console.debug("Storage: getClientPenalties found %s records", len(penalties)) return penalties
def getClientLastPenalty(self, client, type='Ban'): """ Return the last penalty added for the given client. :param client: The client whose penalty we want to retrieve. :param type: The type of the penalty we want to retrieve. :return: The last penalty added for the given client """ # where = QueryBuilder(self.db).WhereClause({'type': type, 'client_id': client.id, 'inactive': 0}) # where += ' AND (time_expire = -1 OR time_expire > %s)' % int(time()) # cursor = self.query(QueryBuilder(self.db).SelectQuery('*', 'penalties', where, 'time_add DESC', 1)) # DK: testing get client penalties by IP self.console.debug('Storage: getClientPenalties %s' % client) where = QueryBuilder(self.db).WhereClause({ 'type': type, 'inactive': 0 }) where += ' AND (time_expire = -1 OR time_expire > %s)' % int(time()) where += ' AND client_id IN (SELECT id FROM clients WHERE ip = "%s")' % client.ip cursor = self.query( QueryBuilder(self.db).SelectQuery('*', 'penalties', where, 'time_add DESC', 1)) row = cursor.getOneRow() if not row: return None return self._createPenaltyFromRow(row)
def setClientIpAddress(self, ipalias): """ Insert/update an ipalias in the storage. :param ipalias: The ipalias to be saved. """ self.console.debug('Storage: setClientIpAddress %s' % ipalias) fields = ('num_used', 'ip', 'client_id', 'time_add', 'time_edit') data = {'id': ipalias.id} if ipalias.id else {} for f in fields: if hasattr(ipalias, self.getVar(f)): data[f] = getattr(ipalias, self.getVar(f)) self.console.debug('Storage: setClientIpAddress data %s' % data) if ipalias.id: self.query( QueryBuilder(self.db).UpdateQuery(data, 'ipaliases', {'id': ipalias.id})) else: cursor = self.query( QueryBuilder(self.db).InsertQuery(data, 'ipaliases')) ipalias.id = cursor.lastrowid cursor.close() return ipalias.id
def getClientFirstPenalty(self, client, type='Ban'): where = QueryBuilder(self.db).WhereClause( { 'type' : type, 'client_id' : client.id, 'inactive' : 0 } ) where += ' && (time_expire = -1 || time_expire > %s)' % int(time.time()) cursor = self.query(QueryBuilder(self.db).SelectQuery('*', 'penalties', where, 'time_expire DESC, time_add ASC', 1)) g = cursor.getOneRow() if g: return None if g['type'] == 'Warning': P = b3.clients.ClientWarning() elif g['type'] == 'TempBan': P = b3.clients.ClientTempBan() elif g['type'] == 'Kick': P = b3.clients.ClientKick() elif g['type'] == 'Ban': P = b3.clients.ClientBan() else: P = b3.clients.ClientPenalty() P.id = int(g['id']) P.type = g['type'] P.keyword = g['keyword'] P.reason = g['reason'] P.data = g['data'] P.inactive = int(g['inactive']) P.timeAdd = int(g['time_add']) P.timeEdit = int(g['time_edit']) P.timeExpire = int(g['time_expire']) P.clientId = int(g['client_id']) P.adminId = int(g['admin_id']) P.duration = int(g['duration']) return P
def setClientAlias(self, alias): """ Insert/update an alias in the storage. :param alias: The alias to be saved. :return: The ID of the alias stored into the database. """ self.console.debug('Storage: setClientAlias %s' % alias) fields = ('num_used', 'alias', 'client_id', 'time_add', 'time_edit') data = {'id': alias.id} if alias.id else {} for f in fields: if hasattr(alias, self.getVar(f)): data[f] = getattr(alias, self.getVar(f)) self.console.debug('Storage: setClientAlias data %s' % data) if alias.id: self.query( QueryBuilder(self.db).UpdateQuery(data, 'aliases', {'id': alias.id})) else: cursor = self.query( QueryBuilder(self.db).InsertQuery(data, 'aliases')) alias.id = cursor.lastrowid cursor.close() return alias.id
def setClient(self, client): """ Insert/update a client in the storage. :param client: The client to be saved. :return: The ID of the client stored into the database. """ self.console.debug('Storage: setClient %s' % client) fields = ('ip', 'greeting', 'connections', 'time_edit', 'guid', 'pbid', 'name', 'time_add', 'auto_login', 'mask_level', 'group_bits', 'login', 'password') data = {'id': client.id} if client.id > 0 else {} for f in fields: if hasattr(client, self.getVar(f)): data[f] = getattr(client, self.getVar(f)) self.console.debug('Storage: setClient data %s' % data) if client.id > 0: self.query( QueryBuilder(self.db).UpdateQuery(data, 'clients', {'id': client.id})) else: cursor = self.query( QueryBuilder(self.db).InsertQuery(data, 'clients')) client.id = cursor.lastrowid cursor.close() return client.id
def getClientFirstPenalty(self, client, type='Ban'): where = QueryBuilder(self.db).WhereClause( { 'type' : type, 'client_id' : client.id, 'inactive' : 0 } ) where += ' and (time_expire = -1 or time_expire > %s)' % int(time.time()) cursor = self.query(QueryBuilder(self.db).SelectQuery('*', 'penalties', where, 'time_expire DESC, time_add ASC', 1)) g = cursor.getOneRow() if not g: return None return self._createPenaltyFromRow(g)
def getClientPenalties(self, client, type='Ban'): self.console.debug('Storage: getClientPenalties %s' % client) where = QueryBuilder(self.db).WhereClause({ 'type': type, 'client_id': client.id, 'inactive': 0 }) where += ' && (time_expire = -1 || time_expire > %s)' % int( time.time()) cursor = self.query( QueryBuilder(self.db).SelectQuery('*', 'penalties', where, 'time_add DESC')) if not cursor: return () penalties = [] while not cursor.EOF: g = cursor.getRow() if g['type'] == 'Warning': penaltyType = b3.clients.ClientWarning elif g['type'] == 'TempBan': penaltyType = b3.clients.ClientTempBan elif g['type'] == 'Kick': penaltyType = b3.clients.ClientKick elif g['type'] == 'Ban': penaltyType = b3.clients.ClientBan elif g['type'] == 'Notice': penaltyType = b3.clients.ClientNotice else: penaltyType = b3.clients.Penalty penalty = penaltyType() penalty.id = int(g['id']) penalty.type = g['type'] penalty.keyword = g['keyword'] penalty.reason = g['reason'] penalty.data = g['data'] penalty.inactive = int(g['inactive']) penalty.timeAdd = int(g['time_add']) penalty.timeEdit = int(g['time_edit']) penalty.timeExpire = int(g['time_expire']) penalty.clientId = int(g['client_id']) penalty.adminId = int(g['admin_id']) penalty.duration = int(g['duration']) penalties.append(penalty) cursor.moveNext() cursor.close() return penalties
def setClient(self, client): """ id int(11) PRI NULL auto_increment ip varchar(16) YES NULL greeting varchar(128) YES NULL connections int(11) YES NULL time_edit int(11) YES NULL guid varchar(32) MUL pbid varchar(32) YES NULL name varchar(32) YES NULL time_add int(11) YES NULL auto_login int(11) YES NULL mask_level int(11) YES NULL group_bits int(11) """ self.console.debug('Storage: setClient %s' % client) fields = ( 'ip', 'greeting', 'connections', 'time_edit', 'guid', 'pbid', 'name', 'time_add', 'auto_login', 'mask_level', 'group_bits' ) if client.id > 0: data = { 'id' : client.id } else: data = {} for f in fields: if hasattr(client, self.getVar(f)): data[f] = getattr(client, self.getVar(f)) self.console.debug('Storage: setClient data %s' % data) if client.id > 0: self.query(QueryBuilder(self.db).UpdateQuery(data, 'clients', { 'id' : client.id })) else: cursor = self.query(QueryBuilder(self.db).InsertQuery(data, 'clients')) if cursor: client.id = cursor.lastrowid else: client.id = None return client.id
def db_putauth(self, client, auth): if self.db_getauth(client) is None: q = QueryBuilder(self.console.storage.db).InsertQuery( { 'clientid': client.id, 'auth': auth }, 'authmod') else: q = QueryBuilder(self.console.storage.db).UpdateQuery( {'auth': auth}, 'authmod', {'clientid': client.id}) self.console.storage.query(q)
def setClientPenalty(self, penalty): """ id int(10) UNSIGNED No auto_increment type enum('Ban', 'TempBan', 'Kick', 'Warning') No Ban duration int(10) UNSIGNED No 0 inactive tinyint(1) UNSIGNED No 0 admin_id int(10) UNSIGNED No 0 time_add int(10) UNSIGNED No 0 time_edit int(10) UNSIGNED No 0 time_expire int(11) No 0 reason varchar(255) No keyword varchar(16) No client_id int(10) UNSIGNED No 0 """ fields = ( 'type', 'duration', 'inactive', 'admin_id', 'time_add', 'time_edit', 'time_expire', 'reason', 'keyword', 'client_id', 'data' ) if penalty.id: data = { 'id' : penalty.id } else: data = {} if penalty.keyword and not re.match(r'^[a-z0-9]$', penalty.keyword, re.I): penalty.keyword = '' for f in fields: if hasattr(penalty, self.getVar(f)): data[f] = getattr(penalty, self.getVar(f)) self.console.debug('Storage: setClientPenalty data %s' % data) if penalty.id: self.query(QueryBuilder(self.db).UpdateQuery(data, 'penalties', { 'id' : penalty.id })) else: cursor = self.query(QueryBuilder(self.db).InsertQuery(data, 'penalties')) if cursor: penalty.id = cursor.lastrowid else: penalty.id = None return penalty.id
def getLastPenalties(self, types='Ban', num=5): where = QueryBuilder(self.db).WhereClause( { 'type' : types, 'inactive' : 0 } ) where += ' and (time_expire = -1 or time_expire > %s)' % int(time.time()) cursor = self.query(QueryBuilder(self.db).SelectQuery(fields='*', table='penalties', where=where, orderby='time_add DESC, id DESC', limit=num)) if not cursor: return [] penalties = [] while not cursor.EOF and len(penalties) < num: penalties.append(self._createPenaltyFromRow(cursor.getRow())) cursor.moveNext() cursor.close() return penalties
def getClient(self, client): self.console.debug('Storage: getClient %s' % client) if client.id > 0: cursor = self.query( QueryBuilder(self.db).SelectQuery('*', 'clients', {'id': client.id}, None, 1)) else: cursor = self.query( QueryBuilder(self.db).SelectQuery('*', 'clients', {'guid': client.guid}, None, 1)) if not cursor: # connection failed, try local cache if self.console.config.has_option('admins_cache', client.guid): data = self.console.config.get('admins_cache', client.guid, True) self.console.debug('Pulling user form admins_cache %s' % data) id, name, level = data.split(',') client.id = id.strip() client.name = name.strip() client._tempLevel = int(level.strip()) return client else: raise KeyError, 'No client matching guid %s in admins_cache' % client.guid if not cursor.rowcount: cursor.close() raise KeyError, 'No client matching guid %s' % client.guid found = False for k, v in cursor.getRow().iteritems(): """ if hasattr(client, k) and getattr(client, k): # don't set already set items continue """ setattr(client, self.getVar(k), v) found = True cursor.close() if found: return client else: raise KeyError, 'No client matching guid %s' % client.guid
def getClientAliases(self, client): """ Return the aliases of the given client :param client: The client whose aliases we want to retrieve. :return: List of b3.clients.Alias instances. """ self.console.debug('Storage: getClientAliases %s' % client) cursor = self.query( QueryBuilder(self.db).SelectQuery('*', 'aliases', {'client_id': client.id}, 'id')) aliases = [] while not cursor.EOF: g = cursor.getRow() alias = b3.clients.Alias() alias.id = int(g['id']) alias.alias = g['alias'] alias.timeAdd = int(g['time_add']) alias.timeEdit = int(g['time_edit']) alias.clientId = int(g['client_id']) alias.numUsed = int(g['num_used']) aliases.append(alias) cursor.moveNext() cursor.close() return aliases
def numPenalties(self, client, type='Ban'): """ Return the amount of penalties the given client has according to the given type. :param client: The client whose number of penalties we are interested into. :param type: The penalties type. :return The number of penalties. """ # where = QueryBuilder(self.db).WhereClause({'type': type, 'client_id': client.id, 'inactive': 0}) # where += ' AND (time_expire = -1 OR time_expire > %s)' % int(time()) # cursor = self.query("""SELECT COUNT(id) total FROM penalties WHERE %s""" % where) # DK: testing get client penalties by IP self.console.debug('Storage: getClientPenalties %s' % client) where = QueryBuilder(self.db).WhereClause({ 'type': type, 'inactive': 0 }) where += ' AND (time_expire = -1 OR time_expire > %s)' % int(time()) where += ' AND client_id IN (SELECT id FROM clients WHERE ip = "%s")' % client.ip cursor = self.query( """SELECT COUNT(id) total FROM penalties WHERE %s""" % where) value = int(cursor.getValue('total', 0)) cursor.close() return value
def getClientIpAddresses(self, client): """ Return the ip aliases of the given client. :param client: The client whose ip aliases we want to retrieve. :return: List of b3.clients.IpAlias instances """ self.console.debug('Storage: getClientIpAddresses %s' % client) cursor = self.query( QueryBuilder(self.db).SelectQuery('*', 'ipaliases', {'client_id': client.id}, 'id')) aliases = [] while not cursor.EOF: row = cursor.getRow() ip = b3.clients.IpAlias() ip.id = int(row['id']) ip.ip = row['ip'] ip.timeAdd = int(row['time_add']) ip.timeEdit = int(row['time_edit']) ip.clientId = int(row['client_id']) ip.numUsed = int(row['num_used']) aliases.append(ip) cursor.moveNext() cursor.close() return aliases
def getClientAliases(self, client): self.console.debug('Storage: getClientAliases %s' % client) cursor = self.query( QueryBuilder(self.db).SelectQuery('*', 'aliases', {'client_id': client.id}, 'num_used DESC')) if not cursor: return () aliases = [] while not cursor.EOF: g = cursor.getRow() alias = b3.clients.Alias() alias.id = int(g['id']) alias.alias = g['alias'] alias.timeAdd = int(g['time_add']) alias.timeEdit = int(g['time_edit']) alias.clientId = int(g['client_id']) alias.numUsed = int(g['num_used']) aliases.append(alias) cursor.moveNext() cursor.close() return aliases
def disableClientPenalties(self, client, type='Ban'): self.query( QueryBuilder(self.db).UpdateQuery({'inactive': 1}, 'penalties', { 'type': type, 'client_id': client.id, 'inactive': 0 }))
def load_command_grants(self, client): """ Load client command grants from the storage. :param client: The client whose command grants needs to be loaded """ self.debug('checking command grants for %s [@%s]...', client.name, client.id) try: query = QueryBuilder(self.console.storage.db).SelectQuery( ('id', 'commands'), 'cmdgrants', {'id': client.id}) cursor = self.console.storage.query(query) if cursor.EOF: self.debug('no command grant found for %s [@%s]', client.name, client.id) return row = cursor.getOneRow() # this is to prevent to have empty strings in our set: may happen when we remove all # the command grants from a client and the storage layer will save an empty string grantlist = set( [x for x in row['commands'].split(GRANT_SET_JOIN) if x != '']) setattr(client, GRANT_SET_ATTR, grantlist) self.debug( 'retrieved command grants for %s [@%s] from the storage: %r', client.name, client.id, grantlist) except Exception, e: self.error('could not retrieve command grants for %s [@%s] : %s', client.name, client.id, e)
def getGroups(self): if not self._groups: cursor = self.query( QueryBuilder(self.db).SelectQuery('*', 'groups', None, 'level')) if not cursor: return [] self._groups = [] while not cursor.EOF: g = cursor.getRow() G = b3.clients.Group() G.id = int(g['id']) G.name = g['name'] G.keyword = g['keyword'] G.level = int(g['level']) G.timeAdd = int(g['time_add']) G.timeEdit = int(g['time_edit']) self._groups.append(G) cursor.moveNext() cursor.close() return self._groups