diff options
Diffstat (limited to 'omegle')
-rw-r--r-- | omegle/icq.py | 141 | ||||
-rw-r--r-- | omegle/icqBuddy.py | 194 |
2 files changed, 186 insertions, 149 deletions
diff --git a/omegle/icq.py b/omegle/icq.py new file mode 100644 index 0000000..e8ed739 --- /dev/null +++ b/omegle/icq.py @@ -0,0 +1,141 @@ +#!/usr/bin/python +# -*- vim: encoding: utf-8 -*- +# Yves Fischer, xapek.org 2009 +import struct + +from twisted.words.protocols import oscar +from twisted.internet import reactor, protocol +from twisted.internet.protocol import ClientFactory + +CAP_TYPING = '\x56\x3f\xc8\x09\x0b\x6f\x41\xbd\x9f\x79\x42\x26\x09\xdf\xa2\xf3' + +class ExtendedBOSConnection( oscar.BOSConnection ): + capabilities = [oscar.CAP_CHAT,CAP_TYPING] + + def __init__(self,s,p,**kwargs): + oscar.BOSConnection.__init__(self, s, p,**kwargs) + + """ + handles typing SNAC + """ + def oscar_04_14(self,snac): + data = snac[3] + if len(data) == len("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\t222840035\x00\x02"): + user = data[11:20] + state = data[20:22] + if state == "\x00\x00": #finish + self.receiveTyping(user, "finish") + elif state == "\x00\x01": #idle + self.receiveTyping(user, "idle") + elif state == "\x00\x02": #begin + self.receiveTyping(user, "begin") + else: + print "Unknown state in typing snac\nuser %s\ndata %s\nsnac %s\nstate %X%X" % (user,data,snac,state[0],sate[1]) + else: + print "komisches tpying snac" + + def receiveTyping(self, user, state): + pass + + def initDone( self ): + self.requestSelfInfo() + self.requestSSI().addCallback(self.gotBuddyList) + + def shutdown( self ): + pass + + def updateBuddy(self, user): + print "updateBuddy %s" % user + + def gotBuddyList( self, buddylist ): + self.activateSSI() + self.setProfile("Forget ICQ, MSN, Yahoo and the other shitty protocols! Use XMPP/Jabber!") + self.setIdleTime( 0 ) + self.clientReady() + for user in buddylist[0][0].users: + print "icq: Authorize %s" % user.name + self.sendAuthorizationResponse(user.name, True, '') + + """message - utf8 """ + def receiveCleanMessage( self, user, message, flags ): + raise NotImplementedError('receiveCleanMessage( self, user, message, flags )') + + def _getMessage(self,multiparts): + message = None + if len(multiparts[0]) == 2: + if multiparts[0][1] == "unicode": + message = unicode(multiparts[0][0]) + else: + message = multiparts[0][0].decode(multiparts[0][1],'latin1') + else: + message = str(multiparts[0][0]) + return message + + + def receiveMessage( self, user, multiparts, flags ): + print "icq: receiveMessage(%s,%s,%s)" % (user,multiparts,flags) + if flags != None and "auto" in flags: + print "'auto' message, abort" + return + + # because i cant receive the "budded added signal" i auth on every message + self.sendAuthorizationResponse(user.name, True, '') + + #cleanup message + try: + message = self._getMessage( multiparts ) + #filter qip \x00CHAR\x00CHAR - qip sucks at unicode? + message = filter(lambda x: x!=u"\x00", message) + + self.receiveCleanMessage( user, message, flags ) + except Exception,e: + print "Exception: %s" % e + + def chatReceiveMessage( self, chat, user, message ): + self.receiveMessage( self, user, message, [] ) + + def sendAuthorizationResponse(self, uin, success, responsString): + packet = struct.pack("b", len(uin)) + uin + if success: + packet += struct.pack("b", 1) + else: + packet += struct.pack("b", 0) + packet += struct.pack(">H", len(responsString)) + responsString + self.sendSNACnr(0x13, 0x1a, packet) + + def sendMessage(self, user, messageUtf8): + message = messageUtf8.encode('latin1','replace') + oscar.BOSConnection.sendMessage(self,user,message) + + def connectionLost(self,*args,**kwargs): + print "Connection lost" + oscar.BOSConnection.connectionLost(self,*args,**kwargs) + +class Authenticator( oscar.OscarAuthenticator ): + BOSClass = ExtendedBOSConnection + def connectionLost(self,reason): + oscar.OscarAuthenticator.connectionLost(self,reason) + self.factory.connectionLost(reason) + +class ReconnectOscarFactory(ClientFactory): + OAClass=Authenticator + def __init__(self, uid, password,icq=1): + self.uid = uid + self.password = password + self.icq = icq + + def buildProtocol(self, addr): + p = self.__class__.OAClass(self.uid, self.password,icq=self.icq) + p.factory = self + return p + + def startedConnecting(self, connector): + print 'Started to connect to oscar' + + def connectionLost(self,reason): + print "CONECTION LOST - start njew factory" + reactor.callLater(4.0, reactor.connectTCP, + 'login.icq.com', 5238, self) +# reactor.connectTCP('login.icq.com', 5238, OscarFactory(self.uin, self.password,icq=1)) + + diff --git a/omegle/icqBuddy.py b/omegle/icqBuddy.py index f162a7c..554a434 100644 --- a/omegle/icqBuddy.py +++ b/omegle/icqBuddy.py @@ -1,15 +1,14 @@ #!/usr/bin/python # -*- vim: encoding: utf-8 -*- -import struct +# Yves Fischer, xapek.org 2009 import sys -import thread from twisted.words.protocols import oscar -from twisted.internet import reactor, protocol -from twisted.internet.protocol import ClientFactory +from twisted.internet import reactor from twisted.python import log from omegle import OmegleChat +from icq import ExtendedBOSConnection, ReconnectOscarFactory, Authenticator ICQ_UIN = '446323989' ICQ_PASSWORD = 'gagaga' @@ -52,47 +51,9 @@ class OmegleICQChat(OmegleChat): print "Omegle->%s: (disconnected)" % self.user self.send_icqconn( "==Stranger Disconnected ==" ) -CAP_TYPING = '\x56\x3f\xc8\x09\x0b\x6f\x41\xbd\x9f\x79\x42\x26\x09\xdf\xa2\xf3' -# [4, 20, 0, 0, 2854066430L, '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\t222840035\x00\x02'] - -class OmegleICQ( oscar.BOSConnection ): - capabilities = [oscar.CAP_CHAT,CAP_TYPING] - - def __init__(self,s,p,**kwargs): - oscar.BOSConnection.__init__(self, s, p,**kwargs) - - """ - handles typing SNAC - """ - def oscar_04_14(self,snac): - data = snac[3] - if len(data) == len("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\t222840035\x00\x02"): - user = data[11:20] - state = data[20:22] - if not self.omegleConns.has_key(user): - self.omegleConns[user] = OmegleICQChat(self,user) - - if state == "\x00\x00": #finish - try: - self.omegleConns[user].stopped_typing() - except: - pass - elif state == "\x00\x01": #idle - pass - elif state == "\x00\x02": #begin - try: - self.omegleConns[user].typing() - except: - pass - else: - print "Unknown state in typing snac\nuser %s\ndata %s\nsnac %s\nstate %X%X" % (user,data,snac,state[0],sate[1]) - else: - print "komisches tpying snac" - +class ICQBuddy( ExtendedBOSConnection ): def initDone( self ): - self.requestSelfInfo() - self.requestSSI().addCallback(self.gotBuddyList) - + ExtendedBOSConnection.initDone( self ) self.omegleConns = {} def shutdown( self ): @@ -100,125 +61,60 @@ class OmegleICQ( oscar.BOSConnection ): if conn.is_connected: conn.disconnect() - def updateBuddy(self, user): - print "icq: Update buddy %s" % user - - def gotBuddyList( self, buddylist ): - self.activateSSI() - self.setProfile("Forget ICQ, MSN, Yahoo and the other shitty protocols! Use XMPP/Jabber!") - self.setIdleTime( 0 ) - self.clientReady() - for user in buddylist[0][0].users: - print "icq: Authorize %s" % user.name - self.sendAuthorizationResponse(user.name, True, '') - - def receiveMessage( self, user, multiparts, flags ): - print "icq: receiveMessage(%s,%s,%s)" % (user,multiparts,flags) - if "auto" in flags: - print "'auto' message, abort" - return - - # because i cant receive the "budded added signal" i auth on every message - self.sendAuthorizationResponse(user.name, True, '') + def receiveTyping(self, user, state): + try: + if state == "finish": + self.omegleConns[user].stopped_typing() + elif state == "idle": + pass + elif state == "begin": + self.omegleConns[user].typing() + except: + pass + def receiveCleanMessage( self, user, message, flags ): + print "receiveCleanMessage" if not self.omegleConns.has_key(user.name): self.omegleConns[user.name] = OmegleICQChat(self,user.name) - try: - message = None - if len(multiparts[0]) == 2: - if multiparts[0][1] == "unicode": - message = unicode(multiparts[0][0]) - else: - try: - message = multiparts[0][0].decode(multiparts[0][1]) - except Exception,e: - self.sendMessage(user.name,str(e)) + if not self.omegleConns[user.name].is_connected: + if u"%connect%" in message: + self.omegleConns[user.name].start() + self.sendMessage(user.name, "Please stand by.....") + if client_sucks: + self.sendMessage(user.name, "Hey, dein ICQ-Client sendet scheiss") else: - try: - message = multiparts[0][0].decode('latin1') - except Exception,e: - self.sendMessage(user.name,str(e)) - - #filter qip \x00CHAR\x00CHAR - qip sucks at unicode? - message_neu = filter(lambda x: x!=u"\x00", message) - if len(message_neu) != len(message): - client_sucks = True - message = message_neu - - if not self.omegleConns[user.name].is_connected: - if u"%connect%" in message: - self.omegleConns[user.name].start() - self.sendMessage(user.name, "Please stand by.....") - if client_sucks: - self.sendMessage(user.name, "Hey, dein ICQ-Client sendet scheiss") - else: - print "Not connected" + print "Not connected" # self.sendMessage(user.name, "Not connected, type >connect<") - elif self.omegleConns[user.name].is_connected and u"%disconnect%" in message: - try: - self.omegleConns[user.name].disconnect() - except Exception,e: - self.sendMessage(user.name, str(e)) - self.sendMessage(user.name, "Disconnecting") - elif self.omegleConns[user.name].is_connected and not self.omegleConns[user.name].is_confirmed: - self.sendMessage(user.name, "Wait for connection confirm from omegle") - else: - try: - print "%s->Omegle: %s" % (user.name, message.__repr__()) - self.omegleConns[user.name].send(message) - except Exception,e: - print "icq(%s): Error %s" % (user.name,e) - self.sendMessage(user.name,str(e)) - except Exception,e: - print "error: %s %s -> %s" % (user,multiparts,e) - - def chatReceiveMessage( self, chat, user, message ): - self.receiveMessage( self, user, message, 0 ) - - def sendAuthorizationResponse(self, uin, success, responsString): - packet = struct.pack("b", len(uin)) + uin - if success: - packet += struct.pack("b", 1) + elif self.omegleConns[user.name].is_connected and u"%disconnect%" in message: + try: + self.omegleConns[user.name].disconnect() + except Exception,e: + self.sendMessage(user.name, str(e)) + self.sendMessage(user.name, "Disconnecting") + elif self.omegleConns[user.name].is_connected and not self.omegleConns[user.name].is_confirmed: + self.sendMessage(user.name, "Wait for connection confirm from omegle") else: - packet += struct.pack("b", 0) - packet += struct.pack(">H", len(responsString)) + responsString - self.sendSNACnr(0x13, 0x1a, packet) - -class Authenticator( oscar.OscarAuthenticator ): - BOSClass = OmegleICQ - def connectionLost(self,reason): - oscar.OscarAuthenticator.connectionLost(self,reason) - self.factory.connectionLost(reason) - -class OscarFactory(ClientFactory): - OAClass=Authenticator - def __init__(self, uid, password,icq=1): - self.uid = uid - self.password = password - self.icq = icq - - def buildProtocol(self, addr): - p = OscarFactory.OAClass(self.uid, self.password,icq=self.icq) - p.factory = self - return p - - def startedConnecting(self, connector): - print 'Started to connect to oscar' - - def connectionLost(self,reason): - print "CONECTION LOST - start njew factory" - reactor.callLater(4.0, reactor.connectTCP, - 'login.icq.com', 5238, self) -# reactor.connectTCP('login.icq.com', 5238, OscarFactory(self.uin, self.password,icq=1)) + try: + print "%s->Omegle: %s" % (user.name, message.__repr__()) + self.omegleConns[user.name].send(message) + except Exception,e: + print "icq(%s): Error %s" % (user.name,e) + +class MyAuthenticator( Authenticator ): + BOSClass = ICQBuddy +class Factory( ReconnectOscarFactory ): + OAClass = MyAuthenticator if __name__ == '__main__': import logging logging.basicConfig(level=logging.INFO) log.startLogging(sys.stdout) + print Factory.OAClass + print MyAuthenticator.BOSClass reactor.connectTCP('login.icq.com', 5238, - OscarFactory(uin,password,icq=1)) + Factory(ICQ_UIN,ICQ_PASSWORD,icq=1)) reactor.run() |