2016-12-17 08:06:40 +07:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
run: run
|
|
|
|
}
|
|
|
|
|
|
|
|
var routes = require('./routes');
|
|
|
|
|
|
|
|
var express = require('express');
|
|
|
|
var bodyParser = require('body-parser');
|
|
|
|
var speakeasy = require('speakeasy');
|
2016-12-18 01:36:41 +07:00
|
|
|
var path = require('path');
|
2017-01-21 23:41:06 +07:00
|
|
|
var session = require('express-session');
|
|
|
|
var winston = require('winston');
|
2016-12-17 08:06:40 +07:00
|
|
|
|
2017-01-21 23:41:06 +07:00
|
|
|
function run(config, ldap_client, u2f, fn) {
|
2016-12-18 01:36:41 +07:00
|
|
|
var view_directory = path.resolve(__dirname, '../views');
|
|
|
|
var public_html_directory = path.resolve(__dirname, '../public_html');
|
|
|
|
|
2016-12-17 08:06:40 +07:00
|
|
|
var app = express();
|
2016-12-18 01:36:41 +07:00
|
|
|
app.use(express.static(public_html_directory));
|
2016-12-17 08:06:40 +07:00
|
|
|
app.use(bodyParser.urlencoded({ extended: false }));
|
2017-01-21 23:41:06 +07:00
|
|
|
app.use(bodyParser.json());
|
|
|
|
app.set('trust proxy', 1); // trust first proxy
|
|
|
|
|
|
|
|
app.use(session({
|
|
|
|
secret: config.session_secret,
|
|
|
|
resave: false,
|
|
|
|
saveUninitialized: true,
|
|
|
|
cookie: {
|
|
|
|
secure: false,
|
|
|
|
maxAge: config.session_max_age
|
|
|
|
},
|
|
|
|
}));
|
2016-12-17 08:06:40 +07:00
|
|
|
|
2016-12-18 01:36:41 +07:00
|
|
|
app.set('views', view_directory);
|
2016-12-17 08:06:40 +07:00
|
|
|
app.set('view engine', 'ejs');
|
|
|
|
|
2017-01-21 23:41:06 +07:00
|
|
|
winston.level = 'debug';
|
|
|
|
|
|
|
|
app.set('logger', winston);
|
2016-12-17 08:06:40 +07:00
|
|
|
app.set('ldap client', ldap_client);
|
|
|
|
app.set('totp engine', speakeasy);
|
2017-01-21 23:41:06 +07:00
|
|
|
app.set('u2f', u2f);
|
2016-12-17 08:06:40 +07:00
|
|
|
app.set('config', config);
|
|
|
|
|
|
|
|
app.get ('/login', routes.login);
|
|
|
|
app.get ('/logout', routes.logout);
|
|
|
|
|
2017-01-21 23:41:06 +07:00
|
|
|
app.get ('/_verify', routes.verify);
|
|
|
|
|
|
|
|
app.post ('/_auth/1stfactor', routes.first_factor);
|
|
|
|
app.post ('/_auth/2ndfactor/totp', routes.second_factor.totp);
|
2017-01-19 07:01:37 +07:00
|
|
|
|
2017-01-21 23:41:06 +07:00
|
|
|
app.get ('/_auth/2ndfactor/u2f/register_request', routes.second_factor.u2f.register_request);
|
|
|
|
app.post ('/_auth/2ndfactor/u2f/register', routes.second_factor.u2f.register);
|
|
|
|
app.get ('/_auth/2ndfactor/u2f/sign_request', routes.second_factor.u2f.sign_request);
|
|
|
|
app.post ('/_auth/2ndfactor/u2f/sign', routes.second_factor.u2f.sign);
|
2016-12-17 08:06:40 +07:00
|
|
|
|
2017-01-21 23:41:06 +07:00
|
|
|
return app.listen(config.port, function(err) {
|
2016-12-17 08:06:40 +07:00
|
|
|
console.log('Listening on %d...', config.port);
|
2017-01-21 23:41:06 +07:00
|
|
|
if(fn) fn();
|
2016-12-17 08:06:40 +07:00
|
|
|
});
|
|
|
|
}
|