[sysadmin-bin] Add a prosody's python script for automatically creating new users and mailing the account details a
- From: Andrea Veri <av src gnome org>
- To: gnome-sysadmin gnome org,commits-list gnome org
- Subject: [sysadmin-bin] Add a prosody's python script for automatically creating new users and mailing the account details a
- Date: Sat, 31 Aug 2013 15:22:30 +0000 (UTC)
commit 4c9af33dce754720bebe2c27dd89f4b3b24b9474
Author: Andrea Veri <av gnome org>
Date: Sat Aug 31 17:21:29 2013 +0200
Add a prosody's python script for automatically creating new users and mailing the account details
accordingly.
prosody.py | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 55 insertions(+), 0 deletions(-)
---
diff --git a/prosody.py b/prosody.py
new file mode 100755
index 0000000..cb1177c
--- /dev/null
+++ b/prosody.py
@@ -0,0 +1,55 @@
+#!/usr/bin/python
+# Author: Andrea Veri <av gnome org>
+# Target host: chooser.gnome.org
+# Description: script to automatize new Prosody user creation at jabber.gnome.org. Usage as
+# follows: 'python prosody.py username email'. Example: 'python prosody.py av av gnome org'.
+# TODO: Add some exception handling in the case the prosody daemon isn't running or accepting
+# new user's creation.
+
+import random
+import string
+import pexpect
+from email.mime.text import MIMEText
+import smtplib
+import sys
+
+def create_prosody_account():
+
+ username = sys.argv[1]
+ email = sys.argv[2]
+
+ s = string.lowercase+string.digits
+ random_password = ''.join(random.sample(s, 10))
+
+ child = pexpect.spawn ('prosodyctl adduser %s jabber gnome org' % (username))
+ child.expect ('Enter new password: ')
+ child.sendline ('%s' % random_password)
+ child.expect ('Retype new password: ')
+ child.sendline ('%s' % random_password)
+
+ message = """
+Hi,
+
+as requested, your Jabber account at GNOME.org has been created, the details:
+
+User: %s jabber gnome org
+Password: %s
+
+Please update the password as soon as you can by using the Gajim
+client. Unfortunately this feature is not yet available on Empathy. See
+https://bugzilla.gnome.org/show_bug.cgi?id=576999 for more details. """ % (username, random_password)
+
+ try:
+ msg = MIMEText(message)
+ msg['Subject'] = "Your Jabber account at GNOME.org"
+ msg['From'] = "accounts gnome org"
+ msg['To'] = "%s" % (email)
+ server = smtplib.SMTP("localhost")
+ server.sendmail (msg['From'], msg['To'], msg.as_string())
+ server.quit ()
+ print "Successfully sent email to %s" % (email)
+ except smtplib.SMTPException:
+ print "ERROR: I wasn't able to send the email correctly, please check /var/log/maillog!"
+
+
+create_prosody_account()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]