CEO updated

This commit is contained in:
andrei-mihnea-cerbu
2024-04-20 03:18:44 +03:00
parent 869305a491
commit 57c2c7ec55
81 changed files with 3517 additions and 1035 deletions
+1 -7
View File
@@ -1,7 +1 @@
{
"4659e71f-9bb4-4902-97d8-097efa138333": {
"ip": "192.168.0.195",
"directoryStructure": "{\"to_backup\":{\"files\":[\"fisier_random.txt\"],\"alte fis\":{\"files\":[\"alt fisier.txt\",\"fisier now.txt\",\"New Microsoft Excel Worksheet.xlsx\"]}}}",
"totalSize": 6197
}
}
{}
+3 -2
View File
@@ -1,6 +1,7 @@
{
"id": "335ae110091d3bc5fbc90d5e3786890e",
"id": "7c0ef9d5-23ed-47a6-bfb4-fdcfce436904",
"name": "CEO",
"email": "ceo@yourfirm.com",
"password": "335ae110091d3bc5fbc90d5e3786890e"
"password": "b85cfc54e8dda76e72d7bde7b10ce30a",
"department": "CEO"
}
+4 -4
View File
@@ -1,10 +1,10 @@
{
"1": {
"name": "HR",
"key": "65388e02b16e1cc530502492384ebd29ee6cda57840235d714d59dd460ae148a"
"name": "CEO",
"key": "6f444243063271cc1ea3ccb3621dfebc352fd40e2f58eb6c97b26b7e34fde7a1"
},
"2": {
"name": "Contabili",
"key": "572854d54c42f03ddcbb2beeae574dc4fcd33b251670d4983be49c4242c2d88a"
"name": "HR",
"key": "2c480e5e3fdaca10d4d838b1b16fb44ce0f57238cb4343a839e065f8d6e41dc7"
}
}
+2 -2
View File
@@ -1,9 +1,9 @@
[
{
"id": "4659e71f-9bb4-4902-97d8-097efa138333",
"id": "59c712d9-e6dd-438f-aec9-31ca2ae750e6",
"name": "Andrei Cerbu",
"email": "a@c.com",
"password": "5447045dc3cfaafdb49b365e31dad41eb88616b0b1449930e55fd3a70bd8cee4",
"department": "Contabili"
"department": "HR"
}
]
+13 -2
View File
@@ -26,15 +26,26 @@ router.get('/reset_server', validateBody, (req, res) => {
const ceoDB = req.app.get('ceoDB');
usersDB.writeFile([]);
departmentsDB.writeFile([]);
departmentsDB.writeFile({});
backupSchemesDB.writeFile({});
ceoDB.writeFile({
id: uuidv4(),
name: "CEO",
email: "ceo@yourfirm.com",
password: crypto.randomBytes(16).toString('hex')
password: crypto.randomBytes(16).toString('hex'),
department: "CEO"
});
const ceoDepartment = {
name: "CEO",
key: crypto.randomBytes(32).toString('hex')
}
const departmentsJson = departmentsDB.readFile();
departmentsJson[1] = ceoDepartment;
departmentsDB.writeFile(departmentsJson);
res.status(httpStatus.OK).json({ message: "Resetting the server..." });
});
+12
View File
@@ -44,6 +44,18 @@ router.get('/', validateBody, (req, res) => {
});
});
router.get('/:userId', (req, res) => {
const userId = req.params.userId;
const backupSchemesDB = req.app.get('backupSchemesDB');
let backupSchemesJson = backupSchemesDB.readFile();
const ip = backupSchemesJson[userId].ip;
if (ip) {
res.status(httpStatus.OK).json({message: "IP found", data: ip});
} else {
res.status(httpStatus.NOT_FOUND).send({message: "IP not found"});
}
});
router.use((req, res) => {
return res.status(httpStatus.NOT_FOUND).json({message: "Endpoint not found"});
})
+12 -7
View File
@@ -59,7 +59,7 @@ router.post('/login', validateBody, (req, res) => {
return res.status(httpStatus.UNAUTHORIZED).json({message: 'Invalid credentials.'});
}
return res.status(httpStatus.Ok).json({message: 'Logged in.'});
return res.status(httpStatus.OK).json({message: 'Logged in.', data: ceoDB.readFile()});
});
router.post('/set_security_levels', validateBody, (req, res) => {
@@ -99,13 +99,16 @@ router.delete('/users/:id', validateBody, (req, res) => {
const usersDB = req.app.get('usersDB');
const { id } = req.params;
const userIndex = usersDB.findIndexByKeyValueInArray('id', id);
if(userIndex === -1){
let usersJson = usersDB.readFile();
const userIndex = usersJson.findIndex(user => user.id === id);
if (userIndex === -1) {
return res.status(httpStatus.NOT_FOUND).json({message: 'User not found in system.'});
}
let usersJson = usersDB.readFile;
usersJson.splice(userIndex, 1);
usersDB.writeFile(usersJson);
return res.status(httpStatus.OK).json({ message: 'User deleted successfully.' });
@@ -114,6 +117,7 @@ router.delete('/users/:id', validateBody, (req, res) => {
router.post('/departments', validateBody, (req, res) => {
const departmentsDB = req.app.get('departmentsDB');
const { name } = req.body;
console.log(name);
let jsonDepartments = departmentsDB.readFile();
const nameExists = Object.values(jsonDepartments).some(department => department.name === name);
@@ -164,17 +168,18 @@ router.delete('/departments/:name', validateBody, (req, res) => {
router.put('/', validateBody, (req, res) => {
const ceoDB = req.app.get('ceoDB');
const { name, email } = req.body;
const {id} = ceoDB.readFile()
const {id, department} = ceoDB.readFile()
const newCeo = {
id: id,
name: name,
email: email,
password: crypto.randomBytes(16).toString('hex')
password: crypto.randomBytes(16).toString('hex'),
department: department
}
ceoDB.writeFile(newCeo);
return res.status(httpStatus.OK).json({message: 'Information modified.'});
return res.status(httpStatus.OK).json({message: 'Information modified.', data: newCeo});
});
router.get('/get_decrypt_keys', (req, res) => {