[jdev] Re: Public Jabber Server with telnet support
Julien PUYDT
julien.puydt at laposte.net
Wed Jan 5 04:56:05 CST 2005
Le mercredi 05 janvier 2005 à 09:37 +0100, Jacek Konieczny a écrit :
> On Tue, Jan 04, 2005 at 12:54:45PM -0700, Peter Saint-Andre wrote:
> > You need to type 'telnet jabber.org 5222'. I've used this since 1999 at
> > jabber.org and it still comes in handy, such as when I need to
> > administer a MUC room.
>
> Wow! Hardcore.
> I wonder if you would still use that with XMPP server (SASL
> authentication)... ;-)
I'm using a (very slightly) more civilized approach to debug my gossip
patches: a python script which does the authentification for me.
Snark
PS: the script, in case anyone is interested (improvements welcome):
#!/usr/bin/python
import socket
class VerboseSocket:
def __init__ (self, protocol, type):
self.socket = socket.socket (protocol, type)
def connect (self, host, port):
print 'connecting to %s on port %s' % (host, port)
self.socket.connect ((host, port))
def send (self, data, flags = 0):
print 'SEND:'
print data
self.socket.send (data, flags)
def recv (self, size, flags = 0):
data = self.socket.recv (size, flags)
print 'RECV:'
print data
return data
def fileno (self):
return self.socket.fileno ()
class JabberHelper:
def __init__ (self, name, passwd):
from sys import stdin
import select
s = self.get_ready_socket (name, passwd)
running = True
while running:
(r, w, x) = select.select ([stdin, s], [], [])
if s in r:
data = s.recv (1024)
pass # we don't care about the data: VerboseSocket!
if stdin in r:
s.send (stdin.readline ())
def get_ready_socket (self, name, passwd):
import sre, sha
s = VerboseSocket (socket.AF_INET, socket.SOCK_STREAM)
s.connect ('localhost', 5222)
s.send ("""<?xml version='1.0' encoding='UTF-8'?>""")
s.send ("""<stream:stream xmlns="jabber:client"
xmlns:stream="http://etherx.jabber.org/streams" to="localhost"
id="msg_1">""")
data = s.recv (1024)
match = sre.findall ("id='[0-9A-F]+'", data)[0]
id = match[4:-1]
s.send ("""<iq type="get" id="msg_2"> <query xmlns="jabber:iq:auth">
<username>%s</username></query></iq>""" % name)
s.recv (1024) # just eat the question about our password!
digest = sha.new (id+passwd).hexdigest ()
s.send ("""<iq type="set" id="msg_3"> <query xmlns="jabber:iq:auth">
<username>%s</username><digest>%
s</digest><resource>JabberHelper</resource></query></iq>""" % (name,
digest))
return s
if __name__ == '__main__':
program = JabberHelper ('snark', 'toto')
More information about the JDev
mailing list