Enable disabling of users on Jabber via xmpp

This commit is contained in:
2010-03-24 11:08:02 +00:00
parent 423856a19a
commit 6220f1f07f
2 changed files with 35 additions and 2 deletions

View File

@@ -49,7 +49,7 @@ class JabberService(BaseService):
def disable_user(self, uid):
""" Disable a user """
if self.method == "xmpp":
return False
return self.jabberadmin.disableuser(uid)
else:
username, server = uid.split("@")
return self.ejctl.ban_user(server, username)
@@ -57,7 +57,7 @@ class JabberService(BaseService):
def enable_user(self, uid, password):
""" Enable a user """
if self.method == "xmpp":
return False
return True
else:
username, server = uid.split("@")
return self.ejctl.enable_user(server, username, password)

View File

@@ -1,5 +1,8 @@
import time
import xmpp
import random
import hashlib
import settings
class JabberAdmin():
""" Adds a jabber user to a remote Jabber server """
@@ -119,6 +122,36 @@ class JabberAdmin():
return False
def disableuser(self, username):
try:
self.connect()
except:
return False
pass = hashlib.sha1('%s%s%s' % (username, settings.SECRET_KEY, random.randint(0, 2147483647))).hexdigest()
self.resetpassword(username, pass)
self.kickuser(username)
def kickuser(self, username):
try:
self.connect()
except:
return False
# Send request and get the Session ID
resp = self._client.SendAndWaitForResponse(self._construct_iq_req('http://jabber.org/protocol/commands', 'http://jabber.org/protocol/admin#end-user-session'))
sessionid = resp.getTagAttr('command','sessionid')
values = [ ('hidden', 'FORM_TYPE', 'http://jabber.org/protocol/admin'),
('jid-single', 'accountjid', username) ]
iq = self._construct_form('http://jabber.org/protocol/commands', 'http://jabber.org/protocol/admin#end-user-session', sessionid, values)
# Send request and pray for the best
resp = self._client.SendAndWaitForResponse(iq)
return True
def checkuser(self, username):
try:
self.connect()