summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--web/main.js52
-rw-r--r--web/package.json3
2 files changed, 53 insertions, 2 deletions
diff --git a/web/main.js b/web/main.js
index 616b11e..81897cf 100644
--- a/web/main.js
+++ b/web/main.js
@@ -24,7 +24,8 @@ var engine = require('engine.io'), // web sockets communication handler, sitting
log4js = require('log4js'), // the logger
url = require('url'), // URL parser
express = require('express'), // library providing the Express web framework
- http_app = express(); // web framework engine, sitting on the low-level HTTP handler
+ http_app = express(), // web framework engine, sitting on the low-level HTTP handler
+ bodyParser = require('body-parser');
var SAML_SERVICE_URL = process.env.CODEQ_SAML_SERVICE_URL || 'https://codeq.si/saml/';
@@ -94,9 +95,33 @@ http_server.on('upgrade', function (request, socket, head) {
});
// ================================================================================
+// Misc
+// ================================================================================
+
+var doubleDigit = function (d) {
+ var s = '' + d;
+ if (s.length < 2) return '0' + s;
+ return s;
+};
+
+var tripleDigit = function (d) {
+ var s = '' + d;
+ while (s.length < 3) s = '0' + s;
+ return s;
+};
+
+var formatTimestamp = function (t) {
+ var d = new Date(t);
+ return '' + d.getFullYear() + '-' + doubleDigit(d.getMonth()+1) + '-' + doubleDigit(d.getDate()) + ' ' +
+ doubleDigit(d.getHours()) + ':' + doubleDigit(d.getMinutes()) + ':' + doubleDigit(d.getSeconds()) + '.' + tripleDigit(d.getMilliseconds());
+};
+
+// ================================================================================
// Express web framework, handle any AJAX here
// ================================================================================
+http_app.use(bodyParser.json());
+
http_app.get('/ws/logout', function (req, res) {
var sid = req.query.sid,
session = sessions[sid];
@@ -114,6 +139,31 @@ http_app.get('/ws/logout', function (req, res) {
res.send('OK');
});
+http_app.post('/ws/clientlog', function (req, res) {
+ var b = req.body,
+ logs, i, l, line, output, f;
+ if (!b) {
+ logger.error('Empty clientlog request.');
+ return;
+ }
+ logs = b.logs;
+ if (!logs) {
+ logger.error('Empty logs in a clientlogs request.');
+ return;
+ }
+ output = ['Client logs from ', req.ip];
+ f = req.headers['x-forwarded-for'];
+ if (f) output.push(', forwarded for ', f);
+ output.push(':');
+ for (i = 0; i < logs.length; i++) {
+ l = logs[i];
+ output.push('\n [', formatTimestamp(l.t), '] [', l.l, '] ', l.m);
+ }
+ logger.info(output.join(''));
+ res.set('Content-Type', 'text/plain');
+ res.send('OK');
+});
+
var performSamlAction = function (samlAction, params) {
return new Promise(function (resolve, reject) {
diff --git a/web/package.json b/web/package.json
index b8a4872..c0150a0 100644
--- a/web/package.json
+++ b/web/package.json
@@ -5,6 +5,7 @@
"engine.io": "1.5.x",
"bluebird": "2.9.x",
"log4js": "0.6.x",
- "express": "4.13.x"
+ "express": "4.13.x",
+ "body-parser": "1.14.x"
}
} \ No newline at end of file