Improve the /uinfo interface.
Change the URL scheme to /uinfo/<property>?key=<key> because that makes more sense.
This commit is contained in:
parent
81e772545a
commit
48b5b5d32a
1 changed files with 26 additions and 12 deletions
38
rlgwebd.js
38
rlgwebd.js
|
|
@ -991,12 +991,7 @@ function serveStatic(req, res, fname) {
|
|||
});
|
||||
}
|
||||
else {
|
||||
res.writeHead(404, resheaders);
|
||||
if (req.method != 'HEAD') {
|
||||
res.write("<html><head><title>" + nname + "</title></head>\n<body><h1>"
|
||||
+ nname + " Not Found</h1></body></html>\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("<html><head><title>" + path + "</title></head>\n<body><h1>"
|
||||
+ path + " Not Found</h1></body></html>\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\//)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue