summaryrefslogtreecommitdiffstats
path: root/py-bin/ejabberdctl.py
diff options
context:
space:
mode:
Diffstat (limited to 'py-bin/ejabberdctl.py')
-rw-r--r--py-bin/ejabberdctl.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/py-bin/ejabberdctl.py b/py-bin/ejabberdctl.py
new file mode 100644
index 0000000..a1ef5ff
--- /dev/null
+++ b/py-bin/ejabberdctl.py
@@ -0,0 +1,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
+