Skip to content

Commit

Permalink
Merge pull request #87 from NSWC-Crane/CHRIS_DEV
Browse files Browse the repository at this point in the history
  • Loading branch information
crodriguez6497 authored Aug 13, 2024
2 parents bd52c57 + b1c6f89 commit 7f4fc9c
Show file tree
Hide file tree
Showing 119 changed files with 15,781 additions and 19,467 deletions.
8 changes: 4 additions & 4 deletions C-PAT/C-PAT.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
"usageType": "openSource",
"exemptionText": null
},
"laborHours": 3000,
"version": "0.2.0",
"laborHours": 3200,
"version": "0.3.0",
"date": {
"created": "2023-06-01",
"lastModified": "2024-04-24",
"metadataLastUpdated": "2024-04-24"
"lastModified": "2024-08-13",
"metadataLastUpdated": "2024-08-13"
},
"disclaimerText": "",
"disclaimerURL": ""
Expand Down
74 changes: 74 additions & 0 deletions api/Controllers/IAV.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
!#######################################################################
! C-PATTM SOFTWARE
! CRANE C-PATTM plan of action and milestones software. Use is governed by the Open Source Academic Research License Agreement contained in the file
! crane_C_PAT.1_license.txt, which is part of this software package. BY
! USING OR MODIFYING THIS SOFTWARE, YOU ARE AGREEING TO THE TERMS AND
! CONDITIONS OF THE LICENSE.
!########################################################################
*/

const iavService = require('../Services/iavService')


module.exports.getVramDataUpdatedDate = async function getVramDataUpdatedDate(req, res, next) {
try {
const vramUpdatedDate = await iavService.getVramDataUpdatedDate(req, res, next);
res.status(200).json(vramUpdatedDate);
} catch (error) {
if (error.status === 400) {
res.status(400).json({ error: 'Validation Error', detail: error.errors });
} else {
res.status(500).json({ error: 'Internal Server Error', detail: error.message });
}
}
}

module.exports.getIAVTableData = async function getIAVTableData(req, res, next) {
try {
const iavTableData = await iavService.getIAVTableData(req, res, next);
res.status(200).json(iavTableData);
} catch (error) {
if (error.status === 400) {
res.status(400).json({ error: 'Validation Error', detail: error.errors });
} else {
res.status(500).json({ error: 'Internal Server Error', detail: error.message });
}
}
}

module.exports.mapIAVPluginIds = async function mapIAVPluginIds(req, res, next) {
try {
const updatedCount = await iavService.mapIAVPluginIds(req.body);
res.status(200).json({ message: 'PluginIDs mapped updated successfully', updatedCount });
} catch (error) {
if (error.status === 400) {
res.status(400).json({ error: 'Validation Error', detail: error.errors });
} else {
res.status(500).json({ error: 'Internal Server Error', detail: error.message });
}
}
}

module.exports.getIAVPluginIds = async function getIAVPluginIds(req, res, next) {
try {
const iavPluginIDs = await iavService.getIAVPluginIds(req, res, next);
res.status(200).json(iavPluginIDs);
} catch (error) {
if (error.status === 400) {
res.status(400).json({ error: 'Validation Error', detail: error.errors });
} else {
res.status(500).json({ error: 'Internal Server Error', detail: error.message });
}
}
}

module.exports.getIAVInfoForPlugins = async function getIAVInfoForPlugins(req, res, next) {
try {
const pluginIDs = req.query.pluginIDs;
const iavInfo = await iavService.getIAVInfoForPlugins(pluginIDs);
res.status(200).json(iavInfo);
} catch (error) {
res.status(500).json({ error: 'Internal Server Error', detail: error.message });
}
};
31 changes: 29 additions & 2 deletions api/Controllers/Import.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

const importService = require('../Services/importService');

module.exports.updatePoamAssetsWithStigManagerData = async function updatePoamAssetsWithStigManagerData(req, res, next) {
module.exports.putPoamAssetsWithStigManagerData = async function putPoamAssetsWithStigManagerData(req, res, next) {
try {
const poamAsset = await importService.updatePoamAssetsWithStigManagerData(req, res, next);
const poamAsset = await importService.putPoamAssetsWithStigManagerData(req, res, next);
res.status(200).json(poamAsset);
} catch (error) {
if (error.status === 400) {
Expand Down Expand Up @@ -46,6 +46,33 @@ module.exports.uploadPoamFile = async (req, res, next) => {
});
};

module.exports.importVRAMExcel = async (req, res, next) => {
const file = req.files[0];

if (!file) {
return res.status(400).json({ message: "No file uploaded" });
}

importService.excelFilter(req, file, async (err) => {
if (err) {
return res.status(400).json({
message: err.message,
});
} else {
try {
const result = await importService.importVRAMExcel(file);
res.status(201).json(result);
} catch (error) {
console.error('Error processing VRAM file:', error);
res.status(500).json({
message: "Could not process the file",
error: error.message,
});
}
}
});
};

module.exports.postStigManagerAssets = async function postStigManagerAssets(req, res) {
try {
const { assets } = req.body;
Expand Down
13 changes: 13 additions & 0 deletions api/Controllers/Poam.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ module.exports.getPoamsBySubmitterId = async function getPoamsBySubmitterId(req,
}
};

module.exports.getPluginIDsWithPoam = async function getPluginIDsWithPoam(req, res, next) {
try {
const pluginIDs = await poamService.getPluginIDsWithPoam(req, res, next);
res.status(200).json(pluginIDs);
} catch (error) {
if (error.status === 400) {
res.status(400).json({ error: 'Validation Error', detail: error.errors });
} else {
res.status(500).json({ error: 'Internal Server Error', detail: error.message });
}
}
};

module.exports.postPoam = async function postPoam(req, res, next) {
try {
const poam = await poamService.postPoam(req, res, next);
Expand Down
6 changes: 6 additions & 0 deletions api/Models/collection.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = (sequelize, DataTypes) => {
},
description: {
type: DataTypes.STRING(255),
allowNull: true,
},
created: {
type: DataTypes.DATE,
Expand All @@ -26,6 +27,11 @@ module.exports = (sequelize, DataTypes) => {
},
collectionOrigin: {
type: DataTypes.STRING(15),
allowNull: true,
},
originCollectionId: {
type: DataTypes.INTEGER,
allowNull: true,
},
}, {
tableName: 'collection',
Expand Down
18 changes: 18 additions & 0 deletions api/Models/config.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = (sequelize, DataTypes) => {
const Config = sequelize.define('Config', {
key: {
type: DataTypes.STRING(45),
primaryKey: true,
allowNull: false
},
value: {
type: DataTypes.STRING(255),
allowNull: false
}
}, {
tableName: 'config',
timestamps: false
});

return Config;
};
61 changes: 61 additions & 0 deletions api/Models/iav.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
module.exports = (sequelize, DataTypes) => {
const IAV = sequelize.define('IAV', {
iav: {
type: DataTypes.STRING(25),
primaryKey: true,
allowNull: false
},
status: {
type: DataTypes.STRING(25),
allowNull: true
},
title: {
type: DataTypes.STRING(255),
allowNull: false
},
iavCat: {
type: DataTypes.TINYINT(1),
allowNull: true
},
type: {
type: DataTypes.CHAR(1),
allowNull: false
},
releaseDate: {
type: DataTypes.DATEONLY,
allowNull: true
},
navyComplyDate: {
type: DataTypes.DATEONLY,
allowNull: true
},
supersededBy: {
type: DataTypes.STRING(25),
allowNull: true
},
knownExploits: {
type: DataTypes.STRING(3),
allowNull: true
},
knownDodIncidents: {
type: DataTypes.STRING(3),
allowNull: true
},
nessusPlugins: {
type: DataTypes.INTEGER,
allowNull: true
}
}, {
tableName: 'iav',
timestamps: false
});

IAV.associate = function (models) {
IAV.belongsToMany(models.IAV_Plugin, {
through: 'iav_plugin',
foreignKey: 'iav'
});
};

return IAV;
};
34 changes: 34 additions & 0 deletions api/Models/iav_plugin.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module.exports = (sequelize, DataTypes) => {
const IAV_Plugin = sequelize.define('IAV_Plugin', {
iav: {
type: DataTypes.STRING(25),
primaryKey: true,
allowNull: false,
references: {
model: 'iav',
key: 'iav'
}
},
pluginID: {
type: DataTypes.INTEGER,
primaryKey: true,
allowNull: false
}
}, {
tableName: 'iav_plugin',
timestamps: false,
indexes: [
{
fields: ['pluginID']
}
]
});

IAV_Plugin.associate = function (models) {
IAV_Plugin.belongsToMany(models.IAV, {
through: 'iav_plugin',
foreignKey: 'pluginID'
});
};
return IAV_Plugin;
};
27 changes: 20 additions & 7 deletions api/Services/collectionService.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ exports.getCollections = async function getCollections(userNameInput, req, res,
exports.getCollectionBasicList = async function getCollectionBasicList(req, res, next) {
try {
return await withConnection(async (connection) => {
const sql = "SELECT collectionId, collectionName FROM collection";
const sql = "SELECT collectionId, collectionName, collectionOrigin, originCollectionId FROM collection";
const [rows] = await connection.query(sql);
return rows;
});
Expand All @@ -115,15 +115,28 @@ exports.getCollectionBasicList = async function getCollectionBasicList(req, res,
};

exports.postCollection = async function postCollection(req, res, next) {
if (!req.body.collectionName) req.body.collectionName = undefined
if (!req.body.description) req.body.description = ""
if (!req.body.assetCount) req.body.assetCount = 0;
if (!req.body.poamCount) req.body.poamCount = 0;
if (!req.body.collectionName) {
return next({
status: 400,
errors: {
collectionName: 'is required',
}
});
}
if (!req.body.description) {
req.body.description = ""
}
if (!req.body.collectionOrigin) {
req.body.collectionOrigin = "C-PAT"
}
if (!req.body.originCollectionId) {
req.body.originCollectionId = null;
}

try {
return await withConnection(async (connection) => {
let sql_query = `INSERT INTO cpat.collection (collectionName, description, assetCount, poamCount) VALUES (?, ?, ?, ?) `
await connection.query(sql_query, [req.body.collectionName, req.body.description, 0, 0, 0])
let sql_query = `INSERT INTO cpat.collection (collectionName, description, collectionOrigin, originCollectionId) VALUES (?, ?, ?, ?) `
await connection.query(sql_query, [req.body.collectionName, req.body.description, req.body.collectionOrigin, req.body.originCollectionId])
let sql = "SELECT * FROM cpat.collection WHERE collectionId = LAST_INSERT_ID();"
let [rowCollection] = await connection.query(sql)

Expand Down
Loading

0 comments on commit 7f4fc9c

Please sign in to comment.