blob: 96c7fd85a2e0ab19f93be3b0a90db4fb684489cd [file] [log] [blame]
Timoney, Daniel (dt5972)324ee362017-02-15 10:37:53 -05001var express = require('express');
2var router = express.Router();
3var exec = require('child_process').exec;
4var util = require('util');
5var fs = require('fs');
6var dbRoutes = require('./dbRoutes');
7var csp = require('./csp');
Rotundo, Al (ar3165)18dcbec2019-07-31 14:46:56 +00008var cookieParser = require('cookie-parser');
Timoney, Daniel (dt5972)324ee362017-02-15 10:37:53 -05009var bodyParser = require('body-parser');
10var sax = require('sax'),strict=true,parser = sax.parser(strict);
11var async = require('async');
Rotundo, Al (ar3165)18dcbec2019-07-31 14:46:56 +000012var csrf = require('csurf');
13
14var csrfProtection = csrf({cookie: true});
15router.use(cookieParser());
Timoney, Daniel (dt5972)324ee362017-02-15 10:37:53 -050016
17
18// GET
19router.get('/getParameters', csp.checkAuth, dbRoutes.checkDB, function(req,res) {
20 dbRoutes.getParameters(req,res, {code:'', msg:''}, req.session.loggedInAdmin);
21});
Rotundo, Al (ar3165)18dcbec2019-07-31 14:46:56 +000022router.get('/deleteParameter', csp.checkAuth, dbRoutes.checkDB, csrfProtection, function(req,res) {
Timoney, Daniel (dt5972)324ee362017-02-15 10:37:53 -050023
Rotundo, Al (ar3165)18dcbec2019-07-31 14:46:56 +000024 var privilegeObj = req.session.loggedInAdmin;
25 var tasks = [];
26 tasks.push(function(callback) { dbRoutes.deleteParameter(req,res,callback); });
27 async.series(tasks, function(err,result){
28 var msgArray = new Array();
29 if(err){
30 msgArray.push(err);
31 dbRoutes.getParameters(req,res,{code:'failure', msg:msgArray},privilegeObj);
32 return;
33 }
34 else {
35 msgArray.push('Row successfully deleted from PARAMETERS table.');
36 dbRoutes.getParameters(req,res,{code:'success', msg:msgArray},privilegeObj);
37 return;
38 }
39 });
Timoney, Daniel (dt5972)324ee362017-02-15 10:37:53 -050040});
41
42
43// POST
Rotundo, Al (ar3165)18dcbec2019-07-31 14:46:56 +000044router.post('/addParameter', csp.checkAuth, dbRoutes.checkDB, csrfProtection, function(req,res){
Timoney, Daniel (dt5972)324ee362017-02-15 10:37:53 -050045
46 var privilegeObj = req.session.loggedInAdmin;
47 var tasks = [];
48 tasks.push( function(callback) { dbRoutes.addParameter(req,res,callback); } );
49 async.series(tasks, function(err,result){
50 var msgArray = new Array();
51 if(err){
52 msgArray.push(err);
53 dbRoutes.getParameters(req,res,{code:'failure', msg:msgArray},privilegeObj);
54 return;
55 }
56 else {
57 msgArray.push('Successfully updated PARAMETERS.');
58 dbRoutes.getParameters(req,res,{code:'success', msg:msgArray},privilegeObj);
59 return;
60 }
61 });
62});
63
64// gamma - updateAicSite
Rotundo, Al (ar3165)18dcbec2019-07-31 14:46:56 +000065router.post('/updateParameter', csp.checkAuth, dbRoutes.checkDB, csrfProtection, function(req,res){
Timoney, Daniel (dt5972)324ee362017-02-15 10:37:53 -050066
67 var privilegeObj = req.session.loggedInAdmin;
68 var tasks = [];
69 tasks.push( function(callback) { dbRoutes.updateParameter(req,res,callback); } );
70 async.series(tasks, function(err,result){
71 var msgArray = new Array();
72 if(err){
73 msgArray.push(err);
74 dbRoutes.getParameters(req,res,{code:'success', msg:msgArray},privilegeObj);
75 return;
76 }
77 else {
78 msgArray.push('Successfully updated PARAMETERS.');
79 dbRoutes.getParameters(req,res,{code:'success', msg:msgArray},privilegeObj);
80 return;
81 }
82 });
83});
84
85
86module.exports = router;