From 31e481f26c7c58fb4d7d299f95bc52d352dc75bf Mon Sep 17 00:00:00 2001 From: Sebastian Reichel Date: Sat, 9 Feb 2013 22:16:51 +0100 Subject: support import of PGP keys via web interface --- src/web.vala | 48 +++++++++++++++++++++++++++++++++++++++++ templates/users/import-pgp.html | 22 +++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 templates/users/import-pgp.html diff --git a/src/web.vala b/src/web.vala index ea2e594..98b899f 100644 --- a/src/web.vala +++ b/src/web.vala @@ -100,6 +100,53 @@ public class WebServer { } } + void handler_user_pgp_import(Soup.Server server, Soup.Message msg, string path, GLib.HashTable? query, Soup.ClientContext client) { + try { + var session = new WebSession(server, msg, path, query, client); + if(!session.superuser) { + handler_403(server, msg, path, query, client); + return; + } + + var t = new WebTemplate("users/import-pgp.html", session); + t.replace("TITLE", "KtT Shop System: PGP Key Import"); + t.menu_set_active("users"); + + Soup.Buffer filedata; + var postdata = Soup.Form.decode_multipart(msg, "file", null, null, out filedata); + + if(postdata == null || !postdata.contains("step")) { + t.replace("DATA", ""); + t.replace("STEP1", "block"); + t.replace("STEP2", "none"); + msg.set_response("text/html", Soup.MemoryUse.COPY, t.data); + return; + } else { + var keylist = pgp.import_archive(filedata.data); + string keylisttemplate; + + if(keylist.length > 0) { + keylisttemplate = "\n"; + } else { + keylisttemplate = "

No new keys!

"; + } + + t.replace("DATA", keylisttemplate); + t.replace("STEP1", "none"); + t.replace("STEP2", "block"); + msg.set_response("text/html", Soup.MemoryUse.COPY, t.data); + return; + } + } catch(TemplateError e) { + stderr.printf(e.message+"\n"); + handler_404(server, msg, path, query, client); + } + } + void handler_user_import(Soup.Server server, Soup.Message msg, string path, GLib.HashTable? query, Soup.ClientContext client) { try { var session = new WebSession(server, msg, path, query, client); @@ -773,6 +820,7 @@ public class WebServer { /* users */ srv.add_handler("/users", handler_users); srv.add_handler("/users/import", handler_user_import); + srv.add_handler("/users/import-pgp", handler_user_pgp_import); srv.run_async(); } diff --git a/templates/users/import-pgp.html b/templates/users/import-pgp.html new file mode 100644 index 0000000..57a5d64 --- /dev/null +++ b/templates/users/import-pgp.html @@ -0,0 +1,22 @@ +

Import PGP Keys

+ +
+
+
+ +
+ + +
+
+ + +
+
+ + +
+

The following keys have been found in the archive and imported into the keyring:

+ + {{{DATA}}} +
-- cgit v1.2.3