Skip to content

Commit

Permalink
Fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
pratid committed May 22, 2015
2 parents 5f0f037 + 167d074 commit 8b19260
Show file tree
Hide file tree
Showing 54 changed files with 9,729 additions and 212 deletions.
4 changes: 2 additions & 2 deletions dashboard/Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ module.exports = function (grunt) {

exec: {
istanbul: {
cmd: 'bash -c "./node_modules/.bin/istanbul cover --root <%= dirs.lib[0] %>/ ' +
'--dir <%= dirs.reportCoverage[0] %> --include-all-sources -- ' +
cmd: 'bash -c "./node_modules/.bin/istanbul cover -x "<%= dirs.lib[0] %>/public" --root <%= dirs.lib[0] %>/ ' +
'--dir <%= dirs.reportCoverage[0] %> -- ' +
'\\"`npm root -g`/grunt-cli/bin/grunt\\" test >/dev/null && ' +
'mv <%= dirs.reportCoverage[0] %>/lcov-report <%= clean.lcovCoverage[0] %> && ' +
'./node_modules/.bin/istanbul report --dir <%= dirs.reportCoverage[0] %> text-summary"'
Expand Down
33 changes: 28 additions & 5 deletions dashboard/config/dashboard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,42 @@
logging:
level: DEBUG

#---------------------------------------------------------------------
# HTTP session section (mandatory)
#---------------------------------------------------------------------
session:
secret: 'sssshhh'

#---------------------------------------------------------------------
# Web server paths section (mandatory)
#---------------------------------------------------------------------
paths:
reports_url: '/check/report'
reports_files: '/var/www/html/RegionSanityCheck'

#---------------------------------------------------------------------
# Context Broker section (mandatory)
#---------------------------------------------------------------------
cbroker:
host: '127.0.0.1'
host: 'localhost'
port: 1026
path: '/NGSI10/queryContext'

#---------------------------------------------------------------------
# IdM OAuth2 section (mandatory)
#---------------------------------------------------------------------

idm:
clientId: ''
clientSecret: ''
url: ''
callbackURL: ''

#---------------------------------------------------------------------
# Web server paths section (mandatory)
# mailman-api section (mandatory)
#---------------------------------------------------------------------
paths:
reports_url: '/check/report'
reports_files: '/var/www/html/RegionSanityCheck'
mailman:
host: 'localhost'
port: 8000
path: '/'
email_from: ''
177 changes: 166 additions & 11 deletions dashboard/lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ var express = require('express'),
bodyParser = require('body-parser'),
index = require('./routes/index'),
refresh = require('./routes/refresh'),
subscribe = require('./routes/subscribe'),
unsubscribe = require('./routes/unsubscribe'),
cbroker = require('./routes/cbroker'),
common = require('./routes/common'),
config = require('./config'),
logger = require('./logger'),
dateFormat = require('dateformat'),
auth = require('http-auth');
OAuth2 = require('./oauth2').OAuth2;


var app = express();
Expand All @@ -56,11 +60,15 @@ app.set('view engine', 'jade');
//app.use(favicon(__dirname + '/public/favicon.ico'));

app.use(stylus.middleware(
{ src: __dirname + '/public', compile: compile
{
src: __dirname + '/stylus',
dest: __dirname + "/public/stylesheets",
compile: compile
}
));
))
;

app.use(session({secret: 'ssshhhhh', title_timestamp: ''}));
app.use(session({secret: config.secret}));

// trace all requests
app.use(function (req, res, next) {
Expand All @@ -76,14 +84,159 @@ app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));


var basic = auth.digest({
realm: "Private area",
file: __dirname + "/htpasswd"
});
app.use('/refresh', function (req, res, next) {
logger.debug('Accessing to relaunch');
if (req.session.access_token) {

next();
} else {
common.notAuthorized(req,res);
}
}, refresh);

app.use('/subscribe', function (req, res, next) {
logger.debug('Accessing to subscribe');
if (req.session.access_token) {

next();
} else {
notAuthorized(req,res);
}
}, subscribe);

app.use('/unsubscribe', function (req, res, next) {
logger.debug('Accessing to unSubscribe');
if (req.session.access_token) {

next();
} else {
notAuthorized(req,res);
}
}, unsubscribe);


app.use('/refresh', auth.connect(basic), refresh);
app.use('/', index);

//configure login with oAuth

// Creates oauth library object with the config data
var oa = new OAuth2(config.idm.clientId,
config.idm.clientSecret,
config.idm.url,
'/oauth2/authorize',
'/oauth2/token',
config.idm.callbackURL);





// Handles requests to the main page
app.get('/signin', function (req, res) {
logger.debug({op: 'app#get signin'}, "token: " + req.session.access_token);

// If auth_token is not stored in a session redirect to IDM
if (!req.session.access_token) {
var path = oa.getAuthorizeUrl();
logger.debug({op: 'app#get signin'}, "idm path: " + path);
res.redirect(path);
// If auth_token is stored in a session cookie it sends a button to get user info
} else {

oa.get(config.idm.url+'/user/', req.session.access_token, function (e, response) {
logger.debug("userinfo: " + response);
if (response != undefined) {
var user = JSON.parse(response);
req.session.user = user;
req.session.role =common.parseRoles(user.roles);

}
res.redirect('/');

});

}
});

// Handles requests from IDM with the access code
app.get('/login', function (req, res) {

logger.debug({op: 'app#get login'}, "req:" + req.query.code);

// Using the access code goes again to the IDM to obtain the access_token
oa.getOAuthAccessToken(req.query.code, function (e, results) {
logger.debug({op: 'app#get login'}, "get access token:" + results);

if (results != undefined) {

// Stores the access_token in a session cookie
req.session.access_token = results.access_token;

logger.debug({op: 'app#get login'}, "access_token: " + results.access_token);

oa.get(config.idm.url+'/user/', results.access_token, function (e, response) {
logger.debug({op: 'app#get login'}, "response get userinfo: " + response);
if (response != undefined) {
var user = JSON.parse(response);
req.session.user = user;
req.session.role = common.parseRoles(user.roles);
} else {
req.session.access_token = undefined;
req.session.user = undefined;
req.session.role = undefined;
}
res.redirect('/');

});
} else {
res.redirect('/');

}


});


})
;

// listen request from contextbroker changes
app.post('/contextbroker', function (req, res) {
try {
var region = cbroker.changeReceived(req.body);
logger.info('request received from contextbroker for region: ' + region.node);
subscribe.nofify(region.node, function () {
logger.info("post to list ok");

res.status(200).end();
});
} catch (ex) {
logger.error("error in contextbroker notification: " + ex);
res.status(400).send({ error: 'bad request! ' + ex });
}
});


// Redirection to IDM authentication portal
app.get('/auth', function (req, res) {
var path = oa.getAuthorizeUrl();
res.redirect(path);
});

// Handles logout requests to remove access_token from the session cookie
app.get('/logout', function (req, res) {

req.session.access_token = undefined;
req.session.user = undefined;
req.session.role = undefined;

res.clearCookie('oauth_token');
res.clearCookie('expires_in');

res.redirect('/');
});



// catch 404 and forward to error handler
app.use(function (req, res, next) {
Expand All @@ -95,7 +248,6 @@ app.use(function (req, res, next) {
timestamp: req.session.title_timestamp
});

//next(err);
});


Expand All @@ -113,5 +265,8 @@ app.use(function (err, req, res) {
});




/** @export */
module.exports = app;
module.exports = app

42 changes: 34 additions & 8 deletions dashboard/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,28 @@ var config = {
config_file: path.join(__dirname, '/../config', name + '.yml'),
log_level: 'DEBUG',
listen_port: 3000,
secret:'ssshhh',
paths: {
reports_url: '/check/report',
reports_files: '/var/www/html/RegionSanityCheck'
},
cbroker: {
host: 'localhost',
port: '1026',
path: '/NGSI10/queryContext'
},
paths: {
reports_url: '/check/report',
reports_files: '/var/www/html/RegionSanityCheck'
idm: {
host: 'account.lab.fiware.org',
clientId: '',
clientSecret: '',
url: 'https://account.lab.fiware.org',
callbackURL: 'http://fi-health.lab.fiware.org/login'
},
mailman: {
host: 'localhost',
port: '8000',
path: '/',
email_from: ''
}
};

Expand All @@ -53,7 +67,6 @@ var arg_parser = optimist.demand([])
.options('h', { 'alias': 'help', 'describe': 'show help message and exit', 'boolean': true })
.options('v', { 'alias': 'version', 'describe': 'show version and exit', 'boolean': true });


// read configuration file if exists (path maybe taken from command line)
arg_parser
.options('c', { 'alias': 'config-file', 'describe': 'configuration file', 'string': true,
Expand All @@ -64,19 +77,32 @@ try {
var cfg_parser_result;
var cfg_parse = yamljs.parse(fs.readFileSync(config.config_file, 'utf8'));
cfg_parser_result = [ 'INFO', 'Read configuration file' ];
['logging', 'cbroker', 'paths'].forEach(function (key) {
['logging', 'session', 'paths', 'cbroker', 'idm', 'mailman'].forEach(function (key) {
switch (key in cfg_parse && key) {
case 'logging':
config.log_level = cfg_parse.logging.level;
break;
case 'session':
config.secret = cfg_parse.session.secret;
break;
case 'paths':
Object.keys(config.paths).filter(hasOwnProperty, cfg_parse.paths).forEach(function(key) {
config.paths[key] = cfg_parse.paths[key];
});
break;
case 'cbroker':
Object.keys(config.cbroker).filter(hasOwnProperty, cfg_parse.cbroker).forEach(function(key) {
config.cbroker[key] = cfg_parse.cbroker[key];
});
break;
case 'paths':
Object.keys(config.paths).filter(hasOwnProperty, cfg_parse.paths).forEach(function(key) {
config.paths[key] = cfg_parse.paths[key];
case 'idm':
Object.keys(config.idm).filter(hasOwnProperty, cfg_parse.idm).forEach(function (key) {
config.idm[key] = cfg_parse.idm[key];
});
break;
case 'mailman':
Object.keys(config.mailman).filter(hasOwnProperty, cfg_parse.mailman).forEach(function (key) {
config.mailman[key] = cfg_parse.mailman[key];
});
break;
default:
Expand Down
Empty file removed dashboard/lib/htpasswd
Empty file.

0 comments on commit 8b19260

Please sign in to comment.