summaryrefslogtreecommitdiffstats
path: root/py-bin/ejabberdctl.py
blob: a1ef5ffd3013c6d93735e62078d3c4311e4cb755 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#ejabberdctl 

import subprocess, logging
import config

#x remove
#def __run(path, params, env):
#	params = [path] + params
#	try:
#		result = os.spawnve(os.P_WAIT, path, params, env)
#		return (result == 0)
#	except Exception:
#		return False

class EJabberdCtl:
	def create_account(self, user, server, password):
		if self.__ejabberdctl(["register", user, server, password]):
			logging.info("Created account %s@%s." % (user, server))
			return True
		return False
	
	def remove_account(self, user, server):
		if self.__ejabberdctl(["unregister", user, server]):
			logging.info("Removed account %s@%s." % (user, server))
			return True
		return False
		
	def change_password(self, user, server, password):
		if self.__ejabberdctl(["set-password", user, server, password]):
			logging.info("Changed Password for %s@%s." % (user, server))
			return True
		return False
	
	def __ejabberdctl(self, params):
		return self.__run([config.ejabberdctl_path] + params, config.ejabberdctl_environ)
	
	def __run(self, path_and_params, environ={}):
		try:
			result = subprocess.call(path_and_params, env=environ)
			if result != 0:
				logging.error("Error invoking '%s': Result = %s." % 
					(str(path_and_params), str(result)))
			return (result == 0)
		except Exception, e:
			logging.error("Error invoking '%s': %s." % (str(path_and_params), str(e)))
			return False