mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 23:02:19 +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):
|
def disable_user(self, uid):
|
||||||
""" Disable a user """
|
""" Disable a user """
|
||||||
if self.method == "xmpp":
|
if self.method == "xmpp":
|
||||||
return False
|
return self.jabberadmin.disableuser(uid)
|
||||||
else:
|
else:
|
||||||
username, server = uid.split("@")
|
username, server = uid.split("@")
|
||||||
return self.ejctl.ban_user(server, username)
|
return self.ejctl.ban_user(server, username)
|
||||||
@@ -57,7 +57,7 @@ class JabberService(BaseService):
|
|||||||
def enable_user(self, uid, password):
|
def enable_user(self, uid, password):
|
||||||
""" Enable a user """
|
""" Enable a user """
|
||||||
if self.method == "xmpp":
|
if self.method == "xmpp":
|
||||||
return False
|
return True
|
||||||
else:
|
else:
|
||||||
username, server = uid.split("@")
|
username, server = uid.split("@")
|
||||||
return self.ejctl.enable_user(server, username, password)
|
return self.ejctl.enable_user(server, username, password)
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
import time
|
import time
|
||||||
import xmpp
|
import xmpp
|
||||||
|
import random
|
||||||
|
import hashlib
|
||||||
|
import settings
|
||||||
|
|
||||||
class JabberAdmin():
|
class JabberAdmin():
|
||||||
""" Adds a jabber user to a remote Jabber server """
|
""" Adds a jabber user to a remote Jabber server """
|
||||||
@@ -119,6 +122,36 @@ class JabberAdmin():
|
|||||||
return False
|
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):
|
def checkuser(self, username):
|
||||||
try:
|
try:
|
||||||
self.connect()
|
self.connect()
|
||||||
|
|||||||
Reference in New Issue
Block a user