diff --git a/sso/services/jabber/__init__.py b/sso/services/jabber/__init__.py index 41f56f5..6b3314f 100644 --- a/sso/services/jabber/__init__.py +++ b/sso/services/jabber/__init__.py @@ -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) diff --git a/sso/services/jabber/xmppclient.py b/sso/services/jabber/xmppclient.py index 9828d10..fc4ffb9 100644 --- a/sso/services/jabber/xmppclient.py +++ b/sso/services/jabber/xmppclient.py @@ -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()