From: Adam Chlipala Date: Tue, 24 Mar 2009 15:22:41 +0000 (+0000) Subject: Passgen script (normal user part) X-Git-Url: http://git.hcoop.net/bpt/portal.git/commitdiff_plain/b12b08243ae88e42cca3c5062c018b7517ef308f Passgen script (normal user part) --- diff --git a/passgen/.cvsignore b/passgen/.cvsignore new file mode 100644 index 0000000..635b5dc --- /dev/null +++ b/passgen/.cvsignore @@ -0,0 +1,2 @@ +.cm +passgen.mlt diff --git a/passgen/Makefile b/passgen/Makefile new file mode 100644 index 0000000..59ce744 --- /dev/null +++ b/passgen/Makefile @@ -0,0 +1,4 @@ +all: passgen.mlt + +passgen.mlt: /etc/hcoop.header /etc/hcoop.footer passgen.mlt.in + hcoop_html "HCoop Passgen" passgen.mlt.in >passgen.mlt diff --git a/passgen/after.mlt b/passgen/after.mlt new file mode 100644 index 0000000..ec09e9e --- /dev/null +++ b/passgen/after.mlt @@ -0,0 +1 @@ +<% PassGen.commit () %> diff --git a/passgen/before.mlt b/passgen/before.mlt new file mode 100644 index 0000000..18e4637 --- /dev/null +++ b/passgen/before.mlt @@ -0,0 +1 @@ +<% PassGen.begin () %> diff --git a/passgen/config.sig b/passgen/config.sig new file mode 100644 index 0000000..b61e7c6 --- /dev/null +++ b/passgen/config.sig @@ -0,0 +1,3 @@ +signature CONFIG = sig + val dbstring : string +end diff --git a/passgen/config.sml b/passgen/config.sml new file mode 100644 index 0000000..185526b --- /dev/null +++ b/passgen/config.sml @@ -0,0 +1,5 @@ +structure Config :> CONFIG = struct + +val dbstring = "dbname=passgen" + +end diff --git a/passgen/exn.mlt b/passgen/exn.mlt new file mode 100644 index 0000000..8c13844 --- /dev/null +++ b/passgen/exn.mlt @@ -0,0 +1,28 @@ + +Hcoop Passgen: Exception + + +

Exception

+ +<% switch Web.getExn () of + Fail msg => %> +Fail: <% Web.htmlNl msg %> +<% | OS.SysErr (name, NONE) => %> +System error: <% Web.html name %> +<% | OS.SysErr (name, SOME syserr) => %> +System error: <% Web.html name %>: <% Web.html (OS.errorName syserr) %>: <% Web.htmlNl (OS.errorMsg syserr) %> +<% | IO.Io {name, function, ...} => %> +IO error: <% Web.html name %> for <% Web.html function %>
+<% | PassGen.C.Sql msg => %> +SQL: <% Web.htmlNl msg %> +<% | Web.Format s => %> +Format: <% Web.htmlNl s %> + +<% | ex => %> +Unknown exception kind. Backtrace: +<% foreach s in SMLofNJ.exnHistory ex do %> +
  • <% Web.html s %>
  • +<% end +end %> + + diff --git a/passgen/mlt.conf b/passgen/mlt.conf new file mode 100644 index 0000000..778f75d --- /dev/null +++ b/passgen/mlt.conf @@ -0,0 +1,9 @@ +before before +after after +exn exn + +out out +pub /afs/hcoop.net/user/h/hc/hcoop/public_html/cgi-bin + +cm /usr/local/share/smlsql/smlsql.cm +cm /usr/local/share/smlsql/libpq/sources.cm diff --git a/passgen/out/.cvsignore b/passgen/out/.cvsignore new file mode 100644 index 0000000..72e8ffc --- /dev/null +++ b/passgen/out/.cvsignore @@ -0,0 +1 @@ +* diff --git a/passgen/passgen.mlt.in b/passgen/passgen.mlt.in new file mode 100644 index 0000000..c946638 --- /dev/null +++ b/passgen/passgen.mlt.in @@ -0,0 +1,6 @@ +<% val (id, pass) = PassGen.gen () %> + + + + +
    ID: <% id %>
    Password: <% pass %>
    diff --git a/passgen/passgen.sig b/passgen/passgen.sig new file mode 100644 index 0000000..80ce6af --- /dev/null +++ b/passgen/passgen.sig @@ -0,0 +1,8 @@ +signature PASSGEN = sig + structure C : SQL_CLIENT + + val begin : unit -> unit + val commit : unit -> unit + + val gen : unit -> int * string +end diff --git a/passgen/passgen.sml b/passgen/passgen.sml new file mode 100644 index 0000000..4de2583 --- /dev/null +++ b/passgen/passgen.sml @@ -0,0 +1,45 @@ +structure PassGen :> PASSGEN = struct + +open Config Sql +structure C = PgClient + +val db = ref (NONE : C.conn option) +fun getDb () = valOf (!db) + +fun begin () = + let + val c = C.conn dbstring + in + db := SOME c; + ignore (C.dml c "BEGIN") + end + +fun commit () = + let + val db = getDb () + in + C.dml db "COMMIT"; + C.close db + end + +fun gen () = + let + val db = getDb () + + val id = case C.oneRow db "SELECT nextval('PassSeq')" of + [id] => C.intFromSql id + | _ => raise Fail "Bad nextval() return" + + val proc = Unix.execute ("/usr/bin/apg", ["/usr/bin/apg", "-d", "-n", "1"]) + val inf = Unix.textInstreamOf proc + + val pass = case TextIO.inputLine inf of + NONE => raise Fail "No apg output" + | SOME line => String.substring (line, 0, size line - 1) + in + ignore (Unix.reap proc); + ignore (C.dml db ($`INSERT INTO Pass (id, pass) VALUES (^(C.intToSql id), ^(C.stringToSql pass))`)); + (id, pass) + end + +end diff --git a/passgen/tables.sql b/passgen/tables.sql new file mode 100644 index 0000000..2333bf7 --- /dev/null +++ b/passgen/tables.sql @@ -0,0 +1,5 @@ +CREATE SEQUENCE PassSeq; + +CREATE TABLE Pass( + id INTEGER PRIMARY KEY, + pass TEXT NOT NULL);