Update user data handling in UserIDMiddlewareAD.js and refactor getUserData function
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2024-04-17 17:00:04 +02:00
parent 7a02f2682c
commit 06b1936840
9 changed files with 163 additions and 118 deletions

View File

@@ -4,19 +4,22 @@ const passport = require('passport');
const bodyParser = require('body-parser');
const { logger, logRequestInfo, ErrorLogger } = require('./config/logs');
const path = require("path");
require('dotenv').config();
const { version } = require('./package.json');
const axios = require('axios');
const app = express();
const flash = require('connect-flash');
const crypto = require('crypto');
const fs = require('fs');
const SystemReport = require('./models/reportManager.js');
const routes = require('./routes/routes.js');
const cron = require('node-cron');
require('dotenv').config();
const app = express();
require('./models/fileCreated.js');
let setup;
try {
setup = JSON.parse(fs.readFileSync(path.join('/data', 'setup.json'), 'utf8'));
setup = JSON.parse(fs.readFileSync(path.join(__dirname, 'data', 'setup.json'), 'utf8'));
} catch (err) {
console.error('Error reading setup.json:', err);
process.exit(1);
@@ -33,8 +36,10 @@ if (setup.ldap !== undefined) {
app.use(express.static(path.join(__dirname, 'public')));
app.get(['/data/user.json', '/data/file_info.json', '/data/setup.json'], (req, res) => {
res.status(403).json({ error: 'Access Denied. You do not have permission to access this resource.' });
});app.use(express.urlencoded({ extended: true }));
res.status(403).json({ error: 'Access Denied. You do not have permission to access this resource.' });
});
app.use(express.urlencoded({ extended: true }));
function generateSecretKey() {
return crypto.randomBytes(64).toString('hex');
@@ -54,7 +59,6 @@ app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(flash());
const routes = require('./routes/routes.js');
app.use('/public', express.static(path.join(__dirname, 'public')));
app.set('view engine', 'ejs');
app.set('views', __dirname + '/views');
@@ -62,13 +66,12 @@ app.use(routes);
app.use(logRequestInfo);
const cron = require('node-cron');
cron.schedule('00 03 * * *', async () => {
try {
const report = await SystemReport.generate();
if (report !== null) {
logger.info('System error report generated successfully');
logger.info('System error report generated successfully');
}
} catch (err) {
ErrorLogger.error('Error generating report :', err);
@@ -77,7 +80,7 @@ cron.schedule('00 03 * * *', async () => {
cron.schedule('0 * * * *', async () => {
try {
const fileInfoData = await fs.promises.readFile(path.join(__dirname,'/data/', 'file_info.json'), 'utf8');
const fileInfoData = await fs.promises.readFile(path.join(__dirname, '/data/', 'file_info.json'), 'utf8');
const fileInfo = JSON.parse(fileInfoData);
const now = new Date();
@@ -112,15 +115,9 @@ app.listen(PORT, () => {
console.clear();
if (logger) {
logger.info(`🚀 Your server is available and running on port ${PORT}`);
logger.info(`⚜️ Application developed by Dinawo, part of the SwiftLogic Labs group`);
logger.info(`⚜️ Application developed by Dinawo, part of the SwiftLogic Labs group`);
logger.info(`♨️ Version: ${version}`);
console.log('');
const filesData = fs.readFileSync('files.json', 'utf8');
const files = JSON.parse(filesData);
const numberOfFiles = Object.values(files).flat().length;
logger.info(`🔰 Number of files activated during server startup: ${numberOfFiles}`);
} else {
console.error('🔴 Logger is not initialized');
}