From 81e772545aae64f09a73359f2368b2e0369c837e Mon Sep 17 00:00:00 2001 From: "John \"Elwin\" Edwards" Date: Mon, 13 Aug 2012 09:07:28 -0700 Subject: [PATCH] Add a user information interface at /uinfo. User information can be retrieved at /uinfo?key=&. The only property currently retrievable is email; eventually these will also be settable via POST. --- rlgwebd.js | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/rlgwebd.js b/rlgwebd.js index ac952f2..c6b1439 100755 --- a/rlgwebd.js +++ b/rlgwebd.js @@ -1092,6 +1092,46 @@ function pstatusmsg(req, res) { }); } +function getuinfo(req, res) { + var query = url.parse(req.url, true).query; + if (!("key" in query) || !(query["key"] in logins)) { + sendError(res, 1); + return; + } + var name = logins[query["key"]].name; + var reply = { "u": name }; + function send() { + res.writeHead(200, { "Content-Type": "application/json" }); + res.write(JSON.stringify(reply)); + res.end(); + } + if ("pw" in query) { + /* Don't actually divulge passwords. */ + reply["pw"] = ""; + } + if ("email" in query) { + var address; + function finish(code, signal) { + if (code != 0) { + tslog("sqlickrypt: %d with name %s", code, name); + sendError(res, 2); + } + else { + reply["email"] = address; + send(); + } + } + var subproc = child_process.spawn("/bin/sqlickrypt", ["getmail"]); + subproc.stdout.on("data", function (data) { + address = data.toString().replace(/\n/g, ""); + }); + subproc.on("exit", finish); + subproc.stdin.end(name + '\n', "utf8"); + } + else + send(); +} + var errorcodes = [ "Generic Error", "Not logged in", "Invalid data", "Login failed", "Already playing", "Game launch failed", "Server shutting down", "Game not in progress" ]; @@ -1112,7 +1152,6 @@ function sendError(res, ecode, msg, box) { res.end(); } -// TODO new-objects done to here function webHandler(req, res) { /* default headers for the response */ var resheaders = {'Content-Type': 'text/html'}; @@ -1192,6 +1231,9 @@ function webHandler(req, res) { else if (target == '/status') { statusmsg(req, res); } + else if (target == '/uinfo') { + getuinfo(req, res); + } else if (target.match(/^\/pstatus\//)) { pstatusmsg(req, res); }