mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 06:42:16 +00:00
Enable disabling of users on Jabber via xmpp
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user