backup + decriptare toate fisiere done
This commit is contained in:
@@ -6,7 +6,12 @@ const app = express();
|
|||||||
const port = process.env.PORT || 5000;
|
const port = process.env.PORT || 5000;
|
||||||
|
|
||||||
app.use(cors({
|
app.use(cors({
|
||||||
allowedHeaders: ['Authorization', 'Content-Type'] // Add 'Authorization' to the list of allowed headers
|
origin: '*', // Allow all origins
|
||||||
|
methods: 'GET,POST,PUT,DELETE,PATCH', // Allow all methods
|
||||||
|
allowedHeaders: '*', // Allow all headers
|
||||||
|
credentials: true, // Enable credentials
|
||||||
|
preflightContinue: false,
|
||||||
|
optionsSuccessStatus: 204 // Some legacy browsers (IE11, various SmartTVs) choke on 204
|
||||||
}));
|
}));
|
||||||
app.use(json());
|
app.use(json());
|
||||||
|
|
||||||
|
|||||||
@@ -1 +1,7 @@
|
|||||||
{}
|
{
|
||||||
|
"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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,13 +10,12 @@ const dirStructureModel = Joi.object({
|
|||||||
'string.ip': 'The IP address "{{#value}}" is not valid.',
|
'string.ip': 'The IP address "{{#value}}" is not valid.',
|
||||||
'any.required': 'IP address is required.'
|
'any.required': 'IP address is required.'
|
||||||
}),
|
}),
|
||||||
dir_config: Joi.string().required().messages({
|
directoryStructure: Joi.string().required().messages({
|
||||||
'any.required': 'Directory configuration is required',
|
'any.required': 'Directory configuration is required',
|
||||||
'string.empty': 'Directory configuration must not be empty'
|
'string.empty': 'Directory configuration must not be empty'
|
||||||
}),
|
}),
|
||||||
total_space: Joi.number().positive().required().messages({
|
totalSize: Joi.number().required().messages({
|
||||||
'any.required': 'Total space is required',
|
'any.required': 'Total space is required',
|
||||||
'number.positive': 'Total space must be a positive number',
|
|
||||||
'number.base': 'Total space must be a number'
|
'number.base': 'Total space must be a number'
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ function validateBody(req, res, next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(validationSchema !== undefined){
|
if(validationSchema !== undefined){
|
||||||
|
console.log(req.body);
|
||||||
const {error} = validationSchema.validate(req.body);
|
const {error} = validationSchema.validate(req.body);
|
||||||
if(error){
|
if(error){
|
||||||
const errorMessage = error.details.map(detail => detail.message).join(', ');
|
const errorMessage = error.details.map(detail => detail.message).join(', ');
|
||||||
@@ -22,15 +23,16 @@ function validateBody(req, res, next) {
|
|||||||
|
|
||||||
router.patch('/', validateBody, (req, res) => {
|
router.patch('/', validateBody, (req, res) => {
|
||||||
const backupSchemesDB = req.app.get('backupSchemesDB');
|
const backupSchemesDB = req.app.get('backupSchemesDB');
|
||||||
const { id, ip, backup_schema, size } = req.body;
|
const { id, ip, directoryStructure, totalSize } = req.body;
|
||||||
|
|
||||||
let backupSchemesJson = backupSchemesDB.readFile();
|
let backupSchemesJson = backupSchemesDB.readFile();
|
||||||
backupSchemesJson[id] = {
|
backupSchemesJson[id] = {
|
||||||
ip: ip,
|
ip: ip,
|
||||||
backup_schema: backup_schema,
|
directoryStructure: directoryStructure,
|
||||||
size: size
|
totalSize: totalSize
|
||||||
}
|
}
|
||||||
|
|
||||||
|
backupSchemesDB.writeFile(backupSchemesJson);
|
||||||
return res.status(httpStatus.OK).json({message: 'Backup schema updated'});
|
return res.status(httpStatus.OK).json({message: 'Backup schema updated'});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -74,12 +74,12 @@ router.post('/login', validateBody, (req, res) => {
|
|||||||
const hashedPassword = crypto.createHash('sha256').update(password).digest('hex');
|
const hashedPassword = crypto.createHash('sha256').update(password).digest('hex');
|
||||||
|
|
||||||
if(usersDB.readFile().length === 0){
|
if(usersDB.readFile().length === 0){
|
||||||
return res.status(httpStatus.NOT_FOUND).json({message: 'Invalid credentials.'});
|
return res.status(httpStatus.INTERNAL_SERVER_ERROR).json({message: 'Internal server error.'});
|
||||||
}
|
}
|
||||||
|
|
||||||
if(usersDB.findIndexByKeyValueInArray('email', email) !==
|
if(usersDB.findIndexByKeyValueInArray('email', email) !==
|
||||||
usersDB.findIndexByKeyValueInArray('password', hashedPassword)){
|
usersDB.findIndexByKeyValueInArray('password', hashedPassword)){
|
||||||
return res.status(httpStatus.NOT_FOUND).json({message: 'Invalid credentials.'});
|
return res.status(httpStatus.UNAUTHORIZED).json({message: 'Invalid credentials.'});
|
||||||
}
|
}
|
||||||
|
|
||||||
const userIndex = usersDB.findIndexByKeyValueInArray('email', email);
|
const userIndex = usersDB.findIndexByKeyValueInArray('email', email);
|
||||||
|
|||||||
Generated
+1
@@ -0,0 +1 @@
|
|||||||
|
login.css
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"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
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
Binary file not shown.
@@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"path": "C:\\Users\\Andrei Cerbu\\Documents\\to_backup",
|
||||||
|
"structure": {
|
||||||
|
"to_backup": {
|
||||||
|
"files": [
|
||||||
|
"fisier_random.txt"
|
||||||
|
],
|
||||||
|
"alte fis": {
|
||||||
|
"files": [
|
||||||
|
"alt fisier.txt",
|
||||||
|
"fisier now.txt",
|
||||||
|
"New Microsoft Excel Worksheet.xlsx"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"size": 6197
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
const httpStatus = {
|
||||||
|
// Informational
|
||||||
|
CONTINUE: 100,
|
||||||
|
SWITCHING_PROTOCOLS: 101,
|
||||||
|
PROCESSING: 102,
|
||||||
|
|
||||||
|
// Success
|
||||||
|
OK: 200,
|
||||||
|
CREATED: 201,
|
||||||
|
ACCEPTED: 202,
|
||||||
|
NO_CONTENT: 204,
|
||||||
|
|
||||||
|
// Redirection
|
||||||
|
MOVED_PERMANENTLY: 301,
|
||||||
|
FOUND: 302,
|
||||||
|
SEE_OTHER: 303,
|
||||||
|
NOT_MODIFIED: 304,
|
||||||
|
TEMPORARY_REDIRECT: 307,
|
||||||
|
|
||||||
|
// Client Error
|
||||||
|
BAD_REQUEST: 400,
|
||||||
|
UNAUTHORIZED: 401,
|
||||||
|
FORBIDDEN: 403,
|
||||||
|
NOT_FOUND: 404,
|
||||||
|
METHOD_NOT_ALLOWED: 405,
|
||||||
|
CONFLICT: 409,
|
||||||
|
GONE: 410,
|
||||||
|
UNSUPPORTED_MEDIA_TYPE: 415,
|
||||||
|
|
||||||
|
// Server Error
|
||||||
|
INTERNAL_SERVER_ERROR: 500,
|
||||||
|
NOT_IMPLEMENTED: 501,
|
||||||
|
SERVICE_UNAVAILABLE: 503
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = { httpStatus };
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
const lockfile = require('proper-lockfile');
|
||||||
|
|
||||||
|
async function lockFile(filePath) {
|
||||||
|
try {
|
||||||
|
await lockfile.lock(filePath, {
|
||||||
|
realpath: false,
|
||||||
|
retries: {
|
||||||
|
retries: 10, // Number of retries
|
||||||
|
factor: 2, // The exponential factor
|
||||||
|
minTimeout: 1000, // The number of milliseconds before starting the first retry
|
||||||
|
maxTimeout: 5000, // The maximum number of milliseconds between two retries
|
||||||
|
randomize: true, // Randomizes the timeouts by multiplying with a factor between 1 to 2
|
||||||
|
}
|
||||||
|
});
|
||||||
|
console.log(`File locked: ${filePath}`);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error locking file ${filePath}: ${error.message}`);
|
||||||
|
throw error; // Propagate the error if unable to lock after retries
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function unlockFile(filePath) {
|
||||||
|
try {
|
||||||
|
await lockfile.unlock(filePath);
|
||||||
|
console.log(`File unlocked: ${filePath}`);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error unlocking file ${filePath}: ${error.message}`);
|
||||||
|
// Decide whether to throw the error or not, based on your error handling strategy
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {lockFile, unlockFile}
|
||||||
+1
-1
@@ -1 +1 @@
|
|||||||
�ԗ�۰�s_���(�k��K��:��Fn]C�$
|
ż)ř‰;ĘŃŞÓĆ'Fw-`Źeµ±/öd©K
|
||||||
+1
-1
@@ -1 +1 @@
|
|||||||
äï§¡’a%l:ðIÇ÷ÑÝ
|
i6ŃĆ0ů@éSá“LŻi
|
||||||
@@ -0,0 +1,217 @@
|
|||||||
|
const fs = require('fs').promises; // Ensure you use the promise-based API
|
||||||
|
const path = require('path');
|
||||||
|
const { decryptFileInPlace, encryptFileInPlace, encryptFileWithKey, decryptFileWithKey} = require("../src/main/aes_encrypt");
|
||||||
|
const {lockFile, unlockFile} = require("../helpers/lock_mechanism");
|
||||||
|
|
||||||
|
function extractFilePaths(directoryStructure) {
|
||||||
|
let paths = [];
|
||||||
|
const traverse = (dir, currentPath) => {
|
||||||
|
Object.keys(dir).forEach(key => {
|
||||||
|
if (key === 'files') {
|
||||||
|
dir[key].forEach(file => paths.push(path.join(currentPath, file)));
|
||||||
|
} else {
|
||||||
|
traverse(dir[key], path.join(currentPath, key));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
traverse(directoryStructure, '');
|
||||||
|
return paths;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchFiles(ip, filePaths) {
|
||||||
|
let results = {};
|
||||||
|
|
||||||
|
for (const filePath of filePaths) {
|
||||||
|
const url = `http://${ip}:3000/file_path`;
|
||||||
|
try {
|
||||||
|
const response = await fetch(url, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ filePath })
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) throw new Error(`HTTP status ${response.status}`);
|
||||||
|
|
||||||
|
const arrayBuffer = await response.arrayBuffer(); // Fetch the response as an ArrayBuffer
|
||||||
|
results[filePath] = Buffer.from(arrayBuffer);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error fetching ${filePath}:`, error);
|
||||||
|
results[filePath] = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function removeDirectory(directoryPath) {
|
||||||
|
try {
|
||||||
|
// Check if the directory exists
|
||||||
|
const stats = await fs.stat(directoryPath);
|
||||||
|
if (!stats.isDirectory()) {
|
||||||
|
console.log('The specified path is not a directory.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read all the contents of the directory
|
||||||
|
const files = await fs.readdir(directoryPath);
|
||||||
|
|
||||||
|
// Loop through each file/directory and delete them
|
||||||
|
for (const file of files) {
|
||||||
|
const currentPath = path.join(directoryPath, file);
|
||||||
|
const currentStats = await fs.stat(currentPath);
|
||||||
|
|
||||||
|
if (currentStats.isDirectory()) {
|
||||||
|
// Recursive call for directories
|
||||||
|
await removeDirectory(currentPath);
|
||||||
|
} else {
|
||||||
|
// Delete file
|
||||||
|
await fs.unlink(currentPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Finally, delete the directory itself
|
||||||
|
await fs.rmdir(directoryPath);
|
||||||
|
//console.log(`Directory removed: ${directoryPath}`);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error removing directory: ${error.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function decryptUserSystemConfig() {
|
||||||
|
const configPath = path.join(__dirname, '..', 'usersInSystem.json');
|
||||||
|
await lockFile(configPath);
|
||||||
|
await decryptFileInPlace(configPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function encryptUserSystemConfig(){
|
||||||
|
const configPath = path.join(__dirname, '..', 'usersInSystem.json');
|
||||||
|
await unlockFile(configPath);
|
||||||
|
await encryptFileInPlace(configPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function processBackup() {
|
||||||
|
await decryptUserSystemConfig();
|
||||||
|
const usersConfigPath = path.join(__dirname, '..', 'usersInSystem.json');
|
||||||
|
const backupConfigPath = path.join(__dirname, '..', 'backupSchemes.json');
|
||||||
|
const baseBackupDirPath = path.join(__dirname, '..', 'backup_directories');
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Read and parse the users configuration
|
||||||
|
const usersData = await fs.readFile(usersConfigPath, 'utf8');
|
||||||
|
const usersConfig = JSON.parse(usersData);
|
||||||
|
|
||||||
|
// Read and parse the backup configuration
|
||||||
|
const backupData = await fs.readFile(backupConfigPath, 'utf8');
|
||||||
|
const jsonData = JSON.parse(backupData);
|
||||||
|
|
||||||
|
for (const key in jsonData) {
|
||||||
|
const userBackupDir = path.join(baseBackupDirPath, key);
|
||||||
|
await removeDirectory(userBackupDir);
|
||||||
|
|
||||||
|
const node = jsonData[key];
|
||||||
|
const directoryStructure = JSON.parse(node.directoryStructure);
|
||||||
|
const filePaths = extractFilePaths(directoryStructure);
|
||||||
|
const files = await fetchFiles(node.ip, filePaths);
|
||||||
|
|
||||||
|
await fs.mkdir(userBackupDir, { recursive: true });
|
||||||
|
|
||||||
|
// Find the encryption key for the user's department
|
||||||
|
let encryptionKey = '';
|
||||||
|
for (const dept in usersConfig) {
|
||||||
|
if (usersConfig[dept].users.includes(key)) {
|
||||||
|
encryptionKey = usersConfig[dept].key;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const file in files) {
|
||||||
|
if (files[file]) {
|
||||||
|
const fullPath = path.join(userBackupDir, file);
|
||||||
|
await fs.mkdir(path.dirname(fullPath), { recursive: true });
|
||||||
|
await fs.writeFile(fullPath, files[file]); // Write the binary data
|
||||||
|
|
||||||
|
// Encrypt the file in place after writing it
|
||||||
|
if (encryptionKey) {
|
||||||
|
await encryptFileWithKey(fullPath, encryptionKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to read or process the JSON file:', error);
|
||||||
|
}
|
||||||
|
|
||||||
|
await encryptUserSystemConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getAllFilePaths(dirPath) {
|
||||||
|
let filePaths = [];
|
||||||
|
async function recurse(currentPath) {
|
||||||
|
const entries = await fs.readdir(currentPath, { withFileTypes: true });
|
||||||
|
// Create promises for each entry and process them in parallel
|
||||||
|
const entryPromises = entries.map(async (entry) => {
|
||||||
|
const resolvedPath = path.join(currentPath, entry.name);
|
||||||
|
if (entry.isDirectory()) {
|
||||||
|
// If it's a directory, recurse into it
|
||||||
|
await recurse(resolvedPath);
|
||||||
|
} else {
|
||||||
|
// If it's a file, add it to the file paths array
|
||||||
|
filePaths.push(resolvedPath);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// Wait for all promises to complete
|
||||||
|
await Promise.all(entryPromises);
|
||||||
|
}
|
||||||
|
await recurse(dirPath);
|
||||||
|
return filePaths;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function decryptUserFilesToDirectory(destinationDir) {
|
||||||
|
await decryptUserSystemConfig(); // Ensure user config is decrypted
|
||||||
|
const usersConfigPath = path.join(__dirname, '..', 'usersInSystem.json');
|
||||||
|
const usersConfig = JSON.parse(await fs.readFile(usersConfigPath, 'utf8'));
|
||||||
|
const sourceDir = path.join(__dirname, '..', 'backup_directories');
|
||||||
|
|
||||||
|
try {
|
||||||
|
for (const department in usersConfig) {
|
||||||
|
const { key, users } = usersConfig[department];
|
||||||
|
for (const userId of users) {
|
||||||
|
const userDir = path.join(sourceDir, userId);
|
||||||
|
try {
|
||||||
|
const files = await getAllFilePaths(userDir);
|
||||||
|
for (const filePath of files) {
|
||||||
|
const stats = await fs.stat(filePath);
|
||||||
|
if (stats.isFile()) {
|
||||||
|
// Extract the part of the file path after the userId
|
||||||
|
const relativePath = path.relative(userDir, filePath);
|
||||||
|
|
||||||
|
// Construct the destination file path
|
||||||
|
const destinationFilePath = path.join(destinationDir, userId, relativePath);
|
||||||
|
await fs.mkdir(path.dirname(destinationFilePath), { recursive: true });
|
||||||
|
|
||||||
|
// Decrypt the file in its original location
|
||||||
|
await decryptFileWithKey(filePath, key);
|
||||||
|
|
||||||
|
// Copy the decrypted file to the destination directory
|
||||||
|
await fs.copyFile(filePath, destinationFilePath);
|
||||||
|
console.log(`Decrypted file copied to: ${destinationFilePath}`);
|
||||||
|
|
||||||
|
// Re-encrypt the file in its original location (optional)
|
||||||
|
await encryptFileWithKey(filePath, key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error processing files for user ${userId}: ${error.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error processing decryption: ${error.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
processBackup();
|
||||||
|
decryptUserFilesToDirectory("C:\\Users\\Andrei Cerbu\\Documents\\decrypted");
|
||||||
|
|||||||
@@ -0,0 +1,79 @@
|
|||||||
|
const express = require('express');
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
const Joi = require('joi');
|
||||||
|
const fetch = require('node-fetch');
|
||||||
|
const { httpStatus } = require('../helpers/http_status');
|
||||||
|
|
||||||
|
const app = express();
|
||||||
|
app.use(express.json());
|
||||||
|
|
||||||
|
const filePathSchema = Joi.object({
|
||||||
|
filePath: Joi.string().required()
|
||||||
|
});
|
||||||
|
|
||||||
|
async function getBaseDirectory() {
|
||||||
|
const filePath = path.join(__dirname, '..', 'dirBackup.json');
|
||||||
|
try {
|
||||||
|
const data = await fs.promises.readFile(filePath, 'utf8');
|
||||||
|
const jsonData = JSON.parse(data);
|
||||||
|
return jsonData.path;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error reading the base directory:', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
app.post('/file_path', async (req, res) => {
|
||||||
|
const { error, value } = filePathSchema.validate(req.body);
|
||||||
|
if (error) {
|
||||||
|
return res.status(httpStatus.BAD_REQUEST).json({
|
||||||
|
message: 'Invalid input',
|
||||||
|
data: error.details
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const basePath = await getBaseDirectory();
|
||||||
|
let { filePath } = value;
|
||||||
|
const baseDirName = path.basename(basePath);
|
||||||
|
if (filePath.startsWith(baseDirName + path.sep)) {
|
||||||
|
filePath = filePath.slice(baseDirName.length + 1);
|
||||||
|
}
|
||||||
|
const fullPath = path.resolve(basePath, filePath);
|
||||||
|
|
||||||
|
fs.stat(fullPath, (err, stats) => {
|
||||||
|
if (err) {
|
||||||
|
if (err.code === 'ENOENT') {
|
||||||
|
return res.status(httpStatus.NOT_FOUND).json({
|
||||||
|
message: 'File not found'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return res.status(httpStatus.INTERNAL_SERVER_ERROR).json({
|
||||||
|
message: 'Error accessing the file'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!stats.isFile()) {
|
||||||
|
return res.status(httpStatus.BAD_REQUEST).json({
|
||||||
|
message: 'Path is not a file'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stream the file as binary data
|
||||||
|
res.writeHead(httpStatus.OK, {
|
||||||
|
'Content-Type': 'application/octet-stream',
|
||||||
|
'Content-Disposition': `attachment; filename="${path.basename(fullPath)}"`
|
||||||
|
});
|
||||||
|
const fileStream = fs.createReadStream(fullPath);
|
||||||
|
fileStream.pipe(res);
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
return res.status(httpStatus.INTERNAL_SERVER_ERROR).json({
|
||||||
|
message: 'Error processing request'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const PORT = process.env.PORT || 3000;
|
||||||
|
app.listen(PORT, () => console.log(`Server running on port ${PORT}`));
|
||||||
@@ -0,0 +1,209 @@
|
|||||||
|
const fs = require('fs').promises;
|
||||||
|
const path = require('path');
|
||||||
|
const ip = require('ip');
|
||||||
|
const {encryptFileInPlace, decryptFileInPlace} = require('../src/main/aes_encrypt');
|
||||||
|
const {lockFile, unlockFile} = require("../helpers/lock_mechanism");
|
||||||
|
|
||||||
|
async function fetchBackupSchemes(serverIp) {
|
||||||
|
// Fetching backup schemes from the server
|
||||||
|
const depResponse = await fetch(`http://${serverIp}/backup_schemes`, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {'x-api-key': 'uc_api'}
|
||||||
|
});
|
||||||
|
const backupSchemesJson = await depResponse.json();
|
||||||
|
const backupSchemes = backupSchemesJson['data'];
|
||||||
|
|
||||||
|
// Specify the path where the backup schemes will be saved
|
||||||
|
const destPath = path.join(__dirname, '..', 'backupSchemes.json');
|
||||||
|
|
||||||
|
// Write the fetched backup schemes to the specified file
|
||||||
|
try {
|
||||||
|
await lockFile(destPath);
|
||||||
|
await fs.writeFile(destPath, JSON.stringify(backupSchemes, null, 2)); // Use null, 2 for pretty formatting
|
||||||
|
await unlockFile(destPath);
|
||||||
|
console.log('Backup schemes saved successfully to', destPath);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to save backup schemes:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchUsersAndDepartments(serverIp) {
|
||||||
|
try {
|
||||||
|
// Fetch departments
|
||||||
|
const depResponse = await fetch(`http://${serverIp}/users/departments`, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {'x-api-key': 'uc_api'}
|
||||||
|
});
|
||||||
|
const departmentsJson = await depResponse.json();
|
||||||
|
const departments = departmentsJson['data'];
|
||||||
|
|
||||||
|
// Fetch users
|
||||||
|
const userResponse = await fetch(`http://${serverIp}/users`, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {'x-api-key': 'uc_api'}
|
||||||
|
});
|
||||||
|
const usersJson = await userResponse.json();
|
||||||
|
const users = usersJson['data'];
|
||||||
|
|
||||||
|
// Combine the JSON data
|
||||||
|
const combinedData = Object.values(departments).reduce((acc, {name, key}) => {
|
||||||
|
acc[name] = {
|
||||||
|
key,
|
||||||
|
users: users.filter(user => user.department === name).map(user => user.id)
|
||||||
|
};
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
// Write combined data to a file
|
||||||
|
const filePath = path.join(__dirname, '..', 'usersInSystem.json');
|
||||||
|
await lockFile(filePath);
|
||||||
|
await fs.writeFile(filePath, JSON.stringify(combinedData, null, 2), 'utf8');
|
||||||
|
|
||||||
|
await encryptFileInPlace(filePath);
|
||||||
|
await unlockFile(filePath);
|
||||||
|
console.log('Data has been encrypted and saved.');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to fetch or process data:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function decryptAndGetServerIP(filePath) {
|
||||||
|
try {
|
||||||
|
await lockFile(filePath);
|
||||||
|
await decryptFileInPlace(filePath);
|
||||||
|
|
||||||
|
const fileContent = await fs.readFile(filePath, 'utf8');
|
||||||
|
const jsonData = JSON.parse(fileContent);
|
||||||
|
const serverIP = jsonData.ip;
|
||||||
|
|
||||||
|
await encryptFileInPlace(filePath)
|
||||||
|
await unlockFile(filePath);
|
||||||
|
return serverIP;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('An error occurred:', error);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getDirectoryStructure(dirPath) {
|
||||||
|
const baseName = path.basename(dirPath);
|
||||||
|
const entries = await fs.readdir(dirPath, {withFileTypes: true});
|
||||||
|
const result = {};
|
||||||
|
result[baseName] = {files: []};
|
||||||
|
let totalSize = 0;
|
||||||
|
|
||||||
|
for (let entry of entries) {
|
||||||
|
const entryPath = path.join(dirPath, entry.name);
|
||||||
|
if (entry.isDirectory()) {
|
||||||
|
// Recursively get structure for subdirectories
|
||||||
|
const {structure, size: subSize} = await getDirectoryStructure(entryPath);
|
||||||
|
result[baseName][entry.name] = structure[Object.keys(structure)[0]]; // Object.keys to fetch the first key name
|
||||||
|
totalSize += subSize;
|
||||||
|
} else {
|
||||||
|
// Add file name to the 'files' array and calculate total size
|
||||||
|
const stats = await fs.stat(entryPath);
|
||||||
|
result[baseName].files.push(entry.name);
|
||||||
|
totalSize += stats.size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {structure: result, size: totalSize};
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createBackupScheme(serverIp, structure, size) {
|
||||||
|
let filePath = path.join(__dirname, '..', 'loginData.json');
|
||||||
|
await lockFile(filePath);
|
||||||
|
await decryptFileInPlace(filePath);
|
||||||
|
|
||||||
|
const userContent = await fs.readFile(filePath, 'utf8');
|
||||||
|
const userJson = JSON.parse(userContent);
|
||||||
|
|
||||||
|
await encryptFileInPlace(filePath)
|
||||||
|
await unlockFile(filePath);
|
||||||
|
|
||||||
|
// Find the IP address of the machine
|
||||||
|
const machineIP = ip.address();
|
||||||
|
|
||||||
|
// Prepare the data to be sent
|
||||||
|
const dataToSend = {
|
||||||
|
id: userJson.id,
|
||||||
|
ip: machineIP,
|
||||||
|
directoryStructure: JSON.stringify(structure),
|
||||||
|
totalSize: size
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await fetch(`http://${serverIp}/backup_schemes`, {
|
||||||
|
method: 'PATCH',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'x-api-key': 'uc_api'
|
||||||
|
},
|
||||||
|
body: JSON.stringify(dataToSend)
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
console.log("Backup dir structure submitted.")
|
||||||
|
} else {
|
||||||
|
const data = await response.json()
|
||||||
|
console.log(data.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function watchDirectoryChanges(serverIp) {
|
||||||
|
async function readBackupConfig(filePath) {
|
||||||
|
await lockFile(filePath);
|
||||||
|
const fileContent = await fs.readFile(filePath, 'utf8');
|
||||||
|
await unlockFile(filePath);
|
||||||
|
return JSON.parse(fileContent);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function updateBackupConfig(filePath, structure, size) {
|
||||||
|
const data = {
|
||||||
|
path: filePath,
|
||||||
|
structure: structure,
|
||||||
|
size: size
|
||||||
|
};
|
||||||
|
await lockFile(filePath);
|
||||||
|
await fs.writeFile(path.join(__dirname, '..', 'dirBackup.json'), JSON.stringify(data, null, 2));
|
||||||
|
await unlockFile(filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
const configPath = path.join(__dirname, '..', 'dirBackup.json');
|
||||||
|
const backupConfig = await readBackupConfig(configPath);
|
||||||
|
const storedStructure = backupConfig.structure;
|
||||||
|
|
||||||
|
const {structure: currentStructure, size: currentSize} = await getDirectoryStructure(backupConfig.path);
|
||||||
|
|
||||||
|
if (JSON.stringify(storedStructure) !== JSON.stringify(currentStructure)) {
|
||||||
|
console.log("Directory structure has changed. Updating backup...");
|
||||||
|
await createBackupScheme(serverIp, currentStructure, currentSize);
|
||||||
|
|
||||||
|
await updateBackupConfig(backupConfig.path, currentStructure, currentSize);
|
||||||
|
} else {
|
||||||
|
console.log("No changes detected in the directory structure.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
process.on('SIGINT', () => {
|
||||||
|
console.log('Process terminated');
|
||||||
|
process.exit(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
let serverIp = null
|
||||||
|
decryptAndGetServerIP(path.join(__dirname, '..', 'ipConfig.json')).then(ip => {
|
||||||
|
serverIp = ip;
|
||||||
|
});
|
||||||
|
|
||||||
|
setInterval(() => {
|
||||||
|
fetchUsersAndDepartments(serverIp);
|
||||||
|
}, 5000);
|
||||||
|
|
||||||
|
setInterval(() => {
|
||||||
|
watchDirectoryChanges(serverIp);
|
||||||
|
}, 5000);
|
||||||
|
|
||||||
|
setInterval(() => {
|
||||||
|
fetchBackupSchemes(serverIp);
|
||||||
|
}, 5000);
|
||||||
|
|
||||||
|
|
||||||
|
console.log("Service running. Press CTRL+C to stop.");
|
||||||
|
|||||||
Binary file not shown.
Generated
+181
@@ -9,10 +9,16 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"body-parser": "^1.20.2",
|
||||||
"bootstrap": "^5.3.3",
|
"bootstrap": "^5.3.3",
|
||||||
|
"cors": "^2.8.5",
|
||||||
"electron": "^29.1.5",
|
"electron": "^29.1.5",
|
||||||
"express": "^4.19.2",
|
"express": "^4.19.2",
|
||||||
|
"ip": "^2.0.1",
|
||||||
|
"joi": "^17.12.3",
|
||||||
|
"node-fetch": "^3.3.2",
|
||||||
"nodemon": "^3.1.0",
|
"nodemon": "^3.1.0",
|
||||||
|
"proper-lockfile": "^4.1.2",
|
||||||
"toastify-js": "^1.12.0"
|
"toastify-js": "^1.12.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@@ -39,6 +45,19 @@
|
|||||||
"global-agent": "^3.0.0"
|
"global-agent": "^3.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@hapi/hoek": {
|
||||||
|
"version": "9.3.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@hapi/hoek/-/hoek-9.3.0.tgz",
|
||||||
|
"integrity": "sha512-/c6rf4UJlmHlC9b5BaNvzAcFv7HZ2QHaV0D4/HNlBdvFnvQq8RI4kYdhyPCl7Xj+oWvTWQ8ujhqS53LIgAe6KQ=="
|
||||||
|
},
|
||||||
|
"node_modules/@hapi/topo": {
|
||||||
|
"version": "5.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@hapi/topo/-/topo-5.1.0.tgz",
|
||||||
|
"integrity": "sha512-foQZKJig7Ob0BMAYBfcJk8d77QtOe7Wo4ox7ff1lQYoNNAb6jwcY1ncdoy2e9wQZzvNy7ODZCYJkK8kzmcAnAg==",
|
||||||
|
"dependencies": {
|
||||||
|
"@hapi/hoek": "^9.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@popperjs/core": {
|
"node_modules/@popperjs/core": {
|
||||||
"version": "2.11.8",
|
"version": "2.11.8",
|
||||||
"resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.8.tgz",
|
"resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.8.tgz",
|
||||||
@@ -49,6 +68,24 @@
|
|||||||
"url": "https://opencollective.com/popperjs"
|
"url": "https://opencollective.com/popperjs"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@sideway/address": {
|
||||||
|
"version": "4.1.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/@sideway/address/-/address-4.1.5.tgz",
|
||||||
|
"integrity": "sha512-IqO/DUQHUkPeixNQ8n0JA6102hT9CmaljNTPmQ1u8MEhBo/R4Q8eKLN/vGZxuebwOroDB4cbpjheD4+/sKFK4Q==",
|
||||||
|
"dependencies": {
|
||||||
|
"@hapi/hoek": "^9.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@sideway/formula": {
|
||||||
|
"version": "3.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@sideway/formula/-/formula-3.0.1.tgz",
|
||||||
|
"integrity": "sha512-/poHZJJVjx3L+zVD6g9KgHfYnb443oi7wLu/XKojDviHy6HOEOA6z1Trk5aR1dGcmPenJEgb2sK2I80LeS3MIg=="
|
||||||
|
},
|
||||||
|
"node_modules/@sideway/pinpoint": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@sideway/pinpoint/-/pinpoint-2.0.0.tgz",
|
||||||
|
"integrity": "sha512-RNiOoTPkptFtSVzQevY/yWtZwf/RxyVnPy/OcA9HBM3MlGDnBEYL5B41H0MTn0Uec8Hi+2qUtTfG2WWZBmMejQ=="
|
||||||
|
},
|
||||||
"node_modules/@sindresorhus/is": {
|
"node_modules/@sindresorhus/is": {
|
||||||
"version": "4.6.0",
|
"version": "4.6.0",
|
||||||
"resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.6.0.tgz",
|
"resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.6.0.tgz",
|
||||||
@@ -447,6 +484,26 @@
|
|||||||
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
|
||||||
"integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ=="
|
"integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ=="
|
||||||
},
|
},
|
||||||
|
"node_modules/cors": {
|
||||||
|
"version": "2.8.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz",
|
||||||
|
"integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==",
|
||||||
|
"dependencies": {
|
||||||
|
"object-assign": "^4",
|
||||||
|
"vary": "^1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.10"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/data-uri-to-buffer": {
|
||||||
|
"version": "4.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz",
|
||||||
|
"integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 12"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/debug": {
|
"node_modules/debug": {
|
||||||
"version": "4.3.4",
|
"version": "4.3.4",
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
||||||
@@ -747,6 +804,28 @@
|
|||||||
"pend": "~1.2.0"
|
"pend": "~1.2.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/fetch-blob": {
|
||||||
|
"version": "3.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz",
|
||||||
|
"integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==",
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"type": "github",
|
||||||
|
"url": "https://github.com/sponsors/jimmywarting"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "paypal",
|
||||||
|
"url": "https://paypal.me/jimmywarting"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"dependencies": {
|
||||||
|
"node-domexception": "^1.0.0",
|
||||||
|
"web-streams-polyfill": "^3.0.3"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": "^12.20 || >= 14.13"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/fill-range": {
|
"node_modules/fill-range": {
|
||||||
"version": "7.0.1",
|
"version": "7.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz",
|
||||||
@@ -788,6 +867,17 @@
|
|||||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
||||||
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A=="
|
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A=="
|
||||||
},
|
},
|
||||||
|
"node_modules/formdata-polyfill": {
|
||||||
|
"version": "4.0.10",
|
||||||
|
"resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz",
|
||||||
|
"integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==",
|
||||||
|
"dependencies": {
|
||||||
|
"fetch-blob": "^3.1.2"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12.20.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/forwarded": {
|
"node_modules/forwarded": {
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
|
||||||
@@ -1085,6 +1175,11 @@
|
|||||||
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
|
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
|
||||||
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
|
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
|
||||||
},
|
},
|
||||||
|
"node_modules/ip": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/ip/-/ip-2.0.1.tgz",
|
||||||
|
"integrity": "sha512-lJUL9imLTNi1ZfXT+DU6rBBdbiKGBuay9B6xGSPVjUeQwaH1RIGqef8RZkUtHioLmSNpPR5M4HVKJGm1j8FWVQ=="
|
||||||
|
},
|
||||||
"node_modules/ipaddr.js": {
|
"node_modules/ipaddr.js": {
|
||||||
"version": "1.9.1",
|
"version": "1.9.1",
|
||||||
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz",
|
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz",
|
||||||
@@ -1131,6 +1226,18 @@
|
|||||||
"node": ">=0.12.0"
|
"node": ">=0.12.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/joi": {
|
||||||
|
"version": "17.12.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/joi/-/joi-17.12.3.tgz",
|
||||||
|
"integrity": "sha512-2RRziagf555owrm9IRVtdKynOBeITiDpuZqIpgwqXShPncPKNiRQoiGsl/T8SQdq+8ugRzH2LqY67irr2y/d+g==",
|
||||||
|
"dependencies": {
|
||||||
|
"@hapi/hoek": "^9.3.0",
|
||||||
|
"@hapi/topo": "^5.1.0",
|
||||||
|
"@sideway/address": "^4.1.5",
|
||||||
|
"@sideway/formula": "^3.0.1",
|
||||||
|
"@sideway/pinpoint": "^2.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/json-buffer": {
|
"node_modules/json-buffer": {
|
||||||
"version": "3.0.1",
|
"version": "3.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz",
|
||||||
@@ -1291,6 +1398,41 @@
|
|||||||
"node": ">= 0.6"
|
"node": ">= 0.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/node-domexception": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz",
|
||||||
|
"integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==",
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"type": "github",
|
||||||
|
"url": "https://github.com/sponsors/jimmywarting"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "github",
|
||||||
|
"url": "https://paypal.me/jimmywarting"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10.5.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/node-fetch": {
|
||||||
|
"version": "3.3.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz",
|
||||||
|
"integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==",
|
||||||
|
"dependencies": {
|
||||||
|
"data-uri-to-buffer": "^4.0.0",
|
||||||
|
"fetch-blob": "^3.1.4",
|
||||||
|
"formdata-polyfill": "^4.0.10"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"type": "opencollective",
|
||||||
|
"url": "https://opencollective.com/node-fetch"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/nodemon": {
|
"node_modules/nodemon": {
|
||||||
"version": "3.1.0",
|
"version": "3.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/nodemon/-/nodemon-3.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/nodemon/-/nodemon-3.1.0.tgz",
|
||||||
@@ -1365,6 +1507,14 @@
|
|||||||
"url": "https://github.com/sponsors/sindresorhus"
|
"url": "https://github.com/sponsors/sindresorhus"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/object-assign": {
|
||||||
|
"version": "4.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
|
||||||
|
"integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.10.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/object-inspect": {
|
"node_modules/object-inspect": {
|
||||||
"version": "1.13.1",
|
"version": "1.13.1",
|
||||||
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.1.tgz",
|
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.1.tgz",
|
||||||
@@ -1455,6 +1605,16 @@
|
|||||||
"node": ">=0.4.0"
|
"node": ">=0.4.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/proper-lockfile": {
|
||||||
|
"version": "4.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/proper-lockfile/-/proper-lockfile-4.1.2.tgz",
|
||||||
|
"integrity": "sha512-TjNPblN4BwAWMXU8s9AEz4JmQxnD1NNL7bNOY/AKUzyamc379FWASUhc/K1pL2noVb+XmZKLL68cjzLsiOAMaA==",
|
||||||
|
"dependencies": {
|
||||||
|
"graceful-fs": "^4.2.4",
|
||||||
|
"retry": "^0.12.0",
|
||||||
|
"signal-exit": "^3.0.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/proxy-addr": {
|
"node_modules/proxy-addr": {
|
||||||
"version": "2.0.7",
|
"version": "2.0.7",
|
||||||
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz",
|
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz",
|
||||||
@@ -1570,6 +1730,14 @@
|
|||||||
"url": "https://github.com/sponsors/sindresorhus"
|
"url": "https://github.com/sponsors/sindresorhus"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/retry": {
|
||||||
|
"version": "0.12.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/retry/-/retry-0.12.0.tgz",
|
||||||
|
"integrity": "sha512-9LkiTwjUh6rT555DtE9rTX+BKByPfrMzEAtnlEtdEwr3Nkffwiihqe2bWADg+OQRjt9gl6ICdmB/ZFDCGAtSow==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 4"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/roarr": {
|
"node_modules/roarr": {
|
||||||
"version": "2.15.4",
|
"version": "2.15.4",
|
||||||
"resolved": "https://registry.npmjs.org/roarr/-/roarr-2.15.4.tgz",
|
"resolved": "https://registry.npmjs.org/roarr/-/roarr-2.15.4.tgz",
|
||||||
@@ -1742,6 +1910,11 @@
|
|||||||
"url": "https://github.com/sponsors/ljharb"
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/signal-exit": {
|
||||||
|
"version": "3.0.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz",
|
||||||
|
"integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ=="
|
||||||
|
},
|
||||||
"node_modules/simple-update-notifier": {
|
"node_modules/simple-update-notifier": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/simple-update-notifier/-/simple-update-notifier-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/simple-update-notifier/-/simple-update-notifier-2.0.0.tgz",
|
||||||
@@ -1943,6 +2116,14 @@
|
|||||||
"node": ">=8.0.0"
|
"node": ">=8.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/web-streams-polyfill": {
|
||||||
|
"version": "3.3.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.3.3.tgz",
|
||||||
|
"integrity": "sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 8"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/wrappy": {
|
"node_modules/wrappy": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
|
||||||
|
|||||||
@@ -11,10 +11,16 @@
|
|||||||
"author": "Cerbu Andrei - Mihnea",
|
"author": "Cerbu Andrei - Mihnea",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"body-parser": "^1.20.2",
|
||||||
"bootstrap": "^5.3.3",
|
"bootstrap": "^5.3.3",
|
||||||
|
"cors": "^2.8.5",
|
||||||
"electron": "^29.1.5",
|
"electron": "^29.1.5",
|
||||||
"express": "^4.19.2",
|
"express": "^4.19.2",
|
||||||
|
"ip": "^2.0.1",
|
||||||
|
"joi": "^17.12.3",
|
||||||
|
"node-fetch": "^3.3.2",
|
||||||
"nodemon": "^3.1.0",
|
"nodemon": "^3.1.0",
|
||||||
|
"proper-lockfile": "^4.1.2",
|
||||||
"toastify-js": "^1.12.0"
|
"toastify-js": "^1.12.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
+1
-1
@@ -1 +1 @@
|
|||||||
� �4����~n`���'Tn�oC�:�%:x��
|
Íìè`à¡]'hźV8ŠËºnkAšèùÙVfƒ7K
|
||||||
@@ -70,7 +70,46 @@ async function decryptFileInPlace(filePath) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function cryptForKey(content, key, decrypt = false) {
|
||||||
|
const algorithm = 'aes-256-ctr';
|
||||||
|
const secretKey = crypto.createHash('sha256').update(String(key)).digest('base64').substr(0, 32);
|
||||||
|
let cipher;
|
||||||
|
|
||||||
|
if (decrypt) {
|
||||||
|
cipher = crypto.createDecipheriv(algorithm, secretKey, Buffer.alloc(16, 0)); // Using a zeroed IV for CTR
|
||||||
|
} else {
|
||||||
|
cipher = crypto.createCipheriv(algorithm, secretKey, Buffer.alloc(16, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Buffer.concat([cipher.update(content), cipher.final()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Encrypts a file in place with a given key
|
||||||
|
async function encryptFileWithKey(filePath, key) {
|
||||||
|
try {
|
||||||
|
const fileContent = await fs.promises.readFile(filePath);
|
||||||
|
const encryptedContent = cryptForKey(fileContent, key, false);
|
||||||
|
await fs.promises.writeFile(filePath, encryptedContent);
|
||||||
|
console.log(`File encrypted successfully: ${filePath}`);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error encrypting file: ${error.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function decryptFileWithKey(filePath, key) {
|
||||||
|
try {
|
||||||
|
const fileContent = await fs.promises.readFile(filePath);
|
||||||
|
const decryptedContent = cryptForKey(fileContent, key, true);
|
||||||
|
await fs.promises.writeFile(filePath, decryptedContent);
|
||||||
|
console.log(`File decrypted successfully: ${filePath}`);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error decrypting file: ${error.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
encryptFileInPlace,
|
encryptFileInPlace,
|
||||||
decryptFileInPlace
|
decryptFileInPlace,
|
||||||
|
encryptFileWithKey,
|
||||||
|
decryptFileWithKey,
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-45
@@ -5,6 +5,7 @@ const crypto = require('crypto');
|
|||||||
const {fork} = require('child_process');
|
const {fork} = require('child_process');
|
||||||
|
|
||||||
const {encryptFileInPlace, decryptFileInPlace} = require('./aes_encrypt');
|
const {encryptFileInPlace, decryptFileInPlace} = require('./aes_encrypt');
|
||||||
|
const {lockFile, unlockFile} = require("../../helpers/lock_mechanism");
|
||||||
|
|
||||||
const isMac = process.platform === 'darwin';
|
const isMac = process.platform === 'darwin';
|
||||||
let html_page = undefined;
|
let html_page = undefined;
|
||||||
@@ -160,8 +161,10 @@ app.on('window-all-closed', () => {
|
|||||||
ipcMain.handle('write-file', async (event, fileName, content) => {
|
ipcMain.handle('write-file', async (event, fileName, content) => {
|
||||||
try {
|
try {
|
||||||
let filePath = path.join(__dirname, '..', '..', fileName);
|
let filePath = path.join(__dirname, '..', '..', fileName);
|
||||||
|
await lockFile(filePath);
|
||||||
await fs.promises.writeFile(filePath, content);
|
await fs.promises.writeFile(filePath, content);
|
||||||
await encryptFileInPlace(filePath);
|
await encryptFileInPlace(filePath);
|
||||||
|
await unlockFile(filePath)
|
||||||
console.log(`File successfully written to ${filePath}`);
|
console.log(`File successfully written to ${filePath}`);
|
||||||
return {success: true};
|
return {success: true};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -173,8 +176,9 @@ ipcMain.handle('write-file', async (event, fileName, content) => {
|
|||||||
ipcMain.handle('delete-file', async (event, fileName) => {
|
ipcMain.handle('delete-file', async (event, fileName) => {
|
||||||
try {
|
try {
|
||||||
let filePath = path.join(__dirname, '..', '..', fileName);
|
let filePath = path.join(__dirname, '..', '..', fileName);
|
||||||
console.log(filePath);
|
|
||||||
await fs.promises.unlink(filePath);
|
await fs.promises.unlink(filePath);
|
||||||
|
|
||||||
console.log(`File ${filePath} successfully deleted`);
|
console.log(`File ${filePath} successfully deleted`);
|
||||||
return {success: true};
|
return {success: true};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -186,10 +190,12 @@ ipcMain.handle('delete-file', async (event, fileName) => {
|
|||||||
ipcMain.handle('read-file', async (event, fileName) => {
|
ipcMain.handle('read-file', async (event, fileName) => {
|
||||||
try {
|
try {
|
||||||
let filePath = path.join(__dirname, '..', '..', fileName);
|
let filePath = path.join(__dirname, '..', '..', fileName);
|
||||||
|
await lockFile(filePath);
|
||||||
await decryptFileInPlace(filePath);
|
await decryptFileInPlace(filePath);
|
||||||
const content = await fs.promises.readFile(filePath, 'utf-8');
|
const content = await fs.promises.readFile(filePath, 'utf-8');
|
||||||
|
|
||||||
await encryptFileInPlace(filePath);
|
await encryptFileInPlace(filePath);
|
||||||
|
await unlockFile(filePath);
|
||||||
return {success: true, content};
|
return {success: true, content};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error reading file:', error);
|
console.error('Error reading file:', error);
|
||||||
@@ -265,7 +271,6 @@ ipcMain.on('close-alert-window', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
//External processes
|
//External processes
|
||||||
|
|
||||||
ipcMain.handle('start-fetcher', async (event, args) => {
|
ipcMain.handle('start-fetcher', async (event, args) => {
|
||||||
if (fetcherProcess === null) {
|
if (fetcherProcess === null) {
|
||||||
fetcherProcess = fork(path.join(__dirname, '..', '..', 'jobs', 'fetcher.js'), args, {silent: false});
|
fetcherProcess = fork(path.join(__dirname, '..', '..', 'jobs', 'fetcher.js'), args, {silent: false});
|
||||||
@@ -276,46 +281,3 @@ ipcMain.handle('start-fetcher', async (event, args) => {
|
|||||||
}
|
}
|
||||||
return true; // Indicate that the operation has started
|
return true; // Indicate that the operation has started
|
||||||
});
|
});
|
||||||
|
|
||||||
// Handler to start the backup process
|
|
||||||
ipcMain.handle('start-backup', async (event, args) => {
|
|
||||||
if (backupProcess === null) { // Should this be a unique variable for backupProcess instead?
|
|
||||||
backupProcess = fork(path.join(__dirname, '..', '..', 'jobs', 'backup.js'), args, { silent: false });
|
|
||||||
backupProcess.on('exit', () => {
|
|
||||||
backupProcess = null;
|
|
||||||
// Optionally, notify the renderer process that the backup has finished
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return true; // Indicate that the operation has started
|
|
||||||
});
|
|
||||||
|
|
||||||
// Handler to start the decrypt-files process
|
|
||||||
ipcMain.handle('start-decrypt-files', async (event, args) => {
|
|
||||||
const decryptFilesProcess = fork(path.join(__dirname, '..', '..', 'jobs', 'decrypt_files.js'), args, { silent: false });
|
|
||||||
decryptFilesProcess.on('exit', () => {
|
|
||||||
event.sender.send('decrypt-files-finished', true); // Notify renderer process
|
|
||||||
});
|
|
||||||
return true; // Indicate that the operation has started
|
|
||||||
});
|
|
||||||
|
|
||||||
// Handler to start the send_files process
|
|
||||||
ipcMain.handle('start-send_files', async (event, args) => {
|
|
||||||
// This seems to duplicate the 'start-decrypt-files' process; assuming a different script is intended
|
|
||||||
const sendFilesProcess = fork(path.join(__dirname, '..', '..', 'jobs', 'send_files.js'), args, { silent: false });
|
|
||||||
sendFilesProcess.on('exit', () => {
|
|
||||||
event.sender.send('send-files-finished', true); // Notify renderer process
|
|
||||||
});
|
|
||||||
return true; // Indicate that the operation has started
|
|
||||||
});
|
|
||||||
|
|
||||||
// Handler to start the receiver process
|
|
||||||
ipcMain.handle('start-receiver', async (event, args) => {
|
|
||||||
if (receiverProcess === null) {
|
|
||||||
receiverProcess = fork(path.join(__dirname, '..', '..', 'jobs', 'receiver.js'), args, { silent: false });
|
|
||||||
receiverProcess.on('exit', () => {
|
|
||||||
receiverProcess = null;
|
|
||||||
// Optionally, notify the renderer process that the receiver has finished
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return true; // Indicate that the operation has started
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -2,13 +2,13 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta content="width=device-width, initial-scale=1.0" name="viewport">
|
||||||
<link rel="stylesheet" href="../css/alert_modal.css">
|
<link href="../css/alert_modal.css" rel="stylesheet">
|
||||||
<script src="../js/alert_modal.js"></script>
|
<script src="../js/alert_modal.js"></script>
|
||||||
<title>Alert Modal</title>
|
<title>Alert Modal</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="myModal" class="container">
|
<div class="container" id="myModal">
|
||||||
<div class="main_component">
|
<div class="main_component">
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<!--Here goes the message-->
|
<!--Here goes the message-->
|
||||||
|
|||||||
@@ -2,11 +2,11 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta content="width=device-width, initial-scale=1.0" name="viewport">
|
||||||
<link rel="icon" href="../assets/hard-disk.ico" type="image/x-icon">
|
<link href="../assets/hard-disk.ico" rel="icon" type="image/x-icon">
|
||||||
|
|
||||||
<link rel="stylesheet" href="../css/change_department.css">
|
<link href="../css/change_department.css" rel="stylesheet">
|
||||||
<link rel="stylesheet" href="../css/transition.css">
|
<link href="../css/transition.css" rel="stylesheet">
|
||||||
|
|
||||||
<script src="../js/change_department.js"></script>
|
<script src="../js/change_department.js"></script>
|
||||||
<script src="../js/transition.js"></script>
|
<script src="../js/transition.js"></script>
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
</head>
|
</head>
|
||||||
<body onload="fadeIn()">
|
<body onload="fadeIn()">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<form id="departmentForm" class="department-form">
|
<form class="department-form" id="departmentForm">
|
||||||
<div class="department-form-title">
|
<div class="department-form-title">
|
||||||
<h2>Choose your department</h2>
|
<h2>Choose your department</h2>
|
||||||
<hr>
|
<hr>
|
||||||
@@ -24,8 +24,8 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="department-form-footer">
|
<div class="department-form-footer">
|
||||||
<button id="back" type="button" name="back">Back</button>
|
<button id="back" name="back" type="button">Back</button>
|
||||||
<button id="submit" type="submit" name="submit">Submit</button>
|
<button id="submit" name="submit" type="submit">Submit</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -2,11 +2,11 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta content="width=device-width, initial-scale=1.0" name="viewport">
|
||||||
<link rel="icon" href="../assets/hard-disk.ico" type="image/x-icon">
|
<link href="../assets/hard-disk.ico" rel="icon" type="image/x-icon">
|
||||||
|
|
||||||
<link rel="stylesheet" href="../css/sending_file_confirmation.css">
|
<link href="../css/sending_file_confirmation.css" rel="stylesheet">
|
||||||
<link rel="stylesheet" href="../css/transition.css">
|
<link href="../css/transition.css" rel="stylesheet">
|
||||||
|
|
||||||
<script src="../js/transition.js"></script>
|
<script src="../js/transition.js"></script>
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
<div class="header">
|
<div class="header">
|
||||||
<h1>SENDING THE FILE!</h1>
|
<h1>SENDING THE FILE!</h1>
|
||||||
<h2>PlEASE WAIT</h2>
|
<h2>PlEASE WAIT</h2>
|
||||||
<img src="../assets/loading.gif" alt="Description of GIF">
|
<img alt="Description of GIF" src="../assets/loading.gif">
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -2,11 +2,11 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta content="width=device-width, initial-scale=1.0" name="viewport">
|
||||||
<link rel="icon" href="../assets/hard-disk.ico" type="image/x-icon">
|
<link href="../assets/hard-disk.ico" rel="icon" type="image/x-icon">
|
||||||
|
|
||||||
<link rel="stylesheet" href="../css/ip_submit.css">
|
<link href="../css/ip_submit.css" rel="stylesheet">
|
||||||
<link rel="stylesheet" href="../css/transition.css">
|
<link href="../css/transition.css" rel="stylesheet">
|
||||||
|
|
||||||
<script src="../js/ip_submit.js"></script>
|
<script src="../js/ip_submit.js"></script>
|
||||||
<script src="../js/transition.js"></script>
|
<script src="../js/transition.js"></script>
|
||||||
@@ -15,16 +15,16 @@
|
|||||||
</head>
|
</head>
|
||||||
<body onload="fadeIn()">
|
<body onload="fadeIn()">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<form id="ipForm" class="ip-form">
|
<form class="ip-form" id="ipForm">
|
||||||
<div class="ip-form-title">
|
<div class="ip-form-title">
|
||||||
<h2>IP Config</h2>
|
<h2>IP Config</h2>
|
||||||
<hr>
|
<hr>
|
||||||
</div>
|
</div>
|
||||||
<div class="ip-form-content">
|
<div class="ip-form-content">
|
||||||
<input id="ipInput" type="text" name="ip" placeholder="192.168.x.x : Port">
|
<input id="ipInput" name="ip" placeholder="192.168.x.x : Port" type="text">
|
||||||
</div>
|
</div>
|
||||||
<div class="ip-form-footer">
|
<div class="ip-form-footer">
|
||||||
<button id="submit" type="submit" name="submit">Submit</button>
|
<button id="submit" name="submit" type="submit">Submit</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -2,11 +2,11 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta content="width=device-width, initial-scale=1.0" name="viewport">
|
||||||
<link rel="icon" href="../assets/hard-disk.ico" type="image/x-icon">
|
<link href="../assets/hard-disk.ico" rel="icon" type="image/x-icon">
|
||||||
|
|
||||||
<link rel="stylesheet" href="../css/login.css">
|
<link href="../css/login.css" rel="stylesheet">
|
||||||
<link rel="stylesheet" href="../css/transition.css">
|
<link href="../css/transition.css" rel="stylesheet">
|
||||||
|
|
||||||
<script src="../js/login.js"></script>
|
<script src="../js/login.js"></script>
|
||||||
<script src="../js/transition.js"></script>
|
<script src="../js/transition.js"></script>
|
||||||
@@ -19,18 +19,18 @@
|
|||||||
<h1>DO WE KNOW</h1>
|
<h1>DO WE KNOW</h1>
|
||||||
<h1>EACH OTHER?</h1>
|
<h1>EACH OTHER?</h1>
|
||||||
</div>
|
</div>
|
||||||
<form id="loginForm" class="login-form">
|
<form class="login-form" id="loginForm">
|
||||||
<div class="login-form-title">
|
<div class="login-form-title">
|
||||||
<h2>Login</h2>
|
<h2>Login</h2>
|
||||||
<hr>
|
<hr>
|
||||||
</div>
|
</div>
|
||||||
<div class="login-form-content">
|
<div class="login-form-content">
|
||||||
<input type="email" name="email" placeholder="Email">
|
<input name="email" placeholder="Email" type="email">
|
||||||
<input type="password" name="password" placeholder="Password">
|
<input name="password" placeholder="Password" type="password">
|
||||||
</div>
|
</div>
|
||||||
<div class="login-form-footer">
|
<div class="login-form-footer">
|
||||||
<button id="signup" type="submit" name="signup">Sign Up</button>
|
<button id="signup" name="signup" type="submit">Sign Up</button>
|
||||||
<button id="submit" type="submit" name="submit">Submit</button>
|
<button id="submit" name="submit" type="submit">Submit</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -2,11 +2,11 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta content="width=device-width, initial-scale=1.0" name="viewport">
|
||||||
<link rel="icon" href="../assets/hard-disk.ico" type="image/x-icon">
|
<link href="../assets/hard-disk.ico" rel="icon" type="image/x-icon">
|
||||||
|
|
||||||
<link rel="stylesheet" href="../css/main_menu.css">
|
<link href="../css/main_menu.css" rel="stylesheet">
|
||||||
<link rel="stylesheet" href="../css/transition.css">
|
<link href="../css/transition.css" rel="stylesheet">
|
||||||
|
|
||||||
<script src="../js/main_menu.js"></script>
|
<script src="../js/main_menu.js"></script>
|
||||||
<script src="../js/transition.js"></script>
|
<script src="../js/transition.js"></script>
|
||||||
@@ -15,13 +15,13 @@
|
|||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body onload="fadeIn()">
|
<body onload="fadeIn()">
|
||||||
<div id="overlay" class="overlay">
|
<div class="overlay" id="overlay">
|
||||||
<form id="ceo_validation" class="ceo-validation-form">
|
<form class="ceo-validation-form" id="ceo_validation">
|
||||||
<h2>CEO Authentication</h2>
|
<h2>CEO Authentication</h2>
|
||||||
<input type="password" id="ceo_password" placeholder="Enter CEO's password" required>
|
<input id="ceo_password" placeholder="Enter CEO's password" required type="password">
|
||||||
<div class="form-actions">
|
<div class="form-actions">
|
||||||
<button type="button" id="back_button">Back</button>
|
<button id="back_button" type="button">Back</button>
|
||||||
<button type="submit" id="submit_button">Submit</button>
|
<button id="submit_button" type="submit">Submit</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
@@ -33,7 +33,7 @@
|
|||||||
<h1 id="username_field"></h1>
|
<h1 id="username_field"></h1>
|
||||||
<h2>Hope you have a productive day!</h2>
|
<h2>Hope you have a productive day!</h2>
|
||||||
</div>
|
</div>
|
||||||
<img src="../assets/user_1144760.png" alt="">
|
<img alt="" src="../assets/user_1144760.png">
|
||||||
</div>
|
</div>
|
||||||
<div class="left_block_content">
|
<div class="left_block_content">
|
||||||
<div class="left_block_buttons">
|
<div class="left_block_buttons">
|
||||||
@@ -57,7 +57,7 @@
|
|||||||
<h1>NOTIFICATIONS</h1>
|
<h1>NOTIFICATIONS</h1>
|
||||||
<hr>
|
<hr>
|
||||||
</div>
|
</div>
|
||||||
<div id="notifications" class="notifications">
|
<div class="notifications" id="notifications">
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -2,11 +2,11 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta content="width=device-width, initial-scale=1.0" name="viewport">
|
||||||
<link rel="icon" href="../assets/hard-disk.ico" type="image/x-icon">
|
<link href="../assets/hard-disk.ico" rel="icon" type="image/x-icon">
|
||||||
|
|
||||||
<link rel="stylesheet" href="../css/profile.css">
|
<link href="../css/profile.css" rel="stylesheet">
|
||||||
<link rel="stylesheet" href="../css/transition.css">
|
<link href="../css/transition.css" rel="stylesheet">
|
||||||
|
|
||||||
<script src="../js/profile.js"></script>
|
<script src="../js/profile.js"></script>
|
||||||
<script src="../js/transition.js"></script>
|
<script src="../js/transition.js"></script>
|
||||||
@@ -15,19 +15,19 @@
|
|||||||
</head>
|
</head>
|
||||||
<body onload="fadeIn()">
|
<body onload="fadeIn()">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<form id="profileForm" class="profile-form">
|
<form class="profile-form" id="profileForm">
|
||||||
<div class="profile-form-title">
|
<div class="profile-form-title">
|
||||||
<h2>Profile</h2>
|
<h2>Profile</h2>
|
||||||
<hr>
|
<hr>
|
||||||
</div>
|
</div>
|
||||||
<div class="profile-form-content">
|
<div class="profile-form-content">
|
||||||
<input type="email" name="email" placeholder="Email">
|
<input name="email" placeholder="Email" type="email">
|
||||||
<input type="text" name="username" placeholder="Username">
|
<input name="username" placeholder="Username" type="text">
|
||||||
<input type="password" name="password" placeholder="Password">
|
<input name="password" placeholder="Password" type="password">
|
||||||
</div>
|
</div>
|
||||||
<div class="profile-form-footer">
|
<div class="profile-form-footer">
|
||||||
<button type="button" name="login">Back</button>
|
<button name="login" type="button">Back</button>
|
||||||
<button type="submit" name="submit">Submit</button>
|
<button name="submit" type="submit">Submit</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -2,11 +2,11 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta content="width=device-width, initial-scale=1.0" name="viewport">
|
||||||
<link rel="icon" href="../assets/hard-disk.ico" type="image/x-icon">
|
<link href="../assets/hard-disk.ico" rel="icon" type="image/x-icon">
|
||||||
|
|
||||||
<link rel="stylesheet" href="../css/sending_file_confirmation.css">
|
<link href="../css/sending_file_confirmation.css" rel="stylesheet">
|
||||||
<link rel="stylesheet" href="../css/transition.css">
|
<link href="../css/transition.css" rel="stylesheet">
|
||||||
|
|
||||||
<script src="../js/transition.js"></script>
|
<script src="../js/transition.js"></script>
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
<div class="header">
|
<div class="header">
|
||||||
<h1>SENDING THE FILE!</h1>
|
<h1>SENDING THE FILE!</h1>
|
||||||
<h2>PlEASE WAIT</h2>
|
<h2>PlEASE WAIT</h2>
|
||||||
<img src="../assets/loading.gif" alt="Description of GIF">
|
<img alt="Description of GIF" src="../assets/loading.gif">
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -2,11 +2,11 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta content="width=device-width, initial-scale=1.0" name="viewport">
|
||||||
<link rel="icon" href="../assets/hard-disk.ico" type="image/x-icon">
|
<link href="../assets/hard-disk.ico" rel="icon" type="image/x-icon">
|
||||||
|
|
||||||
<link rel="stylesheet" href="../css/share_file.css">
|
<link href="../css/share_file.css" rel="stylesheet">
|
||||||
<link rel="stylesheet" href="../css/transition.css">
|
<link href="../css/transition.css" rel="stylesheet">
|
||||||
|
|
||||||
<script src="../js/share_file.js"></script>
|
<script src="../js/share_file.js"></script>
|
||||||
<script src="../js/transition.js"></script>
|
<script src="../js/transition.js"></script>
|
||||||
@@ -28,14 +28,14 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="left_block_content">
|
<div class="left_block_content">
|
||||||
<button id="selectFile" type="button" name="select_file">Select</button>
|
<button id="selectFile" name="select_file" type="button">Select</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="left_block_footer">
|
<div class="left_block_footer">
|
||||||
<button id="backButton" type="button" name="back">Back</button>
|
<button id="backButton" name="back" type="button">Back</button>
|
||||||
<button id="submitButton" type="submit" name="submit">Submit</button>
|
<button id="submitButton" name="submit" type="submit">Submit</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<form id="userDestForm" class="right_block">
|
<form class="right_block" id="userDestForm">
|
||||||
<div class="choose_user_form_title">
|
<div class="choose_user_form_title">
|
||||||
<h1>USERS</h1>
|
<h1>USERS</h1>
|
||||||
<hr>
|
<hr>
|
||||||
|
|||||||
@@ -2,11 +2,11 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta content="width=device-width, initial-scale=1.0" name="viewport">
|
||||||
<link rel="icon" href="../assets/hard-disk.ico" type="image/x-icon">
|
<link href="../assets/hard-disk.ico" rel="icon" type="image/x-icon">
|
||||||
|
|
||||||
<link rel="stylesheet" href="../css/sign_up_confirmation.css">
|
<link href="../css/sign_up_confirmation.css" rel="stylesheet">
|
||||||
<link rel="stylesheet" href="../css/transition.css">
|
<link href="../css/transition.css" rel="stylesheet">
|
||||||
|
|
||||||
<script src="../js/sign_up_confirmation.js"></script>
|
<script src="../js/sign_up_confirmation.js"></script>
|
||||||
<script src="../js/transition.js"></script>
|
<script src="../js/transition.js"></script>
|
||||||
|
|||||||
@@ -2,11 +2,11 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta content="width=device-width, initial-scale=1.0" name="viewport">
|
||||||
<link rel="icon" href="../assets/hard-disk.ico" type="image/x-icon">
|
<link href="../assets/hard-disk.ico" rel="icon" type="image/x-icon">
|
||||||
|
|
||||||
<link rel="stylesheet" href="../css/sign_up_department.css">
|
<link href="../css/sign_up_department.css" rel="stylesheet">
|
||||||
<link rel="stylesheet" href="../css/transition.css">
|
<link href="../css/transition.css" rel="stylesheet">
|
||||||
|
|
||||||
<script src="../js/sign_up_departments.js"></script>
|
<script src="../js/sign_up_departments.js"></script>
|
||||||
<script src="../js/transition.js"></script>
|
<script src="../js/transition.js"></script>
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
<h1>ABOUT</h1>
|
<h1>ABOUT</h1>
|
||||||
<h1>YOUR WORK</h1>
|
<h1>YOUR WORK</h1>
|
||||||
</div>
|
</div>
|
||||||
<form id="signupForm" class="signup-form">
|
<form class="signup-form" id="signupForm">
|
||||||
<div class="signup-form-title">
|
<div class="signup-form-title">
|
||||||
<h2>Choose your department</h2>
|
<h2>Choose your department</h2>
|
||||||
<hr>
|
<hr>
|
||||||
@@ -29,8 +29,8 @@
|
|||||||
<!-- add the list query for departments-->
|
<!-- add the list query for departments-->
|
||||||
</div>
|
</div>
|
||||||
<div class="signup-form-footer">
|
<div class="signup-form-footer">
|
||||||
<button id="back" type="button" name="back">Back</button>
|
<button id="back" name="back" type="button">Back</button>
|
||||||
<button id="submit" type="submit" name="submit">Submit</button>
|
<button id="submit" name="submit" type="submit">Submit</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -2,11 +2,11 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta content="width=device-width, initial-scale=1.0" name="viewport">
|
||||||
<link rel="icon" href="../assets/hard-disk.ico" type="image/x-icon">
|
<link href="../assets/hard-disk.ico" rel="icon" type="image/x-icon">
|
||||||
|
|
||||||
<link rel="stylesheet" href="../css/transition.css">
|
<link href="../css/transition.css" rel="stylesheet">
|
||||||
<link rel="stylesheet" href="../css/sing_up_profile.css">
|
<link href="../css/sing_up_profile.css" rel="stylesheet">
|
||||||
|
|
||||||
<script src="../js/sign_up_profile.js"></script>
|
<script src="../js/sign_up_profile.js"></script>
|
||||||
<script src="../js/transition.js"></script>
|
<script src="../js/transition.js"></script>
|
||||||
@@ -19,19 +19,19 @@
|
|||||||
<h1>LET US MEET</h1>
|
<h1>LET US MEET</h1>
|
||||||
<h1>EACH OTHER</h1>
|
<h1>EACH OTHER</h1>
|
||||||
</div>
|
</div>
|
||||||
<form id="signupForm" class="signup-form">
|
<form class="signup-form" id="signupForm">
|
||||||
<div class="signup-form-title">
|
<div class="signup-form-title">
|
||||||
<h2>Sign Up</h2>
|
<h2>Sign Up</h2>
|
||||||
<hr>
|
<hr>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<input type="email" name="email" placeholder="Email">
|
<input name="email" placeholder="Email" type="email">
|
||||||
<input type="text" name="name" placeholder="Username">
|
<input name="name" placeholder="Username" type="text">
|
||||||
<input type="password" name="password" placeholder="Password">
|
<input name="password" placeholder="Password" type="password">
|
||||||
</div>
|
</div>
|
||||||
<div class="signup-form-footer">
|
<div class="signup-form-footer">
|
||||||
<button id="login" type="button" name="login">Login</button>
|
<button id="login" name="login" type="button">Login</button>
|
||||||
<button id="continue" type="submit" name="submit">Continue</button>
|
<button id="continue" name="submit" type="submit">Continue</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
@@ -32,9 +32,11 @@ document.addEventListener('DOMContentLoaded', async function () {
|
|||||||
email: email,
|
email: email,
|
||||||
password: password
|
password: password
|
||||||
})
|
})
|
||||||
}).then(response => {
|
}).then(async response => {
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
fadeOut('main_menu.html');
|
fadeOut('main_menu.html');
|
||||||
|
} else {
|
||||||
|
await window.electronAPI.deleteFile('loginData.json');
|
||||||
}
|
}
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
@@ -80,8 +82,8 @@ document.addEventListener('DOMContentLoaded', async function () {
|
|||||||
|
|
||||||
return response.json();
|
return response.json();
|
||||||
}).then(async data => {
|
}).then(async data => {
|
||||||
console.log(data)
|
data.data.password = password
|
||||||
await window.electronAPI.writeFile('loginData.json', JSON.stringify(responseBody.message, null, 2));
|
await window.electronAPI.writeFile('loginData.json', JSON.stringify(data.data, null, 2));
|
||||||
fadeOut('main_menu.html');
|
fadeOut('main_menu.html');
|
||||||
})
|
})
|
||||||
.catch(async error => {
|
.catch(async error => {
|
||||||
@@ -90,4 +92,8 @@ document.addEventListener('DOMContentLoaded', async function () {
|
|||||||
.catch(error => console.error('Error showing alert:', error));
|
.catch(error => console.error('Error showing alert:', error));
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function delayWithTimeout(ms) {
|
||||||
|
return new Promise(resolve => setTimeout(resolve, ms));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
sТH╙╪щ░|W`щ─vЗ/кфф■]аr┼╞╕'=З└╦ь^≤u⌠о╪р.м/о┤чPI≤л≈ Xчzйы+чCw═В ╕EЩЛ╜╛КИ0Ч2└P╧К[╕Ж©┘Ё/
|
||||||
|
А+∙▌╣;8║╬"Ш&┴▐БnЛB}░юeDЕ-Ю$b╡~©JBНVhРаЭ␍C+r▓g&аh:ИV∙Д*╥y8В<␍{╟оnY!щy>OсШ ╠OДd┬┘≤┌iц├. lDY)÷Х─┤÷СЮ┌│;╚╒УЯ& зУ+А\wШГ╒}ЧB°Я©Сsь╠©▌╚╨╟#©┌▌=∙М╥▌X⌠⌠а╢uёы╤╓qЛcud╖ш╜е ╪q┼└d╗©O╣Iу
|
||||||
Reference in New Issue
Block a user