diff --git a/rlgwebd.js b/rlgwebd.js index 75071f2..d262616 100755 --- a/rlgwebd.js +++ b/rlgwebd.js @@ -1137,6 +1137,49 @@ function getuinfo(req, res) { } } +function setuinfo(req, res, postdata) { + var urlobj = url.parse(req.url, true); + var query = urlobj.query; + if (!("key" in query) || !(query["key"] in logins)) { + sendError(res, 1); + return; + } + var name = logins[query["key"]].name; + var match = urlobj.pathname.match(/^\/[^\/]*\/(.*)/); + if (!match || !match[1]) { + send404(res, urlobj.pathname, true); + return; + } + var which = match[1]; + if (!("v" in postdata)) { + sendError(res, 2, "No value provided"); + return; + } + if (which == "email" || which == "pw") { + var args; + if (which == "email") + args = ["setmail"]; + else + args = ["setpw"]; + var child = child_process.execFile("/bin/sqlickrypt", args, + function (err, stdout, stderr) { + if (err) { + tslog("Could not set %s: sqlickrypt error %d", which, err.code); + sendError(res, 2); + } + else { + tslog("User %s has changed %s", name, which); + res.writeHead(200, { "Content-Type": "application/json" }); + res.end(JSON.stringify({"t": "t"})); + } + }); + child.stdin.end(name + "\n" + postdata.v + "\n", "utf8"); + } + else { + send404(res, urlobj.pathname, true); + } +} + var errorcodes = [ "Generic Error", "Not logged in", "Invalid data", "Login failed", "Already playing", "Game launch failed", "Server shutting down", "Game not in progress" ]; @@ -1227,6 +1270,9 @@ function webHandler(req, res) { else if (target == "/quit") { stopgame(res, formdata); } + else if (target.match(/^\/uinfo\//)) { + setuinfo(req, res, formdata); + } else { res.writeHead(405, resheaders); res.end();