[Da-tools-commits] ./da-tools/userdir-ldap-cgi-python r21: added ssh fingerprint to machine template

Robin Wittler real at geek-at-work.org
Wed Feb 4 13:45:10 UTC 2009


------------------------------------------------------------
revno: 21
committer: Robin Wittler <real at geek-at-work.org>
branch nick: userdir-ldap-cgi-python
timestamp: Wed 2009-02-04 14:45:10 +0100
message:
  added ssh fingerprint to machine template
modified:
  ud_ldap_ng/lib/libformat.py
  ud_ldap_ng/templates/machine.html
-------------- next part --------------
=== modified file 'ud_ldap_ng/lib/libformat.py'
--- a/ud_ldap_ng/lib/libformat.py	2009-01-29 20:09:39 +0000
+++ b/ud_ldap_ng/lib/libformat.py	2009-02-04 13:45:10 +0000
@@ -6,10 +6,12 @@
 
 
 import re
+from md5 import md5
 
 compiled_regex_type = type(re.compile(''))
 re_debian_url_markup = re.compile('^(?:\[\[)(.*?)(?:\|(.*?))?(?:\]\])(.*?)$')
 re_email_regex = re.compile('^.*?@.*?\..*?$')
+re_two_char = re.compile('..')
 
 map_dict = {'*': lambda x: x.replace('*', '', 1),
 			'@': lambda x: x.replace('@', '', 1), 
@@ -103,5 +105,17 @@
 		txt = value(txt)
 	return txt
 
+def get_fingerprint(pubkey):
+	'''takes a ssh pubkey and returns the fingerprint.
+
+	@param pubkey              the pubkey
+	@type pubkey               str
+	@return                    str
+	'''
+	keytype, key, comment = pubkey.rstrip().split(' ')
+	if keytype not in ('ssh-rsa', 'ssh-dss'):
+		raise TypeError('pubkey is not a valid ssh pubkey')
+	return ':'.join(re.findall(re_two_char, md5(key.decode('base64')).hexdigest()))
+
 if __name__ == '__main__':
 	pass

=== modified file 'ud_ldap_ng/templates/machine.html'
--- a/ud_ldap_ng/templates/machine.html	2009-01-30 08:58:34 +0000
+++ b/ud_ldap_ng/templates/machine.html	2009-02-04 13:45:10 +0000
@@ -43,8 +43,15 @@
 				</div>
 				-->
 				<div id="text">
-					<%! from ud_ldap_ng.lib.libformat import is_email_addr, is_markup_string, is_public, map_chars %>
+					<%! from ud_ldap_ng.lib.libformat import is_email_addr, is_markup_string, is_public, map_chars, get_fingerprint %>
 					<% host = c.result.next() %>
+					<% 
+						try:
+							hostkey = get_fingerprint(host.get('sshRSAHostKey', ['',])[0])
+						except:
+							hostkey = ''
+						host.setdefault('ssh hostkey fingerprint', [hostkey,])
+					%>
 					% for hostname in host.get('hostname', ['Unknown Hostname',]):
 					<h1>Information about ${hostname}</h1>
 					% endfor



More information about the Da-tools-commits mailing list