MAJOR: Updates for Authenticated Web UI and CLI #30

Open
coolaj86 wants to merge 77 commits from next into master
1 changed files with 80 additions and 53 deletions
Showing only changes of commit 26939a62cf - Show all commits

View File

@ -599,6 +599,7 @@ function handleApi(req, res) {
));
}
function route() {
if (/\b(config)\b/.test(opts.pathname) && /get/i.test(req.method)) {
getConfigOnly();
return;
@ -657,6 +658,32 @@ function handleApi(req, res) {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify({"error":{"message":"unrecognized rpc"}}));
}
if (!req.headers['content-length'] && !req.headers['content-type']) {
route();
return;
}
var body = '';
req.on('readable', function () {
var data;
while (true) {
data = req.read();
if (!data) { break; }
body += data.toString();
}
});
req.on('end', function () {
try {
opts.body = JSON.parse(body);
} catch(e) {
res.statusCode = 400;
res.end('{"error":{"message":"POST body is not valid json"}}');
return;
}
route();
});
}
function serveControlsHelper() {
controlServer = http.createServer(handleRemoteClient);