r107038 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107037‎ | r107038 | r107039 >
Date:03:08, 22 December 2011
Author:laner
Status:deferred
Tags:openstack 
Comment:
Send public ssh key fingerprint in instance creation email. Resolves bug 27308.
Modified paths:
  • /trunk/extensions/OpenStackManager/scripts/mail-instance-creator.py (modified) (history)

Diff [purge]

Index: trunk/extensions/OpenStackManager/scripts/mail-instance-creator.py
@@ -1,6 +1,6 @@
22 #!/usr/bin/python
33 import urllib
4 -import os
 4+import subprocess
55
66 from xml.dom import minidom
77 from optparse import OptionParser
@@ -24,17 +24,16 @@
2525 dom = minidom.parse(urllib.urlopen(subjecturl))
2626 subject = dom.getElementsByTagName('expandtemplates')[0].firstChild.data
2727 dom = minidom.parse(urllib.urlopen(bodyurl))
 28+ p = subprocess.Popen("ssh-keygen -lf /etc/ssh/ssh_host_rsa_key.pub", shell=True, stdout=subprocess.PIPE)
 29+ fingerprint = p.communicate()[0]
 30+ fingerprint = fingerprint.split(' ')[1]
2831 body = dom.getElementsByTagName('expandtemplates')[0].firstChild.data
29 - body = body + ' ' + gethostname()
30 - sendmail_location = "/usr/sbin/sendmail" # sendmail location
31 - p = os.popen("%s -t" % sendmail_location, "w")
32 - p.write("From: %s\n" % fromaddress)
33 - p.write("To: %s\n" % toaddress)
34 - p.write("Subject: %s\n" % subject)
35 - p.write("\n") # blank line separating headers from body
36 - p.write(body)
37 - status = p.close()
38 - return status
 32+ body = body + ' ' + gethostname() + ' (' + fingerprint + ')'
 33+ message = "From: %s\nTo: %s\nSubject: %s\n\n%s" % (fromaddress, toaddress, subject, body)
 34+ p = subprocess.Popen("/usr/sbin/sendmail -t", shell=True, stdin=subprocess.PIPE)
 35+ p.communicate(message)
 36+ if p.wait() != 0:
 37+ return 1
3938
4039 if __name__ == "__main__":
4140 main()

Status & tagging log