]> git.ipfire.org Git - ipfire.org.git/commitdiff
people: Allow downloading SSH keys
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 17 Oct 2018 15:11:02 +0000 (16:11 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 17 Oct 2018 15:12:45 +0000 (16:12 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/backend/accounts.py
src/web/__init__.py
src/web/people.py

index 9f29da82a1ba3de4a3979f02465adb90c1076456..361f29b7874bb6fdfd32574ee5f6afa6cd6b2d21 100644 (file)
@@ -590,6 +590,14 @@ class Account(Object):
 
                return ret
 
+       def get_ssh_key_by_hash_md5(self, hash_md5):
+               for key in self.ssh_keys:
+                       if not key.hash_md5() == hash_md5:
+                               continue
+
+                       return key
+
+
 if __name__ == "__main__":
        a = Accounts()
 
index a25a1a00760a2831495c803882b65da4733073bc..f0099c19d3384ca970db84aa5ecaeb608ec4b6d9 100644 (file)
@@ -261,6 +261,7 @@ class Application(tornado.web.Application):
                        (r"/users/(\w+)/edit", people.UserEditHandler),
                        (r"/users/(\w+)/passwd", people.UserPasswdHandler),
                        (r"/users/(\w+)/ssh-keys", people.SSHKeysIndexHandler),
+                       (r"/users/(\w+)/ssh-keys/(MD5\:.*)", people.SSHKeysDownloadHandler),
                        (r"/users/(\w+)/sip", people.SIPHandler),
                ]  + authentication_handlers)
 
index 5cad8e2a81f575d7107712718e46692c1ea57107..d714cae3702a553438cc6dc37cb2e4178cc2f60a 100644 (file)
@@ -113,6 +113,24 @@ class SSHKeysIndexHandler(base.BaseHandler):
                self.render("people/ssh-keys/index.html", account=account)
 
 
+class SSHKeysDownloadHandler(base.BaseHandler):
+       @tornado.web.authenticated
+       def get(self, uid, hash_md5):
+               account = self.backend.accounts.get_by_uid(uid)
+               if not account:
+                       raise tornado.web.HTTPError(404, "Could not find account %s" % uid)
+
+               # Get SSH key
+               key = account.get_ssh_key_by_hash_md5(hash_md5)
+               if not key:
+                       raise tornado.web.HTTPError(404, "Could not find key: %s" % hash_md5)
+
+               # Set HTTP Headers
+               self.add_header("Content-Type", "text/plain")
+
+               self.finish(key.keydata)
+
+
 class SIPHandler(base.BaseHandler):
        @tornado.web.authenticated
        def get(self, uid):