# HG changeset patch # User John "Elwin" Edwards # Date 1345948411 25200 # Node ID 5ad15380f8511262136acda989dad31563138f63 # Parent fbeb0bf2b51dbadf6f31a0daf5b0d32fcafc613d Improve the /uinfo interface. Change the URL scheme to /uinfo/?key= because that makes more sense. diff -r fbeb0bf2b51d -r 5ad15380f851 rlgwebd.js --- a/rlgwebd.js Mon Aug 13 09:07:28 2012 -0700 +++ b/rlgwebd.js Sat Aug 25 19:33:31 2012 -0700 @@ -991,12 +991,7 @@ }); } else { - res.writeHead(404, resheaders); - if (req.method != 'HEAD') { - res.write("" + nname + "\n

" - + nname + " Not Found

\n"); - } - res.end(); + send404(res, nname, req.method == 'HEAD'); } }); return; @@ -1093,11 +1088,18 @@ } function getuinfo(req, res) { - var query = url.parse(req.url, true).query; + var urlobj = url.parse(req.url, true); + var query = urlobj.query; if (!("key" in query) || !(query["key"] in logins)) { sendError(res, 1); return; } + var match = urlobj.pathname.match(/^\/[^\/]*\/(.*)/); + if (!match || !match[1]) { + send404(res, urlobj.pathname, req.method == 'HEAD'); + return; + } + var which = match[1]; var name = logins[query["key"]].name; var reply = { "u": name }; function send() { @@ -1105,11 +1107,12 @@ res.write(JSON.stringify(reply)); res.end(); } - if ("pw" in query) { + if (which == "pw") { /* Don't actually divulge passwords. */ reply["pw"] = ""; + send(); } - if ("email" in query) { + else if (which == "email") { var address; function finish(code, signal) { if (code != 0) { @@ -1128,8 +1131,10 @@ subproc.on("exit", finish); subproc.stdin.end(name + '\n', "utf8"); } - else - send(); + else { + send404(res, urlobj.pathname, req.method == 'HEAD'); + return; + } } var errorcodes = [ "Generic Error", "Not logged in", "Invalid data", @@ -1152,6 +1157,15 @@ res.end(); } +function send404(res, path, nopage) { + res.writeHead(404, {"Content-Type": "text/html; charset=utf-8"}); + if (!nopage) { + res.write("" + path + "\n

" + + path + " Not Found

\n"); + } + res.end(); +} + function webHandler(req, res) { /* default headers for the response */ var resheaders = {'Content-Type': 'text/html'}; @@ -1231,7 +1245,7 @@ else if (target == '/status') { statusmsg(req, res); } - else if (target == '/uinfo') { + else if (target.match(/^\/uinfo\//)) { getuinfo(req, res); } else if (target.match(/^\/pstatus\//)) {