aboutsummaryrefslogtreecommitdiffstats
path: root/admportal/server/router/routes/user.js
blob: df5f8607856a286d3fb2ea7d3461d36a0cba5158 (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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
var express = require('express');
var router = express.Router();
var exec = require('child_process').exec;
var util = require('util');
var fs = require('fs');
var dbRoutes = require('./dbRoutes');
var csp = require('./csp');
var cookieParser = require('cookie-parser');
var csrf = require('csurf');
var bodyParser = require('body-parser');
//var sax = require('sax'),strict=true,parser = sax.parser(strict);

var csrfProtection = csrf({cookie: true});
router.use(cookieParser());

// SVC_LOGIC table columns
var _module=''; // cannot use module its a reserved word
var version='';
var rpc='';
var mode='';
var xmlfile='';


//router.use(bodyParser());
router.use(bodyParser.urlencoded({ extended: true }));


// GET
router.get('/listUsers', csp.checkAuth, function(req,res) {
	dbRoutes.listUsers(req,res, {user:req.session.loggedInAdmin,code:'', msg:''} );
});
// POST
router.post('/updateUser', csp.checkAuth, csrfProtection, function(req,res,next){
	dbRoutes.updateUser(req,res,{code:'',msg:''});
});
router.post('/addUser', csp.checkAuth, csrfProtection, function(req,res) {
	dbRoutes.addUser(req,res, {code:'', msg:''} );
});
router.get('/deleteUser', csp.checkAuth, csrfProtection, function(req,res) {
	dbRoutes.deleteUser(req,res, {code:'', msg:''} );
});

//router.get('/activate', csp.checkAuth, function(req,res){

	//var _module = req.query.module;
	//var rpc = req.query.rpc;
	//var version = req.query.version;
	//var mode = req.query.mode;

	//dbRoutes.activate(req,res,_module,rpc,version,mode);
//});

//router.get('/deactivate', csp.checkAuth, function(req,res){

	//var _module = req.query.module;
	//var rpc = req.query.rpc;
	//var version = req.query.version;
	//var mode = req.query.mode;
//
	//dbRoutes.deactivate(req,res,_module,rpc,version,mode);
//});

//router.get('/deleteDG', csp.checkAuth, function(req,res){

	//var _module = req.query.module;
	//var rpc = req.query.rpc;
	//var version = req.query.version;
	//var mode = req.query.mode;

	//dbRoutes.deleteDG(req,res,_module,rpc,version,mode);
//});
/*
// SAX
parser.onerror = function (e) {
	logger.debug('onerror');
  // an error happened.
};
parser.ontext = function (t) {
  // got some text.  t is the string of text.
	logger.debug('ontext:'+t);
};
parser.onopentag = function (node) {
  // opened a tag.  node has "name" and "attributes"
	if ( node.name == 'service-logic' )
	{
		_module = node.attributes.module;
		version = node.attributes.version;
	}
	if ( node.name == 'method' )
	{
		rpc = node.attributes.rpc;
		mode = node.attributes.mode;
	}
};
parser.onattribute = function (attr) {
  // an attribute.  attr has "name" and "value"
	logger.debug('onattribute:'+attr);
};
parser.onend = function () {
  // parser stream is done, and ready to have more stuff written to it.
	logger.debug('onend:');
};
*/



//router.post('/upload', csp.checkAuth, function(req, res, next){

/*
logger.debug("upload");
	if(req.files.filename){
        if (req.files.filename.size == 0) {
			resultObj = 
				{code:'danger', msg:'There was an error uploading the file, please try again.'};
			dbRoutes.listSLA(req,res, resultObj);
        }
        fs.exists(req.files.filename.path, function(exists) {
            if(exists) {
				resultObj = {code:'success', msg:'File sucessfully uploaded.'};

				// parse xml
				try {
    				var file_buf = fs.readFileSync(req.files.filename.path, "utf8");
logger.debug('file '+req.files.filename);

					
					// call Dan's svclogic shell script from here
					 var commandToExec = process.cwd()
            			+ "/shell/svclogic.sh load "
						+ req.files.filename.path + " "
						+ process.cwd()
						+ "/config/svclogic.properties";

        			logger.debug("commandToExec:" + commandToExec);
        			child = exec(commandToExec ,function (error,stdout,stderr){
            			if(error){
                			logger.info("error:" + error);
            			}
            			if(stderr){
                			logger.info("stderr:" + stderr);
            			}
            			if(stdout){
							logger.info("OUTPUT:" + stdout);
							dbRoutes.listSLA(req,res, resultObj);
						}

						// remove the grave accents, the sax parser does not like them
    					//parser.write(file_buf.replace(/\`/g,'').toString('utf8')).close();
						//dbRoutes.addDG(_module,version,rpc,mode,file_buf,req,res);
						//dbRoutes.listSLA(req,res, resultObj);
					});
				} catch(ex) {
    				// keep 'em silent
					logger.debug('sax error:'+ex);
				}

            } else {
				resultObj = 
					{code:'danger', msg:'There was an error uploading the file, please try again.'};
				dbRoutes.listSLA(req,res, resultObj);
            }
        });
	}
	else {
		resultObj = 
			{code:'danger', msg:'There was an error uploading the file, please try again.'};
		dbRoutes.listSLA(req,res, resultObj);
	}
});
*/

module.exports = router;