summaryrefslogtreecommitdiffstats
path: root/admportal/server/router/routes/root.js
blob: b314d7dbe76c5ff9e3a74ca1c3fd7af6bd3e0464 (plain)
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
var express = require('express');
var router = express.Router();
var csp = require('./csp.js');
var dbRoutes = require('./dbRoutes.js');
var sla = require('./sla');
var os = require('os');
var async = require('async');
var OdlInterface = require('./OdlInterface');
var properties = require(process.env.SDNC_CONFIG_DIR + '/admportal.json');



router.use('/healthcheck', function(req,res){
	res.render('pages/healthcheck');
});
router.get('/test', function(req,res){

//console.log('port='+ req.socket.localPort);
//console.log('port='+ req.protocol);

	// pass host, username and password to ODL
	var username = properties.odlUser;
	var password = properties.odlPasswd;
	var auth = 'Basic ' + new Buffer(username + ':' + password).toString('base64');

	// target host for ODL request
	var host = properties.odlHost;
	var header = {'Host': host, 'Authorization': auth, 'Content-Type': 'application/yang.data+json'};
	var c_header = {'Host': properties.odlConexusHost, 'Authorization': auth, 'Content-Type': 'application/yang.data+json'};

// path = '/restconf/config/SLI-API:healthcheck',
	var _options = {
		method			  : 'POST',
        host              : host,
        headers           : header,
        port              : '8443',
		path			  : '/restconf/operations/SLI-API:healthcheck',
        rejectUnauthorized: false,
        strictSSL         : false
	};
	var c_options = {
		method			  : 'POST',
        host              : properties.odlConexusHost,
        headers           : c_header,
        port              : '8543',
		path			  : '/restconf/operations/SLI-API:healthcheck',
        rejectUnauthorized: false,
        strictSSL         : false
	};


    var tasks = [];
    //tasks.push( function(callback) { dbRoutes.testdb(req,res,callback); } );

	tasks.push ( createFunctionObj(_options) );

	tasks.push ( createFunctionObj(c_options) );

    async.series(tasks, function(err,result){
    	if(err) {
			res.status(400).send(err);
			return;
    	}
		res.status(200).send(result);
		return;
	});
});

function createFunctionObj( loptions ) {
	return function(callback) { OdlInterface.Healthcheck(loptions,callback); };
}

router.get('/mytree', function(req,res) {
	res.render('pages/tree');
});
router.get('/setuplogin', function(req,res) {
	res.render('pages/setuplogin');
});
router.post('/formSetupLogin', function(req,res) {
	dbRoutes.saveSetupLogin(req,res);
});
router.post('/formSignUp', function(req,res) {
	dbRoutes.saveUser(req,res);
});
router.post('/formlogin', csp.login, function(req,res) {
});
router.get('/login', function(req,res) {
	res.render('pages/login');
	// handle get
});
router.get('/signup', function(req,res) {
	res.render('pages/signup');
	// handle get
});
router.get('/info', function(req,res) {
	// handle get
	res.send("login info");
});
router.get('/logout', csp.logout, function(req,res) {
    // handle get
});
router.get('/csplogout', function(req,res) {
    // handle get
	res.render("pages/csplogout", {result:{code:'success', msg:'You have been successfylly logged out.'},header:process.env.MAIN_MENU});
});
router.get('/getuser', function(req,res) {
    // handle get
    res.render("pages/home");
});

module.exports = router;