Timoney, Daniel (dt5972) | 324ee36 | 2017-02-15 10:37:53 -0500 | [diff] [blame] | 1 | var express = require('express'); |
| 2 | var router = express.Router(); |
| 3 | var csp = require('./csp.js'); |
| 4 | var dbRoutes = require('./dbRoutes.js'); |
| 5 | var sla = require('./sla'); |
| 6 | var os = require('os'); |
| 7 | var async = require('async'); |
Al Rotundo | 2f8e4d0 | 2017-03-24 13:54:52 +0000 | [diff] [blame] | 8 | var OdlInterface = require('./OdlInterface'); |
Timoney, Daniel (dt5972) | 324ee36 | 2017-02-15 10:37:53 -0500 | [diff] [blame] | 9 | var properties = require(process.env.SDNC_CONFIG_DIR + '/admportal.json'); |
| 10 | |
| 11 | |
| 12 | |
| 13 | router.use('/healthcheck', function(req,res){ |
| 14 | res.render('pages/healthcheck'); |
| 15 | }); |
| 16 | router.get('/test', function(req,res){ |
| 17 | |
| 18 | //console.log('port='+ req.socket.localPort); |
| 19 | //console.log('port='+ req.protocol); |
| 20 | |
| 21 | // pass host, username and password to ODL |
| 22 | var username = properties.odlUser; |
| 23 | var password = properties.odlPasswd; |
| 24 | var auth = 'Basic ' + new Buffer(username + ':' + password).toString('base64'); |
| 25 | |
| 26 | // target host for ODL request |
| 27 | var host = properties.odlHost; |
| 28 | var header = {'Host': host, 'Authorization': auth, 'Content-Type': 'application/yang.data+json'}; |
| 29 | var c_header = {'Host': properties.odlConexusHost, 'Authorization': auth, 'Content-Type': 'application/yang.data+json'}; |
| 30 | |
| 31 | // path = '/restconf/config/SLI-API:healthcheck', |
| 32 | var _options = { |
| 33 | method : 'POST', |
| 34 | host : host, |
| 35 | headers : header, |
| 36 | port : '8443', |
| 37 | path : '/restconf/operations/SLI-API:healthcheck', |
| 38 | rejectUnauthorized: false, |
| 39 | strictSSL : false |
| 40 | }; |
| 41 | var c_options = { |
| 42 | method : 'POST', |
| 43 | host : properties.odlConexusHost, |
| 44 | headers : c_header, |
| 45 | port : '8543', |
| 46 | path : '/restconf/operations/SLI-API:healthcheck', |
| 47 | rejectUnauthorized: false, |
| 48 | strictSSL : false |
| 49 | }; |
| 50 | |
| 51 | |
| 52 | var tasks = []; |
| 53 | //tasks.push( function(callback) { dbRoutes.testdb(req,res,callback); } ); |
| 54 | |
| 55 | tasks.push ( createFunctionObj(_options) ); |
| 56 | |
| 57 | tasks.push ( createFunctionObj(c_options) ); |
| 58 | |
| 59 | async.series(tasks, function(err,result){ |
| 60 | if(err) { |
| 61 | res.status(400).send(err); |
| 62 | return; |
| 63 | } |
| 64 | res.status(200).send(result); |
| 65 | return; |
| 66 | }); |
| 67 | }); |
| 68 | |
| 69 | function createFunctionObj( loptions ) { |
Al Rotundo | 2f8e4d0 | 2017-03-24 13:54:52 +0000 | [diff] [blame] | 70 | return function(callback) { OdlInterface.Healthcheck(loptions,callback); }; |
Timoney, Daniel (dt5972) | 324ee36 | 2017-02-15 10:37:53 -0500 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | router.get('/mytree', function(req,res) { |
| 74 | res.render('pages/tree'); |
| 75 | }); |
| 76 | router.get('/setuplogin', function(req,res) { |
| 77 | res.render('pages/setuplogin'); |
| 78 | }); |
Al Rotundo | 2f8e4d0 | 2017-03-24 13:54:52 +0000 | [diff] [blame] | 79 | router.post('/formSetupLogin', function(req,res) { |
Timoney, Daniel (dt5972) | 324ee36 | 2017-02-15 10:37:53 -0500 | [diff] [blame] | 80 | dbRoutes.saveSetupLogin(req,res); |
| 81 | }); |
Al Rotundo | 2f8e4d0 | 2017-03-24 13:54:52 +0000 | [diff] [blame] | 82 | router.post('/formSignUp', function(req,res) { |
Timoney, Daniel (dt5972) | 324ee36 | 2017-02-15 10:37:53 -0500 | [diff] [blame] | 83 | dbRoutes.saveUser(req,res); |
| 84 | }); |
Al Rotundo | 2f8e4d0 | 2017-03-24 13:54:52 +0000 | [diff] [blame] | 85 | router.post('/formlogin', csp.login, function(req,res) { |
Timoney, Daniel (dt5972) | 324ee36 | 2017-02-15 10:37:53 -0500 | [diff] [blame] | 86 | }); |
| 87 | router.get('/login', function(req,res) { |
| 88 | res.render('pages/login'); |
| 89 | // handle get |
| 90 | }); |
| 91 | router.get('/signup', function(req,res) { |
| 92 | res.render('pages/signup'); |
| 93 | // handle get |
| 94 | }); |
| 95 | router.get('/info', function(req,res) { |
| 96 | // handle get |
| 97 | res.send("login info"); |
| 98 | }); |
| 99 | router.get('/logout', csp.logout, function(req,res) { |
| 100 | // handle get |
| 101 | }); |
| 102 | router.get('/csplogout', function(req,res) { |
| 103 | // handle get |
| 104 | res.render("pages/csplogout", {result:{code:'success', msg:'You have been successfylly logged out.'},header:process.env.MAIN_MENU}); |
| 105 | }); |
| 106 | router.get('/getuser', function(req,res) { |
| 107 | // handle get |
| 108 | res.render("pages/home"); |
| 109 | }); |
| 110 | |
| 111 | module.exports = router; |