def handle_line(self): if self.socket: bytes = '' try: bytes = self.socket.recv(4096) except: pass if len(bytes) == 0: self.disconnect() self.buffer += bytes in_lines = self.buffer.split('\n') self.lines.extend([l + '\n' for l in in_lines[:-1]]) self.buffer = in_lines[-1] for line in self.lines: tmp_debug("IO", "%s => O: %s" % (self.uid, deprotect(line))) line = line.strip() # if locked, we are waiting for a result if not self.locked: if line.lower().startswith('action:'): self.action = \ Action(line[line.find(':') + 1:].strip()) elif line == '': if self.action: self.locked = bigtime() self.push(self.action) self.action = None else: if ':' in line: k = line.split(':')[0] v = line[line.find(':') + 1:].strip() if self.action: self.action.add_parameters({k: v}) self.lines = []
def burials(self): apocalypse = bigtime(-10) for peer in self.peers: if peer and peer.locked and peer.logged and peer.locked < apocalypse: peer.locked = 0 tmp_debug("SQUIRM", "Removing the very old lock of %s" % \ peer.uid)
def __init__(self, octopasty, channel, details): Thread.__init__(self) self.octopasty = octopasty self.socket = channel self.details = details self.action = None self.logged = False self.authtype = None self.multiple_servers = list() self.id = 'unknown_%d' % bigtime() self.locked = 0 self.wants_events = False self.binded_server = None self.keep_flow = False self.buffer = '' self.lines = list()
def auth_user(self, emiter, locked, username, secret, wants_events): login_sucessfull = False client = self.clients.get(emiter) if username in self.config.get('users'): hashed = self.config.get('users').get(username).get('password') if client.authtype is None: if sha1(secret).hexdigest() == hashed: login_sucessfull = True elif client.authtype[0] == 'md5': key = client.authtype[1] _md5 = md5(key) _md5.update(self.config.get('users').get(username).get('password')) if secret == _md5.hexdigest(): login_sucessfull = True if login_sucessfull: old_id = client.id client.id = '%s_%d' % (username, bigtime()) self.clients.pop(old_id) self.clients.update({client.id: client}) client.logged = True _servers = self.config.get('users').get(username).get('servers') _servers = [s.strip() for s in _servers.split(',')] if len(_servers) == 1: client.binded_server = _servers[0] else: client.multiple_servers = _servers client.wants_events = wants_events response = Success(parameters=dict( Message='Authentication accepted')) p = dict(emiter='__internal__', locked=locked, timestamp=time(), packet=response, dest=client.id) tmp_debug("AUTH", "'%s' logged successfully" % username) self.out_queue.put(Packet(p)) else: response = Error(parameters=dict(Message='Authentication failed')) p = dict(emiter='__internal__', locked=locked, timestamp=time(), packet=response, dest=client.id) client.send(Packet(p)) tmp_debug("AUTH", "'%s' failed to login" % username) client.disconnect()
def login(self): self.push(Login(self.user, self.password), emiter='__internal__', dest=self.server, locked=bigtime())