Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an ejabberd python library?

Is there an ejabberd python library wherein I can register user to ejabberd from python programmatically?

Right now I'm executing "ejabberdctl register" command using the python commands module.

like image 671
Marconi Avatar asked Feb 28 '11 11:02

Marconi


2 Answers

XMPP XEP-0077

If you have activated mod_register for In-Band registration on your Ejabberd server, then, as pointed out by @Drake, you can use an XMPP library to register users.

In Python, I would recommend Sleek XMPP. The Getting started examples are, well, a good starting point.

HTTP

If you have activated mod_register_web then you can send a HTTP POST request to http://<SERVERNAME>:5280/admin/server/<VIRTUALHOSTNAME>/users/. This URL expects the following 3 parameters:

  • newusername
  • newuserpassword
  • addnewuser

where the expected value for the addnewuser param seems to be the string "Add User".

Assuming you have an ejabberd admin user called user and with password password, using the requests HTTP library for Python, you could do something like the following:

import requests
from requests.auth import HTTPBasicAuth

server = "NAME OF YOUR EJABBERD SERVER"
virtualhost = "NAME OF YOUR EJABBERD HOST"
url = "http://%s:5280/admin/server/%s/user/" % (server, virtualhost)
auth = HTTPBasicAuth("user", "password")
data = {
    'newusername': "new_user",
    'newuserpassword': "new_password",
    'addnewuser': "Add User"
}
resp = requests.post(url, data=data, auth=auth)


assert resp.status_code == 200
like image 141
Rodrigue Avatar answered Oct 10 '22 10:10

Rodrigue


ejabberd is a Jabber/XMPP instant messaging server. That means you can make use of any XMPP module, like xmppy.

Also, check this thread: Which is the most mature Python XMPP library for a GChat client?.

like image 28
Drake Guan Avatar answered Oct 10 '22 11:10

Drake Guan