-
Notifications
You must be signed in to change notification settings - Fork 66
/
app.js
85 lines (70 loc) · 2.7 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/**
* Hosts the latest kibana3 and elasticsearch behind Google OAuth2 Authentication
* with nodejs and express.
* License: MIT
* Copyright: Funplus Game Inc.
* Author: Fang Li.
* Project: https://github.com/fangli/kibana-authentication-proxy
*/
var express = require('express');
var https = require('https');
var http = require('http');
var fs = require('fs');
var config = require('./config');
var app = express();
console.log('Server starting...');
app.use(express.cookieParser());
app.use(express.session({ secret: config.cookie_secret }));
// Authentication
require('./lib/basic-auth').configureBasic(express, app, config);
require('./lib/google-oauth').configureOAuth(express, app, config);
require('./lib/cas-auth.js').configureCas(express, app, config);
// Setup ES proxy
require('./lib/es-proxy').configureESProxy(app, config.es_host, config.es_port,
config.es_username, config.es_password);
// Serve config.js for kibana3
// We should use special config.js for the frontend and point the ES to __es/
app.get('/config.js', kibana3configjs);
// Serve all kibana3 frontend files
app.use(express.compress());
app.use('/', express.static(__dirname + '/kibana/src', {maxAge: config.brower_cache_maxage || 0}));
run();
function run() {
if (config.enable_ssl_port === true) {
var options = {
key: fs.readFileSync(config.ssl_key_file),
cert: fs.readFileSync(config.ssl_cert_file),
};
https.createServer(options, app).listen(config.listen_port_ssl);
console.log('Server listening on ' + config.listen_port_ssl + '(SSL)');
}
http.createServer(app).listen(config.listen_port);
console.log('Server listening on ' + config.listen_port);
}
function kibana3configjs(req, res) {
function getKibanaIndex() {
var raw_index = config.kibana_es_index;
var user_type = config.which_auth_type_for_kibana_index;
var user;
if (raw_index.indexOf('%user%') > -1) {
if (user_type === 'google') {
user = req.googleOauth.id;
} else if (user_type === 'basic') {
user = req.user;
} else if (user_type === 'cas') {
user = req.session.cas_user_name;
} else {
user = 'unknown';
}
return raw_index.replace(/%user%/gi, user);
} else {
return raw_index;
}
}
res.setHeader('Content-Type', 'application/javascript');
res.end("define(['settings'], " +
"function (Settings) {'use strict'; return new Settings({elasticsearch: '/__es', default_route : '/dashboard/file/default.json'," +
"kibana_index: '" +
getKibanaIndex() +
"', panel_names: ['histogram', 'map', 'pie', 'table', 'filtering', 'timepicker', 'text', 'hits', 'column', 'trends', 'bettermap', 'query', 'terms', 'sparklines'] }); });");
}