diff --git a/rlgwebd.js b/rlgwebd.js
index c6b1439..75071f2 100755
--- a/rlgwebd.js
+++ b/rlgwebd.js
@@ -991,12 +991,7 @@ function serveStatic(req, res, fname) {
});
}
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 pstatusmsg(req, res) {
}
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 @@ function getuinfo(req, res) {
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 @@ function getuinfo(req, res) {
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 @@ function sendError(res, ecode, msg, box) {
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 @@ function webHandler(req, res) {
else if (target == '/status') {
statusmsg(req, res);
}
- else if (target == '/uinfo') {
+ else if (target.match(/^\/uinfo\//)) {
getuinfo(req, res);
}
else if (target.match(/^\/pstatus\//)) {