1 var express = require('express');
2 var router = express.Router();
3 var exec = require('child_process').exec;
4 var util = require('util');
5 var fs = require('fs');
6 var dbRoutes = require('./dbRoutes');
7 var csp = require('./csp');
8 var multer = require('multer');
9 var bodyParser = require('body-parser');
10 var sax = require('sax'),strict=true,parser = sax.parser(strict);
11 var async = require('async');
12 var l_ = require('lodash');
15 // used for file upload button, retain original file name
16 //router.use(bodyParser());
17 router.use(bodyParser.urlencoded({
21 //var upload = multer({ dest: process.cwd() + '/uploads/', rename: function(fieldname,filename){ return filename; } });
24 var storage = multer.diskStorage({
25 destination: function (req, file, cb) {
26 cb(null, process.cwd() + '/uploads/')
28 filename: function (req, file, cb) {
29 cb(null, file.originalname )
38 //router.use(express.json());
39 //router.use(express.urlencoded());
40 //router.use(multer({ dest: './uploads/' }));
43 var selectNetworkProfile = "SELECT network_type,technology FROM NETWORK_PROFILE ORDER BY network_type";
45 var selectNbVlanRange = "SELECT vlan_plan_id,plan_type,purpose,LPAD(range_start,4,0) range_start,LPAD(range_end,4,0) range_end,generated from VLAN_RANGES ORDER BY vlan_plan_id";
47 var selectNbVlanPool = "SELECT aic_site_id,availability_zone,vlan_plan_id,plan_type,purpose,LPAD(vlan_id,4,0) vlan_id,status FROM VLAN_POOL ORDER BY aic_site_id,availability_zone,vlan_plan_id,vlan_id";
49 router.get('/getNetworkProfile', csp.checkAuth, dbRoutes.checkDB, function(req,res) {
50 dbRoutes.getTable(req,res,selectNetworkProfile,'gamma/networkProfile',{code:'', msg:''}, req.session.loggedInAdmin);
52 router.get('/getNbVlanRange', csp.checkAuth, dbRoutes.checkDB, function(req,res) {
53 dbRoutes.getTable(req,res,selectNbVlanRange,'gamma/nbVlanRange',{code:'', msg:''}, req.session.loggedInAdmin);
56 router.get('/getNbVlanPool', csp.checkAuth, dbRoutes.checkDB, function(req,res) {
57 if (typeof req.query.vlan_plan_id == "undefined"){
58 dbRoutes.getTable(req,res,selectNbVlanPool,'gamma/nbVlanPool',{code:'', msg:''}, req.session.loggedInAdmin);
60 var sql = "SELECT aic_site_id,availability_zone,vlan_plan_id,plan_type,purpose,vlan_id,status FROM VLAN_POOL WHERE vlan_plan_id='" + req.query.vlan_plan_id + "' AND vlan_id BETWEEN "
61 + req.query.range_start + " AND " + req.query.range_end;
62 dbRoutes.getTable(req,res,sql,'gamma/nbVlanPool',{code:'', msg:''}, req.session.loggedInAdmin);
66 router.post('/addNetworkProfile', csp.checkAuth, dbRoutes.checkDB, function(req,res){
68 var network_type = removeNL(req.body.nf_network_type);
69 var technology = removeNL(req.body.nf_technology);
70 var sql = "INSERT INTO NETWORK_PROFILE (network_type,technology) VALUES ("
71 + "'"+ network_type + "',"
72 + "'"+ technology + "')";
74 var privilegeObj = req.session.loggedInAdmin;
76 tasks.push( function(callback) { dbRoutes.addRow(sql,req,res,callback); } );
77 async.series(tasks, function(err,result){
78 var msgArray = new Array();
82 dbRoutes.getTable(req,res,ucpePhsCredentials, 'gamma/networkProfile', {code:'failure', msg:msgArray},privilegeObj);
89 msgArray.push('Successfully added Network Profile.');
90 dbRoutes.getTable(req,res,selectNetworkProfile, 'gamma/networkProfile', {code:'success', msg:msgArray},privilegeObj);
95 msgArray.push('Was not able to add Network Profile.');
96 dbRoutes.getTable(req,res,ucpePhsCredentials, 'gamma/networkProfile', {code:'failure', msg:msgArray},privilegeObj);
103 router.post('/saveNbVlanRange', csp.checkAuth, dbRoutes.checkDB, function(req,res){
105 var plan_type = req.body.nf_plan_type;
106 var purpose = req.body.nf_purpose;
107 var range_start = padLeft(removeNL(req.body.nf_range_start),4);
108 var range_end = padLeft(removeNL(req.body.nf_range_end),4);
110 var privilegeObj = req.session.loggedInAdmin;
112 tasks.push( function(callback) {
113 dbRoutes.saveNbVlanRange(range_start,range_end,plan_type,purpose,req,res,callback);
116 // will probably need to be a new call that is a transaction if i use a new
117 // plan_type-purpose-counter table.
118 //tasks.push( function(callback) { dbRoutes.addRow(sql,req,res,callback); } );
119 async.series(tasks, function(err,result){
120 var msgArray = new Array();
124 dbRoutes.getTable(req,res,selectNbVlanRange, 'gamma/nbVlanRange', {code:'failure', msg:msgArray},privilegeObj);
129 msgArray.push('Successfully added VLAN Range.');
130 dbRoutes.getTable(req,res,selectNbVlanRange, 'gamma/nbVlanRange', {code:'success', msg:msgArray},privilegeObj);
136 router.get('/deleteNetworkProfile', csp.checkAuth, dbRoutes.checkDB, function(req,res) {
138 var privilegeObj = req.session.loggedInAdmin;
140 tasks.push(function(callback){
141 dbRoutes.executeSQL("DELETE FROM NETWORK_PROFILE WHERE network_type = '" + req.query.network_type + "'", req,res,callback);
144 async.series(tasks, function(err,result)
146 var msgArray = new Array();
148 msgArray.push("Error: " + err);
149 dbRoutes.getTable(req,res,selectNetworkProfile, 'gamma/networkProfile', {code:'failure', msg:msgArray},privilegeObj);
154 if ( result[0] == 1 )
156 msgArray.push('Successfully deleted Network Profile.');
157 dbRoutes.getTable(req,res,selectNetworkProfile, 'gamma/networkProfile', {code:'success', msg:msgArray},privilegeObj);
162 msgArray.push('No rows removed.');
163 dbRoutes.getTable(req,res,selectNetworkProfile, 'gamma/networkProfile', {code:'failure', msg:msgArray},privilegeObj);
170 router.get('/deleteNbVlanRange', csp.checkAuth, dbRoutes.checkDB, function(req,res) {
172 var privilegeObj = req.session.loggedInAdmin;
175 tasks.push(function(callback){
176 dbRoutes.deleteNbVlanRange(req.query.vlan_plan_id,req,res,callback);
178 async.series(tasks, function(err,result)
180 var msgArray = new Array();
183 dbRoutes.getTable(req,res,selectNbVlanRange, 'gamma/nbVlanRange', {code:'failure', msg:msgArray},privilegeObj);
188 msgArray.push('Successfully deleted Range.');
189 dbRoutes.getTable(req,res,selectNbVlanRange, 'gamma/nbVlanRange', {code:'success', msg:msgArray},privilegeObj);
195 router.post('/updateNetworkProfile', csp.checkAuth, dbRoutes.checkDB, function(req,res){
197 var sql = "UPDATE NETWORK_PROFILE SET "
198 + "network_type='"+ removeNL(req.body.uf_network_type) + "', "
199 + "technology='" + removeNL(req.body.uf_technology) + "' "
200 + "WHERE network_type='" + removeNL(req.body.uf_key_network_type) + "'";
203 var privilegeObj = req.session.loggedInAdmin;
205 tasks.push( function(callback) { dbRoutes.executeSQL(sql,req,res,callback); } );
206 async.series(tasks, function(err,result){
207 var msgArray = new Array();
210 dbRoutes.getTable(req,res,selectNetworkProfile, 'gamma/networkProfile', {code:'failure', msg:msgArray},privilegeObj);
214 msgArray.push('Successfully updated Network Profile.');
215 dbRoutes.getTable(req,res,selectNetworkProfile, 'gamma/networkProfile', {code:'success', msg:msgArray},privilegeObj);
221 router.post('/updateNbVlanPool', csp.checkAuth, dbRoutes.checkDB, function(req,res){
223 var sql = "UPDATE VLAN_POOL SET "
224 + "status='"+ removeNL(req.body.uf_status) + "' "
225 + " WHERE aic_site_id='" + removeNL(req.body.uf_key_aic_site_id) + "'"
226 + " AND availability_zone='" + removeNL(req.body.uf_key_availability_zone) + "'"
227 + " AND vlan_plan_id='" + removeNL(req.body.uf_key_vlan_plan_id) + "'"
228 + " AND plan_type='" + removeNL(req.body.uf_key_plan_type) + "'"
229 + " AND purpose='" + removeNL(req.body.uf_key_purpose) + "'"
230 + " AND vlan_id=" + removeNL(req.body.uf_key_vlan_id);
233 var privilegeObj = req.session.loggedInAdmin;
235 tasks.push( function(callback) { dbRoutes.executeSQL(sql,req,res,callback); } );
236 async.series(tasks, function(err,result){
237 var msgArray = new Array();
240 dbRoutes.getTable(req,res,selectNbVlanPool, 'gamma/nbVlanPool', {code:'failure', msg:msgArray},privilegeObj);
244 msgArray.push('Successfully updated Network Profile.');
245 dbRoutes.getTable(req,res,selectNbVlanPool, 'gamma/nbVlanPool', {code:'success', msg:msgArray},privilegeObj);
251 router.post('/updateNbVlanPool', csp.checkAuth, dbRoutes.checkDB, function(req,res){
253 router.get('/generateNbVlanPool', csp.checkAuth, dbRoutes.checkDB, function(req,res){
255 var vlan_plan_id = req.query.vlan_plan_id;
256 var plan_type = req.query.plan_type;
257 var purpose = req.query.purpose;
258 var range_start = req.query.range_start;
259 var range_end = req.query.range_end;
261 var privilegeObj = req.session.loggedInAdmin;
263 tasks.push( function(callback) {
264 dbRoutes.generateNbVlanPool(range_start,range_end,plan_type,purpose,vlan_plan_id,req,res,callback);
267 // will probably need to be a new call that is a transaction if i use a new
268 // plan_type-purpose-counter table.
269 //tasks.push( function(callback) { dbRoutes.addRow(sql,req,res,callback); } );
270 async.series(tasks, function(err,result){
271 var msgArray = new Array();
275 dbRoutes.getTable(req,res,selectNbVlanRange, 'gamma/nbVlanRange', {code:'failure', msg:msgArray},privilegeObj);
280 msgArray.push('Successfully added VLAN Range.');
281 dbRoutes.getTable(req,res,selectNbVlanRange, 'gamma/nbVlanRange', {code:'success', msg:msgArray},privilegeObj);
291 router.get('/getServiceHoming', csp.checkAuth, dbRoutes.checkDB, function(req,res) {
292 dbRoutes.getServiceHoming(req,res, {code:'', msg:''}, req.session.loggedInAdmin);
294 router.get('/getServiceHomingRollback', csp.checkAuth, dbRoutes.checkDB, function(req,res) {
295 dbRoutes.getServiceHomingRollback(req,res, {code:'', msg:''}, req.session.loggedInAdmin);
297 router.get('/getVlanPool', csp.checkAuth, dbRoutes.checkDB, function(req,res) {
298 dbRoutes.getVlanPool(req,res, {code:'', msg:''}, req.session.loggedInAdmin);
300 router.get('/getAicSite', csp.checkAuth, dbRoutes.checkDB, function(req,res) {
301 dbRoutes.getAicSite(req,res, {code:'', msg:''}, req.session.loggedInAdmin);
303 router.get('/getAicSwitch', csp.checkAuth, dbRoutes.checkDB, function(req,res) {
304 dbRoutes.getAicSwitch(req,res, {code:'', msg:''}, req.session.loggedInAdmin);
306 router.get('/getAicAvailZone', csp.checkAuth, dbRoutes.checkDB, function(req,res) {
307 dbRoutes.getAicAvailZone(req,res, {code:'', msg:''}, req.session.loggedInAdmin);
309 router.get('/getVpePool', csp.checkAuth, dbRoutes.checkDB, function(req,res) {
310 dbRoutes.getVpePool(req,res,{code:'', msg:''}, req.session.loggedInAdmin);
312 router.get('/getVplspePool', csp.checkAuth, dbRoutes.checkDB, function(req,res) {
313 dbRoutes.getVplspePool(req,res, {code:'', msg:''}, req.session.loggedInAdmin);
316 // ROLLBACK SERVICE_HOMING
317 router.get('/rollbackServiceHoming', csp.checkAuth, dbRoutes.checkDB, function(req,res) {
319 var privilegeObj = req.session.loggedInAdmin;
321 tasks.push(function(callback) {
322 dbRoutes.rollbackServiceHoming(req,res,callback);
324 async.series(tasks, function(err,result){
325 var msgArray = new Array();
328 dbRoutes.getServiceHomingRollback(req,res,{code:'failure', msg:msgArray},privilegeObj);
332 msgArray.push('SERVICE_HOMING table successfully restored.');
333 dbRoutes.getServiceHoming(req,res,{code:'success', msg:msgArray},privilegeObj);
339 // DELETE SERVICE_HOMING
340 router.get('/deleteServiceHoming', csp.checkAuth, dbRoutes.checkDB, function(req,res) {
342 var privilegeObj = req.session.loggedInAdmin;
344 tasks.push(function(callback) {
345 dbRoutes.deleteServiceHoming(req,res,callback);
347 async.series(tasks, function(err,result){
348 var msgArray = new Array();
351 dbRoutes.getServiceHoming(req,res,{code:'failure', msg:msgArray},privilegeObj);
355 msgArray.push('Row successfully deleted from SERVICE_HOMING table.');
356 dbRoutes.getServiceHoming(req,res,{code:'success', msg:msgArray},privilegeObj);
364 router.get('/deleteSite', csp.checkAuth, dbRoutes.checkDB, function(req,res) {
366 var privilegeObj = req.session.loggedInAdmin;
368 tasks.push(function(callback) {
369 dbRoutes.deleteSite(req,res,callback);
371 async.series(tasks, function(err,result){
372 var msgArray = new Array();
375 dbRoutes.getAicSite(req,res,{code:'failure', msg:msgArray},privilegeObj);
379 msgArray.push('Row successfully deleted from AIC_SITE table.');
380 dbRoutes.getAicSite(req,res,{code:'success', msg:msgArray},privilegeObj);
387 router.get('/deleteSwitch', csp.checkAuth, dbRoutes.checkDB, function(req,res) {
389 var privilegeObj = req.session.loggedInAdmin;
391 tasks.push(function(callback) {
392 dbRoutes.deleteSwitch(req,res,callback);
394 async.series(tasks, function(err,result){
395 var msgArray = new Array();
398 dbRoutes.getAicSwitch(req,res,{code:'failure', msg:msgArray},privilegeObj);
402 msgArray.push('Row successfully deleted from AIC_SWITCH table.');
403 dbRoutes.getAicSwitch(req,res,{code:'success', msg:msgArray},privilegeObj);
409 // DELETE AIC_AVAIL_ZONE_POOL
410 router.get('/deleteZone', csp.checkAuth, dbRoutes.checkDB, function(req,res) {
412 var privilegeObj = req.session.loggedInAdmin;
414 tasks.push(function(callback) {
415 dbRoutes.deleteZone(req,res,callback);
417 async.series(tasks, function(err,result){
418 var msgArray = new Array();
421 dbRoutes.getAicAvailZone(req,res,{code:'failure', msg:msgArray},privilegeObj);
425 msgArray.push('Row successfully deleted from AIC_AVAIL_ZONE_POOL table.');
426 dbRoutes.getAicAvailZone(req,res,{code:'success', msg:msgArray},privilegeObj);
432 // DELETE VLAN_ID_POOL
433 router.get('/deleteVlanPool', csp.checkAuth, dbRoutes.checkDB, function(req,res) {
435 var privilegeObj = req.session.loggedInAdmin;
437 tasks.push(function(callback) {
438 dbRoutes.deleteVlanPool(req,res,callback);
440 async.series(tasks, function(err,result){
441 var msgArray = new Array();
444 dbRoutes.getVlanPool(req,res,{code:'failure', msg:msgArray},privilegeObj);
448 msgArray.push('Row successfully deleted from VLAN_ID_POOL table.');
449 dbRoutes.getVlanPool(req,res,{code:'success', msg:msgArray},privilegeObj);
456 router.get('/deleteVpePool', csp.checkAuth, dbRoutes.checkDB, function(req,res) {
458 var privilegeObj = req.session.loggedInAdmin;
460 tasks.push(function(callback) {
461 dbRoutes.deleteVpePool(req,res,callback);
463 async.series(tasks, function(err,result){
464 var msgArray = new Array();
467 dbRoutes.getVpePool(req,res,{code:'failure', msg:msgArray},privilegeObj);
471 msgArray.push('Row successfully deleted from VPE_POOL table.');
472 dbRoutes.getVpePool(req,res,{code:'success', msg:msgArray},privilegeObj);
480 router.get('/deleteVplspePool', csp.checkAuth, dbRoutes.checkDB, function(req,res) {
482 var privilegeObj = req.session.loggedInAdmin;
484 tasks.push(function(callback) {
485 dbRoutes.deleteVplspePool(req,res,callback);
487 async.series(tasks, function(err,result){
488 var msgArray = new Array();
491 dbRoutes.getVplspePool(req,res,{code:'failure', msg:msgArray},privilegeObj);
495 msgArray.push('Row successfully deleted from VPLSPE_POOL table.');
496 dbRoutes.getVplspePool(req,res,{code:'success', msg:msgArray},privilegeObj);
503 router.post('/addServiceHoming', csp.checkAuth, dbRoutes.checkDB, function(req,res){
505 var privilegeObj = req.session.loggedInAdmin;
507 tasks.push( function(callback) { dbRoutes.addWebServiceHoming(req,res,callback); } );
508 async.series(tasks, function(err,result){
509 var msgArray = new Array();
512 dbRoutes.getServiceHoming(req,res,{code:'failure', msg:msgArray},privilegeObj);
516 msgArray.push('Successfully added SERVICE_HOMING');
517 dbRoutes.getServiceHoming(req,res,{code:'success', msg:msgArray},privilegeObj);
524 // gamma - updateProvStatus
525 router.post('/updateProvStatus', csp.checkAuth, dbRoutes.checkDB, function(req,res){
528 var privilegeObj = req.session.loggedInAdmin;
530 tasks.push( function(callback) { dbRoutes.updateProvStatus(req,res,callback); } );
531 async.series(tasks, function(err,result){
532 var msgArray = new Array();
535 dbRoutes.getVpePool(req,res,{code:'failure', msg:msgArray},privilegeObj);
539 msgArray.push('Successfully updated Provisioning Status');
540 dbRoutes.getVpePool(req,res,{code:'success', msg:msgArray},privilegeObj);
546 // gamma - updateAicSite
547 router.post('/updateAicSite', csp.checkAuth, dbRoutes.checkDB, function(req,res){
549 var privilegeObj = req.session.loggedInAdmin;
551 tasks.push( function(callback) { dbRoutes.updateAicSite(req,res,callback); } );
552 async.series(tasks, function(err,result){
553 var msgArray = new Array();
556 dbRoutes.getAicSite(req,res,{code:'failure', msg:msgArray},privilegeObj);
560 msgArray.push('Successfully updated AIC_SITE table.');
561 dbRoutes.getAicSite(req,res,{code:'success', msg:msgArray},privilegeObj);
567 // gamma - updateAicSwitch
568 router.post('/updateAicSwitch', csp.checkAuth, dbRoutes.checkDB, function(req,res){
570 var privilegeObj = req.session.loggedInAdmin;
572 tasks.push( function(callback) { dbRoutes.updateAicSwitch(req,res,callback); } );
573 async.series(tasks, function(err,result){
574 var msgArray = new Array();
577 dbRoutes.getAicSwitch(req,res,{code:'failure', msg:msgArray},privilegeObj);
581 msgArray.push('Successfully updated AIC_SWITCH table.');
582 dbRoutes.getAicSwitch(req,res,{code:'success', msg:msgArray},privilegeObj);
588 // gamma - updateAicAvailZone
589 router.post('/updateAicAvailZone', csp.checkAuth, dbRoutes.checkDB, function(req,res){
590 var privilegeObj = req.session.loggedInAdmin;
592 tasks.push( function(callback) { dbRoutes.updateAicAvailZone(req,res,callback); } );
593 async.series(tasks, function(err,result){
594 var msgArray = new Array();
597 dbRoutes.getAicAvailZone(req,res,{code:'failure', msg:msgArray},privilegeObj);
601 msgArray.push('Successfully updated AIC_AVAIL_ZONE_POOL table.');
602 dbRoutes.getAicAvailZone(req,res,{code:'success', msg:msgArray},privilegeObj);
608 // gamma - updateVlanPool
609 router.post('/updateVlanPool', csp.checkAuth, dbRoutes.checkDB, function(req,res){
611 var privilegeObj = req.session.loggedInAdmin;
613 tasks.push( function(callback) { dbRoutes.updateVlanPool(req,res,callback); } );
614 async.series(tasks, function(err,result){
615 var msgArray = new Array();
618 dbRoutes.getVlanPool(req,res,{code:'failure', msg:msgArray},privilegeObj);
622 msgArray.push('Successfully updated VLAN_ID_POOL table.');
623 dbRoutes.getVlanPool(req,res,{code:'success', msg:msgArray},privilegeObj);
629 // gamma - updateVpePool
630 router.post('/updateVpePool', csp.checkAuth, dbRoutes.checkDB, function(req,res){
631 var privilegeObj = req.session.loggedInAdmin;
633 tasks.push( function(callback) { dbRoutes.updateVpePool(req,res,callback); } );
634 async.series(tasks, function(err,result){
635 var msgArray = new Array();
638 dbRoutes.getVpePool(req,res,{code:'failure', msg:msgArray},privilegeObj);
642 msgArray.push('Successfully updated VPE_POOL table.');
643 dbRoutes.getVpePool(req,res,{code:'success', msg:msgArray},privilegeObj);
649 // gamma - updateVplspePool
650 router.post('/updateVplspePool', csp.checkAuth, dbRoutes.checkDB, function(req,res){
652 var privilegeObj = req.session.loggedInAdmin;
654 tasks.push( function(callback) { dbRoutes.updateVplspePool(req,res,callback); } );
655 async.series(tasks, function(err,result){
656 var msgArray = new Array();
659 dbRoutes.getVplspePool(req,res,{code:'failure', msg:msgArray},privilegeObj);
663 msgArray.push('Successfully updated VPLSPE_POOL table.');
664 dbRoutes.getVplspePool(req,res,{code:'success', msg:msgArray},privilegeObj);
671 // gamma - updateServiceHoming
672 router.post('/updateServiceHoming', csp.checkAuth, dbRoutes.checkDB, function(req,res){
674 var privilegeObj = req.session.loggedInAdmin;
676 tasks.push( function(callback) { dbRoutes.updateServiceHoming(req,res,callback); } );
677 async.series(tasks, function(err,result){
678 var msgArray = new Array();
681 dbRoutes.getServiceHoming(req,res,{code:'failure', msg:msgArray},privilegeObj);
685 msgArray.push('Successfully updated SERVICE_HOMING table.');
686 dbRoutes.getServiceHoming(req,res,{code:'success', msg:msgArray},privilegeObj);
693 router.post('/uploadVLAN', csp.checkAuth, dbRoutes.checkDB, upload.single('filename'), function(req, res, next){
695 var msgArray = new Array();
696 var privilegeObj = req.session.loggedInAdmin;
698 if(req.file.originalname){
699 if (req.file.originalname.size == 0) {
700 dbRoutes.getVlanPool(req,res,{code:'danger', msg:'There was an error uploading the file, please try again.'},privilegeObj);
703 fs.exists(req.file.path, function(exists) {
706 var str = req.file.originalname;
708 // check for valid filename format
709 var tagpos = str.search("_ctag_pool");
710 var csvpos = str.search(".csv");
711 if(tagpos != 13 || csvpos != 23){
712 var msgArray = new Array();
713 msgArray.push('Not a valid filename, format must be pp_YYYYMMDDHH_ctag_pool.csv');
714 dbRoutes.getVlanPool(req,res,{code:'failure', msg:msgArray},privilegeObj);
719 var csv = require('csv');
721 // the job of the parser is to convert a CSV file
722 // to a list of rows (array of rows)
723 var parser = csv.parse({
724 columns: function(line) {
725 // By defining this callback, we get handed the
726 // first line of the spreadsheet. Which we'll
727 // ignore and effectively skip this line from processing
729 skip_empty_lines: true
734 var transformer = csv.transform(function(data){
735 // this will get row by row data, so for example,
736 //logger.debug(data[0]+','+data[1]+','+data[2]);
737 f[row] = new Array();
738 for ( col=0; col<data.length; col++ )
740 f[row][col] = data[col];
746 // called when done with processing the CSV
747 transformer.on("finish", function() {
749 var funcArray = new Array();
751 function createFunction(lrow,res)
753 return function(callback) { dbRoutes.addVLAN(lrow,res,callback); }
756 // loop for each row and create an array of callbacks for async.parallelLimit
757 // had to create a function above 'createFunction' to get
758 for (var x=0; x<f.length; x++)
760 funcArray.push( createFunction(f[x],res) );
763 // make db calls in parrallel
764 //async.parallelLimit(funcArray, 5, function(err,result){
765 async.series(funcArray, function(err,result){
768 dbRoutes.getVlanPool(req,res, result,privilegeObj);
772 // result array has an entry in it, success entries are blank, figure out
773 // how many are not blank, aka errors.
775 for(var i=0;i<result.length;i++){
776 if ( result[i].length > 0 )
782 var rowsProcessed = f.length - rowError;
783 result.push(rowsProcessed + ' of ' + f.length + ' rows processed.');
786 result = {code:'failure', msg:result};
790 result = {code:'success', msg:result};
792 dbRoutes.getVlanPool(req,res,result,privilegeObj);
799 var stream = fs.createReadStream(req.file.path, "utf8");
800 stream.pipe(parser).pipe(transformer);
804 console.error('error:'+ex);
806 msgArray.push('There was an error uploading the file. '+ex);
807 dbRoutes.getVlanPool(req,res, {code:'danger', msg:msgArray}, privilegeObj);
813 msgArray.push('There was an error uploading the file.');
814 dbRoutes.getVlanPool(req,res, {code:'danger', msg:msgArray}, privilegeObj);
821 msgArray.push('There was an error uploading the file.');
822 dbRoutes.getVlanPool(req,res, {code:'danger', msg:msgArray}, privilegeObj);
830 router.post('/uploadAicSite', csp.checkAuth, dbRoutes.checkDB, upload.single('filename'), function(req, res){
832 var msgArray = new Array();
833 var privilegeObj = req.session.loggedInAdmin;
835 if(req.file.originalname){
836 if (req.file.originalname.size == 0) {
837 dbRoutes.getAicSite(req,res, {code:'danger', msg:'There was an error uploading the file, please try again.'}, privilegeObj);
840 fs.exists(req.file.path, function(exists) {
843 var str = req.file.originalname;
845 // check for valid filename format
846 var tagpos = str.search("_site");
847 var csvpos = str.search(".csv");
848 if(tagpos != 13 || csvpos != 18){
850 msgArray.push('Not a valid filename, format must be pp_YYYYMMDDHH_site.csv');
851 dbRoutes.getAicSite(req,res,{code:'failure', msg:msgArray},privilegeObj);
856 var csv = require('csv');
858 // the job of the parser is to convert a CSV file
859 // to a list of rows (array of rows)
860 var parser = csv.parse({
861 columns: function(line) {
862 // By defining this callback, we get handed the
863 // first line of the spreadsheet. Which we'll
864 // ignore and effectively skip this line from processing
866 skip_empty_lines: true
871 var transformer = csv.transform(function(data){
872 // this will get row by row data, so for example,
873 //logger.debug(data[0]+','+data[1]+','+data[2]);
875 // build an array of rows
876 f[row] = new Array();
877 for ( col=0; col<data.length; col++ )
879 f[row][col] = data[col];
884 // called when done with processing the CSV
885 transformer.on("finish", function() {
887 var funcArray = new Array();
889 function createFunction(lrow,res)
891 return function(callback) { dbRoutes.addAicSite(lrow,res,callback); }
894 // loop for each row and create an array of callbacks for async.parallelLimit
895 // had to create a function above 'createFunction' to get
896 for (var x=0; x<f.length; x++)
898 funcArray.push( createFunction(f[x],res) );
901 // make db calls in parrallel
902 async.parallelLimit(funcArray, 50, function(err,result){
905 dbRoutes.getAicSite(req,res, result,privilegeObj);
909 // result array has an entry in it, success entries are blank, figure out
910 // how many are not blank, aka errors.
912 for(var i=0;i<result.length;i++){
913 if ( result[i].length > 0 )
919 var rowsProcessed = f.length - rowError;
920 result.push(rowsProcessed + ' of ' + f.length + ' rows processed.');
923 result = {code:'failure', msg:result};
927 result = {code:'success', msg:result};
929 dbRoutes.getAicSite(req,res,result,privilegeObj);
935 var stream = fs.createReadStream(req.file.path, "utf8");
936 stream.pipe(parser).pipe(transformer);
941 msgArray.push('There was an error uploading the file. '+ex);
942 dbRoutes.getAicSite(req,res,{code:'danger', msg:msgArray},privilegeObj);
948 msgArray.push('There was an error uploading the file.');
949 dbRoutes.getAicSite(req,res,{code:'danger', msg:msgArray},privilegeObj);
956 msgArray.push('There was an error uploading the file.');
957 dbRoutes.getAicSite(req,res,{code:'danger', msg:msgArray},privilegeObj);
963 router.post('/uploadAicSwitch', csp.checkAuth, dbRoutes.checkDB, upload.single('filename'), function(req, res){
965 var msgArray = new Array();
966 var privilegeObj = req.session.loggedInAdmin;
968 if(req.file.originalname){
969 if (req.file.originalname.size == 0) {
970 dbRoutes.getAicSwitch(req,res,{code:'danger', msg:'There was an error uploading the file, please try again.'},privilegeObj);
973 fs.exists(req.file.path, function(exists) {
977 var str = req.file.orignalname;
979 // check for valid filename format
980 var tagpos = str.search("_switch");
981 var csvpos = str.search(".csv");
982 if(tagpos != 13 || csvpos != 20){
984 msgArray.push('Not a valid filename, format must be pp_YYYYMMDDHH_switch.csv');
985 dbRoutes.getAicSwitch(req,res,{code:'failure', msg:msgArray},privilegeObj);
990 var csv = require('csv');
992 // the job of the parser is to convert a CSV file
993 // to a list of rows (array of rows)
994 var parser = csv.parse({
995 columns: function(line) {
996 // By defining this callback, we get handed the
997 // first line of the spreadsheet. Which we'll
998 // ignore and effectively skip this line from processing
1000 skip_empty_lines: true
1004 var f = new Array();
1005 var transformer = csv.transform(function(data){
1006 // this will get row by row data, so for example,
1007 //logger.debug(data[0]+','+data[1]+','+data[2]);
1009 // build an array of rows
1010 f[row] = new Array();
1011 for ( col=0; col<data.length; col++ )
1013 f[row][col] = data[col];
1018 // called when done with processing the CSV
1019 transformer.on("finish", function() {
1021 var funcArray = new Array();
1023 function createFunction(lrow,res)
1025 return function(callback) { dbRoutes.addAicSwitch(lrow,res,callback); }
1028 // loop for each row and create an array of callbacks for async.parallelLimit
1029 // had to create a function above 'createFunction' to get
1030 for (var x=0; x<f.length; x++)
1032 funcArray.push( createFunction(f[x],res) );
1035 // make db calls in parrallel
1036 async.parallelLimit(funcArray, 50, function(err,result){
1039 dbRoutes.getAicSwitch(req,res,result,privilegeObj);
1043 // result array has an entry in it, success entries are blank, figure out
1044 // how many are not blank, aka errors.
1046 for(var i=0;i<result.length;i++){
1047 if ( result[i].length > 0 )
1053 var rowsProcessed = f.length - rowError;
1054 result.push(rowsProcessed + ' of ' + f.length + ' rows processed.');
1057 result = {code:'failure', msg:result};
1061 result = {code:'success', msg:result};
1063 dbRoutes.getAicSwitch(req,res,result,privilegeObj);
1069 var stream = fs.createReadStream(req.file.path, "utf8");
1070 stream.pipe(parser).pipe(transformer);
1074 msgArray.length = 0;
1075 msgArray.push('There was an error uploading the file. '+ex);
1076 dbRoutes.getAicSwitch(req,res,{code:'danger', msg:msgArray},privilegeObj);
1081 msgArray.length = 0;
1082 msgArray.push('There was an error uploading the file.');
1083 dbRoutes.getAicSwitch(req,res,{code:'danger', msg:msgArray},privilegeObj);
1089 msgArray.length = 0;
1090 msgArray.push('There was an error uploading the file.');
1091 dbRoutes.getAicSwitch(req,res,{code:'danger', msg:msgArray},privilegeObj);
1098 router.post('/uploadAicAvailZone', csp.checkAuth, dbRoutes.checkDB, upload.single('filename'), function(req, res){
1100 var msgArray = new Array();
1101 var privilegeObj = req.session.loggedInAdmin;
1103 if(req.file.originalname){
1104 if (req.file.originalname.size == 0) {
1105 dbRoutes.getAicAvailZone(req,res,{code:'failure', msg:'There was an error uploading the file, please try again.'},privilegeObj);
1108 fs.exists(req.file.path, function(exists) {
1112 var str = req.file.originalname;
1114 // check for valid filename format
1115 var tagpos = str.search("_availabilityzone");
1116 var csvpos = str.search(".csv");
1117 if(tagpos != 13 || csvpos != 30){
1118 msgArray.length = 0;
1119 msgArray.push('Not a valid filename, format must be pp_YYYYMMDDHH_availabilityzone.csv');
1120 dbRoutes.getAicAvailZone(req,res,{code:'failure', msg:msgArray},privilegeObj);
1125 var csv = require('csv');
1127 // the job of the parser is to convert a CSV file
1128 // to a list of rows (array of rows)
1129 var parser = csv.parse({
1130 columns: function(line) {
1131 // By defining this callback, we get handed the
1132 // first line of the spreadsheet. Which we'll
1133 // ignore and effectively skip this line from processing
1135 skip_empty_lines: true
1139 var f = new Array();
1140 var transformer = csv.transform(function(data){
1141 // this will get row by row data, so for example,
1142 //logger.debug(data[0]+','+data[1]+','+data[2]);
1144 // build an array of rows
1145 f[row] = new Array();
1146 for ( col=0; col<data.length; col++ )
1148 f[row][col] = data[col];
1153 // called when done with processing the CSV
1154 transformer.on("finish", function() {
1156 var funcArray = new Array();
1158 function createFunction(lrow,res)
1160 return function(callback) { dbRoutes.addAicAvailZone(lrow,res,callback); }
1163 // loop for each row and create an array of callbacks for async.parallelLimit
1164 // had to create a function above 'createFunction' to get
1165 for (var x=0; x<f.length; x++)
1167 funcArray.push( createFunction(f[x],res) );
1170 // make db calls in parrallel
1171 async.parallelLimit(funcArray, 50, function(err,result){
1174 dbRoutes.getAicAvailZone(req,res,result,privilegeObj);
1178 // result array has an entry in it, success entries are blank, figure out
1179 // how many are not blank, aka errors.
1181 for(var i=0;i<result.length;i++){
1182 if ( result[i].length > 0 )
1188 var rowsProcessed = f.length - rowError;
1189 result.push(rowsProcessed + ' of ' + f.length + ' rows processed.');
1192 result = {code:'failure', msg:result};
1196 result = {code:'success', msg:result};
1198 dbRoutes.getAicAvailZone(req,res,result,privilegeObj);
1204 var stream = fs.createReadStream(req.file.path, "utf8");
1205 stream.pipe(parser).pipe(transformer);
1209 msgArray.length = 0;
1210 msgArray.push('There was an error uploading the file. '+ex);
1211 dbRoutes.getAicAvailZone(req,res,{code:'danger', msg:msgArray},privilegeObj);
1216 msgArray.length = 0;
1217 msgArray.push('There was an error uploading the file.');
1218 dbRoutes.getAicAvailZone(req,res,{code:'danger', msg:msgArray},privilegeObj);
1224 msgArray.length = 0;
1225 msgArray.push('There was an error uploading the file.');
1226 dbRoutes.getAicAvailZone(req,res,{code:'danger', msg:msgArray},privilegeObj);
1233 router.post('/uploadVpePool', csp.checkAuth, dbRoutes.checkDB, upload.single('filename'), function(req, res){
1235 var msgArray = new Array();
1236 var privilegeObj = req.session.loggedInAdmin;
1238 if(req.file.originalname){
1239 if (req.file.originalname.size == 0) {
1240 dbRoutes.getVpePool(req,res,{code:'failure', msg:'There was an error uploading the file, please try again.'},privilegeObj);
1243 fs.exists(req.file.path, function(exists) {
1247 var str = req.file.originalname;
1249 // check for valid filename format
1250 var tagpos = str.search("_vpe");
1251 var csvpos = str.search(".csv");
1252 if(tagpos != 13 || csvpos != 17){
1253 msgArray.length = 0;
1254 msgArray.push('Not a valid filename, format must be pp_YYYYMMDDHH_vpe.csv');
1255 var resultObj = {code:'failure', msg:msgArray};
1256 dbRoutes.getVpePool(req,res,resultObj,privilegeObj);
1261 var csv = require('csv');
1263 // the job of the parser is to convert a CSV file
1264 // to a list of rows (array of rows)
1265 var parser = csv.parse({
1266 columns: function(line) {
1267 // By defining this callback, we get handed the
1268 // first line of the spreadsheet. Which we'll
1269 // ignore and effectively skip this line from processing
1271 skip_empty_lines: true
1275 var f = new Array();
1276 var transformer = csv.transform(function(data){
1277 // this will get row by row data, so for example,
1278 //logger.debug(data[0]+','+data[1]+','+data[2]);
1280 // build an array of rows
1281 f[row] = new Array();
1282 for ( col=0; col<data.length; col++ )
1284 f[row][col] = data[col];
1289 // called when done with processing the CSV
1290 transformer.on("finish", function() {
1292 var funcArray = new Array();
1294 function createFunction(lrow,res)
1296 return function(callback) { dbRoutes.addVpePool(lrow,res,callback); }
1299 // loop for each row and create an array of callbacks for async.parallelLimit
1300 // had to create a function above 'createFunction' to get
1301 for (var x=0; x<f.length; x++)
1303 funcArray.push( createFunction(f[x],res) );
1306 // make db calls in parrallel
1307 async.parallelLimit(funcArray, 50, function(err,result){
1310 dbRoutes.getVpePool(req,res,result,privilegeObj);
1314 // result array has an entry in it, success entries are blank, figure out
1315 // how many are not blank, aka errors.
1317 for(var i=0;i<result.length;i++){
1318 if ( result[i].length > 0 )
1324 var rowsProcessed = f.length - rowError;
1325 result.push(rowsProcessed + ' of ' + f.length + ' rows processed.');
1328 result = {code:'failure', msg:result};
1332 result = {code:'success', msg:result};
1334 dbRoutes.getVpePool(req,res,result,privilegeObj);
1340 var stream = fs.createReadStream(req.file.path, "utf8");
1341 stream.pipe(parser).pipe(transformer);
1345 msgArray.length = 0;
1346 msgArray.push('There was an error uploading the file. '+ex);
1347 dbRoutes.getVpePool(req,res,{code:'danger', msg:msgArray},privilegeObj);
1352 msgArray.length = 0;
1353 msgArray.push('There was an error uploading the file.');
1354 dbRoutes.getVpePool(req,res,{code:'danger', msg:msgArray},privilegeObj);
1360 msgArray.length = 0;
1361 msgArray.push('There was an error uploading the file.');
1362 dbRoutes.getVpePool(req,res,{code:'danger', msg:msgArray},privilegeObj);
1369 router.post('/uploadVplspePool', csp.checkAuth, dbRoutes.checkDB, upload.single('filename'), function(req, res){
1371 var msgArray = new Array();
1372 var privilegeObj = req.session.loggedInAdmin;
1374 if(req.file.originalname){
1375 if (req.file.originalname.size == 0) {
1376 dbRoutes.getVplspePool(req,res,{code:'failure', msg:'There was an error uploading the file, please try again.'},privilegeObj);
1379 fs.exists(req.file.path, function(exists) {
1383 var str = req.file.originalname;
1385 // check for valid filename format
1386 var tagpos = str.search("_vpls");
1387 var csvpos = str.search(".csv");
1388 if(tagpos != 13 || csvpos != 18){
1389 msgArray.length = 0;
1390 msgArray.push('Not a valid filename, format must be pp_YYYYMMDDHH_vpls.csv');
1391 dbRoutes.getVplspePool(req,res,{code:'failure', msg:msgArray},privilegeObj);
1396 var csv = require('csv');
1398 // the job of the parser is to convert a CSV file
1399 // to a list of rows (array of rows)
1400 var parser = csv.parse({
1401 columns: function(line) {
1402 // By defining this callback, we get handed the
1403 // first line of the spreadsheet. Which we'll
1404 // ignore and effectively skip this line from processing
1406 skip_empty_lines: true
1410 var f = new Array();
1411 var transformer = csv.transform(function(data){
1412 // this will get row by row data, so for example,
1413 //logger.debug(data[0]+','+data[1]+','+data[2]);
1415 // build an array of rows
1416 f[row] = new Array();
1417 for ( col=0; col<data.length; col++ )
1419 f[row][col] = data[col];
1424 // called when done with processing the CSV
1425 transformer.on("finish", function() {
1427 var funcArray = new Array();
1429 function createFunction(lrow,res)
1431 return function(callback) { dbRoutes.addVplspePool(lrow,res,callback); }
1433 // loop for each row and create an array of callbacks for async.parallelLimit
1434 // had to create a function above 'createFunction' to get
1435 for (var x=0; x<f.length; x++)
1437 funcArray.push( createFunction(f[x],res) );
1440 // make db calls in parrallel
1441 async.parallelLimit(funcArray, 50, function(err,result){
1444 dbRoutes.getVplspePool(req,res,result,privilegeObj);
1448 // result array has an entry in it, success entries are blank, figure out
1449 // how many are not blank, aka errors.
1451 for(var i=0;i<result.length;i++){
1452 if ( result[i].length > 0 )
1457 var rowsProcessed = f.length - rowError;
1458 result.push(rowsProcessed + ' of ' + f.length + ' rows processed.');
1461 result = {code:'failure', msg:result};
1465 result = {code:'success', msg:result};
1467 dbRoutes.getVplspePool(req,res,result,privilegeObj);
1473 var stream = fs.createReadStream(req.file.path, "utf8");
1474 stream.pipe(parser).pipe(transformer);
1478 msgArray.length = 0;
1479 msgArray.push('There was an error uploading the file. '+ex);
1480 dbRoutes.getVplspePool(req,res,{code:'danger', msg:msgArray},privilegeObj);
1485 msgArray.length = 0;
1486 msgArray.push('There was an error uploading the file.');
1487 dbRoutes.getVplspePool(req,res,{code:'danger', msg:msgArray},privilegeObj);
1493 msgArray.length = 0;
1494 msgArray.push('There was an error uploading the file.');
1495 dbRoutes.getVplspePool(req,res,{code:'danger', msg:msgArray},privilegeObj);
1502 router.post('/uploadServiceHoming', csp.checkAuth, dbRoutes.checkDB, upload.single('filename'), function(req, res)
1504 var msgArray = new Array();
1505 var privilegeObj = req.session.loggedInAdmin;
1507 if(req.file.originalname)
1509 if (req.file.originalname.size == 0) {
1510 dbRoutes.getServiceHoming(req,res,{code:'failure', msg:'There was an error uploading the file, please try again.'},privilegeObj);
1513 fs.exists(req.file.path, function(exists)
1517 var str = req.file.originalname;
1519 // check for valid filename format
1520 var csvpos = str.search(".csv");
1521 if( (l_.startsWith(str,'aichoming_') != true) || csvpos != 18)
1523 msgArray.length = 0;
1524 msgArray.push('Not a valid filename, format must be aichoming_mmddYYYY.csv');
1525 //msgArray.push('Not a valid filename, format must be pp_YYYYMMDDHH_vpls.csv');
1526 dbRoutes.getServiceHoming(req,res,{code:'failure', msg:msgArray},privilegeObj);
1532 var csv = require('csv');
1534 // the job of the parser is to convert a CSV file
1535 // to a list of rows (array of rows)
1536 var parser = csv.parse({
1537 columns: function(line) {
1538 // By defining this callback, we get handed the
1539 // first line of the spreadsheet. Which we'll
1540 // ignore and effectively skip this line from processing
1542 skip_empty_lines: true
1546 var f = new Array();
1547 var csvrows = new Array();
1548 var transformer = csv.transform(function(data){
1549 // this will get row by row data, so for example,
1550 //logger.debug(data[0]+','+data[1]+','+data[2]);
1552 // build an array of rows
1553 f[row] = new Array();
1554 for ( col=0; col<data.length; col++ )
1556 f[row][col] = data[col];
1561 // called when done with processing the CSV
1562 transformer.on("finish", function()
1564 var funcArray = new Array();
1566 function createFunction(lrow,res)
1568 return function(callback) { dbRoutes.addServiceHoming(lrow,req,res,callback); }
1570 funcArray.push(function(callback) {
1571 dbRoutes.saveServiceHoming(req,res,callback);
1573 // loop for each row and create an array of callbacks for async.parallelLimit
1574 // had to create a function above 'createFunction' to get
1575 for (var x=0; x<f.length; x++)
1577 funcArray.push( createFunction(f[x],res) );
1580 // make db calls in series
1581 async.series(funcArray, function(err,result)
1585 result = {code:'failure', msg:result};
1586 dbRoutes.getServiceHoming(req,res,result,privilegeObj);
1590 { // result array has an entry in it, success entries are blank, figure out
1591 // how many are not blank, aka errors.
1593 for(var i=0;i<result.length;i++)
1595 if ( result[i].length > 0 )
1600 var rowsProcessed = f.length - rowError;
1601 result.push(rowsProcessed + ' of ' + f.length + ' rows processed.');
1604 result = {code:'failure', msg:result};
1608 result = {code:'success', msg:result};
1610 dbRoutes.getServiceHoming(req,res,result,privilegeObj);
1616 var stream = fs.createReadStream(req.file.path, "utf8");
1617 stream.pipe(parser).pipe(transformer);
1621 msgArray.length = 0;
1622 msgArray.push('There was an error uploading the file. '+ex);
1623 dbRoutes.getServiceHoming(req,res,{code:'danger', msg:msgArray},privilegeObj);
1628 msgArray.length = 0;
1629 msgArray.push('There was an error uploading the file.');
1630 dbRoutes.getServiceHoming(req,res,{code:'danger', msg:msgArray},privilegeObj);
1637 msgArray.length = 0;
1638 msgArray.push('There was an error uploading the file.');
1639 dbRoutes.getServiceHoming(req,res,{code:'danger', msg:msgArray},privilegeObj);
1644 function removeNL(s) {
1646 ** Remove NewLine, CarriageReturn and Tab characters from a String
1647 ** s string to be processed
1648 ** returns new string
1651 for (i=0; i < s.length; i++)
1653 if (s.charAt(i) != '\n' &&
1654 s.charAt(i) != '\r' &&
1655 s.charAt(i) != '\t')
1662 function padLeft(nr, n, str){
1663 return Array(n-String(nr).length+1).join(str||'0')+nr;
1667 module.exports = router;