summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/web.vala48
-rw-r--r--templates/users/import-pgp.html22
2 files changed, 70 insertions, 0 deletions
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<string,string>? 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 = "<ul>\n";
+ foreach(string s in keylist) {
+ keylisttemplate += "<li>"+s+"</li>\n";
+ }
+ keylisttemplate += "</ul>\n";
+ } else {
+ keylisttemplate = "<p><b>No new keys!</b></p>";
+ }
+
+ 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<string,string>? 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 @@
+<h2>Import PGP Keys</h2>
+
+<div style="display: {{{STEP1}}}">
+ <form action="#" method="POST" enctype="multipart/form-data" class="form-horizontal">
+ <div class="control-group">
+ <label class="control-label" for="file">Archive File (zip, tar.gz, ...) containing PGP keys</label>
+ <div class="controls">
+ <input type="file" accept="text/csv" name="file"></input>
+ <input type="hidden" name="step" value="1"></input>
+ </div>
+ </div>
+
+ <button class="btn btn-primary" type="submit">Import</button>
+ </form>
+</div>
+
+
+<div style="display: {{{STEP2}}}">
+ <p>The following keys have been found in the archive and imported into the keyring:</p>
+
+ {{{DATA}}}
+</div>